diff options
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget')
3 files changed, 30 insertions, 25 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/CertifyKeySpinner.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/CertifyKeySpinner.java index e3c9804bb..48550d257 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/CertifyKeySpinner.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/CertifyKeySpinner.java @@ -20,6 +20,7 @@ package org.sufficientlysecure.keychain.ui.widget; import android.content.Context; import android.database.Cursor; import android.net.Uri; +import android.os.Bundle; import android.support.v4.content.CursorLoader; import android.support.v4.content.Loader; import android.util.AttributeSet; @@ -48,7 +49,7 @@ public class CertifyKeySpinner extends KeySpinner { } @Override - public Loader<Cursor> onCreateLoader() { + public Loader<Cursor> onCreateLoader(int loaderId, Bundle data) { // This is called when a new Loader needs to be created. This // sample only has one Loader, so we don't care about the ID. Uri baseUri = KeychainContract.KeyRings.buildUnifiedKeyRingsUri(); @@ -74,4 +75,14 @@ public class CertifyKeySpinner extends KeySpinner { // creating a Cursor for the data being displayed. return new CursorLoader(getContext(), baseUri, projection, where, null, null); } + + @Override + public void onLoadFinished(Loader<Cursor> loader, Cursor data) { + super.onLoadFinished(loader, data); + // If there is only one choice, pick it by default + if (mAdapter.getCount() == 2) { + setSelection(1); + } + } + } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeySpinner.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeySpinner.java index 3a31fc9f4..2c198d4bf 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeySpinner.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeySpinner.java @@ -40,14 +40,14 @@ import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.util.Log; -public abstract class KeySpinner extends Spinner { +public abstract class KeySpinner extends Spinner implements LoaderManager.LoaderCallbacks<Cursor> { public interface OnKeyChangedListener { public void onKeyChanged(long masterKeyId); } - private long mSelectedKeyId; - private SelectKeyAdapter mAdapter = new SelectKeyAdapter(); - private OnKeyChangedListener mListener; + protected long mSelectedKeyId; + protected SelectKeyAdapter mAdapter = new SelectKeyAdapter(); + protected OnKeyChangedListener mListener; public KeySpinner(Context context) { super(context); @@ -83,8 +83,6 @@ public abstract class KeySpinner extends Spinner { }); } - public abstract Loader<Cursor> onCreateLoader(); - @Override public void setOnItemSelectedListener(OnItemSelectedListener listener) { throw new UnsupportedOperationException(); @@ -102,27 +100,22 @@ public abstract class KeySpinner extends Spinner { public void reload() { if (getContext() instanceof FragmentActivity) { - ((FragmentActivity) getContext()).getSupportLoaderManager().restartLoader(hashCode(), null, new LoaderManager.LoaderCallbacks<Cursor>() { - @Override - public Loader<Cursor> onCreateLoader(int id, Bundle args) { - return KeySpinner.this.onCreateLoader(); - } - - @Override - public void onLoadFinished(Loader<Cursor> loader, Cursor data) { - mAdapter.swapCursor(data); - } - - @Override - public void onLoaderReset(Loader<Cursor> loader) { - mAdapter.swapCursor(null); - } - }); + ((FragmentActivity) getContext()).getSupportLoaderManager().restartLoader(0, null, this); } else { Log.e(Constants.TAG, "KeySpinner must be attached to FragmentActivity, this is " + getContext().getClass()); } } + @Override + public void onLoadFinished(Loader<Cursor> loader, Cursor data) { + mAdapter.swapCursor(data); + } + + @Override + public void onLoaderReset(Loader<Cursor> loader) { + mAdapter.swapCursor(null); + } + public long getSelectedKeyId() { return mSelectedKeyId; } @@ -131,7 +124,7 @@ public abstract class KeySpinner extends Spinner { this.mSelectedKeyId = selectedKeyId; } - private class SelectKeyAdapter extends BaseAdapter implements SpinnerAdapter { + protected class SelectKeyAdapter extends BaseAdapter implements SpinnerAdapter { private CursorAdapter inner; private int mIndexUserId; private int mIndexKeyId; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SignKeySpinner.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SignKeySpinner.java index a1ed2c065..d0517d464 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SignKeySpinner.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SignKeySpinner.java @@ -20,6 +20,7 @@ package org.sufficientlysecure.keychain.ui.widget; import android.content.Context; import android.database.Cursor; import android.net.Uri; +import android.os.Bundle; import android.support.v4.content.CursorLoader; import android.support.v4.content.Loader; import android.util.AttributeSet; @@ -39,7 +40,7 @@ public class SignKeySpinner extends KeySpinner { } @Override - public Loader<Cursor> onCreateLoader() { + public Loader<Cursor> onCreateLoader(int loaderId, Bundle data) { // This is called when a new Loader needs to be created. This // sample only has one Loader, so we don't care about the ID. Uri baseUri = KeychainContract.KeyRings.buildUnifiedKeyRingsUri(); |