fix(library): manage the Hidden tab from Manage stores (#2920)

The Hidden tab was the only Library tab missing from Manage stores, and
it was turned on from the Display options instead.

- Hidden is now listed in Manage stores, after Custom games by default,
with its own switch and drag handle like Favorites and Custom games
- It starts off, and a switch someone already turned on keeps its state
- Removes the Hidden entry from the Display options
- The Hidden tab is still never shown in the music tab

Adds tests for the default, the saved switch and the sort order.
This commit is contained in:
FX1922 authored and GitHub committed 2026-11-20 09:22:35 +03:00
commit a29315f7e0
5 files changed
+44 -30

No files matched your search

@@ -17,6 +17,7 @@ import com.droiddeck.launcher.frontend.SteamHidden
import com.droiddeck.launcher.session.SessionPrefs
internal const val LIBRARY_HIDDEN = "hidden"
internal val HIDDEN_DOT = androidx.compose.ui.graphics.Color(0xFF9AA0A6)
internal object LibraryHidden {
var keys by mutableStateOf<Set<String>>(emptySet())
@@ -177,15 +177,15 @@ internal fun installedFirst(entries: List<LibraryEntry>): List<LibraryEntry> = e
internal const val LIBRARY_ALL = "all"
internal fun librarySources(
entries: List<LibraryEntry>, order: List<String>, always: Set<String> = emptySet(), favorites: Set<String> = emptySet(),
hidden: (LibraryEntry) -> Boolean = { false }, showHidden: Boolean = false, offStores: Set<String> = emptySet(),
places: List<Pair<String, String?>> = DEFAULT_LIBRARY_PLACES, offTabs: Set<String> = emptySet(),
hidden: (LibraryEntry) -> Boolean = { false }, offStores: Set<String> = emptySet(),
places: List<Pair<String, String?>> = DEFAULT_LIBRARY_PLACES, offTabs: Set<String> = setOf(LIBRARY_HIDDEN),
): List<String> {
val tabs = arrangeStoreTabs(order, offStores)
val shown = tabs.filter { it.shown }.map { it.store.id }.toSet() + LIBRARY_OWN_TABS - offTabs
return (placeLibraryTabs(tabs.map { it.store.id }, places).filter { it in shown } + Library.SOURCE_COLLECTION + LIBRARY_HIDDEN)
return (placeLibraryTabs(tabs.map { it.store.id }, places).filter { it in shown } + Library.SOURCE_COLLECTION)
.filter { source ->
when (source) {
LIBRARY_HIDDEN -> showHidden
LIBRARY_HIDDEN -> true
LIBRARY_FAVORITES -> entries.any { it.favoriteKey in favorites && !hidden(it) }
else -> source in always || entries.any { it.source == source && !hidden(it) }
}
@@ -201,14 +201,11 @@ internal object LibraryDisplay {
private set
var size by mutableStateOf(true)
private set
var hidden by mutableStateOf(false)
private set
fun load(context: android.content.Context) {
level = SessionPrefs.libraryCardLevel(context).coerceIn(0, scales.lastIndex)
title = SessionPrefs.libraryShowTitle(context)
size = SessionPrefs.libraryShowSize(context)
hidden = SessionPrefs.libraryShowHidden(context)
}
fun step(context: android.content.Context, by: Int) {
@@ -225,11 +222,6 @@ internal object LibraryDisplay {
size = !size
SessionPrefs.setLibraryShowSize(context, size)
}
fun toggleHidden(context: android.content.Context) {
hidden = !hidden
SessionPrefs.setLibraryShowHidden(context, hidden)
}
}
private enum class ToggleAt { NONE, TOP, SPLIT, BOTTOM }
@@ -380,10 +372,10 @@ internal fun LibraryPage(s: FrontEndState, a: FrontEndActions, selected: String,
val sources = librarySources(
all, storeTabs.map { it.store.id },
listOfNotNull(Store.ITCH.id.takeIf { itchSignedIn && !soundMode }, Store.GAMEJOLT.id.takeIf { gameJoltSignedIn && !soundMode }, Library.ADDED.takeIf { stores }).toSet() + signInChips,
favorites, concealed, LibraryDisplay.hidden && !soundMode,
favorites, concealed,
offStores = if (soundMode) emptySet() else storeTabs.filterNot { it.shown }.map { it.store.id }.toSet(),
places = if (soundMode) DEFAULT_LIBRARY_PLACES else StoreTabsState.libraryPlaces,
offTabs = if (soundMode) emptySet() else StoreTabsState.libraryHidden,
offTabs = if (soundMode) setOf(LIBRARY_HIDDEN) else StoreTabsState.libraryHidden,
)
val source = LibraryView.source.takeIf { it == LIBRARY_ALL || it in sources } ?: LIBRARY_ALL
val q = LibraryView.query.trim().lowercase()
@@ -1011,7 +1003,7 @@ private fun sourceDot(src: String): Color? {
alpha = if (DevPreview.library == LibraryPreview.SAMPLE || (DevPreview.library != LibraryPreview.SIGNED_OUT && StoresState.isSignedIn(store) && StoresState.expired[store] != true)) 1f else 0.35f,
)
src == LIBRARY_FAVORITES -> FavoritesColours.dot
src == LIBRARY_HIDDEN -> Color(0xFF9AA0A6)
src == LIBRARY_HIDDEN -> HIDDEN_DOT
src == Library.SOURCE_STEAM || src == Library.ADDED || src == Library.SOURCE_COLLECTION -> sourceColours(src).dot
else -> null
}
@@ -1369,7 +1361,7 @@ internal fun DisplayButton() {
HeaderIconButton(title, Icons.Filled.Visibility, "display") {
val from = at ?: return@HeaderIconButton
Steps.ask(StepAsk(
anchor = from, side = StepSide.Left, accent = pal.signal, pillCorner = 8.dp, items = 5,
anchor = from, side = StepSide.Left, accent = pal.signal, pillCorner = 8.dp, items = 4,
handle = { Icon(Icons.Filled.Visibility, null, tint = pal.signal, modifier = Modifier.size(18.dp)) },
) {
StepTitle(title)
@@ -1392,10 +1384,6 @@ internal fun DisplayButton() {
stringResource(R.string.library_display_size), selected = LibraryDisplay.size, enabled = open,
modifier = Modifier.fillMaxWidth().stepItem(3),
) { LibraryDisplay.toggleSize(ctx) }
StepChoice(
stringResource(R.string.apps_filter_hidden), selected = LibraryDisplay.hidden, enabled = open,
modifier = Modifier.fillMaxWidth().stepItem(4),
) { LibraryDisplay.toggleHidden(ctx) }
}
})
}
@@ -82,7 +82,7 @@ internal object StoreTabsState {
SessionPrefs.settleStoresTabOrder(context, Store.entries.map { it.id })
tabs = arrangeStoreTabs(SessionPrefs.storesTabOrder(context), SessionPrefs.storesTabHidden(context))
libraryPlaces = SessionPrefs.libraryTabPlaces(context) ?: DEFAULT_LIBRARY_PLACES
libraryHidden = SessionPrefs.libraryTabsHidden(context)
libraryHidden = SessionPrefs.libraryTabsHidden(context) + listOfNotNull(LIBRARY_HIDDEN.takeUnless { SessionPrefs.libraryShowHidden(context) })
}
/** [ids] may hold the Library's own tabs among the stores; each one's place is kept as the tab it follows. */
@@ -110,20 +110,21 @@ internal object StoreTabsState {
fun setLibraryShown(context: android.content.Context, id: String, show: Boolean) {
libraryHidden = if (show) libraryHidden - id else libraryHidden + id
SessionPrefs.setLibraryTabsHidden(context, libraryHidden)
if (id == LIBRARY_HIDDEN) SessionPrefs.setLibraryShowHidden(context, show)
else SessionPrefs.setLibraryTabsHidden(context, libraryHidden - LIBRARY_HIDDEN)
}
private fun save(context: android.content.Context, arranged: Boolean) =
SessionPrefs.saveStoresTabs(context, tabs.map { it.store.id }, tabs.filterNot { it.shown }.map { it.store.id }.toSet(), arranged)
}
/** The Library tabs that are not stores but sort among them in Manage stores. Only Favorites and Custom games can be hidden. */
internal val LIBRARY_OWN_TABS = listOf(LIBRARY_FAVORITES, Library.SOURCE_STEAM, Library.ADDED)
internal val LIBRARY_HIDEABLE_TABS = setOf(LIBRARY_FAVORITES, Library.ADDED)
/** The Library tabs that are not stores but sort among them in Manage stores. Only Favorites, Custom games and Hidden can be turned off; Hidden starts off. */
internal val LIBRARY_OWN_TABS = listOf(LIBRARY_FAVORITES, Library.SOURCE_STEAM, Library.ADDED, LIBRARY_HIDDEN)
internal val LIBRARY_HIDEABLE_TABS = setOf(LIBRARY_FAVORITES, Library.ADDED, LIBRARY_HIDDEN)
/** Favorites, then Steam, ahead of the stores; Custom games after them (null: the end). */
/** Favorites, then Steam, ahead of the stores; Custom games and Hidden after them (null: the end). */
internal val DEFAULT_LIBRARY_PLACES: List<Pair<String, String?>> =
listOf(LIBRARY_FAVORITES to "", Library.SOURCE_STEAM to LIBRARY_FAVORITES, Library.ADDED to null)
listOf(LIBRARY_FAVORITES to "", Library.SOURCE_STEAM to LIBRARY_FAVORITES, Library.ADDED to null, LIBRARY_HIDDEN to null)
/**
* Puts the Library's own tabs into a store tab order. Each goes after the tab it follows ("" for first; null or a tab that is gone
@@ -338,9 +339,14 @@ private fun LibraryTabSortRow(id: String, held: Boolean, offset: Float, hint: St
val label = when (id) {
LIBRARY_FAVORITES -> stringResource(R.string.soundtracks_favorites)
Library.ADDED -> stringResource(R.string.library_custom_games)
LIBRARY_HIDDEN -> stringResource(R.string.apps_filter_hidden)
else -> stringResource(R.string.source_steam)
}
val dot = if (id == LIBRARY_FAVORITES) FavoritesColours.dot else sourceColours(id).dot
val dot = when (id) {
LIBRARY_FAVORITES -> FavoritesColours.dot
LIBRARY_HIDDEN -> HIDDEN_DOT
else -> sourceColours(id).dot
}
SortRowFrame(held, offset, modifier.testTag("store-row-$id"), hot, src, onFocus) {
Box(contentAlignment = Alignment.Center, modifier = Modifier.size(width = STORE_HANDLE, height = STORE_ROW).testTag("store-handle-$id")) {
Icon(Icons.Filled.DragHandle, null, tint = if (held) pal.signal else colors.onSurfaceVariant, modifier = Modifier.size(20.dp))
@@ -30,10 +30,16 @@ class LibraryHiddenTest {
assertFalse(inLibrarySource(LIBRARY_HIDDEN, cs, emptySet(), hidden))
}
@Test fun theHiddenTabIsLastAndOnlyWhenEnabled() {
@Test fun theHiddenTabIsLastAndOnlyWhenTurnedOn() {
val entries = listOf(tf2, cs)
assertEquals(listOf(Library.SOURCE_STEAM), librarySources(entries, emptyList(), hidden = hidden))
assertEquals(listOf(Library.SOURCE_STEAM, LIBRARY_HIDDEN), librarySources(entries, emptyList(), hidden = hidden, showHidden = true))
assertEquals(listOf(Library.SOURCE_STEAM, LIBRARY_HIDDEN), librarySources(entries, emptyList(), hidden = hidden, offTabs = emptySet()))
}
@Test fun theHiddenTabSortsLastUnlessMoved() {
assertEquals(listOf(LIBRARY_FAVORITES, Library.SOURCE_STEAM, "epic", Library.ADDED, LIBRARY_HIDDEN), placeLibraryTabs(listOf("epic"), DEFAULT_LIBRARY_PLACES))
val moved = placeLibraryTabs(listOf("epic"), listOf(LIBRARY_HIDDEN to "epic"))
assertEquals(listOf("epic", LIBRARY_HIDDEN), moved.filter { it == "epic" || it == LIBRARY_HIDDEN })
}
@Test fun aStoreTabWithOnlyHiddenGamesDisappears() {
@@ -39,4 +39,17 @@ class StoreTabsStateTest {
assertFalse(StoreTabsState.setShown(ctx, last, false))
assertTrue(StoreTabsState.tabs.single { it.store == last }.shown)
}
@Test fun theHiddenTabStartsOffAndItsSwitchSurvivesAReload() {
assertTrue(LIBRARY_HIDDEN in StoreTabsState.libraryHidden)
StoreTabsState.setLibraryShown(ctx, LIBRARY_HIDDEN, true)
assertTrue(SessionPrefs.libraryShowHidden(ctx))
StoreTabsState.load(ctx)
assertFalse(LIBRARY_HIDDEN in StoreTabsState.libraryHidden)
StoreTabsState.setLibraryShown(ctx, LIBRARY_FAVORITES, false)
assertEquals(setOf(LIBRARY_FAVORITES), SessionPrefs.libraryTabsHidden(ctx))
StoreTabsState.setLibraryShown(ctx, LIBRARY_HIDDEN, false)
StoreTabsState.load(ctx)
assertEquals(setOf(LIBRARY_FAVORITES, LIBRARY_HIDDEN), StoreTabsState.libraryHidden)
}
}