From e2bd3ae83164dca93f938f5d41bd67e50a5f1408 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Tue, 4 Feb 2014 20:18:14 +0100 Subject: [PATCH] reworking some parts of import activity code --- .../keychain/ui/ImportKeysActivity.java | 54 ++++++++++++------- .../keychain/ui/ImportKeysServerFragment.java | 24 ++++----- 2 files changed, 46 insertions(+), 32 deletions(-) diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java index 70f3c955a..443b9d71f 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java @@ -57,6 +57,8 @@ public class ImportKeysActivity extends DrawerActivity implements ActionBar.OnNa + "IMPORT_KEY_FROM_QR_CODE"; public static final String ACTION_IMPORT_KEY_FROM_KEY_SERVER = Constants.INTENT_PREFIX + "IMPORT_KEY_FROM_KEY_SERVER"; + public static final String ACTION_IMPORT_KEY_FROM_KEY_SERVER_AND_RETURN = Constants.INTENT_PREFIX + + "IMPORT_KEY_FROM_KEY_SERVER_AND_RETURN"; // Actions for internal use only: public static final String ACTION_IMPORT_KEY_FROM_FILE = Constants.INTENT_PREFIX @@ -125,21 +127,21 @@ public class ImportKeysActivity extends DrawerActivity implements ActionBar.OnNa if (scheme != null && scheme.toLowerCase(Locale.ENGLISH).equals(Constants.FINGERPRINT_SCHEME)) { /* Scanning a fingerprint directly with Barcode Scanner */ - getSupportActionBar().setSelectedNavigationItem(0); - loadFragment(ImportKeysQrCodeFragment.class, null, mNavigationStrings[0]); loadFromFingerprintUri(savedInstanceState, dataUri); } else if (ACTION_IMPORT_KEY.equals(action)) { /* Keychain's own Actions */ + + // display file fragment getSupportActionBar().setSelectedNavigationItem(1); loadFragment(ImportKeysFileFragment.class, null, mNavigationStrings[1]); if (dataUri != null) { - // directly load data + // action: directly load data startListFragment(savedInstanceState, null, dataUri, null); } else if (extras.containsKey(EXTRA_KEY_BYTES)) { byte[] importData = intent.getByteArrayExtra(EXTRA_KEY_BYTES); - // directly load data + // action: directly load data startListFragment(savedInstanceState, importData, null, null); } } else if (ACTION_IMPORT_KEY_FROM_KEY_SERVER.equals(action)) { @@ -161,28 +163,39 @@ public class ImportKeysActivity extends DrawerActivity implements ActionBar.OnNa return; } - // search directly + // display key server fragment with query getSupportActionBar().setSelectedNavigationItem(0); Bundle args = new Bundle(); args.putString(ImportKeysServerFragment.ARG_QUERY, query); loadFragment(ImportKeysServerFragment.class, args, mNavigationStrings[0]); + // action: search immediately startListFragment(savedInstanceState, null, null, query); - } else { - // Other actions - startListFragment(savedInstanceState, null, null, null); + } else if (ACTION_IMPORT_KEY_FROM_FILE.equals(action)) { - if (ACTION_IMPORT_KEY_FROM_FILE.equals(action)) { - getSupportActionBar().setSelectedNavigationItem(1); - loadFragment(ImportKeysFileFragment.class, null, mNavigationStrings[1]); - } else if (ACTION_IMPORT_KEY_FROM_QR_CODE.equals(action)) { - // also exposed in AndroidManifest - getSupportActionBar().setSelectedNavigationItem(2); - loadFragment(ImportKeysQrCodeFragment.class, null, mNavigationStrings[2]); - } else if (ACTION_IMPORT_KEY_FROM_NFC.equals(action)) { - getSupportActionBar().setSelectedNavigationItem(3); - loadFragment(ImportKeysNFCFragment.class, null, mNavigationStrings[3]); - } + // NOTE: this only displays the appropriate fragment, no actions are taken + getSupportActionBar().setSelectedNavigationItem(1); + loadFragment(ImportKeysFileFragment.class, null, mNavigationStrings[1]); + + // no immediate actions! + startListFragment(savedInstanceState, null, null, null); + } else if (ACTION_IMPORT_KEY_FROM_QR_CODE.equals(action)) { + // also exposed in AndroidManifest + + // NOTE: this only displays the appropriate fragment, no actions are taken + getSupportActionBar().setSelectedNavigationItem(2); + loadFragment(ImportKeysQrCodeFragment.class, null, mNavigationStrings[2]); + + // no immediate actions! + startListFragment(savedInstanceState, null, null, null); + } else if (ACTION_IMPORT_KEY_FROM_NFC.equals(action)) { + + // NOTE: this only displays the appropriate fragment, no actions are taken + getSupportActionBar().setSelectedNavigationItem(3); + loadFragment(ImportKeysNFCFragment.class, null, mNavigationStrings[3]); + + // no immediate actions! + startListFragment(savedInstanceState, null, null, null); } } @@ -261,12 +274,13 @@ public class ImportKeysActivity extends DrawerActivity implements ActionBar.OnNa String query = "0x" + fingerprint; - // search directly + // display key server fragment with query getSupportActionBar().setSelectedNavigationItem(0); Bundle args = new Bundle(); args.putString(ImportKeysServerFragment.ARG_QUERY, query); loadFragment(ImportKeysServerFragment.class, args, mNavigationStrings[0]); + // action: search directly startListFragment(savedInstanceState, null, null, query); } diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysServerFragment.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysServerFragment.java index 2e0956d8b..d77015aa7 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysServerFragment.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysServerFragment.java @@ -127,21 +127,21 @@ public class ImportKeysServerFragment extends Fragment { mImportActivity = (ImportKeysActivity) getActivity(); // set displayed values - if (getArguments() != null && getArguments().containsKey(ARG_QUERY)) { - String query = getArguments().getString(ARG_QUERY); - mQueryEditText.setText(query, TextView.BufferType.EDITABLE); + if (getArguments() != null) { + if (getArguments().containsKey(ARG_QUERY)) { + String query = getArguments().getString(ARG_QUERY); + mQueryEditText.setText(query, TextView.BufferType.EDITABLE); - String keyServer = null; - if (getArguments().containsKey(ARG_KEY_SERVER)) { - keyServer = getArguments().getString(ARG_KEY_SERVER); - int keyServerPos = mServerAdapter.getPosition(keyServer); - mServerSpinner.setSelection(keyServerPos); - } else { - keyServer = (String) mServerSpinner.getSelectedItem(); + Log.d(Constants.TAG, "query: " + query); } - Log.d(Constants.TAG, "query: " + query); - Log.d(Constants.TAG, "keyServer: " + keyServer); + if (getArguments().containsKey(ARG_KEY_SERVER)) { + String keyServer = getArguments().getString(ARG_KEY_SERVER); + int keyServerPos = mServerAdapter.getPosition(keyServer); + mServerSpinner.setSelection(keyServerPos); + + Log.d(Constants.TAG, "keyServer: " + keyServer); + } } }