Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
Fix duplicated item on MIUI
Browse files Browse the repository at this point in the history
  • Loading branch information
tehcneko committed Mar 25, 2022
1 parent 778ff8f commit b47be37
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions app/src/main/java/io/github/tehcneko/undo/UndoHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,24 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
var editor = editorField.get(param.thisObject);
var textView = textViewField.get(editor);
var menu = (Menu) param.args[0];
if ((boolean) XposedHelpers.callMethod(textView, "canUndo")) {
menu.add(Menu.NONE, android.R.id.undo, 2, undoId)
.setAlphabeticShortcut('z')
.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
var undoItem = menu.findItem(undoId);
if (undoItem == null) {
if ((boolean) XposedHelpers.callMethod(textView, "canUndo")) {
menu.add(Menu.NONE, android.R.id.undo, 2, undoId)
.setAlphabeticShortcut('z')
.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
}
} else {
undoItem.setVisible((boolean) XposedHelpers.callMethod(textView, "canUndo"));
}
if ((boolean) XposedHelpers.callMethod(textView, "canRedo")) {
menu.add(Menu.NONE, android.R.id.redo, 3, redoId)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
var redoItem = menu.findItem(redoId);
if (redoItem == null) {
if ((boolean) XposedHelpers.callMethod(textView, "canRedo")) {
menu.add(Menu.NONE, android.R.id.redo, 3, redoId)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
}
} else {
redoItem.setVisible((boolean) XposedHelpers.callMethod(textView, "canRedo"));
}
}
});
Expand Down

0 comments on commit b47be37

Please sign in to comment.