feat: consistent bottom screen bar and menu-first navigation in sessions (#2084)

This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-11-04 13:26:35 -05:00
1 parent 940efdab3a
commit eed9edaa1c
18 files changed
+852 -575

No files matched your search

@@ -4,8 +4,8 @@ import org.junit.Assert.assertEquals
import org.junit.Test
class SecondScreenModeTest {
@Test fun withNothingRememberedTheDashboardOpens() {
assertEquals(SecondScreenMode.DASHBOARD, SecondScreenMode.opening(null, deckPad = true, dashboard = true))
@Test fun withNothingRememberedDeckPadsGetControlsAndOthersTheDashboard() {
assertEquals(SecondScreenMode.DECK_CONTROLS, SecondScreenMode.opening(null, deckPad = true, dashboard = true))
assertEquals(SecondScreenMode.DASHBOARD, SecondScreenMode.opening(null, deckPad = false, dashboard = true))
}
@@ -27,7 +27,7 @@ class SecondScreenModeTest {
}
@Test fun anUnknownOrClosedChoiceFallsBackToTheDefault() {
assertEquals(SecondScreenMode.DASHBOARD, SecondScreenMode.opening("none", deckPad = true, dashboard = true))
assertEquals(SecondScreenMode.DECK_CONTROLS, SecondScreenMode.opening("none", deckPad = true, dashboard = true))
assertEquals(SecondScreenMode.DASHBOARD, SecondScreenMode.opening("gone", deckPad = false, dashboard = true))
assertEquals(SecondScreenMode.DECK_CONTROLS, SecondScreenMode.opening("none", deckPad = true))
assertEquals(SecondScreenMode.KEYBOARD_TRACKPAD, SecondScreenMode.opening("gone", deckPad = false))
@@ -1,9 +1,7 @@
package com.droiddeck.launcher.ui
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Test
class BottomDashboardTest {
@@ -17,10 +15,11 @@ class BottomDashboardTest {
assertNull(pickBottomPage("shots", emptyList()))
}
@Test fun withNothingPickedTheChatOpens() {
@Test fun withNothingPickedTheStatsOpen() {
val ids = listOf("telemetry", "downloads", "notifications", "screenshots", "chat")
assertEquals("chat", pickBottomPage(null, ids))
assertEquals("chat", pickBottomPage("gone", ids))
assertEquals("telemetry", pickBottomPage(null, ids))
assertEquals("telemetry", pickBottomPage("gone", ids))
assertEquals("chat", pickBottomPage("chat", ids))
assertEquals("telemetry", pickBottomPage("telemetry", ids))
assertEquals("screenshots", pickBottomPage("screenshots", ids))
}
@@ -29,12 +28,6 @@ class BottomDashboardTest {
assertEquals("telemetry", pageForGameStart(listOf("telemetry", "downloads", "chat")))
assertNull(pageForGameStart(listOf("downloads", "chat")))
}
@Test fun tabNamesShowOnlyWhileEveryTabFits() {
assertTrue(bottomTabsWithLabels(640f, 4))
assertFalse(bottomTabsWithLabels(640f, 5))
assertFalse(bottomTabsWithLabels(360f, 3))
}
}
class BottomDownloadsRateTest {
@@ -60,7 +53,7 @@ class BottomTelemetryLapTimeTest {
assertEquals("screenshots", SessionBottomTab.picked("2026-11-01-01-steam"))
assertNull(SessionBottomTab.picked("2026-11-01-02-steam"))
assertNull(SessionBottomTab.picked(null))
assertEquals("chat", pickBottomPage(SessionBottomTab.picked("2026-11-01-02-steam"), listOf("telemetry", "chat", "screenshots")))
assertEquals("telemetry", pickBottomPage(SessionBottomTab.picked("2026-11-01-02-steam"), listOf("telemetry", "chat", "screenshots")))
}
@Test fun theStripNamesTheSteamClient() {
@@ -0,0 +1,78 @@
package com.droiddeck.launcher.ui
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.performClick
import com.droiddeck.launcher.R
import com.droiddeck.launcher.session.SessionService
import com.droiddeck.launcher.session.SessionState
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertNull
import org.junit.Rule
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], qualifiers = "w640dp-h480dp-land", application = android.app.Application::class)
class BottomScreenBarTest {
@get:Rule val compose = createRobolectricComposeRule()
private val context = RuntimeEnvironment.getApplication()
@After fun reset() {
SessionState.mode = SessionService.MODE_DESKTOP
}
@Test fun steamSessionsGetSteamAndQuickAccess() {
SessionState.mode = SessionService.MODE_STEAM
var steam = 0
var qam = 0
val model = sessionBarModel("Trackpad", {}, {}, { steam++ }, { qam++ })
assertNotNull(model.onSteam)
assertNotNull(model.onQam)
model.onSteam?.invoke()
model.onQam?.invoke()
assertEquals(1, steam)
assertEquals(1, qam)
}
@Test fun otherSessionsLeaveSteamOut() {
SessionState.mode = SessionService.MODE_DESKTOP
val model = sessionBarModel("Trackpad", {}, {}, {}, {})
assertNull(model.onSteam)
assertNull(model.onQam)
}
@Test fun everyButtonOnTheBarReachesItsAction() {
var closes = 0
var menus = 0
var steam = 0
var qam = 0
var keyboard = 0
compose.setContent {
DroidDeckTheme {
BottomScreenBar(BottomBarModel("Trackpad", { closes++ }, { menus++ }, { steam++ }, { qam++ },
listOf(BarExtra(context.getString(R.string.second_show_keyboard), icon = R.drawable.ic_bottom_keyboard) { keyboard++ })))
}
}
for (label in listOf(R.string.common_close, R.string.touch_droiddeck_menu, R.string.drawer_steam_menu, R.string.drawer_open_qam,
R.string.second_show_keyboard)) {
compose.onNodeWithContentDescription(context.getString(label)).performClick()
}
compose.waitForIdle()
assertEquals(listOf(1, 1, 1, 1, 1), listOf(closes, menus, steam, qam, keyboard))
}
@Test fun aBarWithoutMenuOrSteamShowsOnlyClose() {
compose.setContent {
DroidDeckTheme { BottomScreenBar(BottomBarModel("Terminal", {}, null, null, null)) }
}
compose.onNodeWithContentDescription(context.getString(R.string.common_close)).assertExists()
compose.onNodeWithContentDescription(context.getString(R.string.touch_droiddeck_menu)).assertDoesNotExist()
compose.onNodeWithContentDescription(context.getString(R.string.drawer_steam_menu)).assertDoesNotExist()
compose.onNodeWithContentDescription(context.getString(R.string.drawer_open_qam)).assertDoesNotExist()
}
}
@@ -1,6 +1,8 @@
package com.droiddeck.launcher.ui
import android.content.ComponentName
import android.view.MotionEvent
import androidx.activity.ComponentActivity
import android.view.View
import com.droiddeck.launcher.input.JoyConPadTest
import com.droiddeck.launcher.input.PadBridge
@@ -9,8 +11,10 @@ import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.Robolectric
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.Shadows.shadowOf
import org.robolectric.annotation.Config
import java.nio.file.Files
@@ -22,10 +26,14 @@ class DeckControlsPanelTest {
val directory = Files.createTempDirectory("deck-panel").toFile()
try {
SessionState.deckPad = false
val app = RuntimeEnvironment.getApplication()
shadowOf(app.packageManager).addActivityIfNotPresent(ComponentName(app, ComponentActivity::class.java))
val activity = Robolectric.buildActivity(ComponentActivity::class.java).setup().get()
for (pad in listOf(null, PadBridge(directory))) for (portraitDock in listOf(false, true)) {
val name = "pad=${pad != null} portraitDock=$portraitDock"
val panel = DeckControlsPanel(RuntimeEnvironment.getApplication(), onClose = {}, onSteamMenu = {}, onQam = {},
val panel = DeckControlsPanel(activity, onClose = {}, onSteamMenu = {}, onQam = {},
pad = pad, portraitDock = portraitDock)
activity.setContentView(panel)
assertEquals(name, pad == null, panel.deckControls)
val (w, h) = if (portraitDock) 720 to 1000 else 1200 to 480
panel.measure(View.MeasureSpec.makeMeasureSpec(w, View.MeasureSpec.EXACTLY),
@@ -123,32 +123,6 @@ class SessionSecondScreenTest {
}
}
@Test fun desktopTrackpadOmitsSteamShortcuts() = checkShortcuts(steam = false)
@Test fun steamTrackpadKeepsWorkingSteamShortcuts() = checkShortcuts(steam = true)
@Test fun trackpadMenuButtonOnlyAppearsWhenTheMenuCanMove() {
SessionState.mode = SessionService.MODE_STEAM
val activity = Robolectric.buildActivity(SessionActivity::class.java).get()
val display = activity.getSystemService(DisplayManager::class.java).getDisplay(Display.DEFAULT_DISPLAY)
val label = context.getString(R.string.touch_droiddeck_menu)
for (movable in listOf(false, true)) {
var menus = 0
val panel = SecondScreenPresentation(activity, display, { _, _, _, _ -> }, { _, _ -> }, {},
{}, {}, {}, onMenu = if (movable) ({ menus++ }) else null)
try {
panel.create()
panel.showMode(SecondScreenMode.KEYBOARD_TRACKPAD)
val buttons = descendants(panel.window!!.decorView).filter { it.contentDescription == label }.toList()
assertEquals(if (movable) 1 else 0, buttons.size)
buttons.forEach { it.performClick() }
assertEquals(if (movable) 1 else 0, menus)
} finally {
panel.closeControls()
}
}
}
@Test
@Config(sdk = [34], shadows = [PadBridgeRoutingTest.RegisteredKeyEvent::class])
fun controllerBumpersReachTheSecondScreenInBothSessionModes() {
@@ -250,33 +224,6 @@ class SessionSecondScreenTest {
assertEquals(listOf(SecondScreenMode.KEYBOARD_TRACKPAD, SecondScreenMode.TERMINAL), selected)
}
private fun checkShortcuts(steam: Boolean) {
SessionState.mode = if (steam) SessionService.MODE_STEAM else SessionService.MODE_DESKTOP
val activity = Robolectric.buildActivity(SessionActivity::class.java).get()
val display = activity.getSystemService(DisplayManager::class.java).getDisplay(Display.DEFAULT_DISPLAY)
var menus = 0
var qams = 0
val panel = SecondScreenPresentation(activity, display, { _, _, _, _ -> }, { _, _ -> }, {},
{ menus++ }, { qams++ }, {})
try {
panel.create()
panel.showMode(SecondScreenMode.KEYBOARD_TRACKPAD)
val buttons = descendants(panel.window!!.decorView).filterIsInstance<TextView>().filter { it.isClickable }.toList()
assertTrue(buttons.any { it.text == context.getString(R.string.second_show_keyboard) })
val shortcuts = buttons.filter { it.text == "STEAM" || it.text == "•••" }
if (steam) {
assertEquals(2, shortcuts.size)
shortcuts.forEach { it.performClick() }
assertEquals(1, menus)
assertEquals(1, qams)
} else {
assertTrue(shortcuts.isEmpty())
}
} finally {
panel.closeControls()
}
}
private fun descendants(view: View): Sequence<View> = sequence {
yield(view)
if (view is ViewGroup) for (index in 0 until view.childCount) yieldAll(descendants(view.getChildAt(index)))