start the library on the stored tab instead of scrolling to it

The pager's settled-page collector reports its initial value, so a cold start
wrote Albums back before the stored tab had been read - racing the very setting
this branch added, able to pin the app to Albums and overwrite the choice. The
screen waits for the stored tab before composing now, so the pager latches the
right page and the initial report matches it, which also drops the spurious
scroll and the search clear that came with it. The report is guarded anyway.

The data layer no longer names a UI tab from a coincidentally same-named enum:
it returns the raw stored value and the view model owns the Albums fallback.
This commit is contained in:
austinried
2026-10-04 00:30:04 +00:00
parent cf92604e3a
commit 92637deb48
5 changed files with 32 additions and 30 deletions
@@ -10,6 +10,7 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.test.runTest
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Test
import org.junit.runner.RunWith
import java.io.File
@@ -32,6 +33,7 @@ class UserPreferencesTest {
ListQuery("Added", descending = true, starred = StarredFilter.Starred, downloaded = true),
)
prefs.setListQuery(LibraryListTab.Artists, ListQuery("AlbumCount", descending = true))
prefs.setListQuery(LibraryListTab.Playlists, ListQuery("Updated", starred = StarredFilter.NotStarred))
assertEquals(
ListQuery("Added", descending = true, starred = StarredFilter.Starred, downloaded = true),
@@ -41,30 +43,10 @@ class UserPreferencesTest {
ListQuery("AlbumCount", descending = true),
prefs.listQuery(LibraryListTab.Artists).first(),
)
file.delete()
}
@Test
fun everyTabsListQueryIsKeptIndependently() =
runTest {
val file = File.createTempFile("user-prefs", ".preferences_pb").apply { delete() }
val store = PreferenceDataStoreFactory.create(scope = backgroundScope) { file }
val prefs = UserPreferences(store)
prefs.setListQuery(LibraryListTab.Albums, ListQuery("Added", descending = true, downloaded = true))
prefs.setListQuery(LibraryListTab.Artists, ListQuery("AlbumCount", starred = StarredFilter.NotStarred))
prefs.setListQuery(LibraryListTab.Playlists, ListQuery("Updated", descending = true))
assertEquals(
ListQuery("Added", descending = true, downloaded = true),
prefs.listQuery(LibraryListTab.Albums).first(),
ListQuery("Updated", starred = StarredFilter.NotStarred),
prefs.listQuery(LibraryListTab.Playlists).first(),
)
assertEquals(
ListQuery("AlbumCount", starred = StarredFilter.NotStarred),
prefs.listQuery(LibraryListTab.Artists).first(),
)
assertEquals(ListQuery("Updated", descending = true), prefs.listQuery(LibraryListTab.Playlists).first())
file.delete()
}
@@ -76,7 +58,7 @@ class UserPreferencesTest {
val store = PreferenceDataStoreFactory.create(scope = backgroundScope) { file }
val prefs = UserPreferences(store)
assertEquals("Albums", prefs.libraryTab().first())
assertNull(prefs.libraryTab().first())
prefs.setLibraryTab("Playlists")
@@ -0,0 +1,16 @@
package com.subtracks.ui.library
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class LibraryTabTest {
@Test
fun theStoredNameMapsToItsTabAndAnythingElseToAlbums() {
assertEquals(LibraryTab.Playlists, libraryTabFor("Playlists"))
assertEquals(LibraryTab.Albums, libraryTabFor(null))
assertEquals(LibraryTab.Albums, libraryTabFor("Books"))
}
}