diff options
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui')
6 files changed, 85 insertions, 99 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java index 298772e7d..70fb3b3d6 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java @@ -18,9 +18,7 @@ package org.sufficientlysecure.keychain.ui; import android.annotation.TargetApi; -import android.app.Activity; import android.app.ProgressDialog; -import android.content.Context; import android.content.Intent; import android.net.Uri; import android.nfc.NdefMessage; @@ -31,17 +29,12 @@ import android.os.Message; import android.os.Messenger; import android.os.Parcelable; import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentTransaction; import android.support.v4.view.ViewPager; -import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBarActivity; -import android.util.DisplayMetrics; -import android.util.TypedValue; import android.view.MotionEvent; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; -import android.widget.ArrayAdapter; import com.github.johnpersano.supertoasts.SuperCardToast; import com.github.johnpersano.supertoasts.SuperToast; @@ -52,7 +45,6 @@ import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.helper.OtherHelper; import org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry; -import org.sufficientlysecure.keychain.keyimport.KeybaseKeyserver; import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.service.KeychainIntentService; @@ -378,8 +370,8 @@ public class ImportKeysActivity extends ActionBarActivity { startListFragment(savedInstanceState, null, null, query); } - public void loadCallback(byte[] importData, Uri dataUri, String serverQuery, String keyServer, String keybaseQuery) { - mListFragment.loadNew(importData, dataUri, serverQuery, keyServer, keybaseQuery); + public void loadCallback(ImportKeysListFragment.LoaderState loaderState) { + mListFragment.loadNew(loaderState); } /** @@ -490,7 +482,8 @@ public class ImportKeysActivity extends ActionBarActivity { } }; - if (mListFragment.getKeyBytes() != null || mListFragment.getDataUri() != null) { + ImportKeysListFragment.LoaderState ls = mListFragment.getLoaderState(); + if (ls instanceof ImportKeysListFragment.BytesLoaderState) { Log.d(Constants.TAG, "importKeys started"); // Send all information needed to service to import key in other thread @@ -516,7 +509,9 @@ public class ImportKeysActivity extends ActionBarActivity { // start service with intent startService(intent); - } else if (mListFragment.getServerQuery() != null) { + } else if (ls instanceof ImportKeysListFragment.KeyserverLoaderState) { + ImportKeysListFragment.KeyserverLoaderState sls = (ImportKeysListFragment.KeyserverLoaderState) ls; + // Send all information needed to service to query keys in other thread Intent intent = new Intent(this, KeychainIntentService.class); @@ -525,7 +520,7 @@ public class ImportKeysActivity extends ActionBarActivity { // fill values for this action Bundle data = new Bundle(); - data.putString(KeychainIntentService.DOWNLOAD_KEY_SERVER, mListFragment.getKeyServer()); + data.putString(KeychainIntentService.DOWNLOAD_KEY_SERVER, sls.keyserver); // get selected key entries ArrayList<ImportKeysListEntry> selectedEntries = mListFragment.getSelectedEntries(); @@ -542,7 +537,7 @@ public class ImportKeysActivity extends ActionBarActivity { // start service with intent startService(intent); - } else if (mListFragment.getKeybaseQuery() != null) { + } else if (ls instanceof ImportKeysListFragment.KeybaseLoaderState) { // Send all information needed to service to query keys in other thread Intent intent = new Intent(this, KeychainIntentService.class); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysFileFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysFileFragment.java index 060e9bab2..60e5324c5 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysFileFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysFileFragment.java @@ -85,7 +85,7 @@ public class ImportKeysFileFragment extends Fragment { return; } } - mImportActivity.loadCallback(sendText.getBytes(), null, null, null, null); + mImportActivity.loadCallback(new ImportKeysListFragment.BytesLoaderState(sendText.getBytes(), null)); } }); @@ -107,7 +107,7 @@ public class ImportKeysFileFragment extends Fragment { if (resultCode == Activity.RESULT_OK && data != null) { // load data - mImportActivity.loadCallback(null, data.getData(), null, null, null); + mImportActivity.loadCallback(new ImportKeysListFragment.BytesLoaderState(null, data.getData())); } break; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysKeybaseFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysKeybaseFragment.java index 9264829ea..3a82bdc32 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysKeybaseFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysKeybaseFragment.java @@ -117,6 +117,6 @@ public class ImportKeysKeybaseFragment extends Fragment { } private void search(String query) { - mImportActivity.loadCallback(null, null, null, null, query); + mImportActivity.loadCallback(new ImportKeysListFragment.KeybaseLoaderState(query)); } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java index 7d8dc4a6c..cba6dd78f 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java @@ -27,8 +27,6 @@ import android.support.v4.util.LongSparseArray; import android.view.View; import android.widget.ListView; -import com.devspark.appmsg.AppMsg; - import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.helper.Preferences; @@ -60,11 +58,7 @@ public class ImportKeysListFragment extends ListFragment implements private Activity mActivity; private ImportKeysAdapter mAdapter; - private byte[] mKeyBytes; - private Uri mDataUri; - private String mServerQuery; - private String mKeyServer; - private String mKeybaseQuery; + private LoaderState mLoaderState; private static final int LOADER_ID_BYTES = 0; private static final int LOADER_ID_SERVER_QUERY = 1; @@ -72,24 +66,8 @@ public class ImportKeysListFragment extends ListFragment implements private LongSparseArray<ParcelableKeyRing> mCachedKeyData; - public byte[] getKeyBytes() { - return mKeyBytes; - } - - public Uri getDataUri() { - return mDataUri; - } - - public String getServerQuery() { - return mServerQuery; - } - - public String getKeybaseQuery() { - return mKeybaseQuery; - } - - public String getKeyServer() { - return mKeyServer; + public LoaderState getLoaderState() { + return mLoaderState; } public List<ImportKeysListEntry> getData() { @@ -124,6 +102,37 @@ public class ImportKeysListFragment extends ListFragment implements return frag; } + static public class LoaderState { + } + + static public class BytesLoaderState extends LoaderState { + byte[] keyBytes; + Uri dataUri; + + BytesLoaderState(byte[] keyBytes, Uri dataUri) { + this.keyBytes = keyBytes; + this.dataUri = dataUri; + } + } + + static public class KeyserverLoaderState extends LoaderState { + String serverQuery; + String keyserver; + + KeyserverLoaderState(String serverQuery, String keyserver) { + this.serverQuery = serverQuery; + this.keyserver = keyserver; + } + } + + static public class KeybaseLoaderState extends LoaderState { + String keybaseQuery; + + KeybaseLoaderState(String keybaseQuery) { + this.keybaseQuery = keybaseQuery; + } + } + /** * Define Adapter and Loader on create of Activity */ @@ -140,43 +149,20 @@ public class ImportKeysListFragment extends ListFragment implements mAdapter = new ImportKeysAdapter(mActivity); setListAdapter(mAdapter); - mDataUri = getArguments().getParcelable(ARG_DATA_URI); - mKeyBytes = getArguments().getByteArray(ARG_BYTES); - mServerQuery = getArguments().getString(ARG_SERVER_QUERY); - - // TODO: this is used when scanning QR Code. Currently it simply uses keyserver nr 0 - mKeyServer = Preferences.getPreferences(getActivity()) - .getKeyServers()[0]; - - if (mDataUri != null || mKeyBytes != null) { - // Start out with a progress indicator. - setListShown(false); - - // Prepare the loader. Either re-connect with an existing one, - // or start a new one. - // give arguments to onCreateLoader() - getLoaderManager().initLoader(LOADER_ID_BYTES, null, this); - } - - if (mServerQuery != null && mKeyServer != null) { - // Start out with a progress indicator. - setListShown(false); - - // Prepare the loader. Either re-connect with an existing one, - // or start a new one. - // give arguments to onCreateLoader() - getLoaderManager().initLoader(LOADER_ID_SERVER_QUERY, null, this); + if (getArguments().containsKey(ARG_DATA_URI) || getArguments().containsKey(ARG_BYTES)) { + Uri dataUri = getArguments().getParcelable(ARG_DATA_URI); + byte[] bytes = getArguments().getByteArray(ARG_BYTES); + mLoaderState = new BytesLoaderState(bytes, dataUri); + } else if (getArguments().containsKey(ARG_SERVER_QUERY)) { + String query = getArguments().getString(ARG_SERVER_QUERY); + // TODO: this is used when scanning QR Code or updating a key. + // Currently it simply uses keyserver nr 0 + String keyserver = Preferences.getPreferences(getActivity()) + .getKeyServers()[0]; + mLoaderState = new KeyserverLoaderState(query, keyserver); } - if (mKeybaseQuery != null) { - // Start out with a progress indicator. - setListShown(false); - - // Prepare the loader. Either re-connect with an existing one, - // or start a new one. - // give arguments to onCreateLoader() - getLoaderManager().initLoader(LOADER_ID_KEYBASE, null, this); - } + restartLoaders(); } @Override @@ -192,31 +178,33 @@ public class ImportKeysListFragment extends ListFragment implements mAdapter.notifyDataSetChanged(); } - public void loadNew(byte[] keyBytes, Uri dataUri, String serverQuery, String keyServer, String keybaseQuery) { - mKeyBytes = keyBytes; - mDataUri = dataUri; - mServerQuery = serverQuery; - mKeyServer = keyServer; - mKeybaseQuery = keybaseQuery; + public void loadNew(LoaderState loaderState) { + mLoaderState = loaderState; + + restartLoaders(); + } - if (mKeyBytes != null || mDataUri != null) { + private void restartLoaders() { + if (mLoaderState instanceof BytesLoaderState) { // Start out with a progress indicator. setListShown(false); getLoaderManager().restartLoader(LOADER_ID_BYTES, null, this); - } - - if (mServerQuery != null && mKeyServer != null) { + getLoaderManager().destroyLoader(LOADER_ID_SERVER_QUERY); + getLoaderManager().destroyLoader(LOADER_ID_KEYBASE); + } else if (mLoaderState instanceof KeyserverLoaderState) { // Start out with a progress indicator. setListShown(false); + getLoaderManager().destroyLoader(LOADER_ID_BYTES); getLoaderManager().restartLoader(LOADER_ID_SERVER_QUERY, null, this); - } - - if (mKeybaseQuery != null) { + getLoaderManager().destroyLoader(LOADER_ID_KEYBASE); + } else if (mLoaderState instanceof KeybaseLoaderState) { // Start out with a progress indicator. setListShown(false); + getLoaderManager().destroyLoader(LOADER_ID_BYTES); + getLoaderManager().destroyLoader(LOADER_ID_SERVER_QUERY); getLoaderManager().restartLoader(LOADER_ID_KEYBASE, null, this); } } @@ -226,14 +214,17 @@ public class ImportKeysListFragment extends ListFragment implements onCreateLoader(int id, Bundle args) { switch (id) { case LOADER_ID_BYTES: { - InputData inputData = getInputData(mKeyBytes, mDataUri); + BytesLoaderState ls = (BytesLoaderState) mLoaderState; + InputData inputData = getInputData(ls.keyBytes, ls.dataUri); return new ImportKeysListLoader(mActivity, inputData); } case LOADER_ID_SERVER_QUERY: { - return new ImportKeysListServerLoader(getActivity(), mServerQuery, mKeyServer); + KeyserverLoaderState ls = (KeyserverLoaderState) mLoaderState; + return new ImportKeysListServerLoader(getActivity(), ls.serverQuery, ls.keyserver); } case LOADER_ID_KEYBASE: { - return new ImportKeysListKeybaseLoader(getActivity(), mKeybaseQuery); + KeybaseLoaderState ls = (KeybaseLoaderState) mLoaderState; + return new ImportKeysListKeybaseLoader(getActivity(), ls.keybaseQuery); } default: @@ -280,7 +271,8 @@ public class ImportKeysListFragment extends ListFragment implements ((ImportKeysListLoader.NonPgpPart) error).getCount() + " " + getResources(). getQuantityString(R.plurals.error_import_non_pgp_part, ((ImportKeysListLoader.NonPgpPart) error).getCount()), - Notify.Style.OK); + Notify.Style.OK + ); } else { Notify.showNotify(getActivity(), R.string.error_generic_report_bug, Notify.Style.ERROR); } @@ -289,7 +281,6 @@ public class ImportKeysListFragment extends ListFragment implements case LOADER_ID_SERVER_QUERY: case LOADER_ID_KEYBASE: - // TODO: possibly fine-tune message building for these two cases if (error == null) { // No error } else if (error instanceof Keyserver.QueryTooShortException) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysQrCodeFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysQrCodeFragment.java index 0cbb51c77..b7ffef0ed 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysQrCodeFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysQrCodeFragment.java @@ -129,7 +129,7 @@ public class ImportKeysQrCodeFragment extends Fragment { // is this a full key encoded as qr code? if (scannedContent.startsWith("-----BEGIN PGP")) { - mImportActivity.loadCallback(scannedContent.getBytes(), null, null, null, null); + mImportActivity.loadCallback(new ImportKeysListFragment.BytesLoaderState(scannedContent.getBytes(), null)); return; } @@ -208,7 +208,7 @@ public class ImportKeysQrCodeFragment extends Fragment { for (String in : mQrCodeContent) { result += in; } - mImportActivity.loadCallback(result.getBytes(), null, null, null, null); + mImportActivity.loadCallback(new ImportKeysListFragment.BytesLoaderState(result.getBytes(), null)); } } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysServerFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysServerFragment.java index eabc8348c..c7467d789 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysServerFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysServerFragment.java @@ -170,8 +170,8 @@ public class ImportKeysServerFragment extends Fragment { mImportActivity = (ImportKeysActivity) activity; } - private void search(String query, String keyServer) { - mImportActivity.loadCallback(null, null, query, keyServer, null); + private void search(String query, String keyserver) { + mImportActivity.loadCallback(new ImportKeysListFragment.KeyserverLoaderState(query, keyserver)); } } |