Rotating the browser clears filters chosen in the search screen

Open
#23,744 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
58/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
android, kotlin
Domain
mobile

Research direction

Start with the new test recreating keeps the chosen filters in AnkiDroid/src/test/java/com/ichi2/anki/browser/CardBrowserSearchErrorTest.kt, which uses openSearch, searchViewModel.setFlagsFilter and filtersFlow. Read how the search filters are held in the browser's ViewModel and what happens to them when the activity is recreated. Done when this test passes and the other tests in that file still pass.

Written by the indexing model from the issue text.

Description

code-scan

Assisted-by: Claude Opus 5.5 max

[EXISTING] Rotating the browser clears filters chosen in the search screen
Subject: [EXISTING] Rotating the browser clears filters chosen in the search screen

Choosing a filter such as a flag in the open search screen, then rotating, resets the filter before the search is submitted.

⚠️ This issue existed before the PR and should likely be split off into a separate issue.

---
diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/browser/CardBrowserSearchErrorTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/browser/CardBrowserSearchErrorTest.kt
index 4e1608764f..07db2361df 100644
--- a/AnkiDroid/src/test/java/com/ichi2/anki/browser/CardBrowserSearchErrorTest.kt
+++ b/AnkiDroid/src/test/java/com/ichi2/anki/browser/CardBrowserSearchErrorTest.kt
@@ -10,6 +10,7 @@ import androidx.test.core.app.ActivityScenario
 import com.ichi2.anki.BottomNavController.NavigationItem
 import com.ichi2.anki.CardBrowser
 import com.ichi2.anki.DeckPicker
+import com.ichi2.anki.Flag
 import com.ichi2.anki.RobolectricTest
 import com.ichi2.anki.browser.search.SearchRequest
 import com.ichi2.anki.ioDispatcher
@@ -94,6 +95,18 @@ class CardBrowserSearchErrorTest : RobolectricTest() {
             assertSame(rejectedSearch, activityViewModel.searchJob)
         }
 
+    @Test
+    fun `recreating keeps the chosen filters`() =
+        withSuccessfulSearch { recreate ->
+            openSearch("cat")
+            searchViewModel.setFlagsFilter(listOf(Flag.RED))
+
+            val restored = recreate()
+            restored.awaitSearch()
+
+            assertEquals(listOf(Flag.RED), restored.searchViewModel.filtersFlow.value.flags)
+        }
+
     @Test
     fun `recreating the browser does not rerun a rejected search`() =
         withSuccessfulSearch { recreate ->

Found while reviewing https://github.com/ankidroid/Anki-Android/pull/23344

Dominant language
Kotlin
Stars
12.3k
Forks
3.1k
Avg merge
2d 1h
Merged PRs (30d)
311

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ankidroid/Anki-Android

All issues in ankidroid/Anki-Android

Similar issues

More Kotlin issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.