address review: save the selected tab by name and drop the dead songIds query

This commit is contained in:
austinried
2026-10-04 00:29:59 +00:00
parent e3af5ed0ac
commit f05a1c79a8
5 changed files with 20 additions and 15 deletions
@@ -104,9 +104,6 @@ interface LibraryDao {
limit: Int,
): List<String>
@Query("SELECT id FROM songs WHERE sourceId = :sourceId")
suspend fun songIds(sourceId: Long): List<String>
@Query("SELECT id FROM songs WHERE sourceId = :sourceId AND id > :afterId ORDER BY id LIMIT :limit")
suspend fun songIdsAfter(
sourceId: Long,
@@ -46,7 +46,7 @@ fun appModule(
single<PlayerConnection> { MediaSessionConnection(context.applicationContext, get()) }
single { PlaybackController(get(), get(), get()) }
viewModel { RootViewModel(get()) }
viewModel { LibraryViewModel(get(), get(), get(), get()) }
viewModel { LibraryViewModel(get(), get(), get(), get(), get()) }
viewModel { SettingsViewModel(get(), get()) }
viewModel { AddSourceViewModel(get(), get()) }
viewModel { params -> AlbumDetailViewModel(get(), get(), get(), params.get()) }
@@ -186,14 +186,16 @@ fun LibraryRoute(
viewModel: LibraryViewModel = koinViewModel(),
playbackController: PlaybackController = koinInject(),
) {
var selectedTab by rememberSaveable { mutableStateOf(LibraryTab.Albums) }
var previousTab by rememberSaveable { mutableStateOf(LibraryTab.Albums) }
var selectedTabName by rememberSaveable { mutableStateOf(LibraryTab.Albums.name) }
var previousTabName by rememberSaveable { mutableStateOf(LibraryTab.Albums.name) }
val selectedTab = LibraryTab.entries.firstOrNull { it.name == selectedTabName } ?: LibraryTab.Albums
val previousTab = LibraryTab.entries.firstOrNull { it.name == previousTabName } ?: LibraryTab.Albums
val syncing by viewModel.syncing.collectAsStateWithLifecycle()
val listTab = selectedTab.listTab()
LaunchedEffect(selectedTab) {
if (previousTab != selectedTab) {
viewModel.setSearch(previousTab.listTab(), "")
previousTab = selectedTab
previousTabName = selectedTab.name
}
}
val listQuery by viewModel.listQuery(listTab).collectAsStateWithLifecycle()
@@ -208,7 +210,6 @@ fun LibraryRoute(
val artwork = rememberArtworkColors(playbackController.coverArt(playback.item, thumbnail = true))
val itemActions =
ItemActions(
playSong = { viewModel.playSong(it.id) },
playAlbum = { viewModel.playAlbum(it.id) },
shuffleAlbum = { viewModel.shuffleAlbum(it.id) },
playPlaylist = { viewModel.playPlaylist(it.id) },
@@ -219,7 +220,7 @@ fun LibraryRoute(
)
LibraryScreen(
selectedTab = selectedTab,
onTabSelected = { selectedTab = it },
onTabSelected = { selectedTabName = it.name },
syncing = syncing,
bottomInset = bottomInset,
artwork = artwork,
@@ -18,6 +18,7 @@ import com.subtracks.data.repo.LibraryRepository
import com.subtracks.data.repo.SourceRepository
import com.subtracks.data.sync.SyncManager
import com.subtracks.data.sync.SyncStatus
import com.subtracks.playback.PlaybackController
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
@@ -35,6 +36,7 @@ class LibraryViewModel(
private val libraryRepository: LibraryRepository,
private val sourceRepository: SourceRepository,
private val syncManager: SyncManager,
private val playbackController: PlaybackController,
private val userPreferences: UserPreferences,
) : ViewModel() {
private val listQueries: Map<LibraryListTab, StateFlow<ListQuery>> =