fix(controls): improve post-assignment dialog - #21571
Conversation
|
First PR! 🚀 We sincerely appreciate that you have taken the time to propose a change to AnkiDroid! Please have patience with us as we are all volunteers - we will get to this as soon as possible. |
|
Important Maintainers: This PR contains Strings changes
|
david-allison
left a comment
There was a problem hiding this comment.
Handle the case where the binding is already assigned to 'Show answer': - 'No' will remove it without confirmation.
I'd question using yes/no over more descriptive strings. Material design used to discourage yes/no.
@manocormen FYI - I'll defer to your thoughts here
| val items = | ||
| arrayOf( | ||
| getString(R.string.only_answer), | ||
| getString(R.string.flip_and_answer), | ||
| getString(R.string.dialog_yes), | ||
| getString(R.string.dialog_no), | ||
| ) |
There was a problem hiding this comment.
nit: inline this, we're no longer calling setItems(items)
|
Material 3 seem to still discourage yes/no, so instead we could use:
|
|
@manocormen since we are discussing a more descriptive alert dialog, perhaps you could reconsider my earlier implementation: @david-allison Happy to update the PR once changes are decided. |
|
@Sanjeev-Narang In your earlier design, I liked the concision of "Keep" / "Remove", but I found the dialog at tad confusing in context: we've just assigned a gesture to action1, and now we're told "The gesture is already assigned to action2": to me, it makes it sound like a conflict, so I'd favor Zorn's simpler design (but with descriptive buttons). @david-allison I'm not sure this is on the table, but we could also simplify: remove the secondary dialog altogether. |
|
@manocormen It's been few days, should we wait for David's response or implement the strings the way you suggested? ("assign it", "don't assign it" and "unassign it") |
|
I'll likely be able to get to this over the weekend, please go with @manocormen's guidance on this one |
|
@Sanjeev-Narang Thanks for bearing with us. We had a chat internally. Please implement the following behavior: If the gesture is already assigned to Show answer, don't show the dialog at all. This keeps the shortcut focused on intuitive positive assignments and sidesteps potentially confusing unassignment language. |
|
@manocormen sounds good. I'll implement this in next 1-2 days. In the meantime, i'm marking this PR as draft |
3a35c57 to
6d0edb3
Compare
|
Snapshot diff report vs
All 7 changed screenshotsPreferencesScreenshotTest
|
| negativeButton(text = getString(R.string.skip)) { | ||
| answerPref.addBinding(binding, CardSide.ANSWER) | ||
| val filtered = | ||
| showAnswerPref?.getMappableBindings()?.filterNot { | ||
| it.binding == binding && (it.side == CardSide.QUESTION || it.side == CardSide.BOTH) | ||
| } | ||
| } | ||
| showAnswerPref?.value = filtered?.toPreferenceString() | ||
| } |
There was a problem hiding this comment.
Unless I'm missing something, skipping should simply assign the binding on the answer side.
There was a problem hiding this comment.
i'm really sorry. i forgot to remove that code. gonna fix this in couple of minutes.
6d0edb3 to
8d04499
Compare
|
@manocormen I've updated the code. |
manocormen
left a comment
There was a problem hiding this comment.
Thank you, LGTM. A maintainer will review this when possible; please give them time.
There was a problem hiding this comment.
Looks great!!!
Please add this test, rebase on main to fix the conflicts, then it should be good to go
See: https://github.com/ankidroid/Anki-Android/wiki/Development-Guide#applying-a-patch
Please squash the change in and force push. Let me know if you need help with this
Index: AnkiDroid/src/test/java/com/ichi2/anki/preferences/ControlsSettingsFragmentTest.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/preferences/ControlsSettingsFragmentTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/preferences/ControlsSettingsFragmentTest.kt
--- a/AnkiDroid/src/test/java/com/ichi2/anki/preferences/ControlsSettingsFragmentTest.kt (revision 8d04499f8a0877c6e438641f84be7637235f495d)
+++ b/AnkiDroid/src/test/java/com/ichi2/anki/preferences/ControlsSettingsFragmentTest.kt (date 1788818943645)
@@ -33,6 +33,8 @@
import org.hamcrest.Matchers.not
import org.junit.Test
import org.junit.runner.RunWith
+import org.robolectric.shadows.ShadowDialog
+import kotlin.test.assertNull
@RunWith(AndroidJUnit4::class)
class ControlsSettingsFragmentTest : RobolectricTest() {
@@ -84,6 +86,22 @@
assertThat("binding not assigned to answer", answerBindings, hasItem(equalTo(Pair(binding, CardSide.ANSWER))))
}
}
+
+ @Test
+ fun `no dialog if binding is already assigned to show answer`() {
+ withControlsSettings {
+ val binding = Binding.GestureInput(Gesture.SWIPE_UP)
+ showAnswerPref.addBinding(binding, CardSide.QUESTION)
+
+ answerPref.setBinding(binding)
+
+ assertNull(ShadowDialog.getLatestDialog(), "no dialog should be shown")
+ val showAnswerBindings = showAnswerPref.getMappableBindings().map { Pair(it.binding, it.side) }
+ val answerBindings = answerPref.getMappableBindings().map { Pair(it.binding, it.side) }
+ assertThat("binding not kept on Show answer", showAnswerBindings, hasItem(Pair(binding, CardSide.QUESTION)))
+ assertThat("binding not assigned to answer", answerBindings, hasItem(Pair(binding, CardSide.ANSWER)))
+ }
+ }
}
private val ControlsSettingsFragment.showAnswerPref
| * launches the [ControlsSettingsFragment] and runs [block] on it. | ||
| */ | ||
| context(_: DeferredNavigation) | ||
| private fun withControlsSettings(block: ControlsSettingsFragment.() -> Unit) { |
8d04499 to
846c468
Compare
|
@david-allison I added the patch. Please review |
|
Cheers! No need to ping, it's on my queue as soon as you push |
Fixes 20759
846c468 to
1ba9b77
Compare
david-allison
left a comment
There was a problem hiding this comment.
LGTM!
I have force pushed to get this in with a couple of nitpicks:
- strings are renamed to have a
dialog_prefix - a typo in a test name was fixed
Awaiting a strings sync, and merge. On us
Thank you so much for your time and effort here! 🫡
Purpose / Description
The 'Only answer' option is supposed to remove the binding from 'Show answer' but it was not doing that. The dialog's appearance was not consistent with the previous subsequent dialogs in controls. Also need to implement option 3 mentioned in the issue.
Fixes
Approach
Before:

After:

How Has This Been Tested?
Unit test, API36
Learning (optional, can help others)
Learnt about controls settings, testing and the issue related codebase of AnkiDroid
Checklist
Please, go through these checks before submitting the PR.