Added auto decrypt on close

This commit is contained in:
M66B 2020-11-25 09:17:37 +01:00
parent 6d39a843fe
commit 4c6dddf11c
4 changed files with 63 additions and 2 deletions

View File

@ -4991,6 +4991,43 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
}
}
private void handleExit() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
boolean auto_undecrypt = prefs.getBoolean("auto_undecrypt", false);
if (auto_undecrypt) {
List<Long> ids = new ArrayList<>();
for (int i = 0; i < adapter.getItemCount(); i++) {
TupleMessageEx message = adapter.getItemAtPosition(i);
if (message == null)
continue;
if ((EntityMessage.PGP_SIGNENCRYPT.equals(message.ui_encrypt) &&
!EntityMessage.PGP_SIGNENCRYPT.equals(message.encrypt)) ||
(EntityMessage.SMIME_SIGNENCRYPT.equals(message.ui_encrypt) &&
!EntityMessage.SMIME_SIGNENCRYPT.equals(message.encrypt)))
ids.add(message.id);
}
Bundle args = new Bundle();
args.putLongArray("ids", Helper.toLongArray(ids));
new SimpleTask<Void>() {
@Override
protected Void onExecute(Context context, Bundle args) throws Throwable {
long[] ids = args.getLongArray("ids");
for (long id : ids)
lockMessage(id);
return null;
}
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(getParentFragmentManager(), ex);
}
}.execute(this, args, "messages:lock");
}
}
private void navigate(long id, final boolean left) {
if (!getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED))
return;
@ -5450,6 +5487,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
return true;
}
handleExit();
return false;
}

View File

@ -72,6 +72,7 @@ public class FragmentOptionsEncryption extends FragmentBase implements SharedPre
private SwitchCompat swSign;
private SwitchCompat swEncrypt;
private SwitchCompat swAutoDecrypt;
private SwitchCompat swAutoUndoDecrypt;
private Spinner spOpenPgp;
private TextView tvOpenPgpStatus;
@ -90,7 +91,7 @@ public class FragmentOptionsEncryption extends FragmentBase implements SharedPre
private List<String> openPgpProvider = new ArrayList<>();
private final static String[] RESET_OPTIONS = new String[]{
"sign_default", "encrypt_default", "auto_decrypt",
"sign_default", "encrypt_default", "auto_decrypt", "auto_undecrypt",
"openpgp_provider", "autocrypt", "autocrypt_mutual", "encrypt_subject",
"check_certificate"
};
@ -109,6 +110,7 @@ public class FragmentOptionsEncryption extends FragmentBase implements SharedPre
swSign = view.findViewById(R.id.swSign);
swEncrypt = view.findViewById(R.id.swEncrypt);
swAutoDecrypt = view.findViewById(R.id.swAutoDecrypt);
swAutoUndoDecrypt = view.findViewById(R.id.swAutoUndoDecrypt);
spOpenPgp = view.findViewById(R.id.spOpenPgp);
tvOpenPgpStatus = view.findViewById(R.id.tvOpenPgpStatus);
@ -170,6 +172,13 @@ public class FragmentOptionsEncryption extends FragmentBase implements SharedPre
}
});
swAutoUndoDecrypt.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("auto_undecrypt", checked).apply();
}
});
// PGP
spOpenPgp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@ -363,6 +372,7 @@ public class FragmentOptionsEncryption extends FragmentBase implements SharedPre
swEncrypt.setChecked(prefs.getBoolean("encrypt_default", false));
swSign.setEnabled(!swEncrypt.isChecked());
swAutoDecrypt.setChecked(prefs.getBoolean("auto_decrypt", false));
swAutoUndoDecrypt.setChecked(prefs.getBoolean("auto_undecrypt", false));
String provider = prefs.getString("openpgp_provider", "org.sufficientlysecure.keychain");
spOpenPgp.setTag(provider);

View File

@ -73,6 +73,17 @@
app:layout_constraintTop_toBottomOf="@id/swEncrypt"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swAutoUndoDecrypt"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_auto_undo_decrypt"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swAutoDecrypt"
app:switchPadding="12dp" />
<!-- PGP -->
<eu.faircode.email.FixedTextView
@ -85,7 +96,7 @@
android:textAppearance="@style/TextAppearance.AppCompat.Large"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swAutoDecrypt" />
app:layout_constraintTop_toBottomOf="@id/swAutoUndoDecrypt" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvOpenPgp"

View File

@ -487,6 +487,7 @@
<string name="title_advanced_sign_default">Sign by default</string>
<string name="title_advanced_encrypt_default">Encrypt by default</string>
<string name="title_advanced_auto_decrypt">Automatically decrypt messages</string>
<string name="title_advanced_auto_undo_decrypt">Undo decryption on closing conversation</string>
<string name="title_advanced_openpgp">OpenPGP provider</string>
<string name="title_advanced_autocrypt">Use Autocrypt</string>
<string name="title_advanced_autocrypt_mutual">Autocrypt mutual mode</string>