use LoaderFragment in ViewKey tabs

Closes #616
This commit is contained in:
Vincent Breitmoser 2014-05-08 13:57:46 +02:00
parent 596478a212
commit 185c4eed43
7 changed files with 35 additions and 53 deletions

View File

@ -23,7 +23,6 @@ import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
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;
@ -46,7 +45,7 @@ import se.emilsjolander.stickylistheaders.StickyListHeadersAdapter;
import se.emilsjolander.stickylistheaders.StickyListHeadersListView; import se.emilsjolander.stickylistheaders.StickyListHeadersListView;
public class ViewKeyCertsFragment extends Fragment public class ViewKeyCertsFragment extends LoaderFragment
implements LoaderManager.LoaderCallbacks<Cursor>, AdapterView.OnItemClickListener { implements LoaderManager.LoaderCallbacks<Cursor>, AdapterView.OnItemClickListener {
// These are the rows that we will retrieve. // These are the rows that we will retrieve.
@ -79,18 +78,19 @@ public class ViewKeyCertsFragment extends Fragment
private static final int LOADER_ID = 4; private static final int LOADER_ID = 4;
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup superContainer, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.view_key_certs_fragment, container, false); View root = super.onCreateView(inflater, superContainer, savedInstanceState);
View view = inflater.inflate(R.layout.view_key_certs_fragment, getContainer());
return view; mStickyList = (StickyListHeadersListView) view.findViewById(R.id.list);
return root;
} }
@Override @Override
public void onActivityCreated(Bundle savedInstanceState) { public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState); super.onActivityCreated(savedInstanceState);
mStickyList = (StickyListHeadersListView) getActivity().findViewById(R.id.list);
if (!getArguments().containsKey(ARG_DATA_URI)) { if (!getArguments().containsKey(ARG_DATA_URI)) {
Log.e(Constants.TAG, "Data missing. Should be Uri of key!"); Log.e(Constants.TAG, "Data missing. Should be Uri of key!");
getActivity().finish(); getActivity().finish();
@ -120,6 +120,7 @@ public class ViewKeyCertsFragment extends Fragment
@Override @Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) { public Loader<Cursor> onCreateLoader(int id, Bundle args) {
setContentShown(false);
// Now create and return a CursorLoader that will take care of // Now create and return a CursorLoader that will take care of
// creating a Cursor for the data being displayed. // creating a Cursor for the data being displayed.
return new CursorLoader(getActivity(), mDataUri, PROJECTION, null, null, SORT_ORDER); return new CursorLoader(getActivity(), mDataUri, PROJECTION, null, null, SORT_ORDER);
@ -132,6 +133,8 @@ public class ViewKeyCertsFragment extends Fragment
mAdapter.swapCursor(data); mAdapter.swapCursor(data);
mStickyList.setAdapter(mAdapter); mStickyList.setAdapter(mAdapter);
setContentShown(true);
} }
/** /**

View File

@ -44,12 +44,11 @@ import org.sufficientlysecure.keychain.util.Log;
import java.util.Date; import java.util.Date;
public class ViewKeyKeysFragment extends Fragment implements public class ViewKeyKeysFragment extends LoaderFragment implements
LoaderManager.LoaderCallbacks<Cursor> { LoaderManager.LoaderCallbacks<Cursor> {
public static final String ARG_DATA_URI = "uri"; public static final String ARG_DATA_URI = "uri";
private LinearLayout mContainer;
private ListView mKeys; private ListView mKeys;
private ViewKeyKeysAdapter mKeysAdapter; private ViewKeyKeysAdapter mKeysAdapter;
@ -57,13 +56,13 @@ public class ViewKeyKeysFragment extends Fragment implements
private Uri mDataUri; private Uri mDataUri;
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup superContainer, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.view_key_keys_fragment, container, false); View root = super.onCreateView(inflater, superContainer, savedInstanceState);
View view = inflater.inflate(R.layout.view_key_keys_fragment, getContainer());
mContainer = (LinearLayout) view.findViewById(R.id.container);
mKeys = (ListView) view.findViewById(R.id.keys); mKeys = (ListView) view.findViewById(R.id.keys);
return view; return root;
} }
@Override @Override
@ -81,9 +80,6 @@ public class ViewKeyKeysFragment extends Fragment implements
} }
private void loadData(Uri dataUri) { private void loadData(Uri dataUri) {
getActivity().setProgressBarIndeterminateVisibility(true);
mContainer.setVisibility(View.GONE);
mDataUri = dataUri; mDataUri = dataUri;
Log.i(Constants.TAG, "mDataUri: " + mDataUri.toString()); Log.i(Constants.TAG, "mDataUri: " + mDataUri.toString());
@ -104,6 +100,7 @@ public class ViewKeyKeysFragment extends Fragment implements
}; };
public Loader<Cursor> onCreateLoader(int id, Bundle args) { public Loader<Cursor> onCreateLoader(int id, Bundle args) {
setContentShown(false);
Uri baseUri = Keys.buildKeysUri(mDataUri); Uri baseUri = Keys.buildKeysUri(mDataUri);
return new CursorLoader(getActivity(), baseUri, KEYS_PROJECTION, null, null, null); return new CursorLoader(getActivity(), baseUri, KEYS_PROJECTION, null, null, null);
} }
@ -117,8 +114,7 @@ public class ViewKeyKeysFragment extends Fragment implements
// old cursor once we return.) // old cursor once we return.)
mKeysAdapter.swapCursor(data); mKeysAdapter.swapCursor(data);
getActivity().setProgressBarIndeterminateVisibility(false); setContentShown(true);
mContainer.setVisibility(View.VISIBLE);
} }
/** /**

View File

@ -21,15 +21,12 @@ import android.content.Intent;
import android.database.Cursor; import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
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;
import android.text.format.DateFormat;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ListView; import android.widget.ListView;
import com.devspark.appmsg.AppMsg; import com.devspark.appmsg.AppMsg;
@ -37,7 +34,6 @@ import com.devspark.appmsg.AppMsg;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.R;import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.provider.KeychainContract.Keys;
import org.sufficientlysecure.keychain.provider.KeychainContract.UserIds; import org.sufficientlysecure.keychain.provider.KeychainContract.UserIds;
import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.ui.adapter.ViewKeyUserIdsAdapter; import org.sufficientlysecure.keychain.ui.adapter.ViewKeyUserIdsAdapter;
@ -45,12 +41,11 @@ import org.sufficientlysecure.keychain.util.Log;
import java.util.Date; import java.util.Date;
public class ViewKeyMainFragment extends Fragment implements public class ViewKeyMainFragment extends LoaderFragment implements
LoaderManager.LoaderCallbacks<Cursor> { LoaderManager.LoaderCallbacks<Cursor> {
public static final String ARG_DATA_URI = "uri"; public static final String ARG_DATA_URI = "uri";
private LinearLayout mContainer;
private View mActionEdit; private View mActionEdit;
private View mActionEditDivider; private View mActionEditDivider;
private View mActionEncrypt; private View mActionEncrypt;
@ -70,10 +65,10 @@ public class ViewKeyMainFragment extends Fragment implements
private Uri mDataUri; private Uri mDataUri;
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup superContainer, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.view_key_main_fragment, container, false); View root = super.onCreateView(inflater, superContainer, savedInstanceState);
View view = inflater.inflate(R.layout.view_key_main_fragment, getContainer());
mContainer = (LinearLayout) view.findViewById(R.id.container);
mUserIds = (ListView) view.findViewById(R.id.view_key_user_ids); mUserIds = (ListView) view.findViewById(R.id.view_key_user_ids);
mActionEdit = view.findViewById(R.id.view_key_action_edit); mActionEdit = view.findViewById(R.id.view_key_action_edit);
mActionEditDivider = view.findViewById(R.id.view_key_action_edit_divider); mActionEditDivider = view.findViewById(R.id.view_key_action_edit_divider);
@ -81,7 +76,7 @@ public class ViewKeyMainFragment extends Fragment implements
mActionCertify = view.findViewById(R.id.view_key_action_certify); mActionCertify = view.findViewById(R.id.view_key_action_certify);
mActionCertifyDivider = view.findViewById(R.id.view_key_action_certify_divider); mActionCertifyDivider = view.findViewById(R.id.view_key_action_certify_divider);
return view; return root;
} }
@Override @Override
@ -99,9 +94,6 @@ public class ViewKeyMainFragment extends Fragment implements
} }
private void loadData(Uri dataUri) { private void loadData(Uri dataUri) {
getActivity().setProgressBarIndeterminateVisibility(true);
mContainer.setVisibility(View.GONE);
mDataUri = dataUri; mDataUri = dataUri;
Log.i(Constants.TAG, "mDataUri: " + mDataUri.toString()); Log.i(Constants.TAG, "mDataUri: " + mDataUri.toString());
@ -143,6 +135,8 @@ public class ViewKeyMainFragment extends Fragment implements
static final int INDEX_UNIFIED_HAS_ENCRYPT = 5; static final int INDEX_UNIFIED_HAS_ENCRYPT = 5;
public Loader<Cursor> onCreateLoader(int id, Bundle args) { public Loader<Cursor> onCreateLoader(int id, Bundle args) {
setContentShown(false);
switch (id) { switch (id) {
case LOADER_ID_UNIFIED: { case LOADER_ID_UNIFIED: {
Uri baseUri = KeyRings.buildUnifiedKeyRingUri(mDataUri); Uri baseUri = KeyRings.buildUnifiedKeyRingUri(mDataUri);
@ -219,8 +213,7 @@ public class ViewKeyMainFragment extends Fragment implements
break; break;
} }
getActivity().setProgressBarIndeterminateVisibility(false); setContentShown(true);
mContainer.setVisibility(View.VISIBLE);
} }
/** /**

View File

@ -53,12 +53,11 @@ import org.sufficientlysecure.keychain.util.QrCodeUtils;
import java.io.IOException; import java.io.IOException;
public class ViewKeyShareFragment extends Fragment implements public class ViewKeyShareFragment extends LoaderFragment implements
LoaderManager.LoaderCallbacks<Cursor> { LoaderManager.LoaderCallbacks<Cursor> {
public static final String ARG_DATA_URI = "uri"; public static final String ARG_DATA_URI = "uri";
private LinearLayout mContainer;
private TextView mFingerprint; private TextView mFingerprint;
private ImageView mFingerprintQrCode; private ImageView mFingerprintQrCode;
private View mFingerprintShareButton; private View mFingerprintShareButton;
@ -77,12 +76,12 @@ public class ViewKeyShareFragment extends Fragment implements
private Uri mDataUri; private Uri mDataUri;
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup superContainer, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.view_key_share_fragment, container, false); View root = super.onCreateView(inflater, superContainer, savedInstanceState);
View view = inflater.inflate(R.layout.view_key_share_fragment, getContainer());
mProviderHelper = new ProviderHelper(ViewKeyShareFragment.this.getActivity()); mProviderHelper = new ProviderHelper(ViewKeyShareFragment.this.getActivity());
mContainer = (LinearLayout) view.findViewById(R.id.container);
mFingerprint = (TextView) view.findViewById(R.id.view_key_fingerprint); mFingerprint = (TextView) view.findViewById(R.id.view_key_fingerprint);
mFingerprintQrCode = (ImageView) view.findViewById(R.id.view_key_fingerprint_qr_code_image); mFingerprintQrCode = (ImageView) view.findViewById(R.id.view_key_fingerprint_qr_code_image);
mFingerprintShareButton = view.findViewById(R.id.view_key_action_fingerprint_share); mFingerprintShareButton = view.findViewById(R.id.view_key_action_fingerprint_share);
@ -142,7 +141,7 @@ public class ViewKeyShareFragment extends Fragment implements
} }
}); });
return view; return root;
} }
private void share(Uri dataUri, ProviderHelper providerHelper, boolean fingerprintOnly, private void share(Uri dataUri, ProviderHelper providerHelper, boolean fingerprintOnly,
@ -232,9 +231,6 @@ public class ViewKeyShareFragment extends Fragment implements
} }
private void loadData(Uri dataUri) { private void loadData(Uri dataUri) {
getActivity().setProgressBarIndeterminateVisibility(true);
mContainer.setVisibility(View.GONE);
mDataUri = dataUri; mDataUri = dataUri;
Log.i(Constants.TAG, "mDataUri: " + mDataUri.toString()); Log.i(Constants.TAG, "mDataUri: " + mDataUri.toString());
@ -260,6 +256,7 @@ public class ViewKeyShareFragment extends Fragment implements
static final int INDEX_UNIFIED_EXPIRY = 8; static final int INDEX_UNIFIED_EXPIRY = 8;
public Loader<Cursor> onCreateLoader(int id, Bundle args) { public Loader<Cursor> onCreateLoader(int id, Bundle args) {
setContentShown(false);
switch (id) { switch (id) {
case LOADER_ID_UNIFIED: { case LOADER_ID_UNIFIED: {
Uri baseUri = KeyRings.buildUnifiedKeyRingUri(mDataUri); Uri baseUri = KeyRings.buildUnifiedKeyRingUri(mDataUri);
@ -299,8 +296,7 @@ public class ViewKeyShareFragment extends Fragment implements
} }
} }
getActivity().setProgressBarIndeterminateVisibility(false); setContentShown(true);
mContainer.setVisibility(View.VISIBLE);
} }
/** /**

View File

@ -11,8 +11,7 @@
android:descendantFocusability="beforeDescendants" android:descendantFocusability="beforeDescendants"
android:orientation="vertical" android:orientation="vertical"
android:paddingLeft="16dp" android:paddingLeft="16dp"
android:paddingRight="16dp" android:paddingRight="16dp">
android:id="@+id/container">
<TextView <TextView
style="@style/SectionHeader" style="@style/SectionHeader"

View File

@ -1,5 +1,4 @@
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" <ScrollView 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_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
@ -12,9 +11,7 @@
android:descendantFocusability="beforeDescendants" android:descendantFocusability="beforeDescendants"
android:orientation="vertical" android:orientation="vertical"
android:paddingLeft="16dp" android:paddingLeft="16dp"
android:paddingRight="16dp" android:paddingRight="16dp">
android:id="@+id/container"
android:visibility="visible">
<TextView <TextView
style="@style/SectionHeader" style="@style/SectionHeader"

View File

@ -1,5 +1,4 @@
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" <ScrollView 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_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
@ -12,8 +11,7 @@
android:descendantFocusability="beforeDescendants" android:descendantFocusability="beforeDescendants"
android:orientation="vertical" android:orientation="vertical"
android:paddingLeft="16dp" android:paddingLeft="16dp"
android:paddingRight="16dp" android:paddingRight="16dp">
android:id="@+id/container">
<TextView <TextView
style="@style/SectionHeader" style="@style/SectionHeader"