From bf2dc8edc3e78ce8279571c2d82253fe5bede1b1 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Wed, 8 Jul 2015 04:53:43 +0200 Subject: multi-decrypt: add cancelled state --- .../keychain/ui/DecryptListFragment.java | 51 +++++++++++++++++++++- .../src/main/res/layout/decrypt_list_entry.xml | 20 +++++++++ 2 files changed, 69 insertions(+), 2 deletions(-) (limited to 'OpenKeychain') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptListFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptListFragment.java index b38968753..0222cc617 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptListFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptListFragment.java @@ -85,6 +85,7 @@ public class DecryptListFragment public static final String ARG_INPUT_URIS = "input_uris"; public static final String ARG_OUTPUT_URIS = "output_uris"; + public static final String ARG_CANCELLED_URIS = "cancelled_uris"; public static final String ARG_RESULTS = "results"; private static final int REQUEST_CODE_OUTPUT = 0x00007007; @@ -92,6 +93,7 @@ public class DecryptListFragment private ArrayList mInputUris; private HashMap mOutputUris; private ArrayList mPendingInputUris; + private ArrayList mCancelledInputUris; private Uri mCurrentInputUri; @@ -155,6 +157,7 @@ public class DecryptListFragment outState.putParcelable(ARG_RESULTS, new ParcelableHashMap<>(results)); outState.putParcelable(ARG_OUTPUT_URIS, new ParcelableHashMap<>(mOutputUris)); + outState.putParcelableArrayList(ARG_CANCELLED_URIS, mCancelledInputUris); } @@ -165,25 +168,34 @@ public class DecryptListFragment Bundle args = savedInstanceState != null ? savedInstanceState : getArguments(); ArrayList inputUris = getArguments().getParcelableArrayList(ARG_INPUT_URIS); + ArrayList cancelledUris = args.getParcelableArrayList(ARG_CANCELLED_URIS); ParcelableHashMap outputUris = args.getParcelable(ARG_OUTPUT_URIS); ParcelableHashMap results = args.getParcelable(ARG_RESULTS); - displayInputUris(inputUris, + displayInputUris(inputUris, cancelledUris, outputUris != null ? outputUris.getMap() : null, results != null ? results.getMap() : null ); } - private void displayInputUris(ArrayList inputUris, HashMap outputUris, + private void displayInputUris(ArrayList inputUris, ArrayList cancelledUris, + HashMap outputUris, HashMap results) { mInputUris = inputUris; mOutputUris = outputUris != null ? outputUris : new HashMap(inputUris.size()); + mCancelledInputUris = cancelledUris != null ? cancelledUris : new ArrayList(); mPendingInputUris = new ArrayList<>(); for (Uri uri : inputUris) { mAdapter.add(uri); + + if (mCancelledInputUris.contains(uri)) { + mAdapter.setCancelled(uri); + continue; + } + if (results != null && results.containsKey(uri)) { processResult(uri, results.get(uri)); } else { @@ -247,6 +259,7 @@ public class DecryptListFragment mAdapter.setProgress(mCurrentInputUri, progress, max, msg); return true; } + @Override public void onQueuedOperationError(DecryptVerifyResult result) { final Uri uri = mCurrentInputUri; @@ -267,6 +280,20 @@ public class DecryptListFragment cryptoOperation(); } + @Override + public void onCryptoOperationCancelled() { + super.onCryptoOperationCancelled(); + + Uri uri = mCurrentInputUri; + mCurrentInputUri = null; + + mCancelledInputUris.add(uri); + mAdapter.setCancelled(uri); + + cryptoOperation(); + + } + private void processResult(final Uri uri, final DecryptVerifyResult result) { new AsyncTask() { @@ -528,12 +555,14 @@ public class DecryptListFragment int mProgress, mMax; String mProgressMsg; + boolean mCancelled; ViewModel(Context context, Uri uri) { mContext = context; mInputUri = uri; mProgress = 0; mMax = 100; + mCancelled = false; } void addResult(DecryptVerifyResult result) { @@ -553,6 +582,10 @@ public class DecryptListFragment return mResult != null; } + void setCancelled(boolean cancelled) { + mCancelled = cancelled; + } + void setProgress(int progress, int max, String msg) { if (msg != null) { mProgressMsg = msg; @@ -610,6 +643,13 @@ public class DecryptListFragment // - replace the contents of the view with that element final ViewModel model = mDataset.get(position); + if (model.mCancelled) { + if (holder.vAnimator.getDisplayedChild() != 3) { + holder.vAnimator.setDisplayedChild(3); + } + return; + } + if (!model.hasResult()) { bindItemProgress(holder, model); return; @@ -738,6 +778,13 @@ public class DecryptListFragment notifyItemChanged(pos); } + public void setCancelled(Uri uri) { + ViewModel newModel = new ViewModel(mContext, uri); + int pos = mDataset.indexOf(newModel); + mDataset.get(pos).setCancelled(true); + notifyItemChanged(pos); + } + public void addResult(Uri uri, DecryptVerifyResult result, Drawable icon, OnClickListener onFileClick, OnClickListener onKeyClick) { diff --git a/OpenKeychain/src/main/res/layout/decrypt_list_entry.xml b/OpenKeychain/src/main/res/layout/decrypt_list_entry.xml index d58542e62..4c4e75834 100644 --- a/OpenKeychain/src/main/res/layout/decrypt_list_entry.xml +++ b/OpenKeychain/src/main/res/layout/decrypt_list_entry.xml @@ -286,6 +286,26 @@ + + + + + + \ No newline at end of file -- cgit v1.2.3