From 6b2c68679c12a4614cc9a6b5b9a67418e8e85dc4 Mon Sep 17 00:00:00 2001 From: Brayan Oliveira <69634269+brayandso@users.noreply.github.com> Date: Mon, 27 May 2024 20:33:16 -0300 Subject: [PATCH] feat(new reviewer): user action --- .../src/main/assets/scripts/ankidroid.js | 13 +++++ .../ichi2/anki/previewer/PreviewerHelpers.kt | 4 +- .../ui/windows/reviewer/ReviewerFragment.kt | 9 ++++ .../ui/windows/reviewer/ReviewerViewModel.kt | 7 +++ AnkiDroid/src/main/res/menu/reviewer2.xml | 54 +++++++++++++++++++ 5 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 AnkiDroid/src/main/assets/scripts/ankidroid.js diff --git a/AnkiDroid/src/main/assets/scripts/ankidroid.js b/AnkiDroid/src/main/assets/scripts/ankidroid.js new file mode 100644 index 000000000000..5cf49c6085ae --- /dev/null +++ b/AnkiDroid/src/main/assets/scripts/ankidroid.js @@ -0,0 +1,13 @@ +"use strict"; +globalThis.ankidroid = globalThis.ankidroid || {}; + +globalThis.ankidroid.userAction = function (number) { + try { + let userJs = globalThis[`userJs${number}`]; + if (userJs != null) { + userJs(); + } + } catch (e) { + alert(e); + } +}; diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/previewer/PreviewerHelpers.kt b/AnkiDroid/src/main/java/com/ichi2/anki/previewer/PreviewerHelpers.kt index 62e38ad0bc23..1275355d22f9 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/previewer/PreviewerHelpers.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/previewer/PreviewerHelpers.kt @@ -36,7 +36,7 @@ class NoteEditorDestination(val cardId: Long) { /** * Not exactly equal to anki's stdHtml. Some differences: - * * `ankidroid.css` is added + * * `ankidroid.css` and `ankidroid.js` are added * * `bridgeCommand()` is ignored * * Aimed to be used only for reviewing/previewing cards @@ -77,7 +77,6 @@ fun stdHtml( ":root[class*=night-mode] { --canvas: $canvasColor; --fg: $fgColor; }" } - @Suppress("UnnecessaryVariable") // necessary for the HTML notation @Language("HTML") val html = """ @@ -98,6 +97,7 @@ fun stdHtml(
+