ImportKeys: Add import single key from cloud
- Refactoring needed
This commit is contained in:
@@ -343,9 +343,10 @@ public class ImportKeysActivity extends BaseActivity implements ImportKeysListen
|
|||||||
|
|
||||||
String keyserver = null;
|
String keyserver = null;
|
||||||
ArrayList<ParcelableKeyRing> keyList = null;
|
ArrayList<ParcelableKeyRing> keyList = null;
|
||||||
LoaderState loaderState = listFragment.getState();
|
|
||||||
|
|
||||||
Log.d(Constants.TAG, "importKey started");
|
Log.d(Constants.TAG, "importKey started");
|
||||||
|
|
||||||
|
LoaderState loaderState = listFragment.getState();
|
||||||
if (loaderState instanceof BytesLoaderState) {
|
if (loaderState instanceof BytesLoaderState) {
|
||||||
// instead of giving the entries by Intent extra, cache them into a
|
// instead of giving the entries by Intent extra, cache them into a
|
||||||
// file to prevent Java Binder problems on heavy imports
|
// file to prevent Java Binder problems on heavy imports
|
||||||
@@ -362,13 +363,15 @@ public class ImportKeysActivity extends BaseActivity implements ImportKeysListen
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (loaderState instanceof CloudLoaderState) {
|
} else if (loaderState instanceof CloudLoaderState) {
|
||||||
//TODO
|
ArrayList<ParcelableKeyRing> keys = new ArrayList<>();
|
||||||
|
keys.add(keyRing);
|
||||||
|
|
||||||
|
keyList = keys;
|
||||||
|
keyserver = ((CloudLoaderState) loaderState).mCloudPrefs.keyserver;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImportKeysOperationCallback callback = new ImportKeysOperationCallback(this, keyserver, keyList);
|
ImportKeysOperationCallback callback = new ImportKeysOperationCallback(this, keyserver, keyList);
|
||||||
mOperationHelper = new CryptoOperationHelper(1, this, callback, R.string.progress_importing);
|
new CryptoOperationHelper(1, this, callback, R.string.progress_importing).cryptoOperation();
|
||||||
|
|
||||||
mOperationHelper.cryptoOperation();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -381,48 +384,24 @@ public class ImportKeysActivity extends BaseActivity implements ImportKeysListen
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String keyserver = null;
|
|
||||||
ArrayList<ParcelableKeyRing> keyList = null;
|
|
||||||
LoaderState loaderState = listFragment.getState();
|
|
||||||
|
|
||||||
Log.d(Constants.TAG, "importKeys started");
|
Log.d(Constants.TAG, "importKeys started");
|
||||||
if (loaderState instanceof BytesLoaderState) {
|
// instead of giving the entries by Intent extra, cache them into a
|
||||||
// instead of giving the entries by Intent extra, cache them into a
|
// file to prevent Java Binder problems on heavy imports
|
||||||
// file to prevent Java Binder problems on heavy imports
|
// read FileImportCache for more info.
|
||||||
// read FileImportCache for more info.
|
try {
|
||||||
try {
|
// We parcel this iteratively into a file - anything we can
|
||||||
// We parcel this iteratively into a file - anything we can
|
// display here, we should be able to import.
|
||||||
// display here, we should be able to import.
|
ParcelableFileCache<ParcelableKeyRing> cache =
|
||||||
ParcelableFileCache<ParcelableKeyRing> cache =
|
new ParcelableFileCache<>(this, ImportOperation.CACHE_FILE_NAME);
|
||||||
new ParcelableFileCache<>(this, ImportOperation.CACHE_FILE_NAME);
|
cache.writeCache(listFragment.getData());
|
||||||
cache.writeCache(listFragment.getData());
|
} catch (IOException e) {
|
||||||
} catch (IOException e) {
|
Log.e(Constants.TAG, "Problem writing cache file", e);
|
||||||
Log.e(Constants.TAG, "Problem writing cache file", e);
|
Notify.create(this, "Problem writing cache file!", Notify.Style.ERROR).show();
|
||||||
Notify.create(this, "Problem writing cache file!", Notify.Style.ERROR).show();
|
return;
|
||||||
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<ParcelableKeyRing> keys = new ArrayList<>();
|
|
||||||
|
|
||||||
// change the format into ParcelableKeyRing
|
|
||||||
List<ImportKeysListEntry> 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);
|
ImportKeysOperationCallback callback = new ImportKeysOperationCallback(this, null, null);
|
||||||
mOperationHelper = new CryptoOperationHelper(1, this, callback, R.string.progress_importing);
|
new CryptoOperationHelper(1, this, callback, R.string.progress_importing).cryptoOperation();
|
||||||
|
|
||||||
mOperationHelper.cryptoOperation();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -141,23 +141,10 @@ public class ImportKeysAdapter extends RecyclerView.Adapter<ImportKeysAdapter.Vi
|
|||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(ViewHolder holder, int position) {
|
public void onBindViewHolder(ViewHolder holder, int position) {
|
||||||
final ImportKeysListEntry entry = mData.get(position);
|
final ImportKeysListEntry entry = mData.get(position);
|
||||||
|
String userId = entry.getUserIds().get(0); // main user id
|
||||||
holder.importButton.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
if (mLoaderState instanceof BytesLoaderState) {
|
|
||||||
mListener.importKey(new ParcelableKeyRing(entry.getEncodedRing()));
|
|
||||||
} else if (mLoaderState instanceof CloudLoaderState) {
|
|
||||||
//TODO
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Highlighter highlighter = new Highlighter(mContext, entry.getQuery());
|
|
||||||
// main user id
|
|
||||||
String userId = entry.getUserIds().get(0);
|
|
||||||
OpenPgpUtils.UserId userIdSplit = KeyRing.splitUserId(userId);
|
OpenPgpUtils.UserId userIdSplit = KeyRing.splitUserId(userId);
|
||||||
|
|
||||||
|
Highlighter highlighter = new Highlighter(mContext, entry.getQuery());
|
||||||
// name
|
// name
|
||||||
if (userIdSplit.name != null) {
|
if (userIdSplit.name != null) {
|
||||||
// show red user id if it is a secret key
|
// show red user id if it is a secret key
|
||||||
@@ -283,6 +270,18 @@ public class ImportKeysAdapter extends RecyclerView.Adapter<ImportKeysAdapter.Vi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
holder.importButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
if (mLoaderState instanceof BytesLoaderState) {
|
||||||
|
mListener.importKey(new ParcelableKeyRing(entry.getEncodedRing()));
|
||||||
|
} else if (mLoaderState instanceof CloudLoaderState) {
|
||||||
|
mListener.importKey(new ParcelableKeyRing(entry.getFingerprintHex(), entry.getKeyIdHex(),
|
||||||
|
entry.getKeybaseName(), entry.getFbUsername()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user