mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-21 22:05:59 +00:00
feat(dual-screen): Dashboard opens on Chat; a game start shows In-game stats
With no tab picked yet the Dashboard opens on Chat; the last tab the user tapped still opens next time. When a game starts while the Dashboard is showing it switches to In-game stats. That switch is not saved, so the user's own pick is kept.
This commit is contained in:
1 parent
e75505c019
commit
5045002de1
3 files changed
+33
-2
No files matched your search
@@ -218,6 +218,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
private lateinit var touchscreenGestures: TouchscreenGestures
|
||||
private var gestureConfig = com.droiddeck.launcher.input.TouchGestureConfig()
|
||||
private var gestureGame: String? = null
|
||||
private var gameStarts by mutableIntStateOf(0)
|
||||
private var gestureSettingsOpen by mutableStateOf(false)
|
||||
private var steamImportAsk by mutableStateOf<com.droiddeck.launcher.session.SteamImportPrompt.Ask?>(null)
|
||||
private var steamImportAnswered: String? = null
|
||||
@@ -931,7 +932,11 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (nextGame != gestureGame) { gestureGame = nextGame; refreshGestureConfig() }
|
||||
if (nextGame != gestureGame) {
|
||||
if (nextGame != null) gameStarts++
|
||||
gestureGame = nextGame
|
||||
refreshGestureConfig()
|
||||
}
|
||||
}
|
||||
LaunchedEffect(drawerOpen, pcKeyboardOpen, achievementsOpen, gestureSettingsOpen, pipUi, SessionState.suspended) {
|
||||
if (drawerOpen || pcKeyboardOpen || achievementsOpen || gestureSettingsOpen || pipUi || SessionState.suspended) {
|
||||
@@ -3125,6 +3130,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
DroidDeckTheme {
|
||||
BottomDashboard(
|
||||
bottomPages(), SessionPrefs.bottomPage(this),
|
||||
gameStarts = gameStarts,
|
||||
onPage = { SessionPrefs.setBottomPage(this, it) },
|
||||
onClose = { selectSecondScreenMode(SecondScreenMode.NONE) },
|
||||
onMenu = if (dockDrawer()) ({ drawerOpen = true }) else null,
|
||||
|
||||
@@ -24,6 +24,7 @@ import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
@@ -53,7 +54,13 @@ class BottomPage(
|
||||
)
|
||||
|
||||
internal fun pickBottomPage(remembered: String?, ids: List<String>): String? =
|
||||
ids.firstOrNull { it == remembered } ?: ids.firstOrNull()
|
||||
ids.firstOrNull { it == remembered } ?: ids.firstOrNull { it == DEFAULT_PAGE } ?: ids.firstOrNull()
|
||||
|
||||
/** The page a game start switches to; not saved, so the page the user picked still opens next time. */
|
||||
internal fun pageForGameStart(ids: List<String>): String? = GAME_PAGE.takeIf { it in ids }
|
||||
|
||||
private const val DEFAULT_PAGE = "chat"
|
||||
private const val GAME_PAGE = "telemetry"
|
||||
|
||||
/** Tabs show their names while every tab still fits at [TAB_WIDTH]; otherwise only the open tab keeps its name. */
|
||||
internal fun bottomTabsWithLabels(widthDp: Float, tabs: Int): Boolean = tabs * TAB_WIDTH + 2 * BAR_BUTTON <= widthDp
|
||||
@@ -68,9 +75,14 @@ fun BottomDashboard(
|
||||
onPage: (String) -> Unit,
|
||||
onClose: () -> Unit,
|
||||
onMenu: (() -> Unit)?,
|
||||
gameStarts: Int = 0,
|
||||
) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
var current by remember { mutableStateOf(pickBottomPage(remembered, pages.map { it.id })) }
|
||||
val startsWhenOpened = remember { gameStarts }
|
||||
LaunchedEffect(gameStarts) {
|
||||
if (gameStarts != startsWhenOpened) pageForGameStart(pages.map { it.id })?.let { current = it }
|
||||
}
|
||||
val page = pages.firstOrNull { it.id == current } ?: pages.firstOrNull()
|
||||
BoxWithConstraints(Modifier.fillMaxSize().background(colors.background)) {
|
||||
val labels = bottomTabsWithLabels(maxWidth.value, pages.size)
|
||||
|
||||
@@ -17,6 +17,19 @@ class BottomDashboardTest {
|
||||
assertNull(pickBottomPage("shots", emptyList()))
|
||||
}
|
||||
|
||||
@Test fun withNothingPickedTheChatOpens() {
|
||||
val ids = listOf("telemetry", "downloads", "notifications", "screenshots", "chat")
|
||||
assertEquals("chat", pickBottomPage(null, ids))
|
||||
assertEquals("chat", pickBottomPage("gone", ids))
|
||||
assertEquals("telemetry", pickBottomPage("telemetry", ids))
|
||||
assertEquals("screenshots", pickBottomPage("screenshots", ids))
|
||||
}
|
||||
|
||||
@Test fun aGameStartShowsTheInGameStats() {
|
||||
assertEquals("telemetry", pageForGameStart(listOf("telemetry", "downloads", "chat")))
|
||||
assertNull(pageForGameStart(listOf("downloads", "chat")))
|
||||
}
|
||||
|
||||
@Test fun tabNamesShowOnlyWhileEveryTabFits() {
|
||||
// Retroid Pocket Duo bottom panel: 1280x960 at 320 dpi = 640 dp wide.
|
||||
assertTrue(bottomTabsWithLabels(640f, 4))
|
||||
|
||||
Reference in new issue
Block a user