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));

View File

@ -842,6 +842,18 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvChunkSize" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swUndoManager"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:checked="true"
android:text="@string/title_advanced_undo_manager"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/sbChunkSize"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swWebViewLegacy"
android:layout_width="0dp"
@ -851,7 +863,7 @@
android:text="@string/title_advanced_webview_legacy"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/sbChunkSize"
app:layout_constraintTop_toBottomOf="@id/swUndoManager"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat

View File

@ -686,6 +686,7 @@
<string name="title_advanced_checkpoints" translatable="false">Checkpoints</string>
<string name="title_advanced_sqlite_cache" translatable="false">Sqlite cache: %1$s %% - %2$s</string>
<string name="title_advanced_chunk_size" translatable="false">Chunk size: %1$d</string>
<string name="title_advanced_undo_manager" translatable="false">Use Android\'s undo manager</string>
<string name="title_advanced_webview_legacy" translatable="false">Old WebView behavior</string>
<string name="title_advanced_modseq" translatable="false">MODSEQ</string>
<string name="title_advanced_expunge" translatable="false">AUTO EXPUNGE</string>