entries = listFragment.getEntries();
+ for (ImportKeysListEntry entry : entries) {
+ keys.add(new ParcelableKeyRing(entry.getFingerprintHex(),
+ entry.getKeyIdHex(), entry.getKeybaseName(), entry.getFbUsername()));
+ }
+
+ keyList = keys;
+ keyserver = sls.mCloudPrefs.keyserver;
+ }
+
+ ImportKeysOperationCallback callback = new ImportKeysOperationCallback(this, keyserver, keyList);
+ mOperationHelper = new CryptoOperationHelper(1, this, callback, R.string.progress_importing);
+
+ mOperationHelper.cryptoOperation();
+ }
+
+ @Override
+ public void handleResult(ImportKeyResult result) {
String intentAction = getIntent().getAction();
- if (ACTION_IMPORT_KEY_FROM_KEYSERVER_AND_RETURN_RESULT.equals(intentAction)
- || ACTION_IMPORT_KEY_FROM_FILE_AND_RETURN.equals(intentAction)) {
+ if (ImportKeysActivity.ACTION_IMPORT_KEY_FROM_KEYSERVER_AND_RETURN_RESULT.equals(intentAction)
+ || ImportKeysActivity.ACTION_IMPORT_KEY_FROM_FILE_AND_RETURN.equals(intentAction)) {
Intent intent = new Intent();
intent.putExtra(ImportKeyResult.EXTRA_RESULT, result);
- setResult(RESULT_OK, intent);
+ setResult(Activity.RESULT_OK, intent);
finish();
} else if (result.isOkNew() || result.isOkUpdated()) {
// User has successfully imported a key, hide first time dialog
@@ -419,35 +412,8 @@ public class ImportKeysActivity extends BaseActivity
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
} else {
- result.createNotify(ImportKeysActivity.this)
- .show((ViewGroup) findViewById(R.id.import_snackbar));
+ result.createNotify(this).show();
}
}
- // methods from CryptoOperationHelper.Callback
-
- @Override
- public ImportKeyringParcel createOperationInput() {
- return new ImportKeyringParcel(mKeyList, mKeyserver);
- }
-
- @Override
- public void onCryptoOperationSuccess(ImportKeyResult result) {
- handleResult(result);
- }
-
- @Override
- public void onCryptoOperationCancelled() {
- // do nothing
- }
-
- @Override
- public void onCryptoOperationError(ImportKeyResult result) {
- handleResult(result);
- }
-
- @Override
- public boolean onCryptoSetProgress(String msg, int progress, int max) {
- return false;
- }
}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysCloudFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysCloudFragment.java
index 51215c946..425fe377f 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysCloudFragment.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysCloudFragment.java
@@ -39,7 +39,8 @@ import android.widget.TextView;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
-import org.sufficientlysecure.keychain.keyimport.loader.CloudLoaderState;
+import org.sufficientlysecure.keychain.keyimport.processing.ImportKeysListener;
+import org.sufficientlysecure.keychain.keyimport.processing.CloudLoaderState;
import org.sufficientlysecure.keychain.util.ContactHelper;
import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.Preferences;
@@ -50,11 +51,13 @@ import java.util.List;
* Consists of the search bar, search button, and search settings button
*/
public class ImportKeysCloudFragment extends Fragment {
+
public static final String ARG_QUERY = "query";
public static final String ARG_DISABLE_QUERY_EDIT = "disable_query_edit";
public static final String ARG_CLOUD_SEARCH_PREFS = "cloud_search_prefs";
- private ImportKeysActivity mImportActivity;
+ private Activity mActivity;
+ private ImportKeysListener mCallback;
private AutoCompleteTextView mQueryEditText;
@@ -154,7 +157,14 @@ public class ImportKeysCloudFragment extends Fragment {
public void onAttach(Activity activity) {
super.onAttach(activity);
- mImportActivity = (ImportKeysActivity) activity;
+ mActivity = activity;
+
+ try {
+ mCallback = (ImportKeysListener) activity;
+ } catch (ClassCastException e) {
+ throw new ClassCastException(activity.toString()
+ + " must implement ImportKeysListener");
+ }
}
@Override
@@ -167,7 +177,7 @@ public class ImportKeysCloudFragment extends Fragment {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.import_cloud_settings:
- Intent intent = new Intent(mImportActivity, SettingsActivity.class);
+ Intent intent = new Intent(mActivity, SettingsActivity.class);
intent.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT, SettingsActivity.CloudSearchPrefsFragment.class.getName());
startActivity(intent);
return true;
@@ -185,7 +195,7 @@ public class ImportKeysCloudFragment extends Fragment {
cloudSearchPrefs = Preferences.getPreferences(getActivity()).getCloudSearchPrefs();
}
- mImportActivity.loadCallback(new CloudLoaderState(query, cloudSearchPrefs));
+ mCallback.loadKeys(new CloudLoaderState(query, cloudSearchPrefs));
toggleKeyboard(false);
}
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 46c4d37e6..d59ae5ce2 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysFileFragment.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysFileFragment.java
@@ -39,8 +39,9 @@ import android.widget.Toast;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.compatibility.ClipboardReflection;
+import org.sufficientlysecure.keychain.keyimport.processing.ImportKeysListener;
+import org.sufficientlysecure.keychain.keyimport.processing.BytesLoaderState;
import org.sufficientlysecure.keychain.pgp.PgpHelper;
-import org.sufficientlysecure.keychain.keyimport.loader.BytesLoaderState;
import org.sufficientlysecure.keychain.ui.util.Notify;
import org.sufficientlysecure.keychain.ui.util.Notify.Style;
import org.sufficientlysecure.keychain.util.FileHelper;
@@ -49,7 +50,10 @@ import org.sufficientlysecure.keychain.util.Log;
import java.io.IOException;
public class ImportKeysFileFragment extends Fragment {
- private ImportKeysActivity mImportActivity;
+
+ private Activity mActivity;
+ private ImportKeysListener mCallback;
+
private View mBrowse;
private View mClipboardButton;
@@ -78,7 +82,6 @@ public class ImportKeysFileFragment extends Fragment {
View view = inflater.inflate(R.layout.import_keys_file_fragment, container, false);
mBrowse = view.findViewById(R.id.import_keys_file_browse);
-
mBrowse.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// open .asc or .gpg files
@@ -100,10 +103,10 @@ public class ImportKeysFileFragment extends Fragment {
sendText = clipboardText.toString();
sendText = PgpHelper.getPgpKeyContent(sendText);
if (sendText == null) {
- Notify.create(mImportActivity, R.string.error_bad_data, Style.ERROR).show();
+ Notify.create(mActivity, R.string.error_bad_data, Style.ERROR).show();
return;
}
- mImportActivity.loadCallback(new BytesLoaderState(sendText.getBytes(), null));
+ mCallback.loadKeys(new BytesLoaderState(sendText.getBytes(), null));
}
}
});
@@ -117,7 +120,14 @@ public class ImportKeysFileFragment extends Fragment {
public void onAttach(Activity activity) {
super.onAttach(activity);
- mImportActivity = (ImportKeysActivity) activity;
+ mActivity = activity;
+
+ try {
+ mCallback = (ImportKeysListener) activity;
+ } catch (ClassCastException e) {
+ throw new ClassCastException(activity.toString()
+ + " must implement ImportKeysListener");
+ }
}
@Override
@@ -130,7 +140,7 @@ public class ImportKeysFileFragment extends Fragment {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.import_all_keys:
- mImportActivity.importAllKeys();
+ mCallback.importKeys();
return true;
}
@@ -161,30 +171,30 @@ public class ImportKeysFileFragment extends Fragment {
private void startImportingKeys() {
boolean isEncrypted;
try {
- isEncrypted = FileHelper.isEncryptedFile(mImportActivity, mCurrentUri);
+ isEncrypted = FileHelper.isEncryptedFile(mActivity, mCurrentUri);
} catch (IOException e) {
Log.e(Constants.TAG, "Error opening file", e);
- Notify.create(mImportActivity, R.string.error_bad_data, Style.ERROR).show();
+ Notify.create(mActivity, R.string.error_bad_data, Style.ERROR).show();
return;
}
if (isEncrypted) {
- Intent intent = new Intent(mImportActivity, DecryptActivity.class);
+ Intent intent = new Intent(mActivity, DecryptActivity.class);
intent.setAction(Intent.ACTION_VIEW);
intent.setData(mCurrentUri);
startActivity(intent);
} else {
- mImportActivity.loadCallback(new BytesLoaderState(null, mCurrentUri));
+ mCallback.loadKeys(new BytesLoaderState(null, mCurrentUri));
}
}
/**
* Request READ_EXTERNAL_STORAGE permission on Android >= 6.0 to read content from "file" Uris.
- *
+ *
* This method returns true on Android < 6, or if permission is already granted. It
* requests the permission and returns false otherwise.
- *
+ *
* see https://commonsware.com/blog/2015/10/07/runtime-permissions-files-action-send.html
*/
private boolean checkAndRequestReadPermission(final Uri uri) {
@@ -225,9 +235,9 @@ public class ImportKeysFileFragment extends Fragment {
if (permissionWasGranted) {
startImportingKeys();
} else {
- Toast.makeText(getActivity(), R.string.error_denied_storage_permission, Toast.LENGTH_LONG).show();
- getActivity().setResult(Activity.RESULT_CANCELED);
- getActivity().finish();
+ Toast.makeText(mActivity, R.string.error_denied_storage_permission, Toast.LENGTH_LONG).show();
+ mActivity.setResult(Activity.RESULT_CANCELED);
+ mActivity.finish();
}
}
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 69337df4e..c6105b18e 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java
@@ -46,15 +46,15 @@ import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.databinding.ImportKeysListFragmentBinding;
import org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry;
import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing;
+import org.sufficientlysecure.keychain.keyimport.processing.AsyncTaskResultWrapper;
+import org.sufficientlysecure.keychain.keyimport.processing.BytesLoaderState;
+import org.sufficientlysecure.keychain.keyimport.processing.CloudLoaderState;
+import org.sufficientlysecure.keychain.keyimport.processing.ImportKeysListCloudLoader;
+import org.sufficientlysecure.keychain.keyimport.processing.ImportKeysListLoader;
+import org.sufficientlysecure.keychain.keyimport.processing.LoaderState;
import org.sufficientlysecure.keychain.operations.results.GetKeyResult;
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
import org.sufficientlysecure.keychain.ui.adapter.ImportKeysAdapter;
-import org.sufficientlysecure.keychain.keyimport.loader.AsyncTaskResultWrapper;
-import org.sufficientlysecure.keychain.keyimport.loader.BytesLoaderState;
-import org.sufficientlysecure.keychain.keyimport.loader.CloudLoaderState;
-import org.sufficientlysecure.keychain.keyimport.loader.ImportKeysListCloudLoader;
-import org.sufficientlysecure.keychain.keyimport.loader.ImportKeysListLoader;
-import org.sufficientlysecure.keychain.keyimport.loader.LoaderState;
import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.ParcelableFileCache.IteratorWithSize;
import org.sufficientlysecure.keychain.util.ParcelableProxy;
@@ -77,6 +77,7 @@ public class ImportKeysListFragment extends Fragment implements
private static final int REQUEST_PERMISSION_READ_EXTERNAL_STORAGE = 12;
private FragmentActivity mActivity;
+
private ImportKeysListFragmentBinding binding;
private ParcelableProxy mParcelableProxy;
@@ -92,16 +93,10 @@ public class ImportKeysListFragment extends Fragment implements
private static final int LOADER_ID_BYTES = 0;
private static final int LOADER_ID_CLOUD = 1;
-
private LongSparseArray mCachedKeyData;
private boolean mShowingOrbotDialog;
-
- public LoaderState getLoaderState() {
- return mLoaderState;
- }
-
/**
* Returns an Iterator (with size) of the selected data items.
* This iterator is sort of a tradeoff, it's slightly more complex than an
@@ -287,7 +282,11 @@ public class ImportKeysListFragment extends Fragment implements
}
}
- public void loadNew(LoaderState loaderState) {
+ public LoaderState getState() {
+ return mLoaderState;
+ }
+
+ public void loadState(LoaderState loaderState) {
mLoaderState = loaderState;
if (mLoaderState instanceof BytesLoaderState) {
@@ -301,17 +300,6 @@ public class ImportKeysListFragment extends Fragment implements
restartLoaders();
}
- public void destroyLoader() {
- LoaderManager loaderManager = getLoaderManager();
-
- if (loaderManager.getLoader(LOADER_ID_BYTES) != null) {
- loaderManager.destroyLoader(LOADER_ID_BYTES);
- }
- if (loaderManager.getLoader(LOADER_ID_CLOUD) != null) {
- loaderManager.destroyLoader(LOADER_ID_CLOUD);
- }
- }
-
private void restartLoaders() {
LoaderManager loaderManager = getLoaderManager();