Scrolling the Flags sheet can clear a selected flag
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 69/100
Research direction
Start with FlagsBottomSheetFragment and the row recycling behavior described in the issue. The attached test in FlagsBottomSheetFragmentTest.kt shows how to reproduce it: bind a checked flag row, recycle it, then bind an unchecked row. The issue is resolved when recycling the row no longer clears the selected flag without a tap.
Written by the indexing model from the issue text.
Description
Assisted-by: GPT-6.2-Sol xhigh & GPT-6.2-Astra xhigh
[EXISTING] Scrolling the Flags sheet can clear a selected flag
⚠️ This issue existed before the PR and should likely be split off into a separate issue.
Subject: [EXISTING] Scrolling the Flags sheet can clear a selected flag
Reusing a checked flag row for an unchecked one can clear the flag selection without a tap.
---
diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/browser/search/FlagsBottomSheetFragmentTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/browser/search/FlagsBottomSheetFragmentTest.kt
index a287880e27..4fa2f9d08d 100644
--- a/AnkiDroid/src/test/java/com/ichi2/anki/browser/search/FlagsBottomSheetFragmentTest.kt
+++ b/AnkiDroid/src/test/java/com/ichi2/anki/browser/search/FlagsBottomSheetFragmentTest.kt
@@ -10,6 +10,7 @@ import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.matcher.RootMatchers.isDialog
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.ichi2.anki.Flag
import com.ichi2.anki.R
import com.ichi2.anki.RobolectricTest
import com.ichi2.anki.browser.withCardBrowserFragment
@@ -18,6 +19,9 @@ import org.hamcrest.Matchers.equalTo
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.Shadows.shadowOf
+import kotlin.test.assertEquals
+import kotlin.test.assertIs
+import kotlin.test.assertTrue
/** Test of [FlagsBottomSheetFragment] */
@RunWith(AndroidJUnit4::class)
@@ -37,4 +41,27 @@ class FlagsBottomSheetFragmentTest : RobolectricTest() {
assertThat(checkbox.contentDescription, equalTo("No flag" as CharSequence))
}
}
+
+ @Test
+ fun `recycling a flag row retains the selected flag`() =
+ withCardBrowserFragment(useSearchView = true) {
+ requireNotNull(searchView).show()
+ advanceRobolectricLooperUntil { searchViewModel.isScreenOpenFlow.value }
+ searchViewModel.setFlagsFilter(listOf(Flag.BLUE))
+
+ val sheet = FlagsBottomSheetFragment.createInstance(requireContext())
+ sheet.show(childFragmentManager)
+ advanceRobolectricLooper()
+ val list = sheet.requireView().findViewById<RecyclerView>(R.id.list)
+ val adapter = assertIs<FlagsBottomSheetFragment.FlagHolderAdapter>(list.adapter)
+ val holder = adapter.onCreateViewHolder(list, 0)
+ adapter.onBindViewHolder(holder, Flag.BLUE.ordinal)
+ assertTrue(holder.binding.checkbox.isChecked)
+
+ adapter.onViewRecycled(holder)
+ adapter.onBindViewHolder(holder, Flag.RED.ordinal)
+ advanceRobolectricLooper()
+
+ assertEquals(listOf(Flag.BLUE), searchViewModel.filtersFlow.value.flags)
+ }
}
Originally posted by @david-allison in https://github.com/ankidroid/Anki-Android/pull/23355#pullrequestreview-5968098762
- Dominant language
- Kotlin
- Stars
- 12.3k
- Forks
- 3.1k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 377
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ankidroid/Anki-Android
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
ankidroid/Anki-Android#23557 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
ankidroid/Anki-Android#23556 ·
Maintainers usually reply within 1 day
-
Next version
Difficulty 2/5 1-3 hours Newbie friendliness 63/100
ankidroid/Anki-Android#23555 ·
Maintainers usually reply within 1 day
-
code-scan
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
ankidroid/Anki-Android#23547 ·
Maintainers usually reply within 1 day
-
code-scan
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
ankidroid/Anki-Android#23545 ·
Maintainers usually reply within 1 day
All issues in ankidroid/Anki-Android
Similar issues
-
hoglite
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Android: with view recycling on, a recycled View keeps its nextFocusLeftPossibly taken A pull request linked to this issue is open or already merged. OpenNeeds: Triage :mag: Platform: Android
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
react/react-native#60167 ·
Maintainers usually reply within 2 days
-
CI/CD ⚒️ Flaky-tests 🐦 python 🐍
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
valkey-io/valkey-glide#7804 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
[New Rule] InMobiOpen
Difficulty 1/5 1-3 hours Newbie friendliness 68/100
LibChecker/LibChecker-Rules#1489 ·