multi-decrypt: add cancelled state

This commit is contained in:
Vincent Breitmoser
2015-07-08 04:53:43 +02:00
parent 5633fcc92f
commit bf2dc8edc3
2 changed files with 69 additions and 2 deletions

View File

@@ -85,6 +85,7 @@ public class DecryptListFragment
public static final String ARG_INPUT_URIS = "input_uris"; public static final String ARG_INPUT_URIS = "input_uris";
public static final String ARG_OUTPUT_URIS = "output_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"; public static final String ARG_RESULTS = "results";
private static final int REQUEST_CODE_OUTPUT = 0x00007007; private static final int REQUEST_CODE_OUTPUT = 0x00007007;
@@ -92,6 +93,7 @@ public class DecryptListFragment
private ArrayList<Uri> mInputUris; private ArrayList<Uri> mInputUris;
private HashMap<Uri, Uri> mOutputUris; private HashMap<Uri, Uri> mOutputUris;
private ArrayList<Uri> mPendingInputUris; private ArrayList<Uri> mPendingInputUris;
private ArrayList<Uri> mCancelledInputUris;
private Uri mCurrentInputUri; private Uri mCurrentInputUri;
@@ -155,6 +157,7 @@ public class DecryptListFragment
outState.putParcelable(ARG_RESULTS, new ParcelableHashMap<>(results)); outState.putParcelable(ARG_RESULTS, new ParcelableHashMap<>(results));
outState.putParcelable(ARG_OUTPUT_URIS, new ParcelableHashMap<>(mOutputUris)); 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(); Bundle args = savedInstanceState != null ? savedInstanceState : getArguments();
ArrayList<Uri> inputUris = getArguments().getParcelableArrayList(ARG_INPUT_URIS); ArrayList<Uri> inputUris = getArguments().getParcelableArrayList(ARG_INPUT_URIS);
ArrayList<Uri> cancelledUris = args.getParcelableArrayList(ARG_CANCELLED_URIS);
ParcelableHashMap<Uri,Uri> outputUris = args.getParcelable(ARG_OUTPUT_URIS); ParcelableHashMap<Uri,Uri> outputUris = args.getParcelable(ARG_OUTPUT_URIS);
ParcelableHashMap<Uri,DecryptVerifyResult> results = args.getParcelable(ARG_RESULTS); ParcelableHashMap<Uri,DecryptVerifyResult> results = args.getParcelable(ARG_RESULTS);
displayInputUris(inputUris, displayInputUris(inputUris, cancelledUris,
outputUris != null ? outputUris.getMap() : null, outputUris != null ? outputUris.getMap() : null,
results != null ? results.getMap() : null results != null ? results.getMap() : null
); );
} }
private void displayInputUris(ArrayList<Uri> inputUris, HashMap<Uri,Uri> outputUris, private void displayInputUris(ArrayList<Uri> inputUris, ArrayList<Uri> cancelledUris,
HashMap<Uri,Uri> outputUris,
HashMap<Uri,DecryptVerifyResult> results) { HashMap<Uri,DecryptVerifyResult> results) {
mInputUris = inputUris; mInputUris = inputUris;
mOutputUris = outputUris != null ? outputUris : new HashMap<Uri,Uri>(inputUris.size()); mOutputUris = outputUris != null ? outputUris : new HashMap<Uri,Uri>(inputUris.size());
mCancelledInputUris = cancelledUris != null ? cancelledUris : new ArrayList<Uri>();
mPendingInputUris = new ArrayList<>(); mPendingInputUris = new ArrayList<>();
for (Uri uri : inputUris) { for (Uri uri : inputUris) {
mAdapter.add(uri); mAdapter.add(uri);
if (mCancelledInputUris.contains(uri)) {
mAdapter.setCancelled(uri);
continue;
}
if (results != null && results.containsKey(uri)) { if (results != null && results.containsKey(uri)) {
processResult(uri, results.get(uri)); processResult(uri, results.get(uri));
} else { } else {
@@ -247,6 +259,7 @@ public class DecryptListFragment
mAdapter.setProgress(mCurrentInputUri, progress, max, msg); mAdapter.setProgress(mCurrentInputUri, progress, max, msg);
return true; return true;
} }
@Override @Override
public void onQueuedOperationError(DecryptVerifyResult result) { public void onQueuedOperationError(DecryptVerifyResult result) {
final Uri uri = mCurrentInputUri; final Uri uri = mCurrentInputUri;
@@ -267,6 +280,20 @@ public class DecryptListFragment
cryptoOperation(); 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) { private void processResult(final Uri uri, final DecryptVerifyResult result) {
new AsyncTask<Void, Void, Drawable>() { new AsyncTask<Void, Void, Drawable>() {
@@ -528,12 +555,14 @@ public class DecryptListFragment
int mProgress, mMax; int mProgress, mMax;
String mProgressMsg; String mProgressMsg;
boolean mCancelled;
ViewModel(Context context, Uri uri) { ViewModel(Context context, Uri uri) {
mContext = context; mContext = context;
mInputUri = uri; mInputUri = uri;
mProgress = 0; mProgress = 0;
mMax = 100; mMax = 100;
mCancelled = false;
} }
void addResult(DecryptVerifyResult result) { void addResult(DecryptVerifyResult result) {
@@ -553,6 +582,10 @@ public class DecryptListFragment
return mResult != null; return mResult != null;
} }
void setCancelled(boolean cancelled) {
mCancelled = cancelled;
}
void setProgress(int progress, int max, String msg) { void setProgress(int progress, int max, String msg) {
if (msg != null) { if (msg != null) {
mProgressMsg = msg; mProgressMsg = msg;
@@ -610,6 +643,13 @@ public class DecryptListFragment
// - replace the contents of the view with that element // - replace the contents of the view with that element
final ViewModel model = mDataset.get(position); final ViewModel model = mDataset.get(position);
if (model.mCancelled) {
if (holder.vAnimator.getDisplayedChild() != 3) {
holder.vAnimator.setDisplayedChild(3);
}
return;
}
if (!model.hasResult()) { if (!model.hasResult()) {
bindItemProgress(holder, model); bindItemProgress(holder, model);
return; return;
@@ -738,6 +778,13 @@ public class DecryptListFragment
notifyItemChanged(pos); 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, public void addResult(Uri uri, DecryptVerifyResult result, Drawable icon,
OnClickListener onFileClick, OnClickListener onKeyClick) { OnClickListener onFileClick, OnClickListener onKeyClick) {

View File

@@ -286,6 +286,26 @@
</LinearLayout> </LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:layout_gravity="center_vertical"
android:drawablePadding="12dp"
android:text="@string/msg_cancelled"
android:drawableLeft="@drawable/status_signature_invalid_cutout_24dp"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
</LinearLayout>
</org.sufficientlysecure.keychain.ui.widget.ToolableViewAnimator> </org.sufficientlysecure.keychain.ui.widget.ToolableViewAnimator>
</android.support.v7.widget.CardView> </android.support.v7.widget.CardView>