Fix: Implements go back twice to exit in the whiteboard for gesture navigation - #20792
Conversation
c5c190b to
9eac988
Compare
There was a problem hiding this comment.
I don't feel this handles Brayan's comment:
If we can also check whether the system is using gestures instead of buttons for navigation, it would be even better.
I skimmed the discussion, as far as I understand it, requiring a confirmation should only occur if the Android back gesture is enabled, rather than buttons.
In addition, implementer's choice
Consider a commit to change the string:
- Press back again to exit
+ Go back again to exit
I had wanted to do this initially (https://stackoverflow.com/questions/74848618/how-to-detect-whether-gesture-navigation-or-button-navigation-is-active). But I was wondering why we wouldn't want to have the same thing for both navigation modes? I can make the change to using insets to detect gestures though, should just involve an extra function to detect gestures and then pass that to the ReEnable. |
|
For future reference, using insets to detect navigation isn't reliable so using settings.secure is better |
9eac988 to
3f8fa87
Compare
80c8dbd to
7096f8e
Compare
7096f8e to
b7ad7ce
Compare
|
hopefully I implemented the compat part correctly, please let me know if there's any issues edit: failing tests will figure it out shortly |
b7ad7ce to
aa24043
Compare
aa24043 to
1406576
Compare
| */ | ||
| fun isUsingSystemGestureNavigation( | ||
| context: Context, | ||
| default: Int = 0, |
There was a problem hiding this comment.
It would be better to have the default as a Boolean
1406576 to
2616670
Compare
|
flaky test I'm pretty sure |
david-allison
left a comment
There was a problem hiding this comment.
Index: compat/src/main/java/com/ichi2/anki/compat/BaseCompat.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/compat/src/main/java/com/ichi2/anki/compat/BaseCompat.kt b/compat/src/main/java/com/ichi2/anki/compat/BaseCompat.kt
--- a/compat/src/main/java/com/ichi2/anki/compat/BaseCompat.kt (revision e911b16a595b247cf9f7842df36658270c0ae0db)
+++ b/compat/src/main/java/com/ichi2/anki/compat/BaseCompat.kt (date 1776886772578)
@@ -289,8 +289,7 @@
// Until API 29, gesture navigation does not exist
override fun isUsingSystemGestureNavigation(
context: Context,
- default: Boolean,
- gestureMode: Int,
+ defaultValue: Boolean,
): Boolean = false
}
Index: compat/src/main/java/com/ichi2/anki/compat/CompatV29.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/compat/src/main/java/com/ichi2/anki/compat/CompatV29.kt b/compat/src/main/java/com/ichi2/anki/compat/CompatV29.kt
--- a/compat/src/main/java/com/ichi2/anki/compat/CompatV29.kt (revision e911b16a595b247cf9f7842df36658270c0ae0db)
+++ b/compat/src/main/java/com/ichi2/anki/compat/CompatV29.kt (date 1776886686118)
@@ -87,11 +87,10 @@
override fun isUsingSystemGestureNavigation(
context: Context,
- default: Boolean,
- gestureMode: Int,
+ defaultValue: Boolean,
): Boolean {
- val defaultMode = if (default) gestureMode else 0
- return Settings.Secure.getInt(context.contentResolver, "navigation_mode", defaultMode) == gestureMode
+ val defaultMode = if (defaultValue) 2 else 0
+ return Settings.Secure.getInt(context.contentResolver, "navigation_mode", defaultMode) == 2
}
companion object {
Index: compat/src/main/java/com/ichi2/anki/compat/Compat.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/compat/src/main/java/com/ichi2/anki/compat/Compat.kt b/compat/src/main/java/com/ichi2/anki/compat/Compat.kt
--- a/compat/src/main/java/com/ichi2/anki/compat/Compat.kt (revision e911b16a595b247cf9f7842df36658270c0ae0db)
+++ b/compat/src/main/java/com/ichi2/anki/compat/Compat.kt (date 1776886772584)
@@ -282,12 +282,10 @@
* Note: this reads a `Settings.Secure` key that is not part of the public API.
* It will not throw, but the result is manufacturer dependent.
*
- * @param default value returned when the `navigation_mode` key is unset
- * @param gestureMode the value of `navigation_mode` representing gesture navigation
+ * @param defaultValue value returned when the `navigation_mode` key is unset
*/
fun isUsingSystemGestureNavigation(
context: Context,
- default: Boolean = false,
- gestureMode: Int = 2,
+ defaultValue: Boolean = false,
): Boolean
}Does this work (untested)
… navigation Assisted-by: Claude Opus 4.6
Assisted-by: Claude Opus 4.6
2616670 to
b13c20a
Compare
|
Maintainers: Please Sync Translations to produce a commit with only the automated changes from this PR. Read more about updating strings on the wiki, |
Note
Tested out Opus 4.6 with code generation, still wrote all the code manually and tested everything physically
Purpose / Description
Currently, the double tap/swipe to back option doesn't work properly in the whiteboard and a single gesture/back press exits. This was a pain point for users who were using the whiteboard for language like Japanese.
Currently, this doesn't detect gestures since it involved an external API and I wasn't very sure of how that worked so didn't want to include it here.
Fixes
Approach
Implements a new doubleBackPressCallback function which intercepts back presses when the whiteboard is enabled. If the user presses back once, a snackbar is shown. If they press back again within 2 seconds, the activity finishes. If they don't, shouldReEnable checks whether the whiteboard is still active.
How Has This Been Tested?
Screen_recording_20260420_121417.webm
Checklist
Please, go through these checks before submitting the PR.