mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-27 11:12:15 -05:00
preserve state in DecryptTextActivity
This commit is contained in:
parent
34c26fe5d1
commit
1deb5dbfda
@ -60,6 +60,7 @@ public abstract class DecryptFragment extends CryptoOperationFragment implements
|
|||||||
LoaderManager.LoaderCallbacks<Cursor> {
|
LoaderManager.LoaderCallbacks<Cursor> {
|
||||||
|
|
||||||
public static final int LOADER_ID_UNIFIED = 0;
|
public static final int LOADER_ID_UNIFIED = 0;
|
||||||
|
public static final String ARG_DECRYPT_VERIFY_RESULT = "decrypt_verify_result";
|
||||||
|
|
||||||
protected LinearLayout mResultLayout;
|
protected LinearLayout mResultLayout;
|
||||||
protected ImageView mEncryptionIcon;
|
protected ImageView mEncryptionIcon;
|
||||||
@ -75,6 +76,7 @@ public abstract class DecryptFragment extends CryptoOperationFragment implements
|
|||||||
private LinearLayout mErrorOverlayLayout;
|
private LinearLayout mErrorOverlayLayout;
|
||||||
|
|
||||||
private OpenPgpSignatureResult mSignatureResult;
|
private OpenPgpSignatureResult mSignatureResult;
|
||||||
|
private DecryptVerifyResult mDecryptVerifyResult;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||||
@ -105,6 +107,27 @@ public abstract class DecryptFragment extends CryptoOperationFragment implements
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSaveInstanceState(Bundle outState) {
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
|
|
||||||
|
outState.putParcelable(ARG_DECRYPT_VERIFY_RESULT, mDecryptVerifyResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onViewStateRestored(Bundle savedInstanceState) {
|
||||||
|
super.onViewStateRestored(savedInstanceState);
|
||||||
|
|
||||||
|
if (savedInstanceState == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DecryptVerifyResult result = savedInstanceState.getParcelable(ARG_DECRYPT_VERIFY_RESULT);
|
||||||
|
if (result != null) {
|
||||||
|
loadVerifyResult(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void lookupUnknownKey(long unknownKeyId) {
|
private void lookupUnknownKey(long unknownKeyId) {
|
||||||
|
|
||||||
// Message is received after importing is done in KeychainIntentService
|
// Message is received after importing is done in KeychainIntentService
|
||||||
@ -183,7 +206,9 @@ public abstract class DecryptFragment extends CryptoOperationFragment implements
|
|||||||
*/
|
*/
|
||||||
protected void loadVerifyResult(DecryptVerifyResult decryptVerifyResult) {
|
protected void loadVerifyResult(DecryptVerifyResult decryptVerifyResult) {
|
||||||
|
|
||||||
|
mDecryptVerifyResult = decryptVerifyResult;
|
||||||
mSignatureResult = decryptVerifyResult.getSignatureResult();
|
mSignatureResult = decryptVerifyResult.getSignatureResult();
|
||||||
|
|
||||||
mResultLayout.setVisibility(View.VISIBLE);
|
mResultLayout.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
// unsigned data
|
// unsigned data
|
||||||
|
@ -21,6 +21,7 @@ package org.sufficientlysecure.keychain.ui;
|
|||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
@ -46,8 +47,6 @@ public class DecryptTextActivity extends BaseActivity {
|
|||||||
// intern
|
// intern
|
||||||
public static final String ACTION_DECRYPT_FROM_CLIPBOARD = Constants.INTENT_PREFIX + "DECRYPT_TEXT_FROM_CLIPBOARD";
|
public static final String ACTION_DECRYPT_FROM_CLIPBOARD = Constants.INTENT_PREFIX + "DECRYPT_TEXT_FROM_CLIPBOARD";
|
||||||
|
|
||||||
DecryptTextFragment mFragment;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@ -148,6 +147,10 @@ public class DecryptTextActivity extends BaseActivity {
|
|||||||
extras = new Bundle();
|
extras = new Bundle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (savedInstanceState != null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (Intent.ACTION_SEND.equals(action) && type != null) {
|
if (Intent.ACTION_SEND.equals(action) && type != null) {
|
||||||
Log.d(Constants.TAG, "ACTION_SEND");
|
Log.d(Constants.TAG, "ACTION_SEND");
|
||||||
Log.logDebugBundle(extras, "SEND extras");
|
Log.logDebugBundle(extras, "SEND extras");
|
||||||
@ -158,7 +161,7 @@ public class DecryptTextActivity extends BaseActivity {
|
|||||||
sharedText = getPgpContent(sharedText);
|
sharedText = getPgpContent(sharedText);
|
||||||
|
|
||||||
if (sharedText != null) {
|
if (sharedText != null) {
|
||||||
loadFragment(savedInstanceState, sharedText);
|
loadFragment(sharedText);
|
||||||
} else {
|
} else {
|
||||||
Log.e(Constants.TAG, "EXTRA_TEXT does not contain PGP content!");
|
Log.e(Constants.TAG, "EXTRA_TEXT does not contain PGP content!");
|
||||||
Toast.makeText(this, R.string.error_invalid_data, Toast.LENGTH_LONG).show();
|
Toast.makeText(this, R.string.error_invalid_data, Toast.LENGTH_LONG).show();
|
||||||
@ -176,7 +179,7 @@ public class DecryptTextActivity extends BaseActivity {
|
|||||||
extraText = getPgpContent(extraText);
|
extraText = getPgpContent(extraText);
|
||||||
|
|
||||||
if (extraText != null) {
|
if (extraText != null) {
|
||||||
loadFragment(savedInstanceState, extraText);
|
loadFragment(extraText);
|
||||||
} else {
|
} else {
|
||||||
Log.e(Constants.TAG, "EXTRA_TEXT does not contain PGP content!");
|
Log.e(Constants.TAG, "EXTRA_TEXT does not contain PGP content!");
|
||||||
Toast.makeText(this, R.string.error_invalid_data, Toast.LENGTH_LONG).show();
|
Toast.makeText(this, R.string.error_invalid_data, Toast.LENGTH_LONG).show();
|
||||||
@ -189,7 +192,7 @@ public class DecryptTextActivity extends BaseActivity {
|
|||||||
String text = getPgpContent(clipboardText);
|
String text = getPgpContent(clipboardText);
|
||||||
|
|
||||||
if (text != null) {
|
if (text != null) {
|
||||||
loadFragment(savedInstanceState, text);
|
loadFragment(text);
|
||||||
} else {
|
} else {
|
||||||
returnInvalidResult();
|
returnInvalidResult();
|
||||||
}
|
}
|
||||||
@ -209,21 +212,14 @@ public class DecryptTextActivity extends BaseActivity {
|
|||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadFragment(Bundle savedInstanceState, String ciphertext) {
|
private void loadFragment(String ciphertext) {
|
||||||
// However, if we're being restored from a previous state,
|
|
||||||
// then we don't need to do anything and should return or else
|
|
||||||
// we could end up with overlapping fragments.
|
|
||||||
if (savedInstanceState != null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create an instance of the fragment
|
// Create an instance of the fragment
|
||||||
mFragment = DecryptTextFragment.newInstance(ciphertext);
|
Fragment frag = DecryptTextFragment.newInstance(ciphertext);
|
||||||
|
|
||||||
// Add the fragment to the 'fragment_container' FrameLayout
|
// Add the fragment to the 'fragment_container' FrameLayout
|
||||||
// NOTE: We use commitAllowingStateLoss() to prevent weird crashes!
|
// NOTE: We use commitAllowingStateLoss() to prevent weird crashes!
|
||||||
getSupportFragmentManager().beginTransaction()
|
getSupportFragmentManager().beginTransaction()
|
||||||
.replace(R.id.decrypt_text_fragment_container, mFragment)
|
.replace(R.id.decrypt_text_fragment_container, frag)
|
||||||
.commitAllowingStateLoss();
|
.commitAllowingStateLoss();
|
||||||
// do it immediately!
|
// do it immediately!
|
||||||
getSupportFragmentManager().executePendingTransactions();
|
getSupportFragmentManager().executePendingTransactions();
|
||||||
|
@ -28,8 +28,6 @@ import android.view.MenuInflater;
|
|||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.LinearLayout;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
@ -48,17 +46,15 @@ import java.io.UnsupportedEncodingException;
|
|||||||
|
|
||||||
public class DecryptTextFragment extends DecryptFragment {
|
public class DecryptTextFragment extends DecryptFragment {
|
||||||
public static final String ARG_CIPHERTEXT = "ciphertext";
|
public static final String ARG_CIPHERTEXT = "ciphertext";
|
||||||
|
public static final String ARG_SHOW_MENU = "show_menu";
|
||||||
|
|
||||||
// view
|
// view
|
||||||
private TextView mText;
|
private TextView mText;
|
||||||
|
|
||||||
// model
|
// model
|
||||||
private String mCiphertext;
|
private String mCiphertext;
|
||||||
private boolean mShowMenuOptions = false;
|
private boolean mShowMenuOptions;
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates new instance of this fragment
|
|
||||||
*/
|
|
||||||
public static DecryptTextFragment newInstance(String ciphertext) {
|
public static DecryptTextFragment newInstance(String ciphertext) {
|
||||||
DecryptTextFragment frag = new DecryptTextFragment();
|
DecryptTextFragment frag = new DecryptTextFragment();
|
||||||
|
|
||||||
@ -115,11 +111,24 @@ public class DecryptTextFragment extends DecryptFragment {
|
|||||||
|
|
||||||
setHasOptionsMenu(true);
|
setHasOptionsMenu(true);
|
||||||
|
|
||||||
String ciphertext = getArguments().getString(ARG_CIPHERTEXT);
|
Bundle args = savedInstanceState == null ? getArguments() : savedInstanceState;
|
||||||
if (ciphertext != null) {
|
mCiphertext = args.getString(ARG_CIPHERTEXT);
|
||||||
mCiphertext = ciphertext;
|
mShowMenuOptions = args.getBoolean(ARG_SHOW_MENU, false);
|
||||||
|
|
||||||
|
if (savedInstanceState == null) {
|
||||||
cryptoOperation(new CryptoInputParcel());
|
cryptoOperation(new CryptoInputParcel());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSaveInstanceState(Bundle outState) {
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
|
|
||||||
|
outState.putString(ARG_CIPHERTEXT, mCiphertext);
|
||||||
|
outState.putBoolean(ARG_SHOW_MENU, mShowMenuOptions);
|
||||||
|
// no need to save the decrypted text, it's in the textview
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -219,7 +219,7 @@ public class KeyFormattingUtils {
|
|||||||
// NOTE: Even though v3 keys are not imported we need to support both fingerprints for
|
// NOTE: Even though v3 keys are not imported we need to support both fingerprints for
|
||||||
// display/comparison before import
|
// display/comparison before import
|
||||||
if (fingerprint.length != 16 && fingerprint.length != 20) {
|
if (fingerprint.length != 16 && fingerprint.length != 20) {
|
||||||
throw new AssertionError("No valid v3 or v4 fingerprint!");
|
throw new IllegalArgumentException("No valid v3 or v4 fingerprint!");
|
||||||
}
|
}
|
||||||
|
|
||||||
return Hex.toHexString(fingerprint).toLowerCase(Locale.ENGLISH);
|
return Hex.toHexString(fingerprint).toLowerCase(Locale.ENGLISH);
|
||||||
|
@ -26,8 +26,7 @@
|
|||||||
android:paddingLeft="16dp"
|
android:paddingLeft="16dp"
|
||||||
android:paddingRight="16dp"
|
android:paddingRight="16dp"
|
||||||
android:paddingTop="4dp"
|
android:paddingTop="4dp"
|
||||||
android:paddingBottom="4dp"
|
android:paddingBottom="4dp">
|
||||||
android:animateLayoutChanges="true">
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
|
Loading…
Reference in New Issue
Block a user