add option to toggle self-encrypt for text

This commit is contained in:
Vincent Breitmoser
2018-03-05 14:02:48 +01:00
parent 285184d7c6
commit 3fdc4059b5
4 changed files with 54 additions and 2 deletions

View File

@@ -131,6 +131,7 @@ public final class Constants {
public static final String FILE_USE_COMPRESSION = "useFileCompression";
public static final String FILE_SELF_ENCRYPT = "fileSelfEncrypt";
public static final String TEXT_USE_COMPRESSION = "useTextCompression";
public static final String TEXT_SELF_ENCRYPT = "textSelfEncrypt";
public static final String USE_ARMOR = "useArmor";
// proxy settings
public static final String USE_NORMAL_PROXY = "useNormalProxy";

View File

@@ -59,11 +59,13 @@ public class EncryptTextFragment
public static final String ARG_TEXT = "text";
public static final String ARG_USE_COMPRESSION = "use_compression";
public static final String ARG_SELF_ENCRYPT = "self_encrypt";
public static final String ARG_RETURN_PROCESS_TEXT = "return_process_text";
private boolean mShareAfterEncrypt;
private boolean mReturnProcessTextAfterEncrypt;
private boolean mUseCompression;
private boolean mSelfEncrypt;
private boolean mHiddenRecipients = false;
private String mMessage = "";
@@ -128,6 +130,7 @@ public class EncryptTextFragment
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean(ARG_USE_COMPRESSION, mUseCompression);
outState.putBoolean(ARG_SELF_ENCRYPT, mSelfEncrypt);
}
@Override
@@ -142,13 +145,18 @@ public class EncryptTextFragment
Bundle args = savedInstanceState == null ? getArguments() : savedInstanceState;
mUseCompression = args.getBoolean(ARG_USE_COMPRESSION, true);
if (args.containsKey(ARG_USE_COMPRESSION)) {
mUseCompression = args.getBoolean(ARG_USE_COMPRESSION, true);
} else {
mUseCompression = prefs.getTextUseCompression();
}
if (args.containsKey(ARG_SELF_ENCRYPT)) {
mSelfEncrypt = args.getBoolean(ARG_SELF_ENCRYPT, true);
} else {
mSelfEncrypt = prefs.getTextSelfEncrypt();
}
setHasOptionsMenu(true);
}
@@ -159,6 +167,7 @@ public class EncryptTextFragment
inflater.inflate(R.menu.encrypt_text_fragment, menu);
menu.findItem(R.id.check_enable_compression).setChecked(mUseCompression);
menu.findItem(R.id.check_enable_self_encrypt).setChecked(mSelfEncrypt);
if (mReturnProcessTextAfterEncrypt) {
menu.findItem(R.id.encrypt_paste).setVisible(true);
@@ -174,6 +183,10 @@ public class EncryptTextFragment
toggleEnableCompression(item, !item.isChecked());
break;
}
case R.id.check_enable_self_encrypt: {
toggleEnableSelfEncrypt(item, !item.isChecked());
break;
}
// case R.id.check_hidden_recipients: {
// mHiddenRecipients = item.isChecked();
// notifyUpdate();
@@ -203,6 +216,28 @@ public class EncryptTextFragment
return true;
}
public void toggleEnableSelfEncrypt(MenuItem item, final boolean selfEncrypt) {
mSelfEncrypt = selfEncrypt;
item.setChecked(selfEncrypt);
Notify.create(getActivity(), selfEncrypt
? R.string.snack_self_encrypt_on
: R.string.snack_self_encrypt_off,
Notify.LENGTH_LONG, Style.OK, new ActionListener() {
@Override
public void onAction() {
Preferences.getPreferences(getActivity()).setTextSelfEncrypt(selfEncrypt);
Notify.create(getActivity(), selfEncrypt
? R.string.snack_self_encrypt_on
: R.string.snack_self_encrypt_off,
Notify.LENGTH_SHORT, Style.OK, null, R.string.btn_saved)
.show(EncryptTextFragment.this, false);
}
}, R.string.btn_save_default).show(this);
}
public void toggleEnableCompression(MenuItem item, final boolean compress) {
mUseCompression = compress;
@@ -264,7 +299,7 @@ public class EncryptTextFragment
data.setEncryptionMasterKeyIds(encryptionKeyIds);
data.setSignatureMasterKeyId(signingKeyId);
if (signingKeyId != Constants.key.none) {
if (signingKeyId != Constants.key.none && mSelfEncrypt) {
data.setAdditionalEncryptId(signingKeyId);
}
} else {

View File

@@ -217,6 +217,16 @@ public class Preferences {
return mSharedPreferences.getBoolean(Pref.TEXT_USE_COMPRESSION, true);
}
public void setTextSelfEncrypt(boolean selfEncrypt) {
SharedPreferences.Editor editor = mSharedPreferences.edit();
editor.putBoolean(Pref.TEXT_SELF_ENCRYPT, selfEncrypt);
editor.commit();
}
public boolean getTextSelfEncrypt() {
return mSharedPreferences.getBoolean(Pref.TEXT_SELF_ENCRYPT, true);
}
public String getTheme() {
return mSharedPreferences.getString(Pref.THEME, Pref.Theme.LIGHT);
}

View File

@@ -31,6 +31,12 @@
android:checked="true"
android:checkable="true" />
<item
android:id="@+id/check_enable_self_encrypt"
android:title="@string/label_enable_self_encrypt"
android:orderInCategory="1"
android:checked="true"
android:checkable="true" />
<!--<item-->
<!--android:id="@+id/check_hidden_recipients"-->
<!--android:title="@string/label_hidden_recipients"-->