diff options
3 files changed, 167 insertions, 56 deletions
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 7db39af6f..c45a641e0 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptListFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptListFragment.java @@ -72,10 +72,14 @@ import org.openintents.openpgp.OpenPgpSignatureResult; import org.sufficientlysecure.keychain.BuildConfig; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing; +import org.sufficientlysecure.keychain.operations.results.ImportKeyResult; import org.sufficientlysecure.keychain.operations.results.InputDataResult; import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyInputParcel; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; +import org.sufficientlysecure.keychain.service.ImportKeyringParcel; import org.sufficientlysecure.keychain.service.InputDataParcel; +import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper; import org.sufficientlysecure.keychain.ui.base.QueueingCryptoOperationFragment; // this import NEEDS to be above the ViewModel AND SubViewHolder one, or it won't compile! (as of 16.09.15) import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils.StatusHolder; @@ -89,6 +93,7 @@ import org.sufficientlysecure.keychain.ui.util.Notify.Style; import org.sufficientlysecure.keychain.util.FileHelper; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.ParcelableHashMap; +import org.sufficientlysecure.keychain.util.Preferences; /** Displays a list of decrypted inputs. @@ -467,8 +472,9 @@ public class DecryptListFragment // un-cancel this one mCancelledInputUris.remove(uri); + mInputDataResults.remove(uri); mPendingInputUris.add(uri); - mAdapter.setCancelled(uri, false); + mAdapter.resetItemData(uri); // check if there are any pending input uris cryptoOperation(); @@ -729,6 +735,66 @@ public class DecryptListFragment return false; } + private void lookupUnknownKey(final Uri inputUri, long unknownKeyId) { + + final ArrayList<ParcelableKeyRing> keyList; + final String keyserver; + + // search config + { + Preferences prefs = Preferences.getPreferences(getActivity()); + Preferences.CloudSearchPrefs cloudPrefs = + new Preferences.CloudSearchPrefs(true, true, prefs.getPreferredKeyserver()); + keyserver = cloudPrefs.keyserver; + } + + { + ParcelableKeyRing keyEntry = new ParcelableKeyRing(null, + KeyFormattingUtils.convertKeyIdToHex(unknownKeyId), null); + ArrayList<ParcelableKeyRing> selectedEntries = new ArrayList<>(); + selectedEntries.add(keyEntry); + + keyList = selectedEntries; + } + + CryptoOperationHelper.Callback<ImportKeyringParcel, ImportKeyResult> callback + = new CryptoOperationHelper.Callback<ImportKeyringParcel, ImportKeyResult>() { + + @Override + public ImportKeyringParcel createOperationInput() { + return new ImportKeyringParcel(keyList, keyserver); + } + + @Override + public void onCryptoOperationSuccess(ImportKeyResult result) { + retryUri(inputUri); + } + + @Override + public void onCryptoOperationCancelled() { + mAdapter.setProcessingKeyLookup(inputUri, false); + } + + @Override + public void onCryptoOperationError(ImportKeyResult result) { + result.createNotify(getActivity()).show(); + mAdapter.setProcessingKeyLookup(inputUri, false); + } + + @Override + public boolean onCryptoSetProgress(String msg, int progress, int max) { + return false; + } + }; + + mAdapter.setProcessingKeyLookup(inputUri, true); + + CryptoOperationHelper importOpHelper = new CryptoOperationHelper<>(2, this, callback, null); + importOpHelper.cryptoOperation(); + + } + + private void deleteFile(Activity activity, Uri uri) { // we can only ever delete a file once, if we got this far either it's gone or it will never work @@ -774,6 +840,7 @@ public class DecryptListFragment int mProgress, mMax; String mProgressMsg; OnClickListener mCancelled; + boolean mProcessingKeyLookup; ViewModel(Uri uri) { mInputUri = uri; @@ -782,7 +849,7 @@ public class DecryptListFragment mCancelled = null; } - void addResult(InputDataResult result) { + void setResult(InputDataResult result) { mResult = result; } @@ -802,6 +869,10 @@ public class DecryptListFragment mMax = max; } + void setProcessingKeyLookup(boolean processingKeyLookup) { + mProcessingKeyLookup = processingKeyLookup; + } + // Depends on inputUri only @Override public boolean equals(Object o) { @@ -870,17 +941,13 @@ public class DecryptListFragment } private void bindItemCancelled(ViewHolder holder, ViewModel model) { - if (holder.vAnimator.getDisplayedChild() != 3) { - holder.vAnimator.setDisplayedChild(3); - } + holder.vAnimator.setDisplayedChild(3); holder.vCancelledRetry.setOnClickListener(model.mCancelled); } private void bindItemProgress(ViewHolder holder, ViewModel model) { - if (holder.vAnimator.getDisplayedChild() != 0) { - holder.vAnimator.setDisplayedChild(0); - } + holder.vAnimator.setDisplayedChild(0); holder.vProgress.setProgress(model.mProgress); holder.vProgress.setMax(model.mMax); @@ -890,11 +957,10 @@ public class DecryptListFragment } private void bindItemSuccess(ViewHolder holder, final ViewModel model) { - if (holder.vAnimator.getDisplayedChild() != 1) { - holder.vAnimator.setDisplayedChild(1); - } + holder.vAnimator.setDisplayedChild(1); - KeyFormattingUtils.setStatus(getResources(), holder, model.mResult.mDecryptVerifyResult); + KeyFormattingUtils.setStatus(getResources(), holder, + model.mResult.mDecryptVerifyResult, model.mProcessingKeyLookup); int numFiles = model.mResult.getOutputUris().size(); holder.resizeFileList(numFiles, LayoutInflater.from(getActivity())); @@ -972,6 +1038,13 @@ public class DecryptListFragment activity.startActivity(intent); } }); + } else { + holder.vSignatureLayout.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View view) { + lookupUnknownKey(model.mInputUri, keyId); + } + }); } } @@ -1000,9 +1073,7 @@ public class DecryptListFragment } private void bindItemFailure(ViewHolder holder, final ViewModel model) { - if (holder.vAnimator.getDisplayedChild() != 2) { - holder.vAnimator.setDisplayedChild(2); - } + holder.vAnimator.setDisplayedChild(2); holder.vErrorMsg.setText(model.mResult.getLog().getLast().mType.getMsgId()); @@ -1067,14 +1138,28 @@ public class DecryptListFragment notifyItemChanged(pos); } - public void addResult(Uri uri, InputDataResult result) { + public void setProcessingKeyLookup(Uri uri, boolean processingKeyLookup) { + ViewModel newModel = new ViewModel(uri); + int pos = mDataset.indexOf(newModel); + mDataset.get(pos).setProcessingKeyLookup(processingKeyLookup); + notifyItemChanged(pos); + } + public void addResult(Uri uri, InputDataResult result) { ViewModel model = new ViewModel(uri); int pos = mDataset.indexOf(model); model = mDataset.get(pos); + model.setResult(result); + notifyItemChanged(pos); + } - model.addResult(result); - + public void resetItemData(Uri uri) { + ViewModel model = new ViewModel(uri); + int pos = mDataset.indexOf(model); + model = mDataset.get(pos); + model.setResult(null); + model.setCancelled(null); + model.setProcessingKeyLookup(false); notifyItemChanged(pos); } @@ -1098,7 +1183,7 @@ public class DecryptListFragment public View vSignatureLayout; public TextView vSignatureName; public TextView vSignatureMail; - public TextView vSignatureAction; + public ViewAnimator vSignatureAction; public View vContextMenu; public TextView vErrorMsg; @@ -1141,7 +1226,7 @@ public class DecryptListFragment vSignatureLayout = itemView.findViewById(R.id.result_signature_layout); vSignatureName = (TextView) itemView.findViewById(R.id.result_signature_name); vSignatureMail= (TextView) itemView.findViewById(R.id.result_signature_email); - vSignatureAction = (TextView) itemView.findViewById(R.id.result_signature_action); + vSignatureAction = (ViewAnimator) itemView.findViewById(R.id.result_signature_action); vFileList = (LinearLayout) itemView.findViewById(R.id.file_list); for (int i = 0; i < vFileList.getChildCount(); i++) { @@ -1205,7 +1290,7 @@ public class DecryptListFragment } @Override - public TextView getSignatureAction() { + public ViewAnimator getSignatureAction() { return vSignatureAction; } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/KeyFormattingUtils.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/KeyFormattingUtils.java index 9ab0db03e..b9b837d71 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/KeyFormattingUtils.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/KeyFormattingUtils.java @@ -28,6 +28,7 @@ import android.text.style.ForegroundColorSpan; import android.view.View; import android.widget.ImageView; import android.widget.TextView; +import android.widget.ViewAnimator; import org.openintents.openpgp.OpenPgpDecryptionResult; import org.openintents.openpgp.OpenPgpSignatureResult; @@ -440,14 +441,15 @@ public class KeyFormattingUtils { View getSignatureLayout(); TextView getSignatureUserName(); TextView getSignatureUserEmail(); - TextView getSignatureAction(); + ViewAnimator getSignatureAction(); boolean hasEncrypt(); } @SuppressWarnings("deprecation") // context.getDrawable is api lvl 21, need to use deprecated - public static void setStatus(Resources resources, StatusHolder holder, DecryptVerifyResult result) { + public static void setStatus(Resources resources, StatusHolder holder, DecryptVerifyResult result, + boolean processingkeyLookup) { if (holder.hasEncrypt()) { OpenPgpDecryptionResult decryptionResult = result.getDecryptionResult(); @@ -488,7 +490,7 @@ public class KeyFormattingUtils { OpenPgpSignatureResult signatureResult = result.getSignatureResult(); int sigText, sigIcon, sigColor; - int sigActionText, sigActionIcon; + int sigActionDisplayedChild; switch (signatureResult.getResult()) { @@ -500,8 +502,7 @@ public class KeyFormattingUtils { sigColor = R.color.key_flag_gray; // won't be used, but makes compiler happy - sigActionText = 0; - sigActionIcon = 0; + sigActionDisplayedChild = -1; break; } @@ -510,8 +511,7 @@ public class KeyFormattingUtils { sigIcon = R.drawable.status_signature_verified_cutout_24dp; sigColor = R.color.key_flag_green; - sigActionText = R.string.decrypt_result_action_show; - sigActionIcon = R.drawable.ic_vpn_key_grey_24dp; + sigActionDisplayedChild = 0; break; } @@ -520,8 +520,7 @@ public class KeyFormattingUtils { sigIcon = R.drawable.status_signature_unverified_cutout_24dp; sigColor = R.color.key_flag_orange; - sigActionText = R.string.decrypt_result_action_show; - sigActionIcon = R.drawable.ic_vpn_key_grey_24dp; + sigActionDisplayedChild = 0; break; } @@ -530,8 +529,7 @@ public class KeyFormattingUtils { sigIcon = R.drawable.status_signature_revoked_cutout_24dp; sigColor = R.color.key_flag_red; - sigActionText = R.string.decrypt_result_action_show; - sigActionIcon = R.drawable.ic_vpn_key_grey_24dp; + sigActionDisplayedChild = 0; break; } @@ -540,8 +538,7 @@ public class KeyFormattingUtils { sigIcon = R.drawable.status_signature_expired_cutout_24dp; sigColor = R.color.key_flag_red; - sigActionText = R.string.decrypt_result_action_show; - sigActionIcon = R.drawable.ic_vpn_key_grey_24dp; + sigActionDisplayedChild = 0; break; } @@ -550,8 +547,7 @@ public class KeyFormattingUtils { sigIcon = R.drawable.status_signature_unknown_cutout_24dp; sigColor = R.color.key_flag_red; - sigActionText = R.string.decrypt_result_action_Lookup; - sigActionIcon = R.drawable.ic_file_download_grey_24dp; + sigActionDisplayedChild = 1; break; } @@ -560,8 +556,7 @@ public class KeyFormattingUtils { sigIcon = R.drawable.status_signature_invalid_cutout_24dp; sigColor = R.color.key_flag_red; - sigActionText = R.string.decrypt_result_action_show; - sigActionIcon = R.drawable.ic_vpn_key_grey_24dp; + sigActionDisplayedChild = 0; break; } @@ -572,13 +567,17 @@ public class KeyFormattingUtils { sigColor = R.color.key_flag_red; // won't be used, but makes compiler happy - sigActionText = 0; - sigActionIcon = 0; + sigActionDisplayedChild = -1; break; } } + // possibly switch out "Lookup" button for progress bar + if (sigActionDisplayedChild == 1 && processingkeyLookup) { + sigActionDisplayedChild = 2; + } + int sigColorRes = resources.getColor(sigColor); holder.getSignatureStatusIcon().setColorFilter(sigColorRes, PorterDuff.Mode.SRC_IN); holder.getSignatureStatusIcon().setImageDrawable(resources.getDrawable(sigIcon)); @@ -591,9 +590,7 @@ public class KeyFormattingUtils { holder.getSignatureLayout().setVisibility(View.VISIBLE); - holder.getSignatureAction().setText(sigActionText); - holder.getSignatureAction().setCompoundDrawablesWithIntrinsicBounds( - 0, 0, sigActionIcon, 0); + holder.getSignatureAction().setDisplayedChild(sigActionDisplayedChild); String userId = result.getSignatureResult().getPrimaryUserId(); KeyRing.UserId userIdSplit = KeyRing.splitUserId(userId); diff --git a/OpenKeychain/src/main/res/layout/decrypt_list_entry.xml b/OpenKeychain/src/main/res/layout/decrypt_list_entry.xml index 4a79f0ccd..8bdfce733 100644 --- a/OpenKeychain/src/main/res/layout/decrypt_list_entry.xml +++ b/OpenKeychain/src/main/res/layout/decrypt_list_entry.xml @@ -26,7 +26,6 @@ android:measureAllChildren="false" custom:initialView="1" android:minHeight="?listPreferredItemHeightSmall" - android:animateLayoutChanges="true" > <LinearLayout @@ -113,6 +112,7 @@ android:id="@+id/result_signature_icon" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_gravity="center_vertical" android:padding="4dp" android:src="@drawable/status_signature_unverified_cutout_24dp" /> @@ -136,6 +136,7 @@ android:clickable="true" android:background="?android:selectableItemBackground" android:orientation="horizontal" + android:minHeight="40dp" > <LinearLayout @@ -144,7 +145,7 @@ android:layout_weight="1" android:paddingRight="4dp" android:paddingLeft="4dp" - android:gravity="center_vertical" + android:layout_gravity="center_vertical" android:orientation="vertical"> <TextView @@ -162,6 +163,8 @@ android:layout_height="wrap_content" android:gravity="center_vertical" android:text="" + android:singleLine="true" + android:ellipsize="end" tools:text="alice@example.com" /> </LinearLayout> @@ -174,19 +177,45 @@ android:layout_marginTop="8dp" android:background="?android:attr/listDivider" /> - <TextView - android:id="@+id/result_signature_action" - android:paddingLeft="8dp" - android:paddingRight="8dp" - android:textAppearance="?android:attr/textAppearanceMedium" + <org.sufficientlysecure.keychain.ui.widget.ToolableViewAnimator android:layout_width="wrap_content" android:layout_height="match_parent" - android:drawableRight="@drawable/ic_vpn_key_grey_24dp" - android:drawablePadding="8dp" - android:gravity="center_vertical" - android:text="" - tools:text="Show" - /> + android:paddingLeft="8dp" + android:paddingRight="8dp" + android:id="@+id/result_signature_action" + android:measureAllChildren="true" + android:inAnimation="@anim/fade_in" + android:outAnimation="@anim/fade_out" + custom:initialView="0" + > + + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:textAppearance="?android:attr/textAppearanceMedium" + android:drawableRight="@drawable/ic_vpn_key_grey_24dp" + android:drawablePadding="8dp" + android:text="@string/decrypt_result_action_show" + /> + + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:textAppearance="?android:attr/textAppearanceMedium" + android:drawableRight="@drawable/ic_file_download_grey_24dp" + android:drawablePadding="8dp" + android:text="@string/decrypt_result_action_Lookup" + /> + + <ProgressBar + android:layout_width="30dp" + android:layout_height="30dp" + android:padding="4dp" + android:layout_gravity="center" /> + + </org.sufficientlysecure.keychain.ui.widget.ToolableViewAnimator> </LinearLayout> |