From 83673adeb9002696b4d76376095908be8ad69ab0 Mon Sep 17 00:00:00 2001 From: Andrea Torlaschi Date: Tue, 12 Jul 2016 22:24:35 +0200 Subject: [PATCH] ImportKeys: Add import single key from cloud - Refactoring needed --- .../keychain/ui/ImportKeysActivity.java | 67 +++++++------------ .../ui/adapter/ImportKeysAdapter.java | 29 ++++---- 2 files changed, 37 insertions(+), 59 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 c11b116cf..03668113c 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java @@ -343,9 +343,10 @@ public class ImportKeysActivity extends BaseActivity implements ImportKeysListen String keyserver = null; ArrayList keyList = null; - LoaderState loaderState = listFragment.getState(); Log.d(Constants.TAG, "importKey started"); + + LoaderState loaderState = listFragment.getState(); if (loaderState instanceof BytesLoaderState) { // instead of giving the entries by Intent extra, cache them into a // file to prevent Java Binder problems on heavy imports @@ -362,13 +363,15 @@ public class ImportKeysActivity extends BaseActivity implements ImportKeysListen return; } } else if (loaderState instanceof CloudLoaderState) { - //TODO + ArrayList keys = new ArrayList<>(); + keys.add(keyRing); + + keyList = keys; + keyserver = ((CloudLoaderState) loaderState).mCloudPrefs.keyserver; } ImportKeysOperationCallback callback = new ImportKeysOperationCallback(this, keyserver, keyList); - mOperationHelper = new CryptoOperationHelper(1, this, callback, R.string.progress_importing); - - mOperationHelper.cryptoOperation(); + new CryptoOperationHelper(1, this, callback, R.string.progress_importing).cryptoOperation(); } @Override @@ -381,48 +384,24 @@ public class ImportKeysActivity extends BaseActivity implements ImportKeysListen return; } - String keyserver = null; - ArrayList keyList = null; - LoaderState loaderState = listFragment.getState(); - Log.d(Constants.TAG, "importKeys started"); - if (loaderState instanceof BytesLoaderState) { - // instead of giving the entries by Intent extra, cache them into a - // file to prevent Java Binder problems on heavy imports - // read FileImportCache for more info. - try { - // We parcel this iteratively into a file - anything we can - // display here, we should be able to import. - ParcelableFileCache cache = - new ParcelableFileCache<>(this, ImportOperation.CACHE_FILE_NAME); - cache.writeCache(listFragment.getData()); - } catch (IOException e) { - Log.e(Constants.TAG, "Problem writing cache file", e); - Notify.create(this, "Problem writing cache file!", Notify.Style.ERROR).show(); - return; - } - } else if (loaderState instanceof CloudLoaderState) { - //TODO This need to be removed because it makes no sense to import "all" from cloud - CloudLoaderState sls = (CloudLoaderState) loaderState; - - // get selected key entries - ArrayList keys = new ArrayList<>(); - - // change the format into ParcelableKeyRing - List 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; + // instead of giving the entries by Intent extra, cache them into a + // file to prevent Java Binder problems on heavy imports + // read FileImportCache for more info. + try { + // We parcel this iteratively into a file - anything we can + // display here, we should be able to import. + ParcelableFileCache cache = + new ParcelableFileCache<>(this, ImportOperation.CACHE_FILE_NAME); + cache.writeCache(listFragment.getData()); + } catch (IOException e) { + Log.e(Constants.TAG, "Problem writing cache file", e); + Notify.create(this, "Problem writing cache file!", Notify.Style.ERROR).show(); + return; } - ImportKeysOperationCallback callback = new ImportKeysOperationCallback(this, keyserver, keyList); - mOperationHelper = new CryptoOperationHelper(1, this, callback, R.string.progress_importing); - - mOperationHelper.cryptoOperation(); + ImportKeysOperationCallback callback = new ImportKeysOperationCallback(this, null, null); + new CryptoOperationHelper(1, this, callback, R.string.progress_importing).cryptoOperation(); } @Override diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java index 1467a35c7..9373a5a7c 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java @@ -141,23 +141,10 @@ public class ImportKeysAdapter extends RecyclerView.Adapter