Added option to enable Android's undo manager

This commit is contained in:
M66B
2022-01-05 18:48:38 +01:00
parent aeaff42614
commit 8705403d3e
4 changed files with 33 additions and 7 deletions

View File

@@ -22,6 +22,7 @@ package eu.faircode.email;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
@@ -44,6 +45,7 @@ import android.view.inputmethod.InputConnection;
import androidx.core.view.inputmethod.EditorInfoCompat;
import androidx.core.view.inputmethod.InputConnectionCompat;
import androidx.core.view.inputmethod.InputContentInfoCompat;
import androidx.preference.PreferenceManager;
import org.jsoup.nodes.Document;
@@ -79,16 +81,17 @@ public class EditTextCompose extends FixedEditText {
void init(Context context) {
Helper.setKeyboardIncognitoMode(this, context);
if (BuildConfig.DEBUG &&
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean undo_manager = prefs.getBoolean("undo_manager", false);
if (undo_manager &&
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
setCustomInsertionActionModeCallback(new ActionMode.Callback() {
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
boolean undo = can(android.R.id.undo);
boolean redo = can(android.R.id.redo);
if (undo)
if (can(android.R.id.undo))
menu.add(Menu.CATEGORY_ALTERNATIVE, R.string.title_undo, 1, R.string.title_undo);
if (redo)
if (can(android.R.id.redo))
menu.add(Menu.CATEGORY_ALTERNATIVE, R.string.title_redo, 2, R.string.title_redo);
return true;
}

View File

@@ -145,6 +145,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
private TextView tvChunkSize;
private SeekBar sbChunkSize;
private ImageButton ibSqliteCache;
private SwitchCompat swUndoManager;
private SwitchCompat swWebViewLegacy;
private SwitchCompat swModSeq;
private SwitchCompat swExpunge;
@@ -190,7 +191,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
"experiments", "crash_reports", "cleanup_attachments",
"protocol", "debug", "log_level", "test1", "test2", "test3", "test4", "test5",
"query_threads", "wal", "checkpoints", "sqlite_cache",
"chunk_size", "webview_legacy",
"chunk_size", "undo_manager", "webview_legacy",
"use_modseq", "perform_expunge", "uid_expunge",
"auth_plain", "auth_login", "auth_ntlm", "auth_sasl",
"keep_alive_poll", "empty_pool", "idle_done",
@@ -290,6 +291,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
ibSqliteCache = view.findViewById(R.id.ibSqliteCache);
tvChunkSize = view.findViewById(R.id.tvChunkSize);
sbChunkSize = view.findViewById(R.id.sbChunkSize);
swUndoManager = view.findViewById(R.id.swUndoManager);
swWebViewLegacy = view.findViewById(R.id.swWebViewLegacy);
swModSeq = view.findViewById(R.id.swModSeq);
swExpunge = view.findViewById(R.id.swExpunge);
@@ -884,6 +886,13 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
}
});
swUndoManager.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("undo_manager", checked).apply();
}
});
swWebViewLegacy.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@@ -1444,6 +1453,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
tvChunkSize.setText(getString(R.string.title_advanced_chunk_size, chunk_size));
sbChunkSize.setProgress(chunk_size);
swUndoManager.setChecked(prefs.getBoolean("undo_manager", false));
swWebViewLegacy.setChecked(prefs.getBoolean("webview_legacy", false));
swModSeq.setChecked(prefs.getBoolean("use_modseq", true));
swExpunge.setChecked(prefs.getBoolean("perform_expunge", true));