Fix portrait game tabs and compact Library and Store filters (#3658)

Keep About, Launch, and Install in the game detail strip. Use dropdowns for top-level sources in portrait and narrow panes. Default Library title and size overlays to off without overriding saved choices.
This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-12-03 18:38:15 -05:00
1 parent 5a18f69c7e
commit 00b354a40a
9 files changed
+241 -69

No files matched your search

@@ -364,13 +364,13 @@ object SessionPrefs {
prefs(context).edit().putInt("libraryCardLevel", level).apply()
}
fun libraryShowTitle(context: Context): Boolean = prefs(context).getBoolean("libraryShowTitle", true)
fun libraryShowTitle(context: Context): Boolean = prefs(context).getBoolean("libraryShowTitle", false)
fun setLibraryShowTitle(context: Context, show: Boolean) {
prefs(context).edit().putBoolean("libraryShowTitle", show).apply()
}
fun libraryShowSize(context: Context): Boolean = prefs(context).getBoolean("libraryShowSize", true)
fun libraryShowSize(context: Context): Boolean = prefs(context).getBoolean("libraryShowSize", false)
fun setLibraryShowSize(context: Context, show: Boolean) {
prefs(context).edit().putBoolean("libraryShowSize", show).apply()
@@ -396,7 +396,7 @@ private fun GameCapsule(scores: GameScores?, actions: @Composable () -> Unit) {
}
@Composable
private fun GameTabBar(
internal fun GameTabBar(
tabs: List<String>, selected: Int, onSelect: (Int) -> Unit,
modifier: Modifier = Modifier, focusRequesters: List<FocusRequester>? = null,
bumpers: Boolean = true, compact: Boolean = false,
@@ -415,10 +415,6 @@ private fun GameTabBar(
if (bumpers) TabBarBumper("LB", stringResource(R.string.widgets_prev_tab), leading = true) { onSelect((selected + tabs.size - 1) % tabs.size) }
androidx.compose.foundation.layout.BoxWithConstraints(Modifier.weight(1f).clip(if (bumpers) RoundedCornerShape(BumperFlat) else CircleShape).onSizeChanged { viewport = it.width }) {
val share = maxWidth / tabs.size.coerceAtLeast(1)
if (tabsAsMenu(maxWidth, tabs.size)) {
TabMenu(tabs, selected, onSelect, focus = focusRequesters)
return@BoxWithConstraints
}
Box(Modifier.horizontalScroll(scroll)) {
spans.getOrNull(selected)?.takeIf { tabHeight > 0 }?.let { span ->
TabHighlight(span, tabHeight, flatStart = bumpers && selected == 0, flatEnd = bumpers && selected == tabs.lastIndex)
@@ -17,6 +17,7 @@ import androidx.compose.foundation.interaction.collectIsPressedAsState
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
@@ -204,9 +205,9 @@ internal object LibraryDisplay {
val scales = listOf(0.75f, 0.875f, 1f, 1.2f, 1.45f)
var level by mutableIntStateOf(DEFAULT_LEVEL)
private set
var title by mutableStateOf(true)
var title by mutableStateOf(false)
private set
var size by mutableStateOf(true)
var size by mutableStateOf(false)
private set
fun load(context: android.content.Context) {
@@ -914,7 +915,7 @@ private fun sourceChipsShown(sources: List<String>, manage: Boolean): Boolean =
@OptIn(androidx.compose.foundation.ExperimentalFoundationApi::class)
@Composable
private fun LibraryFilters(sources: List<String>, source: String, onSource: (String) -> Unit, manage: Boolean) {
internal fun LibraryFilters(sources: List<String>, source: String, onSource: (String) -> Unit, manage: Boolean) {
val chips = sourceChipsShown(sources, manage)
if (!chips && !manage) return
val pal = LocalPalette.current
@@ -931,42 +932,54 @@ private fun LibraryFilters(sources: List<String>, source: String, onSource: (Str
horizontalArrangement = Arrangement.spacedBy(8.dp), verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth().padding(top = 4.dp, bottom = 2.dp),
) {
Box(Modifier.weight(1f).edgeFade(scroll).horizontalScroll(scroll)) {
Row(horizontalArrangement = Arrangement.spacedBy(8.dp), verticalAlignment = Alignment.CenterVertically, modifier = Modifier.focusGroup()) {
for (id in keys) {
val store = Store.byId(id)
val dot = sourceDot(id)
val label = when (id) {
LIBRARY_ALL -> stringResource(R.string.stores_tab_all)
Library.ADDED -> stringResource(R.string.library_custom_games)
LIBRARY_FAVORITES -> stringResource(R.string.soundtracks_favorites)
LIBRARY_HIDDEN -> stringResource(R.string.apps_filter_hidden)
else -> store?.shortLabel ?: sourceLabel(id)
}
androidx.compose.runtime.key(id) {
val reveal = remember { BringIntoViewRequester() }
LaunchedEffect(source) { if (source == id) reveal.bringIntoView() }
StoreChip(
label = label, on = source == id, under = fillShown && highlighted == id, key = id, mark = dot ?: pal.signal,
modifier = Modifier.bringIntoViewRequester(reveal).testTag("library-source-$id")
.onGloballyPositioned { bounds[id] = it.boundsInParent() },
lead = {
if (dot != null) Box(Modifier.size(9.dp).background(dot, CircleShape))
else Icon(Icons.Filled.GridView, null, modifier = Modifier.size(14.dp))
},
onFocused = { focused = it },
paneKey = "libchip:$id",
) { onSource(id) }
BoxWithConstraints(Modifier.weight(1f)) {
if (sourceTabsAsMenu(maxWidth, keys.size)) {
TabMenu(
keys.map { librarySourceChipLabel(it) }, keys.indexOf(source), { onSource(keys[it]) },
chipModifier = Modifier.paneItem("libchip:$source"),
leading = { i, _ -> LibrarySourceMark(sourceDot(keys[i])) },
)
} else Box(Modifier.edgeFade(scroll).horizontalScroll(scroll)) {
Row(horizontalArrangement = Arrangement.spacedBy(8.dp), verticalAlignment = Alignment.CenterVertically, modifier = Modifier.focusGroup()) {
for (id in keys) {
val dot = sourceDot(id)
androidx.compose.runtime.key(id) {
val reveal = remember { BringIntoViewRequester() }
LaunchedEffect(source) { if (source == id) reveal.bringIntoView() }
StoreChip(
label = librarySourceChipLabel(id), on = source == id, under = fillShown && highlighted == id, key = id, mark = dot ?: pal.signal,
modifier = Modifier.bringIntoViewRequester(reveal).testTag("library-source-$id")
.onGloballyPositioned { bounds[id] = it.boundsInParent() },
lead = { LibrarySourceMark(dot) },
onFocused = { focused = it },
paneKey = "libchip:$id",
) { onSource(id) }
}
}
}
if (highlighted in keys) ChipGlide(keys.indexOf(highlighted), bounds[highlighted], tint, visible = fillShown)
}
if (highlighted in keys) ChipGlide(keys.indexOf(highlighted), bounds[highlighted], tint, visible = fillShown)
}
if (manage) ManageStoresChip()
}
}
}
@Composable
private fun librarySourceChipLabel(id: String): String = when (id) {
LIBRARY_ALL -> stringResource(R.string.stores_tab_all)
Library.ADDED -> stringResource(R.string.library_custom_games)
LIBRARY_FAVORITES -> stringResource(R.string.soundtracks_favorites)
LIBRARY_HIDDEN -> stringResource(R.string.apps_filter_hidden)
else -> Store.byId(id)?.shortLabel ?: sourceLabel(id)
}
@Composable
private fun LibrarySourceMark(dot: Color?) {
if (dot != null) Box(Modifier.size(9.dp).background(dot, CircleShape))
else Icon(Icons.Filled.GridView, null, modifier = Modifier.size(14.dp))
}
@Composable
private fun sourceTitle(src: String): String = when (src) {
LIBRARY_ALL -> stringResource(R.string.library_all_games)
@@ -453,7 +453,7 @@ private fun StoreDot(store: Store, signedIn: Boolean) {
@OptIn(androidx.compose.foundation.ExperimentalFoundationApi::class)
@Composable
private fun StoreChips(
internal fun StoreChips(
selected: String, focused: String?, tabs: List<StoreTab>,
onStore: (Store) -> Unit, onSettings: (Rect?) -> Unit, onFocusChip: (String?) -> Unit,
) {
@@ -471,41 +471,41 @@ private fun StoreChips(
Box(Modifier.fillMaxWidth()) {
Row(horizontalArrangement = Arrangement.spacedBy(gap), verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth()) {
val shown = tabs.filter { it.shown }.map { it.store }
androidx.compose.foundation.layout.BoxWithConstraints(Modifier.weight(1f)) {
if (tabsAsMenu(maxWidth, shown.size)) TabMenu(
shown.map { it.shortLabel }, shown.indexOfFirst { it.id == selected }, { onStore(shown[it]) },
chipModifier = shown.fold(Modifier as Modifier) { m, st -> key(st) { m.paneItem("storechip:${st.id}") } },
descriptions = shown.map { st ->
val signedIn = StoresState.isSignedIn(st) && StoresState.expired[st] != true
st.label + if (signedIn || !StoresState.accountsLoaded) "" else " " + stringResource(R.string.stores_chip_signed_out)
},
leading = { i, inList ->
val signedIn = StoresState.isSignedIn(shown[i]) && StoresState.expired[shown[i]] != true
if (inList) Box(Modifier.size(12.dp).background(sourceColours(shown[i].id).dot.copy(alpha = if (signedIn) 1f else 0.35f), CircleShape))
else StoreDot(shown[i], signedIn)
},
) else Box(Modifier.edgeFade(tabScroll).horizontalScroll(tabScroll)) {
Row(horizontalArrangement = Arrangement.spacedBy(gap), verticalAlignment = Alignment.CenterVertically, modifier = Modifier.focusGroup()) {
for (tab in tabs) {
val store = tab.store
if (tab.shown) {
val signedIn = StoresState.isSignedIn(store) && StoresState.expired[store] != true
key(store) {
val reveal = remember { BringIntoViewRequester() }
LaunchedEffect(selected) { if (selected == store.id) reveal.bringIntoView() }
StoreChip(
label = store.shortLabel, on = selected == store.id, under = fillShown && highlighted == store.id, key = store.id, mark = sourceColours(store.id).dot,
modifier = Modifier.bringIntoViewRequester(reveal).onGloballyPositioned { bounds[store.id] = it.boundsInParent() },
lead = { StoreDot(store, signedIn) },
description = store.label + if (signedIn || !StoresState.accountsLoaded) "" else " " + stringResource(R.string.stores_chip_signed_out),
onFocused = onFocusChip,
) { onStore(store) }
BoxWithConstraints(Modifier.weight(1f)) {
if (sourceTabsAsMenu(maxWidth, shown.size)) TabMenu(
shown.map { it.shortLabel }, shown.indexOfFirst { it.id == selected }, { onStore(shown[it]) },
chipModifier = shown.fold(Modifier as Modifier) { m, st -> key(st) { m.paneItem("storechip:${st.id}") } },
descriptions = shown.map { st ->
val signedIn = StoresState.isSignedIn(st) && StoresState.expired[st] != true
st.label + if (signedIn || !StoresState.accountsLoaded) "" else " " + stringResource(R.string.stores_chip_signed_out)
},
leading = { i, inList ->
val signedIn = StoresState.isSignedIn(shown[i]) && StoresState.expired[shown[i]] != true
if (inList) Box(Modifier.size(12.dp).background(sourceColours(shown[i].id).dot.copy(alpha = if (signedIn) 1f else 0.35f), CircleShape))
else StoreDot(shown[i], signedIn)
},
) else Box(Modifier.edgeFade(tabScroll).horizontalScroll(tabScroll)) {
Row(horizontalArrangement = Arrangement.spacedBy(gap), verticalAlignment = Alignment.CenterVertically, modifier = Modifier.focusGroup()) {
for (tab in tabs) {
val store = tab.store
if (tab.shown) {
val signedIn = StoresState.isSignedIn(store) && StoresState.expired[store] != true
key(store) {
val reveal = remember { BringIntoViewRequester() }
LaunchedEffect(selected) { if (selected == store.id) reveal.bringIntoView() }
StoreChip(
label = store.shortLabel, on = selected == store.id, under = fillShown && highlighted == store.id, key = store.id, mark = sourceColours(store.id).dot,
modifier = Modifier.bringIntoViewRequester(reveal).onGloballyPositioned { bounds[store.id] = it.boundsInParent() },
lead = { StoreDot(store, signedIn) },
description = store.label + if (signedIn || !StoresState.accountsLoaded) "" else " " + stringResource(R.string.stores_chip_signed_out),
onFocused = onFocusChip,
) { onStore(store) }
}
}
}
}
ChipGlide(keys.indexOf(highlighted), bounds[highlighted], tint, visible = fillShown)
}
ChipGlide(keys.indexOf(highlighted), bounds[highlighted], tint, visible = fillShown)
}
}
var cogAt by remember { mutableStateOf<Rect?>(null) }
Box(Modifier.onGloballyPositioned { cogAt = it.boundsInRoot() }) {
@@ -1,5 +1,6 @@
package com.droiddeck.launcher.ui
import android.content.res.Configuration
import androidx.compose.foundation.LocalIndication
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
@@ -30,6 +31,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.semantics.contentDescription
@@ -47,6 +49,11 @@ private val TAB_MIN_WIDTH = 96.dp
internal fun tabsAsMenu(width: Dp, count: Int): Boolean =
count > 2 && width < TAB_MENU_BELOW && width / count < TAB_MIN_WIDTH
@Composable
internal fun sourceTabsAsMenu(width: Dp, count: Int): Boolean =
count > 1 && (LocalConfiguration.current.orientation == Configuration.ORIENTATION_PORTRAIT ||
(width < TAB_MENU_BELOW && width / count < TAB_MIN_WIDTH))
/**
* Tabs as one chip naming the shown tab, which opens the list of them, as the second screen's
* picker does. Each of [focus] lands on the chip, so callers that focus a tab still reach it.
@@ -0,0 +1,40 @@
package com.droiddeck.launcher.ui
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.width
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.assertIsSelected
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick
import androidx.compose.ui.unit.dp
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [34], qualifiers = "w360dp-h640dp-port", application = android.app.Application::class)
class GameTabBarTest {
@get:Rule val compose = createRobolectricComposeRule()
@Test fun narrowGameDetailsKeepEachTabInTheStrip() {
compose.setContent {
DroidDeckTheme {
Box(Modifier.width(320.dp)) {
var selected by remember { mutableIntStateOf(0) }
GameTabBar(listOf("About", "Launch", "Install"), selected, { selected = it }, compact = true)
}
}
}
compose.onNodeWithTag("tab-menu").assertDoesNotExist()
for (index in 0..2) {
compose.onNodeWithTag("tab-$index").assertIsDisplayed().performClick().assertIsSelected()
}
}
}
@@ -0,0 +1,35 @@
package com.droiddeck.launcher.ui
import android.content.Context
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [28], manifest = Config.NONE)
class LibraryDisplayTest {
private val context: Context get() = RuntimeEnvironment.getApplication()
@Before fun reset() {
context.getSharedPreferences("session", Context.MODE_PRIVATE).edit().clear().commit()
LibraryDisplay.load(context)
}
@Test fun titleAndSizeDefaultOff() {
assertFalse(LibraryDisplay.title)
assertFalse(LibraryDisplay.size)
}
@Test fun savedChoicesStillLoad() {
LibraryDisplay.toggleTitle(context)
LibraryDisplay.toggleSize(context)
LibraryDisplay.load(context)
assertTrue(LibraryDisplay.title)
assertTrue(LibraryDisplay.size)
}
}
@@ -51,6 +51,7 @@ class LibraryVisibilityTest {
StoreAccounts.keys = CredentialCipher.KeyProvider { SecretKeySpec(ByteArray(32) { 7 }, "AES") }
StoreAccounts.keystoreFailed = false
ctx.getSharedPreferences("session", 0).edit().clear().commit()
SessionPrefs.setLibraryShowTitle(ctx, true)
LibraryView.source = LIBRARY_ALL
LibraryView.query = ""
LibraryView.focusFirst = false
@@ -72,6 +73,7 @@ class LibraryVisibilityTest {
StoresState.library.clear()
StoresState.accounts.clear()
ctx.getSharedPreferences("session", 0).edit().clear().commit()
SessionPrefs.setLibraryShowTitle(ctx, true)
LibraryView.source = LIBRARY_ALL
LibraryView.query = ""
LibraryView.focusFirst = false
@@ -0,0 +1,79 @@
package com.droiddeck.launcher.ui
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.width
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.test.assert
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.hasText
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick
import androidx.compose.ui.unit.dp
import com.droiddeck.launcher.frontend.Library
import com.droiddeck.launcher.stores.Store
import com.droiddeck.launcher.stores.StoreTab
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [34], qualifiers = "w360dp-h640dp-port", application = android.app.Application::class)
class SourceTabMenuTest {
@get:Rule val compose = createRobolectricComposeRule()
private fun showLibrary(width: Int = 360) {
compose.setContent {
DroidDeckTheme {
var source by remember { mutableStateOf(LIBRARY_ALL) }
Box(Modifier.width(width.dp)) {
LibraryFilters(listOf(Library.SOURCE_STEAM, Store.EPIC.id), source, { source = it }, manage = true)
}
}
}
}
@Test fun portraitLibraryPicksASourceAndKeepsManageVisible() {
showLibrary()
compose.onNodeWithTag("library-manage-stores").assertIsDisplayed()
val menu = compose.onNodeWithTag("tab-menu")
menu.assert(hasText("All")).performClick()
compose.onNodeWithTag("tab-menu:2").assertIsDisplayed().performClick()
menu.assert(hasText(Store.EPIC.shortLabel))
}
@Test @Config(qualifiers = "w900dp-h500dp-land")
fun wideLandscapeLibraryKeepsTheChips() {
showLibrary(width = 740)
compose.onNodeWithTag("tab-menu").assertDoesNotExist()
compose.onNodeWithTag("library-source-epic").assertIsDisplayed()
}
@Test @Config(qualifiers = "w900dp-h500dp-land")
fun narrowLibraryPaneUsesTheMenuEvenInLandscape() {
showLibrary(width = 270)
compose.onNodeWithTag("tab-menu").assertIsDisplayed()
}
@Test fun portraitStoreUsesTheMenuEvenWithOnlyTwoVisibleStores() {
compose.setContent {
DroidDeckTheme {
var selected by remember { mutableStateOf(Store.EPIC.id) }
StoreChips(
selected, null, listOf(StoreTab(Store.EPIC, true), StoreTab(Store.GOG, true), StoreTab(Store.EA, false)),
onStore = { selected = it.id }, onSettings = {}, onFocusChip = {},
)
}
}
val menu = compose.onNodeWithTag("tab-menu")
menu.assert(hasText(Store.EPIC.shortLabel)).performClick()
compose.onNodeWithTag("tab-menu:2").assertDoesNotExist()
compose.onNodeWithTag("tab-menu:1").assertIsDisplayed().performClick()
menu.assert(hasText(Store.GOG.shortLabel))
}
}