mirror of
https://github.com/moparisthebest/open-keychain
synced 2025-01-12 05:58:07 -05:00
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.Message;
|
||||
import android.os.Messenger;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.LoaderManager;
|
||||
import android.support.v4.content.CursorLoader;
|
||||
import android.support.v4.content.Loader;
|
||||
@ -45,10 +44,8 @@ import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.animation.AnimationUtils;
|
||||
import android.widget.AbsListView.MultiChoiceModeListener;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.Button;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageButton;
|
||||
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
|
||||
* StickyListHeaders library which does not extend upon ListView.
|
||||
*/
|
||||
public class KeyListFragment extends Fragment
|
||||
public class KeyListFragment extends LoaderFragment
|
||||
implements SearchView.OnQueryTextListener, AdapterView.OnItemClickListener,
|
||||
LoaderManager.LoaderCallbacks<Cursor> {
|
||||
|
||||
private KeyListAdapter mAdapter;
|
||||
private StickyListHeadersListView mStickyList;
|
||||
|
||||
// rebuild functionality of ListFragment, http://stackoverflow.com/a/12504097
|
||||
boolean mListShown;
|
||||
View mProgressContainer;
|
||||
View mListContainer;
|
||||
|
||||
private String mCurQuery;
|
||||
private SearchView mSearchView;
|
||||
// empty list layout
|
||||
@ -101,14 +93,15 @@ public class KeyListFragment extends Fragment
|
||||
* Load custom layout with StickyListView from library
|
||||
*/
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View root = inflater.inflate(R.layout.key_list_fragment, container, false);
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup superContainer, Bundle savedInstanceState) {
|
||||
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);
|
||||
|
||||
// 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() {
|
||||
|
||||
@Override
|
||||
@ -120,7 +113,7 @@ public class KeyListFragment extends Fragment
|
||||
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() {
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
@ -234,9 +222,8 @@ public class KeyListFragment extends Fragment
|
||||
// We have a menu item to show in action bar.
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
// NOTE: Not supported by StickyListHeader, but reimplemented here
|
||||
// Start out with a progress indicator.
|
||||
setListShown(false);
|
||||
setContentShown(false);
|
||||
|
||||
// Create an empty adapter we will use to display the loaded data.
|
||||
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
|
||||
mStickyList.setEmptyView(getActivity().findViewById(R.id.key_list_empty));
|
||||
|
||||
// NOTE: Not supported by StickyListHeader, but reimplemented here
|
||||
// The list should now be shown.
|
||||
if (isResumed()) {
|
||||
setListShown(true);
|
||||
setContentShown(true);
|
||||
} else {
|
||||
setListShownNoAnimation(true);
|
||||
setContentShownNoAnimation(true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -418,43 +404,6 @@ public class KeyListFragment extends Fragment
|
||||
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
|
||||
*/
|
||||
|
@ -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,103 +6,74 @@
|
||||
android:orientation="vertical">
|
||||
|
||||
<!--rebuild functionality of ListFragment -->
|
||||
<LinearLayout
|
||||
android:id="@+id/key_list_progress_container"
|
||||
android:orientation="vertical"
|
||||
|
||||
<se.emilsjolander.stickylistheaders.StickyListHeadersListView
|
||||
android:id="@+id/key_list_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:visibility="visible"
|
||||
android:gravity="center">
|
||||
android:clipToPadding="false"
|
||||
android:drawSelectorOnTop="true"
|
||||
android:fastScrollEnabled="true"
|
||||
android:paddingBottom="16dp"
|
||||
android:paddingLeft="16dp"
|
||||
android:paddingRight="32dp"
|
||||
android:scrollbarStyle="outsideOverlay" />
|
||||
|
||||
<ProgressBar
|
||||
style="?android:attr/progressBarStyleLarge"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
<LinearLayout
|
||||
android:id="@+id/key_list_empty"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:visibility="visible">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:text=""
|
||||
android:paddingTop="4dip"
|
||||
android:singleLine="true" />
|
||||
android:gravity="center"
|
||||
android:text="@string/key_list_empty_text1"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:text=""
|
||||
android:textAppearance="?android:attr/textAppearanceLarge" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="4dp"
|
||||
android:gravity="center"
|
||||
android:text="@string/key_list_empty_text2"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||
|
||||
<com.beardedhen.androidbootstrap.BootstrapButton
|
||||
android:id="@+id/key_list_empty_button_create"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="4dp"
|
||||
android:text="@string/key_list_empty_button_create"
|
||||
bootstrapbutton:bb_icon_left="fa-plus"
|
||||
bootstrapbutton:bb_type="default" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="4dp"
|
||||
android:gravity="center"
|
||||
android:text="@string/key_list_empty_text3"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||
|
||||
<com.beardedhen.androidbootstrap.BootstrapButton
|
||||
android:id="@+id/key_list_empty_button_import"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="4dp"
|
||||
android:text="@string/key_list_empty_button_import"
|
||||
bootstrapbutton:bb_icon_left="fa-download"
|
||||
bootstrapbutton:bb_type="default" />
|
||||
</LinearLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/key_list_list_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<se.emilsjolander.stickylistheaders.StickyListHeadersListView
|
||||
android:id="@+id/key_list_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clipToPadding="false"
|
||||
android:drawSelectorOnTop="true"
|
||||
android:fastScrollEnabled="true"
|
||||
android:paddingBottom="16dp"
|
||||
android:paddingLeft="16dp"
|
||||
android:paddingRight="32dp"
|
||||
android:scrollbarStyle="outsideOverlay" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/key_list_empty"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:visibility="gone">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:text="@string/key_list_empty_text1"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:text=""
|
||||
android:textAppearance="?android:attr/textAppearanceLarge" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="4dp"
|
||||
android:gravity="center"
|
||||
android:text="@string/key_list_empty_text2"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||
|
||||
<com.beardedhen.androidbootstrap.BootstrapButton
|
||||
android:id="@+id/key_list_empty_button_create"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="4dp"
|
||||
android:text="@string/key_list_empty_button_create"
|
||||
bootstrapbutton:bb_icon_left="fa-plus"
|
||||
bootstrapbutton:bb_type="default" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="4dp"
|
||||
android:gravity="center"
|
||||
android:text="@string/key_list_empty_text3"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||
|
||||
<com.beardedhen.androidbootstrap.BootstrapButton
|
||||
android:id="@+id/key_list_empty_button_import"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="4dp"
|
||||
android:text="@string/key_list_empty_button_import"
|
||||
bootstrapbutton:bb_icon_left="fa-download"
|
||||
bootstrapbutton:bb_type="default" />
|
||||
</LinearLayout>
|
||||
|
||||
</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 New Issue
Block a user