From 2227705d650d1e9bf3e59202a093af129c272f04 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Fri, 4 Apr 2014 05:01:35 +0200 Subject: [PATCH] db-overhaul: fix loading indicators in KeyListActivity and ViewKeyActivity --- .../keychain/pgp/PgpImportExport.java | 2 +- .../keychain/provider/KeychainDatabase.java | 1 - .../keychain/provider/KeychainProvider.java | 13 +++++++++---- .../keychain/ui/KeyListFragment.java | 6 +++--- .../keychain/ui/ViewKeyActivity.java | 2 ++ .../keychain/ui/ViewKeyMainFragment.java | 8 ++++++++ .../src/main/res/layout/view_key_main_fragment.xml | 3 ++- 7 files changed, 25 insertions(+), 10 deletions(-) diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java index 49ce8d3bb..d03f3ccc2 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java @@ -260,7 +260,6 @@ public class PgpImportExport { } if (save) { - ProviderHelper.saveKeyRing(mContext, secretKeyRing); // TODO: preserve certifications // (http://osdir.com/ml/encryption.bouncy-castle.devel/2007-01/msg00054.html ?) PGPPublicKeyRing newPubRing = null; @@ -275,6 +274,7 @@ public class PgpImportExport { if (newPubRing != null) { ProviderHelper.saveKeyRing(mContext, newPubRing); } + ProviderHelper.saveKeyRing(mContext, secretKeyRing); // TODO: remove status returns, use exceptions! status = Id.return_value.ok; } diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java index e0cf6b6c5..36e2a7962 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java @@ -124,7 +124,6 @@ public class KeychainDatabase extends SQLiteOpenHelper { KeychainDatabase(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); - // make sure this is only done once, on the first instance! boolean iAmIt = false; synchronized(apg_hack) { diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java index a14b5b3de..1dd6ab08f 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java @@ -168,10 +168,15 @@ public class KeychainProvider extends ContentProvider { @Override public boolean onCreate() { mUriMatcher = buildUriMatcher(); - mKeychainDatabase = new KeychainDatabase(getContext()); return true; } + public KeychainDatabase getDb() { + if(mKeychainDatabase == null) + mKeychainDatabase = new KeychainDatabase(getContext()); + return mKeychainDatabase; + } + /** * {@inheritDoc} */ @@ -441,7 +446,7 @@ public class KeychainProvider extends ContentProvider { orderBy = sortOrder; } - SQLiteDatabase db = mKeychainDatabase.getReadableDatabase(); + SQLiteDatabase db = getDb().getReadableDatabase(); Cursor c = qb.query(db, projection, selection, selectionArgs, groupBy, having, orderBy); // Tell the cursor what uri to watch, so it knows when its source data changes @@ -465,7 +470,7 @@ public class KeychainProvider extends ContentProvider { public Uri insert(Uri uri, ContentValues values) { Log.d(Constants.TAG, "insert(uri=" + uri + ", values=" + values.toString() + ")"); - final SQLiteDatabase db = mKeychainDatabase.getWritableDatabase(); + final SQLiteDatabase db = getDb().getWritableDatabase(); Uri rowUri = null; Long keyId = null; @@ -538,7 +543,7 @@ public class KeychainProvider extends ContentProvider { public int delete(Uri uri, String additionalSelection, String[] selectionArgs) { Log.v(Constants.TAG, "delete(uri=" + uri + ")"); - final SQLiteDatabase db = mKeychainDatabase.getWritableDatabase(); + final SQLiteDatabase db = getDb().getWritableDatabase(); int count; final int match = mUriMatcher.match(uri); diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java index b688dec51..33ccd3a23 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java @@ -154,9 +154,6 @@ public class KeyListFragment extends Fragment } catch (ApiLevelTooLowException e) { } - // this view is made visible if no data is available - mStickyList.setEmptyView(getActivity().findViewById(R.id.key_list_empty)); - /* * ActionBarSherlock does not support MultiChoiceModeListener. Thus multi-selection is only * available for Android >= 3.0 @@ -291,6 +288,9 @@ public class KeyListFragment extends Fragment mStickyList.setAdapter(mAdapter); + // 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()) { diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java index 5760f7d8c..653114c6c 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java @@ -28,6 +28,7 @@ import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBarActivity; import android.view.Menu; import android.view.MenuItem; +import android.view.Window; import android.widget.Toast; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Id; @@ -59,6 +60,7 @@ public class ViewKeyActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { + requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); super.onCreate(savedInstanceState); mExportHelper = new ExportHelper(this); diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyMainFragment.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyMainFragment.java index 616200800..ae8b6d595 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyMainFragment.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyMainFragment.java @@ -30,6 +30,7 @@ import android.text.format.DateFormat; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.LinearLayout; import android.widget.ListView; import android.widget.TextView; @@ -55,6 +56,7 @@ public class ViewKeyMainFragment extends Fragment implements public static final String ARG_DATA_URI = "uri"; + private LinearLayout mContainer; private TextView mName; private TextView mEmail; private TextView mComment; @@ -83,6 +85,7 @@ public class ViewKeyMainFragment extends Fragment implements public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.view_key_main_fragment, container, false); + mContainer = (LinearLayout) view.findViewById(R.id.container); mName = (TextView) view.findViewById(R.id.name); mEmail = (TextView) view.findViewById(R.id.email); mComment = (TextView) view.findViewById(R.id.comment); @@ -121,6 +124,9 @@ public class ViewKeyMainFragment extends Fragment implements return; } + getActivity().setProgressBarIndeterminateVisibility(Boolean.TRUE); + mContainer.setVisibility(View.GONE); + mDataUri = dataUri; Log.i(Constants.TAG, "mDataUri: " + mDataUri.toString()); @@ -319,6 +325,8 @@ public class ViewKeyMainFragment extends Fragment implements default: break; } + getActivity().setProgressBarIndeterminateVisibility(Boolean.FALSE); + mContainer.setVisibility(View.VISIBLE); } /** diff --git a/OpenPGP-Keychain/src/main/res/layout/view_key_main_fragment.xml b/OpenPGP-Keychain/src/main/res/layout/view_key_main_fragment.xml index 6d2bc8874..aa48252ce 100644 --- a/OpenPGP-Keychain/src/main/res/layout/view_key_main_fragment.xml +++ b/OpenPGP-Keychain/src/main/res/layout/view_key_main_fragment.xml @@ -12,7 +12,8 @@ android:descendantFocusability="beforeDescendants" android:orientation="vertical" android:paddingLeft="16dp" - android:paddingRight="16dp"> + android:paddingRight="16dp" + android:id="@+id/container">