multi-decrypt: add retry mechanism

This commit is contained in:
Vincent Breitmoser
2015-07-08 05:15:52 +02:00
parent bf2dc8edc3
commit 9eee9acba2
2 changed files with 63 additions and 15 deletions

View File

@@ -188,11 +188,16 @@ public class DecryptListFragment
mPendingInputUris = new ArrayList<>(); mPendingInputUris = new ArrayList<>();
for (Uri uri : inputUris) { for (final Uri uri : inputUris) {
mAdapter.add(uri); mAdapter.add(uri);
if (mCancelledInputUris.contains(uri)) { if (mCancelledInputUris.contains(uri)) {
mAdapter.setCancelled(uri); mAdapter.setCancelled(uri, new OnClickListener() {
@Override
public void onClick(View v) {
retryUri(uri);
}
});
continue; continue;
} }
@@ -284,11 +289,16 @@ public class DecryptListFragment
public void onCryptoOperationCancelled() { public void onCryptoOperationCancelled() {
super.onCryptoOperationCancelled(); super.onCryptoOperationCancelled();
Uri uri = mCurrentInputUri; final Uri uri = mCurrentInputUri;
mCurrentInputUri = null; mCurrentInputUri = null;
mCancelledInputUris.add(uri); mCancelledInputUris.add(uri);
mAdapter.setCancelled(uri); mAdapter.setCancelled(uri, new OnClickListener() {
@Override
public void onClick(View v) {
retryUri(uri);
}
});
cryptoOperation(); cryptoOperation();
@@ -377,6 +387,22 @@ public class DecryptListFragment
} }
public void retryUri(Uri uri) {
// never interrupt running operations!
if (mCurrentInputUri != null) {
return;
}
// un-cancel this one
mCancelledInputUris.remove(uri);
mPendingInputUris.add(uri);
mAdapter.setCancelled(uri, null);
cryptoOperation();
}
public void displayWithViewIntent(final Uri uri) { public void displayWithViewIntent(final Uri uri) {
Activity activity = getActivity(); Activity activity = getActivity();
if (activity == null || mCurrentInputUri != null) { if (activity == null || mCurrentInputUri != null) {
@@ -555,14 +581,14 @@ public class DecryptListFragment
int mProgress, mMax; int mProgress, mMax;
String mProgressMsg; String mProgressMsg;
boolean mCancelled; OnClickListener 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; mCancelled = null;
} }
void addResult(DecryptVerifyResult result) { void addResult(DecryptVerifyResult result) {
@@ -582,8 +608,8 @@ public class DecryptListFragment
return mResult != null; return mResult != null;
} }
void setCancelled(boolean cancelled) { void setCancelled(OnClickListener retryListener) {
mCancelled = cancelled; mCancelled = retryListener;
} }
void setProgress(int progress, int max, String msg) { void setProgress(int progress, int max, String msg) {
@@ -643,10 +669,8 @@ 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 (model.mCancelled != null) {
if (holder.vAnimator.getDisplayedChild() != 3) { bindItemCancelled(holder, model);
holder.vAnimator.setDisplayedChild(3);
}
return; return;
} }
@@ -663,6 +687,14 @@ public class DecryptListFragment
} }
private void bindItemCancelled(ViewHolder holder, ViewModel model) {
if (holder.vAnimator.getDisplayedChild() != 3) {
holder.vAnimator.setDisplayedChild(3);
}
holder.vCancelledRetry.setOnClickListener(model.mCancelled);
}
private void bindItemProgress(ViewHolder holder, ViewModel model) { private void bindItemProgress(ViewHolder holder, ViewModel model) {
if (holder.vAnimator.getDisplayedChild() != 0) { if (holder.vAnimator.getDisplayedChild() != 0) {
holder.vAnimator.setDisplayedChild(0); holder.vAnimator.setDisplayedChild(0);
@@ -778,10 +810,10 @@ public class DecryptListFragment
notifyItemChanged(pos); notifyItemChanged(pos);
} }
public void setCancelled(Uri uri) { public void setCancelled(Uri uri, OnClickListener retryListener) {
ViewModel newModel = new ViewModel(mContext, uri); ViewModel newModel = new ViewModel(mContext, uri);
int pos = mDataset.indexOf(newModel); int pos = mDataset.indexOf(newModel);
mDataset.get(pos).setCancelled(true); mDataset.get(pos).setCancelled(retryListener);
notifyItemChanged(pos); notifyItemChanged(pos);
} }
@@ -832,6 +864,8 @@ public class DecryptListFragment
public TextView vErrorMsg; public TextView vErrorMsg;
public ImageView vErrorViewLog; public ImageView vErrorViewLog;
public ImageView vCancelledRetry;
public ViewHolder(View itemView) { public ViewHolder(View itemView) {
super(itemView); super(itemView);
@@ -860,6 +894,8 @@ public class DecryptListFragment
vErrorMsg = (TextView) itemView.findViewById(R.id.result_error_msg); vErrorMsg = (TextView) itemView.findViewById(R.id.result_error_msg);
vErrorViewLog = (ImageView) itemView.findViewById(R.id.result_error_log); vErrorViewLog = (ImageView) itemView.findViewById(R.id.result_error_log);
vCancelledRetry = (ImageView) itemView.findViewById(R.id.cancel_retry);
} }
@Override @Override

View File

@@ -293,8 +293,9 @@
android:orientation="horizontal"> android:orientation="horizontal">
<TextView <TextView
android:layout_width="match_parent" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="8dp" android:layout_marginLeft="8dp"
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
@@ -304,6 +305,17 @@
android:textAppearance="?android:attr/textAppearanceMedium" android:textAppearance="?android:attr/textAppearanceMedium"
/> />
<ImageView
android:id="@+id/cancel_retry"
android:scaleType="center"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:clickable="true"
android:padding="6dp"
android:background="?android:selectableItemBackground"
android:src="@drawable/ic_repeat_grey_24dp"
android:layout_gravity="center_vertical" />
</LinearLayout> </LinearLayout>
</org.sufficientlysecure.keychain.ui.widget.ToolableViewAnimator> </org.sufficientlysecure.keychain.ui.widget.ToolableViewAnimator>