fix(music): hide the Favorites soundtrack collection until it has a track (#2835)

The Favorites collection in the music tab was always listed, even when
no tracks had been favorited.

- Favorites is now only listed in the Collections source once it has at
least one track
- With no favorites and no other collections, the Collections tab no
longer shows
- Adding a track to Favorites brings it back
- The collection detail page still resolves Favorites by id, so an
already-open page does not close when its last track is removed

Adds a test for the empty, populated and other-collections cases.
This commit is contained in:
FX1922 authored and GitHub committed 2026-11-18 18:51:02 +03:00
commit 2a274623da
3 files changed
+16 -4

No files matched your search

@@ -177,9 +177,10 @@ object SoundtrackCollections {
source = Library.SOURCE_COLLECTION, soundtrack = true,
)
fun games(context: Context, favoritesLabel: String): List<Library.SteamGame> {
fun games(context: Context, favoritesLabel: String, skipEmptyFavorites: Boolean = false): List<Library.SteamGame> {
val s = snapshot
return listOf(game(context, FAVORITES_ID, favoritesLabel, s.favorites)) + s.collections.map { game(context, it.id, it.name, it.tracks) }
val favorites = if (skipEmptyFavorites && s.favorites.isEmpty()) emptyList() else listOf(game(context, FAVORITES_ID, favoritesLabel, s.favorites))
return favorites + s.collections.map { game(context, it.id, it.name, it.tracks) }
}
fun album(context: Context, id: Int): Soundtrack.Album {
@@ -258,7 +258,7 @@ internal fun LibraryPage(s: FrontEndState, a: FrontEndActions, selected: String,
val favoritesLabel = stringResource(R.string.soundtracks_favorites)
val all = remember(soundMode, s.steamGames, s.soundtracks, s.soundtracksEnabled, cloudRows, owned, installedStore, savedSnapshot, favoritesLabel) {
if (soundMode) s.soundtracks.map { LibraryEntry("sound:${it.appId}", it.source, it.name, it, null, true) } +
(if (s.soundtracks.isEmpty() && savedSnapshot.favorites.isEmpty() && savedSnapshot.collections.isEmpty()) emptyList() else SoundtrackCollections.games(ctx, favoritesLabel))
(if (s.soundtracks.isEmpty() && savedSnapshot.favorites.isEmpty() && savedSnapshot.collections.isEmpty()) emptyList() else SoundtrackCollections.games(ctx, favoritesLabel, skipEmptyFavorites = true))
.map { LibraryEntry("sound:${it.appId}", it.source, it.name, it, null, true) }
else libraryEntries(s.steamGames + cloudRows + if (s.soundtracksEnabled) emptyList() else s.soundtracks.filter { it.library != Library.ADDED }, owned, installedStore)
}
@@ -282,7 +282,7 @@ internal fun LibraryPage(s: FrontEndState, a: FrontEndActions, selected: String,
val gameJoltSignedIn = owned.containsKey(Store.GAMEJOLT)
val sources = librarySources(
all, SessionPrefs.storesTabOrder(ctx),
listOfNotNull(Store.ITCH.id.takeIf { itchSignedIn && !soundMode }, Store.GAMEJOLT.id.takeIf { gameJoltSignedIn && !soundMode }, Library.SOURCE_COLLECTION.takeIf { soundMode }).toSet(),
listOfNotNull(Store.ITCH.id.takeIf { itchSignedIn && !soundMode }, Store.GAMEJOLT.id.takeIf { gameJoltSignedIn && !soundMode }).toSet(),
favorites, concealed, LibraryDisplay.hidden && !soundMode,
)
val source = LibraryView.source.takeIf { it == LIBRARY_ALL || it in sources } ?: LIBRARY_ALL
@@ -40,4 +40,15 @@ class SoundtrackCollectionsTest {
val list = listOf(Collection(2_000_000_005, "x", emptyList()))
assertEquals(2_000_000_006, SoundtrackCollections.nextId(list))
}
@Test fun emptyFavoritesCanBeLeftOutOfTheLibraryList() {
val context = androidx.test.core.app.ApplicationProvider.getApplicationContext<android.content.Context>()
SoundtrackCollections.load(context)
val custom = SoundtrackCollections.create(context, "Chill", emptyList())!!
val favorites = SoundtrackCollections.FAVORITES_ID
assertEquals(listOf(custom), SoundtrackCollections.games(context, "Favorites", skipEmptyFavorites = true).map { it.appId })
assertEquals(listOf(favorites, custom), SoundtrackCollections.games(context, "Favorites").map { it.appId })
SoundtrackCollections.add(context, favorites, listOf(ref("a")))
assertEquals(listOf(favorites, custom), SoundtrackCollections.games(context, "Favorites", skipEmptyFavorites = true).map { it.appId })
}
}