From f102ae5da5394f63298ed0c49195de8baf496bf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Wed, 6 May 2015 03:26:42 +0200 Subject: [PATCH] Move error overlay into generalized DecryptFragment, better error handling in DecryptTextActivity --- .../keychain/ui/DecryptFilesFragment.java | 5 +- .../keychain/ui/DecryptFragment.java | 43 +++- .../keychain/ui/DecryptTextActivity.java | 19 +- .../keychain/ui/DecryptTextFragment.java | 29 +-- .../main/res/layout/decrypt_file_fragment.xml | 212 +++++++++++------- 5 files changed, 186 insertions(+), 122 deletions(-) diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFilesFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFilesFragment.java index e5ddcbbd6..96af45dd2 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFilesFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFilesFragment.java @@ -31,6 +31,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.CheckBox; +import android.widget.LinearLayout; import android.widget.TextView; import org.sufficientlysecure.keychain.Constants; @@ -232,7 +233,6 @@ public class DecryptFilesFragment extends DecryptFragment { returnData.getParcelable(DecryptVerifyResult.EXTRA_RESULT); if (pgpResult.success()) { - switch (mCurrentCryptoOperation) { case KeychainIntentService.ACTION_DECRYPT_METADATA: { askForOutputFilename(pgpResult.getDecryptMetadata().getFilename()); @@ -264,9 +264,8 @@ public class DecryptFilesFragment extends DecryptFragment { break; } } - } else { - pgpResult.createNotify(getActivity()).show(); } + pgpResult.createNotify(getActivity()).show(DecryptFilesFragment.this); } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java index 230f478ae..c5f9821d3 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java @@ -30,6 +30,7 @@ import android.support.v4.content.CursorLoader; import android.support.v4.content.Loader; import android.util.Log; import android.view.View; +import android.widget.Button; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; @@ -61,17 +62,18 @@ public abstract class DecryptFragment extends CryptoOperationFragment implements public static final int LOADER_ID_UNIFIED = 0; protected LinearLayout mResultLayout; - protected ImageView mEncryptionIcon; protected TextView mEncryptionText; protected ImageView mSignatureIcon; protected TextView mSignatureText; - protected View mSignatureLayout; protected TextView mSignatureName; protected TextView mSignatureEmail; protected TextView mSignatureAction; + private LinearLayout mContentLayout; + private LinearLayout mErrorOverlayLayout; + private OpenPgpSignatureResult mSignatureResult; @Override @@ -81,7 +83,6 @@ public abstract class DecryptFragment extends CryptoOperationFragment implements // NOTE: These views are inside the activity! mResultLayout = (LinearLayout) getActivity().findViewById(R.id.result_main_layout); mResultLayout.setVisibility(View.GONE); - mEncryptionIcon = (ImageView) getActivity().findViewById(R.id.result_encryption_icon); mEncryptionText = (TextView) getActivity().findViewById(R.id.result_encryption_text); mSignatureIcon = (ImageView) getActivity().findViewById(R.id.result_signature_icon); @@ -90,6 +91,18 @@ public abstract class DecryptFragment extends CryptoOperationFragment implements mSignatureName = (TextView) getActivity().findViewById(R.id.result_signature_name); mSignatureEmail = (TextView) getActivity().findViewById(R.id.result_signature_email); mSignatureAction = (TextView) getActivity().findViewById(R.id.result_signature_action); + + // Overlay + mContentLayout = (LinearLayout) view.findViewById(R.id.decrypt_content); + mErrorOverlayLayout = (LinearLayout) view.findViewById(R.id.decrypt_error_overlay); + Button vErrorOverlayButton = (Button) view.findViewById(R.id.decrypt_error_overlay_button); + vErrorOverlayButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + mErrorOverlayLayout.setVisibility(View.GONE); + mContentLayout.setVisibility(View.VISIBLE); + } + }); } private void lookupUnknownKey(long unknownKeyId) { @@ -185,6 +198,9 @@ public abstract class DecryptFragment extends CryptoOperationFragment implements getLoaderManager().destroyLoader(LOADER_ID_UNIFIED); + mErrorOverlayLayout.setVisibility(View.GONE); + mContentLayout.setVisibility(View.VISIBLE); + onVerifyLoaded(true); return; @@ -285,6 +301,9 @@ public abstract class DecryptFragment extends CryptoOperationFragment implements setSignatureLayoutVisibility(View.VISIBLE); setShowAction(signatureKeyId); + mErrorOverlayLayout.setVisibility(View.VISIBLE); + mContentLayout.setVisibility(View.GONE); + onVerifyLoaded(false); } else if (isExpired) { @@ -294,6 +313,9 @@ public abstract class DecryptFragment extends CryptoOperationFragment implements setSignatureLayoutVisibility(View.VISIBLE); setShowAction(signatureKeyId); + mErrorOverlayLayout.setVisibility(View.GONE); + mContentLayout.setVisibility(View.VISIBLE); + onVerifyLoaded(true); } else if (isYours) { @@ -304,6 +326,9 @@ public abstract class DecryptFragment extends CryptoOperationFragment implements setSignatureLayoutVisibility(View.VISIBLE); setShowAction(signatureKeyId); + mErrorOverlayLayout.setVisibility(View.GONE); + mContentLayout.setVisibility(View.VISIBLE); + onVerifyLoaded(true); } else if (isVerified) { @@ -313,6 +338,9 @@ public abstract class DecryptFragment extends CryptoOperationFragment implements setSignatureLayoutVisibility(View.VISIBLE); setShowAction(signatureKeyId); + mErrorOverlayLayout.setVisibility(View.GONE); + mContentLayout.setVisibility(View.VISIBLE); + onVerifyLoaded(true); } else { @@ -322,6 +350,9 @@ public abstract class DecryptFragment extends CryptoOperationFragment implements setSignatureLayoutVisibility(View.VISIBLE); setShowAction(signatureKeyId); + mErrorOverlayLayout.setVisibility(View.GONE); + mContentLayout.setVisibility(View.VISIBLE); + onVerifyLoaded(true); } @@ -378,6 +409,9 @@ public abstract class DecryptFragment extends CryptoOperationFragment implements } }); + mErrorOverlayLayout.setVisibility(View.GONE); + mContentLayout.setVisibility(View.VISIBLE); + onVerifyLoaded(true); break; @@ -389,6 +423,9 @@ public abstract class DecryptFragment extends CryptoOperationFragment implements setSignatureLayoutVisibility(View.GONE); + mErrorOverlayLayout.setVisibility(View.VISIBLE); + mContentLayout.setVisibility(View.GONE); + onVerifyLoaded(false); break; } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptTextActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptTextActivity.java index e2f527cee..e2eba3947 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptTextActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptTextActivity.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012-2014 Dominik Schürmann + * Copyright (C) 2012-2015 Dominik Schürmann * Copyright (C) 2010-2014 Thialfihar * * This program is free software: you can redistribute it and/or modify @@ -23,16 +23,16 @@ import android.content.Intent; import android.os.Bundle; import android.text.TextUtils; import android.view.View; +import android.widget.Toast; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; -import org.sufficientlysecure.keychain.intents.OpenKeychainIntents; import org.sufficientlysecure.keychain.compatibility.ClipboardReflection; +import org.sufficientlysecure.keychain.intents.OpenKeychainIntents; import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.operations.results.SingletonResult; import org.sufficientlysecure.keychain.pgp.PgpHelper; import org.sufficientlysecure.keychain.ui.base.BaseActivity; -import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.util.Log; import java.util.regex.Matcher; @@ -138,8 +138,6 @@ public class DecryptTextActivity extends BaseActivity { /** * Handles all actions with this intent - * - * @param intent */ private void handleActions(Bundle savedInstanceState, Intent intent) { String action = intent.getAction(); @@ -162,10 +160,14 @@ public class DecryptTextActivity extends BaseActivity { if (sharedText != null) { loadFragment(savedInstanceState, sharedText); } else { - Notify.create(this, R.string.error_invalid_data, Notify.Style.ERROR).show(); + Log.e(Constants.TAG, "EXTRA_TEXT does not contain PGP content!"); + Toast.makeText(this, R.string.error_invalid_data, Toast.LENGTH_LONG).show(); + finish(); } } else { Log.e(Constants.TAG, "ACTION_SEND received non-plaintext, this should not happen in this activity!"); + Toast.makeText(this, R.string.error_invalid_data, Toast.LENGTH_LONG).show(); + finish(); } } else if (ACTION_DECRYPT_TEXT.equals(action)) { Log.d(Constants.TAG, "ACTION_DECRYPT_TEXT"); @@ -176,7 +178,9 @@ public class DecryptTextActivity extends BaseActivity { if (extraText != null) { loadFragment(savedInstanceState, extraText); } else { - Notify.create(this, R.string.error_invalid_data, Notify.Style.ERROR).show(); + Log.e(Constants.TAG, "EXTRA_TEXT does not contain PGP content!"); + Toast.makeText(this, R.string.error_invalid_data, Toast.LENGTH_LONG).show(); + finish(); } } else if (ACTION_DECRYPT_FROM_CLIPBOARD.equals(action)) { Log.d(Constants.TAG, "ACTION_DECRYPT_FROM_CLIPBOARD"); @@ -191,6 +195,7 @@ public class DecryptTextActivity extends BaseActivity { } } else if (ACTION_DECRYPT_TEXT.equals(action)) { Log.e(Constants.TAG, "Include the extra 'text' in your Intent!"); + Toast.makeText(this, R.string.error_invalid_data, Toast.LENGTH_LONG).show(); finish(); } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptTextFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptTextFragment.java index b8f1aee63..381da6f0d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptTextFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptTextFragment.java @@ -50,8 +50,6 @@ public class DecryptTextFragment extends DecryptFragment { public static final String ARG_CIPHERTEXT = "ciphertext"; // view - private LinearLayout mContentLayout; - private LinearLayout mErrorOverlayLayout; private TextView mText; // model @@ -78,19 +76,8 @@ public class DecryptTextFragment extends DecryptFragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.decrypt_text_fragment, container, false); - mContentLayout = (LinearLayout) view.findViewById(R.id.decrypt_content); - mErrorOverlayLayout = (LinearLayout) view.findViewById(R.id.decrypt_error_overlay); mText = (TextView) view.findViewById(R.id.decrypt_text_plaintext); - Button vErrorOverlayButton = (Button) view.findViewById(R.id.decrypt_error_overlay_button); - vErrorOverlayButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - mErrorOverlayLayout.setVisibility(View.GONE); - mContentLayout.setVisibility(View.VISIBLE); - } - }); - return view; } @@ -203,7 +190,6 @@ public class DecryptTextFragment extends DecryptFragment { returnData.getParcelable(DecryptVerifyResult.EXTRA_RESULT); if (pgpResult.success()) { - byte[] decryptedMessage = returnData .getByteArray(KeychainIntentService.RESULT_DECRYPTED_BYTES); String displayMessage; @@ -219,15 +205,12 @@ public class DecryptTextFragment extends DecryptFragment { } mText.setText(displayMessage); - pgpResult.createNotify(getActivity()).show(); - // display signature result in activity loadVerifyResult(pgpResult); - } else { - pgpResult.createNotify(getActivity()).show(); // TODO: show also invalid layout with different text? } + pgpResult.createNotify(getActivity()).show(DecryptTextFragment.this); } } }; @@ -245,17 +228,7 @@ public class DecryptTextFragment extends DecryptFragment { @Override protected void onVerifyLoaded(boolean hideErrorOverlay) { - mShowMenuOptions = hideErrorOverlay; getActivity().supportInvalidateOptionsMenu(); - - if (hideErrorOverlay) { - mErrorOverlayLayout.setVisibility(View.GONE); - mContentLayout.setVisibility(View.VISIBLE); - } else { - mErrorOverlayLayout.setVisibility(View.VISIBLE); - mContentLayout.setVisibility(View.GONE); - } - } } diff --git a/OpenKeychain/src/main/res/layout/decrypt_file_fragment.xml b/OpenKeychain/src/main/res/layout/decrypt_file_fragment.xml index 60673e475..8374c6aad 100644 --- a/OpenKeychain/src/main/res/layout/decrypt_file_fragment.xml +++ b/OpenKeychain/src/main/res/layout/decrypt_file_fragment.xml @@ -1,99 +1,149 @@ - + android:orientation="vertical"> - - - + android:scrollbars="vertical" + android:layout_height="0dp" + android:layout_weight="1"> - - - - - - - - - - - - - + android:orientation="vertical"> + android:layout_width="match_parent" + android:background="?android:attr/listDivider" /> - - + + + + + + + + + + + + + + + + + + + + + + + - \ No newline at end of file + + + + + + + + +