extract generic LoaderFragment superclass from KeyList
This commit is contained in:
parent
5c747a747f
commit
596478a212
|
@ -29,7 +29,6 @@ import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.os.Messenger;
|
import android.os.Messenger;
|
||||||
import android.support.v4.app.Fragment;
|
|
||||||
import android.support.v4.app.LoaderManager;
|
import android.support.v4.app.LoaderManager;
|
||||||
import android.support.v4.content.CursorLoader;
|
import android.support.v4.content.CursorLoader;
|
||||||
import android.support.v4.content.Loader;
|
import android.support.v4.content.Loader;
|
||||||
|
@ -45,10 +44,8 @@ import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.animation.AnimationUtils;
|
|
||||||
import android.widget.AbsListView.MultiChoiceModeListener;
|
import android.widget.AbsListView.MultiChoiceModeListener;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
@ -78,18 +75,13 @@ import se.emilsjolander.stickylistheaders.StickyListHeadersListView;
|
||||||
* Public key list with sticky list headers. It does _not_ extend ListFragment because it uses
|
* Public key list with sticky list headers. It does _not_ extend ListFragment because it uses
|
||||||
* StickyListHeaders library which does not extend upon ListView.
|
* StickyListHeaders library which does not extend upon ListView.
|
||||||
*/
|
*/
|
||||||
public class KeyListFragment extends Fragment
|
public class KeyListFragment extends LoaderFragment
|
||||||
implements SearchView.OnQueryTextListener, AdapterView.OnItemClickListener,
|
implements SearchView.OnQueryTextListener, AdapterView.OnItemClickListener,
|
||||||
LoaderManager.LoaderCallbacks<Cursor> {
|
LoaderManager.LoaderCallbacks<Cursor> {
|
||||||
|
|
||||||
private KeyListAdapter mAdapter;
|
private KeyListAdapter mAdapter;
|
||||||
private StickyListHeadersListView mStickyList;
|
private StickyListHeadersListView mStickyList;
|
||||||
|
|
||||||
// rebuild functionality of ListFragment, http://stackoverflow.com/a/12504097
|
|
||||||
boolean mListShown;
|
|
||||||
View mProgressContainer;
|
|
||||||
View mListContainer;
|
|
||||||
|
|
||||||
private String mCurQuery;
|
private String mCurQuery;
|
||||||
private SearchView mSearchView;
|
private SearchView mSearchView;
|
||||||
// empty list layout
|
// empty list layout
|
||||||
|
@ -101,14 +93,15 @@ public class KeyListFragment extends Fragment
|
||||||
* Load custom layout with StickyListView from library
|
* Load custom layout with StickyListView from library
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup superContainer, Bundle savedInstanceState) {
|
||||||
View root = inflater.inflate(R.layout.key_list_fragment, container, false);
|
View root = super.onCreateView(inflater, superContainer, savedInstanceState);
|
||||||
|
View view = inflater.inflate(R.layout.key_list_fragment, getContainer());
|
||||||
|
|
||||||
mStickyList = (StickyListHeadersListView) root.findViewById(R.id.key_list_list);
|
mStickyList = (StickyListHeadersListView) view.findViewById(R.id.key_list_list);
|
||||||
mStickyList.setOnItemClickListener(this);
|
mStickyList.setOnItemClickListener(this);
|
||||||
|
|
||||||
// empty view
|
// empty view
|
||||||
mButtonEmptyCreate = (BootstrapButton) root.findViewById(R.id.key_list_empty_button_create);
|
mButtonEmptyCreate = (BootstrapButton) view.findViewById(R.id.key_list_empty_button_create);
|
||||||
mButtonEmptyCreate.setOnClickListener(new OnClickListener() {
|
mButtonEmptyCreate.setOnClickListener(new OnClickListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -120,7 +113,7 @@ public class KeyListFragment extends Fragment
|
||||||
startActivityForResult(intent, 0);
|
startActivityForResult(intent, 0);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
mButtonEmptyImport = (BootstrapButton) root.findViewById(R.id.key_list_empty_button_import);
|
mButtonEmptyImport = (BootstrapButton) view.findViewById(R.id.key_list_empty_button_import);
|
||||||
mButtonEmptyImport.setOnClickListener(new OnClickListener() {
|
mButtonEmptyImport.setOnClickListener(new OnClickListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -131,11 +124,6 @@ public class KeyListFragment extends Fragment
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// rebuild functionality of ListFragment, http://stackoverflow.com/a/12504097
|
|
||||||
mListContainer = root.findViewById(R.id.key_list_list_container);
|
|
||||||
mProgressContainer = root.findViewById(R.id.key_list_progress_container);
|
|
||||||
mListShown = true;
|
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,9 +222,8 @@ public class KeyListFragment extends Fragment
|
||||||
// We have a menu item to show in action bar.
|
// We have a menu item to show in action bar.
|
||||||
setHasOptionsMenu(true);
|
setHasOptionsMenu(true);
|
||||||
|
|
||||||
// NOTE: Not supported by StickyListHeader, but reimplemented here
|
|
||||||
// Start out with a progress indicator.
|
// Start out with a progress indicator.
|
||||||
setListShown(false);
|
setContentShown(false);
|
||||||
|
|
||||||
// Create an empty adapter we will use to display the loaded data.
|
// Create an empty adapter we will use to display the loaded data.
|
||||||
mAdapter = new KeyListAdapter(getActivity(), null, 0);
|
mAdapter = new KeyListAdapter(getActivity(), null, 0);
|
||||||
|
@ -298,12 +285,11 @@ public class KeyListFragment extends Fragment
|
||||||
// this view is made visible if no data is available
|
// this view is made visible if no data is available
|
||||||
mStickyList.setEmptyView(getActivity().findViewById(R.id.key_list_empty));
|
mStickyList.setEmptyView(getActivity().findViewById(R.id.key_list_empty));
|
||||||
|
|
||||||
// NOTE: Not supported by StickyListHeader, but reimplemented here
|
|
||||||
// The list should now be shown.
|
// The list should now be shown.
|
||||||
if (isResumed()) {
|
if (isResumed()) {
|
||||||
setListShown(true);
|
setContentShown(true);
|
||||||
} else {
|
} else {
|
||||||
setListShownNoAnimation(true);
|
setContentShownNoAnimation(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -418,43 +404,6 @@ public class KeyListFragment extends Fragment
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// rebuild functionality of ListFragment, http://stackoverflow.com/a/12504097
|
|
||||||
public void setListShown(boolean shown, boolean animate) {
|
|
||||||
if (mListShown == shown) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mListShown = shown;
|
|
||||||
if (shown) {
|
|
||||||
if (animate) {
|
|
||||||
mProgressContainer.startAnimation(AnimationUtils.loadAnimation(
|
|
||||||
getActivity(), android.R.anim.fade_out));
|
|
||||||
mListContainer.startAnimation(AnimationUtils.loadAnimation(
|
|
||||||
getActivity(), android.R.anim.fade_in));
|
|
||||||
}
|
|
||||||
mProgressContainer.setVisibility(View.GONE);
|
|
||||||
mListContainer.setVisibility(View.VISIBLE);
|
|
||||||
} else {
|
|
||||||
if (animate) {
|
|
||||||
mProgressContainer.startAnimation(AnimationUtils.loadAnimation(
|
|
||||||
getActivity(), android.R.anim.fade_in));
|
|
||||||
mListContainer.startAnimation(AnimationUtils.loadAnimation(
|
|
||||||
getActivity(), android.R.anim.fade_out));
|
|
||||||
}
|
|
||||||
mProgressContainer.setVisibility(View.VISIBLE);
|
|
||||||
mListContainer.setVisibility(View.INVISIBLE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// rebuild functionality of ListFragment, http://stackoverflow.com/a/12504097
|
|
||||||
public void setListShown(boolean shown) {
|
|
||||||
setListShown(shown, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// rebuild functionality of ListFragment, http://stackoverflow.com/a/12504097
|
|
||||||
public void setListShownNoAnimation(boolean shown) {
|
|
||||||
setListShown(shown, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements StickyListHeadersAdapter from library
|
* Implements StickyListHeadersAdapter from library
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -0,0 +1,78 @@
|
||||||
|
package org.sufficientlysecure.keychain.ui;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.view.animation.AnimationUtils;
|
||||||
|
|
||||||
|
import org.sufficientlysecure.keychain.R;
|
||||||
|
|
||||||
|
/** This is a fragment helper class, which implements a generic
|
||||||
|
* progressbar/container view.
|
||||||
|
*
|
||||||
|
* To use it in a fragment, simply subclass, use onCreateView to create the
|
||||||
|
* layout's root view, and ues getContainer() as root view of your subclass.
|
||||||
|
* The layout shows a progress bar by default, and can be switched to the
|
||||||
|
* actual contents by calling setContentShown().
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class LoaderFragment extends Fragment {
|
||||||
|
private boolean mContentShown;
|
||||||
|
private View mProgressContainer;
|
||||||
|
private ViewGroup mContainer;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
View root = inflater.inflate(R.layout.loader_layout, container, false);
|
||||||
|
|
||||||
|
mContentShown = true;
|
||||||
|
mContainer = (ViewGroup) root.findViewById(R.id.loader_container);
|
||||||
|
mProgressContainer = root.findViewById(R.id.loader_progress);
|
||||||
|
|
||||||
|
// content is not shown (by visibility statuses in the layout files)
|
||||||
|
mContentShown = false;
|
||||||
|
|
||||||
|
return root;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ViewGroup getContainer() {
|
||||||
|
return mContainer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContentShown(boolean shown, boolean animate) {
|
||||||
|
if (mContentShown == shown) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mContentShown = shown;
|
||||||
|
if (shown) {
|
||||||
|
if (animate) {
|
||||||
|
mProgressContainer.startAnimation(AnimationUtils.loadAnimation(
|
||||||
|
getActivity(), android.R.anim.fade_out));
|
||||||
|
mContainer.startAnimation(AnimationUtils.loadAnimation(
|
||||||
|
getActivity(), android.R.anim.fade_in));
|
||||||
|
}
|
||||||
|
mProgressContainer.setVisibility(View.GONE);
|
||||||
|
mContainer.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
if (animate) {
|
||||||
|
mProgressContainer.startAnimation(AnimationUtils.loadAnimation(
|
||||||
|
getActivity(), android.R.anim.fade_in));
|
||||||
|
mContainer.startAnimation(AnimationUtils.loadAnimation(
|
||||||
|
getActivity(), android.R.anim.fade_out));
|
||||||
|
}
|
||||||
|
mProgressContainer.setVisibility(View.VISIBLE);
|
||||||
|
mContainer.setVisibility(View.INVISIBLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContentShown(boolean shown) {
|
||||||
|
setContentShown(shown, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContentShownNoAnimation(boolean shown) {
|
||||||
|
setContentShown(shown, false);
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,33 +6,6 @@
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<!--rebuild functionality of ListFragment -->
|
<!--rebuild functionality of ListFragment -->
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/key_list_progress_container"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:visibility="visible"
|
|
||||||
android:gravity="center">
|
|
||||||
|
|
||||||
<ProgressBar
|
|
||||||
style="?android:attr/progressBarStyleLarge"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
|
||||||
android:text=""
|
|
||||||
android:paddingTop="4dip"
|
|
||||||
android:singleLine="true" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<FrameLayout
|
|
||||||
android:id="@+id/key_list_list_container"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent">
|
|
||||||
|
|
||||||
<se.emilsjolander.stickylistheaders.StickyListHeadersListView
|
<se.emilsjolander.stickylistheaders.StickyListHeadersListView
|
||||||
android:id="@+id/key_list_list"
|
android:id="@+id/key_list_list"
|
||||||
|
@ -52,7 +25,7 @@
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:visibility="gone">
|
android:visibility="visible">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
@ -104,5 +77,3 @@
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
</FrameLayout>
|
|
||||||
|
|
39
OpenKeychain/src/main/res/layout/loader_layout.xml
Normal file
39
OpenKeychain/src/main/res/layout/loader_layout.xml
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:bootstrapbutton="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<!--rebuild functionality of ListFragment -->
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/loader_progress"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:gravity="center">
|
||||||
|
|
||||||
|
<ProgressBar
|
||||||
|
style="?android:attr/progressBarStyleLarge"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||||
|
android:text=""
|
||||||
|
android:paddingTop="4dip"
|
||||||
|
android:singleLine="true" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:id="@+id/loader_container"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:visibility="gone">
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
|
</FrameLayout>
|
Loading…
Reference in a new issue