mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 12:28:40 +00:00
feat(ui): reorder tabs, shelve them in More or hide them (#2569)
* feat(ui): reorder tabs, shelve them in More or hide them * fix(ui): back from shelved tabs, startup tab and panel More count
This commit is contained in:
1 parent
cd945a520a
commit
1b65508f56
47 files changed
+584
-100
No files matched your search
@@ -44,6 +44,7 @@ class App : Application() {
|
||||
CrashHandler.install(this)
|
||||
com.droiddeck.launcher.agent.AgentHost.refresh(this)
|
||||
com.droiddeck.launcher.agent.AgentTab.load(this)
|
||||
com.droiddeck.launcher.ui.NavTabs.load(this)
|
||||
com.droiddeck.launcher.ui.AgentPet.install(this)
|
||||
if (com.droiddeck.launcher.agent.AgentTab.visible) com.droiddeck.launcher.lab.LabNotice.openOnInstall = "agent"
|
||||
com.droiddeck.launcher.lab.LabNotice.started(this)
|
||||
|
||||
@@ -3207,6 +3207,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
if (!ok) android.widget.Toast.makeText(this, R.string.setup_reset_settings_partial, android.widget.Toast.LENGTH_LONG).show()
|
||||
com.droiddeck.launcher.ui.Motion.refresh(this)
|
||||
com.droiddeck.launcher.agent.AgentTab.load(this)
|
||||
com.droiddeck.launcher.ui.NavTabs.load(this)
|
||||
if (!switchLauncherIcon(LauncherIcon.DARK)) recreate()
|
||||
}
|
||||
}, "reset-settings").start()
|
||||
|
||||
@@ -7,7 +7,7 @@ import androidx.compose.runtime.setValue
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
|
||||
object AgentTab {
|
||||
var shown by mutableStateOf(false)
|
||||
var shown by mutableStateOf(true)
|
||||
private set
|
||||
|
||||
val visible: Boolean get() = shown && AgentHost.available
|
||||
|
||||
@@ -265,7 +265,7 @@ object SessionPrefs {
|
||||
prefs(context).edit().putBoolean("railLabels", show).apply()
|
||||
}
|
||||
|
||||
fun agentTab(context: Context): Boolean = prefs(context).getBoolean("agentTab", false)
|
||||
fun agentTab(context: Context): Boolean = prefs(context).getBoolean("agentTab", true)
|
||||
|
||||
fun setAgentTab(context: Context, show: Boolean) {
|
||||
prefs(context).edit().putBoolean("agentTab", show).apply()
|
||||
@@ -289,6 +289,24 @@ object SessionPrefs {
|
||||
prefs(context).edit().putString("storesTabHidden", hidden.joinToString(",")).apply()
|
||||
}
|
||||
|
||||
fun navTabOrder(context: Context): List<String> = idList(prefs(context).getString("navTabOrder", null))
|
||||
|
||||
fun setNavTabOrder(context: Context, order: List<String>) {
|
||||
prefs(context).edit().putString("navTabOrder", order.joinToString(",")).apply()
|
||||
}
|
||||
|
||||
fun navTabShelved(context: Context): Set<String> = idList(prefs(context).getString("navTabShelved", "soundtracks,agent")).toSet()
|
||||
|
||||
fun setNavTabShelved(context: Context, keys: Set<String>) {
|
||||
prefs(context).edit().putString("navTabShelved", keys.joinToString(",")).apply()
|
||||
}
|
||||
|
||||
fun navTabHidden(context: Context): Set<String> = idList(prefs(context).getString("navTabHidden", null)).toSet()
|
||||
|
||||
fun setNavTabHidden(context: Context, keys: Set<String>) {
|
||||
prefs(context).edit().putString("navTabHidden", keys.joinToString(",")).apply()
|
||||
}
|
||||
|
||||
private fun idList(raw: String?): List<String> = raw.orEmpty().split(',').map { it.trim() }.filter { it.isNotEmpty() }
|
||||
|
||||
val STORES_SORTS = listOf("lastPlayed", "recentlyInstalled", "titleAsc", "titleDesc", "sizeDesc", "sizeAsc", "releaseDateDesc")
|
||||
|
||||
@@ -18,7 +18,7 @@ object SettingsReset {
|
||||
"storesInstallLanguage",
|
||||
"hud", "hudDeck", "hudFps", "hudBattery", "hudGraph", "hudColor", "hudOpacity", "__KEEP_droidDeckHud__", "__KEEP_droidDeckHudPos__", "backHold", "backActionsInverted", "backDoubleTapMs", "touch", "osc", "shape", "steamController",
|
||||
"gamepadLeft", "gamepadRight", "pipAutoEnter", "unfoldedControls", "unfoldedControlsWithController",
|
||||
"stretch16x9", "picturePosition", "railLabels", "agentTab", "pcKeyboardSize", "pcKeyboardOpacity", "pcKeyboardHiddenKeys",
|
||||
"stretch16x9", "picturePosition", "railLabels", "agentTab", "navTabOrder", "navTabShelved", "navTabHidden", "pcKeyboardSize", "pcKeyboardOpacity", "pcKeyboardHiddenKeys",
|
||||
"gpuDriverMode", "androidDriver", "linuxDriver", "linuxDriver.steam", "linuxDriver.desktop",
|
||||
"tuSysmem", "glThread", "noGlError", "zinkLazy", "mangoapp", "gpuClockPin", "gamescopeRealtime", "ramCapMb", "vramCapMb", "zramClient",
|
||||
"directAudio", "mic", "wifiDiscovery", "clientCpusOverride", "clientCpus", "gameCpus",
|
||||
|
||||
@@ -59,6 +59,8 @@ class DualPanelModel(
|
||||
val appScale: Int,
|
||||
val onSelect: (String) -> Unit,
|
||||
val onResume: () -> Unit,
|
||||
val title: String = selected,
|
||||
val moreDownloads: Int = 0,
|
||||
)
|
||||
|
||||
object DualScreenPanel {
|
||||
@@ -322,7 +324,7 @@ internal fun DualPanelContent(model: DualPanelModel) {
|
||||
Row(Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(stringResource(R.string.app_name), fontSize = 15.sp, fontWeight = FontWeight.Bold, color = pal.signal)
|
||||
Spacer(Modifier.size(12.dp))
|
||||
val (label, _) = railLabelIcon(model.selected)
|
||||
val (label, _) = railLabelIcon(model.title)
|
||||
Text(stringResource(label), fontSize = 15.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground,
|
||||
modifier = Modifier.weight(1f), maxLines = 1, overflow = TextOverflow.Ellipsis)
|
||||
PanelClock()
|
||||
@@ -336,7 +338,7 @@ internal fun DualPanelContent(model: DualPanelModel) {
|
||||
for (row in model.keys.chunked(columns)) {
|
||||
Row(Modifier.fillMaxWidth().height(tileHeight), horizontalArrangement = Arrangement.spacedBy(gap)) {
|
||||
for (key in row) PanelTile(key, key == model.selected, key in model.badges,
|
||||
if (key == "stores") model.storeDownloads else 0, Modifier.weight(1f)) { model.onSelect(key) }
|
||||
if (key == "stores") model.storeDownloads else if (key == NavTabs.MORE) model.moreDownloads else 0, Modifier.weight(1f)) { model.onSelect(key) }
|
||||
repeat(columns - row.size) { Spacer(Modifier.weight(1f)) }
|
||||
}
|
||||
}
|
||||
@@ -400,12 +402,10 @@ private fun PanelClock() {
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun DualPanelPublisher(s: FrontEndState, selected: String, onSelect: (String) -> Unit, a: FrontEndActions) {
|
||||
val badges = buildSet {
|
||||
if (setupNeedsAttention(s)) add("setup")
|
||||
if (s.updates.hasUpdate) add("updates")
|
||||
}
|
||||
val model = DualPanelModel(navigationKeys(s), selected, badges, s.storeDownloadsActive, s.running, s.theme, s.appScale, onSelect, a.onResume)
|
||||
internal fun DualPanelPublisher(s: FrontEndState, selected: String, title: String, onSelect: (String) -> Unit, a: FrontEndActions) {
|
||||
val keys = navigationKeys(s)
|
||||
val badges = keys.filter { railBadge(s, it) }.toSet()
|
||||
val model = DualPanelModel(keys, selected, badges, s.storeDownloadsActive, s.running, s.theme, s.appScale, onSelect, a.onResume, title, railCount(s, NavTabs.MORE))
|
||||
androidx.compose.runtime.SideEffect { DualScreenPanel.model = model }
|
||||
androidx.compose.runtime.DisposableEffect(Unit) { onDispose { DualScreenPanel.model = null } }
|
||||
}
|
||||
|
||||
@@ -273,6 +273,10 @@ private fun Content(
|
||||
DesktopPage(s, a, modifier, onSelect)
|
||||
return
|
||||
}
|
||||
if (selected == NavTabs.MORE) {
|
||||
MorePage(s, a, onSelect, modifier.padding(horizontal = padH).padding(top = padV))
|
||||
return
|
||||
}
|
||||
if (selected == "agent") {
|
||||
AgentPage(modifier.padding(horizontal = padH).padding(top = padV))
|
||||
return
|
||||
|
||||
@@ -51,6 +51,7 @@ import androidx.compose.material.icons.outlined.AutoAwesome
|
||||
import androidx.compose.material.icons.outlined.DesktopWindows
|
||||
import androidx.compose.material.icons.outlined.Layers
|
||||
import androidx.compose.material.icons.outlined.LocalMall
|
||||
import androidx.compose.material.icons.outlined.MoreHoriz
|
||||
import androidx.compose.material.icons.outlined.SportsEsports
|
||||
import androidx.compose.material.icons.outlined.Storefront
|
||||
import androidx.compose.material.icons.outlined.SystemUpdate
|
||||
@@ -124,16 +125,7 @@ internal fun BottomBar(
|
||||
}
|
||||
}
|
||||
|
||||
internal fun navigationKeys(s: FrontEndState) = buildList {
|
||||
add("steam"); add("games")
|
||||
if (s.soundtracksEnabled) add("soundtracks")
|
||||
if (s.gameStoresEnabled) add("stores")
|
||||
add("desktop")
|
||||
if (com.droiddeck.launcher.agent.AgentTab.visible) add("agent")
|
||||
add("components")
|
||||
if (s.isHomeApp) add("android-apps")
|
||||
add("setup"); add("updates")
|
||||
}
|
||||
internal fun navigationKeys(s: FrontEndState) = NavTabs.bar(s)
|
||||
|
||||
internal object RailLabels {
|
||||
var shown by mutableStateOf(true)
|
||||
@@ -208,12 +200,26 @@ internal fun railLabelIcon(key: String): Pair<Int, ImageVector> = when (key) {
|
||||
"agent" -> R.string.rail_agent to Icons.Outlined.AutoAwesome
|
||||
"android-apps" -> R.string.rail_apps to Icons.Outlined.Apps
|
||||
"setup" -> R.string.rail_setup to Icons.Outlined.Tune
|
||||
NavTabs.MORE -> R.string.rail_more to Icons.Outlined.MoreHoriz
|
||||
else -> R.string.rail_updates to Icons.Outlined.SystemUpdate
|
||||
}
|
||||
|
||||
internal fun setupNeedsAttention(s: FrontEndState): Boolean = !s.ready || (s.available != null && s.available != s.installed) ||
|
||||
PhantomProcessLimit.blocksSteam(s.phantomProcessStatus) || com.droiddeck.launcher.sync.Syncthing.needsAttention
|
||||
|
||||
internal fun railBadge(s: FrontEndState, key: String, setupNeedsAttention: Boolean = setupNeedsAttention(s)): Boolean = when (key) {
|
||||
"setup" -> setupNeedsAttention
|
||||
"updates" -> s.updates.hasUpdate
|
||||
NavTabs.MORE -> NavTabs.more(s).any { it != NavTabs.MORE && railBadge(s, it, setupNeedsAttention) }
|
||||
else -> false
|
||||
}
|
||||
|
||||
internal fun railCount(s: FrontEndState, key: String): Int = when (key) {
|
||||
"stores" -> s.storeDownloadsActive
|
||||
NavTabs.MORE -> if ("stores" in NavTabs.more(s)) s.storeDownloadsActive else 0
|
||||
else -> 0
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun NavigationItems(
|
||||
s: FrontEndState, shown: String, compact: Boolean, iconOnly: Boolean, height: Dp, width: Dp,
|
||||
@@ -224,8 +230,8 @@ private fun NavigationItems(
|
||||
val (label, icon) = railLabelIcon(key)
|
||||
key(key) {
|
||||
RailItem(stringResource(label), icon, key, shown == key, compact, iconOnly, height, width,
|
||||
badge = (key == "setup" && setupNeedsAttention) || (key == "updates" && s.updates.hasUpdate),
|
||||
count = if (key == "stores") s.storeDownloadsActive else 0,
|
||||
badge = railBadge(s, key, setupNeedsAttention),
|
||||
count = railCount(s, key),
|
||||
place = place, onFocus = { onFocusSelect(key) }) { onSelect(key) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -468,7 +468,9 @@ fun FrontEndScreen(s: FrontEndState, a: FrontEndActions, page: (@Composable () -
|
||||
@OptIn(ExperimentalComposeUiApi::class)
|
||||
@Composable
|
||||
private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Composable () -> Unit)?, frontFocus: FrontFocus) {
|
||||
var selected by rememberSaveable { mutableStateOf(if (s.shortcutPicker) "games" else "steam") }
|
||||
var selected by rememberSaveable {
|
||||
mutableStateOf(if (s.shortcutPicker) "games" else if (NavTabs.place(s, "steam") == TabPlace.HIDDEN) navigationKeys(s).first { it != "components" } else "steam")
|
||||
}
|
||||
LaunchedEffect(s.shortcutPicker) { if (s.shortcutPicker) selected = "games" }
|
||||
LaunchedEffect(s.navigate) {
|
||||
val target = s.navigate ?: return@LaunchedEffect
|
||||
@@ -575,6 +577,10 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
|
||||
) {
|
||||
selected = if (selected.startsWith("rom:")) "emu:" + selected.removePrefix("rom:").substringBefore(':') else "desktop"
|
||||
}
|
||||
val backToMore = s.pageKey == null && Hops.origin == null && selected in NavTabs.more(s)
|
||||
BackHandler(enabled = !processSettingsPageVisible && backToMore) {
|
||||
selected = NavTabs.MORE
|
||||
}
|
||||
LaunchedEffect(s.isHomeApp) { if (!s.isHomeApp && selected == "android-apps") selected = "steam" }
|
||||
LaunchedEffect(s.soundtracksEnabled) {
|
||||
if (!s.soundtracksEnabled && (selected == "soundtracks" || selected.startsWith("sound:"))) selected = "games"
|
||||
@@ -587,7 +593,7 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
|
||||
}
|
||||
remember { Motion.refresh(ctx); true }
|
||||
|
||||
val railSelection = when {
|
||||
val openTab = when {
|
||||
Hops.origin != null && s.pageKey == Hops.origin?.page -> Hops.origin!!.dest
|
||||
s.pageKey == "performance" -> "steam"
|
||||
s.pageKey == "controller-mapping" -> "setup"
|
||||
@@ -596,6 +602,7 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
|
||||
selected.startsWith("emu:") || selected.startsWith("rom:") || selected.startsWith("user:") || selected == "store" -> "desktop"
|
||||
else -> s.pageKey ?: selected
|
||||
}
|
||||
val railSelection = if (openTab in NavTabs.more(s)) NavTabs.MORE else openTab
|
||||
val railSelectionNow = androidx.compose.runtime.rememberUpdatedState(railSelection)
|
||||
var railPicks by remember { mutableStateOf(0) }
|
||||
val showRailPage: (String, Boolean) -> Unit = { key, focusContent ->
|
||||
@@ -711,7 +718,7 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
|
||||
focusWithinFrames({ frontFocus.last == r.control && anyFocused }) { frontFocus.items[r.control] ?: frontFocus.paneEntry() }
|
||||
}
|
||||
var screenAt by remember { mutableStateOf(Offset.Zero) }
|
||||
if (s.dualScreen) DualPanelPublisher(s, railSelection, { key ->
|
||||
if (s.dualScreen) DualPanelPublisher(s, railSelection, openTab, { key ->
|
||||
if (processSettingsPageVisible) return@DualPanelPublisher
|
||||
if (inputModeManager.inputMode != InputMode.Keyboard) inputModeManager.requestInputMode(InputMode.Keyboard)
|
||||
focusManager.clearFocus(force = true)
|
||||
@@ -834,7 +841,7 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
|
||||
)
|
||||
}
|
||||
}
|
||||
val hasBackTarget = (s.pageKey != null && page != null) ||
|
||||
val hasBackTarget = backToMore || (s.pageKey != null && page != null) ||
|
||||
(s.pageKey == null && Hops.origin?.page == selected) ||
|
||||
((s.pageKey == null || page == null) &&
|
||||
(selected.startsWith("emu:") || selected.startsWith("rom:") || selected.startsWith("user:") || selected == "store"))
|
||||
|
||||
@@ -91,6 +91,7 @@ private const val LAUNCHER_TAB = 2
|
||||
|
||||
internal object SetupTabs {
|
||||
var openLauncher = false
|
||||
var focusTabs = false
|
||||
var openOverview = false
|
||||
}
|
||||
private const val GLASSES_TAB = 6
|
||||
@@ -456,10 +457,9 @@ internal fun SetupPanel(
|
||||
remember { RailLabels.load(railContext) }
|
||||
ToggleRow(host, "rail-labels", stringResource(R.string.setup_rail_labels), stringResource(R.string.setup_rail_labels_hint), RailLabels.shown) { RailLabels.set(railContext, it) }
|
||||
LanguageRow(host, s.language, a.onLanguage)
|
||||
ToggleRow(host, "show-stores", stringResource(R.string.setup_stores), null, s.gameStoresEnabled, onChange = a.onGameStoresEnabled)
|
||||
ToggleRow(host, "show-soundtracks", stringResource(R.string.setup_soundtracks), null, s.soundtracksEnabled, onChange = a.onSoundtracksEnabled)
|
||||
if (s.soundtracksEnabled) ToggleRow(host, "soundtracks-ingame", stringResource(R.string.setup_soundtracks_ingame), stringResource(R.string.setup_soundtracks_ingame_hint), s.soundtracksIngame, onChange = a.onSoundtracksIngame)
|
||||
}
|
||||
TabsSettingsGroup(host, s, a)
|
||||
}
|
||||
val device: @Composable () -> Unit = {
|
||||
SettingsGroup(stringResource(R.string.setup_group_device)) {
|
||||
@@ -598,9 +598,6 @@ internal fun SetupPanel(
|
||||
ToggleRow(host, "agent-commands", stringResource(R.string.setup_agent_commands), null, s.agentCommands) { a.onAgentCommands() }
|
||||
if (com.droiddeck.launcher.agent.AgentHost.available) {
|
||||
val agentContext = androidx.compose.ui.platform.LocalContext.current
|
||||
ToggleRow(host, "agent-tab", stringResource(R.string.setup_agent_tab), null, com.droiddeck.launcher.agent.AgentTab.shown) {
|
||||
com.droiddeck.launcher.agent.AgentTab.set(agentContext, it)
|
||||
}
|
||||
ToggleRow(host, "agent-pet", stringResource(R.string.setup_agent_pet), stringResource(R.string.setup_agent_pet_hint), AgentPet.enabled) {
|
||||
AgentPet.set(agentContext, it)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import androidx.compose.foundation.LocalIndication
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.hoverable
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.BoxWithConstraints
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.Role
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.droiddeck.launcher.R
|
||||
|
||||
@Composable
|
||||
internal fun MorePage(s: FrontEndState, a: FrontEndActions, onSelect: (String) -> Unit, modifier: Modifier) {
|
||||
val keys = NavTabs.more(s)
|
||||
val open: (String) -> Unit = { key -> if (key == "components") a.onComponents(true) else onSelect(key) }
|
||||
Column(modifier.verticalScroll(rememberScrollState())) {
|
||||
PageHeader(stringResource(R.string.rail_more)) {
|
||||
Spacer(Modifier.weight(1f))
|
||||
SecondaryButton(stringResource(R.string.more_edit_tabs), compact = true) {
|
||||
SetupTabs.openLauncher = true
|
||||
SetupTabs.focusTabs = true
|
||||
onSelect("setup")
|
||||
}
|
||||
}
|
||||
BoxWithConstraints(Modifier.fillMaxWidth()) {
|
||||
val gap = 12.dp
|
||||
val columns = ((maxWidth + gap) / (160.dp + gap)).toInt().coerceIn(2, 5)
|
||||
Column(verticalArrangement = Arrangement.spacedBy(gap)) {
|
||||
keys.chunked(columns).forEachIndexed { r, row ->
|
||||
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(gap)) {
|
||||
row.forEachIndexed { c, key ->
|
||||
MoreTile(s, key, first = r == 0 && c == 0, Modifier.weight(1f)) { open(key) }
|
||||
}
|
||||
repeat(columns - row.size) { Spacer(Modifier.weight(1f)) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun MoreTile(s: FrontEndState, key: String, first: Boolean, modifier: Modifier, onClick: () -> Unit) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val pal = LocalPalette.current
|
||||
val (label, icon) = railLabelIcon(key)
|
||||
val src = remember { MutableInteractionSource() }
|
||||
val hot = rememberHot(src)
|
||||
val shape = RoundedCornerShape(18.dp)
|
||||
val count = railCount(s, key)
|
||||
Box(
|
||||
contentAlignment = Alignment.Center,
|
||||
modifier = modifier
|
||||
.then(if (first) Modifier.paneEntry() else Modifier.paneItem("more:$key"))
|
||||
.testTag("more-$key")
|
||||
.height(112.dp).clip(shape)
|
||||
.background(if (hot) pal.signal.copy(alpha = 0.12f) else colors.surface)
|
||||
.glideBorder(hot, shape, pal.signal, pal.line)
|
||||
.hoverable(src)
|
||||
.clickable(interactionSource = src, indication = LocalIndication.current, role = Role.Tab, onClick = onClick)
|
||||
.controllerConfirm(onClick = onClick),
|
||||
) {
|
||||
Column(horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
Icon(icon, contentDescription = null, tint = if (hot) pal.signal else colors.onSurfaceVariant, modifier = Modifier.size(30.dp))
|
||||
Text(stringResource(label), fontSize = 14.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground,
|
||||
maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = Modifier.padding(horizontal = 8.dp))
|
||||
}
|
||||
if (railBadge(s, key)) Box(Modifier.align(Alignment.TopEnd).padding(12.dp).size(9.dp).clip(CircleShape).background(AttentionAmber))
|
||||
if (count > 0) Box(Modifier.align(Alignment.TopEnd).padding(10.dp)) { CountPill(count) }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import android.content.Context
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import com.droiddeck.launcher.agent.AgentHost
|
||||
import com.droiddeck.launcher.agent.AgentTab
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
|
||||
internal enum class TabPlace { BAR, MORE, HIDDEN }
|
||||
|
||||
internal object NavTabs {
|
||||
const val MORE = "more"
|
||||
val FEATURES = setOf("stores", "soundtracks", "agent")
|
||||
val ALL = listOf("steam", "games", "soundtracks", "stores", "desktop", "agent", "components", "android-apps", "setup", "updates")
|
||||
|
||||
var order by mutableStateOf(ALL)
|
||||
private set
|
||||
var shelved by mutableStateOf(emptySet<String>())
|
||||
private set
|
||||
var hidden by mutableStateOf(emptySet<String>())
|
||||
private set
|
||||
|
||||
fun load(context: Context) {
|
||||
order = arrange(SessionPrefs.navTabOrder(context))
|
||||
shelved = SessionPrefs.navTabShelved(context).intersect(ALL.toSet())
|
||||
hidden = SessionPrefs.navTabHidden(context).intersect(ALL.toSet()) - FEATURES - "setup"
|
||||
}
|
||||
|
||||
fun arrange(saved: List<String>): List<String> {
|
||||
val listed = saved.filter { it in ALL }.distinct()
|
||||
val missing = ALL.filterNot { it in listed }
|
||||
val out = listed.toMutableList()
|
||||
for (key in missing) {
|
||||
val before = ALL.subList(0, ALL.indexOf(key)).lastOrNull { it in out }
|
||||
out.add(if (before == null) 0 else out.indexOf(before) + 1, key)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
fun available(s: FrontEndState, key: String): Boolean = when (key) {
|
||||
"android-apps" -> s.isHomeApp
|
||||
"agent" -> AgentHost.available
|
||||
else -> true
|
||||
}
|
||||
|
||||
fun hideable(key: String) = key != "setup"
|
||||
|
||||
fun place(s: FrontEndState, key: String): TabPlace = when {
|
||||
featureOff(s, key) || key in hidden -> TabPlace.HIDDEN
|
||||
key in shelved -> TabPlace.MORE
|
||||
else -> TabPlace.BAR
|
||||
}
|
||||
|
||||
private fun featureOff(s: FrontEndState, key: String) = when (key) {
|
||||
"stores" -> !s.gameStoresEnabled
|
||||
"soundtracks" -> !s.soundtracksEnabled
|
||||
"agent" -> !AgentTab.shown
|
||||
else -> false
|
||||
}
|
||||
|
||||
fun listed(s: FrontEndState) = order.filter { available(s, it) }
|
||||
|
||||
fun more(s: FrontEndState) = listed(s).filter { place(s, it) == TabPlace.MORE }
|
||||
|
||||
fun bar(s: FrontEndState): List<String> {
|
||||
val shown = listed(s).filter { place(s, it) == TabPlace.BAR }
|
||||
return if (more(s).isEmpty()) shown else shown + MORE
|
||||
}
|
||||
|
||||
fun move(context: Context, s: FrontEndState, key: String, step: Int) {
|
||||
val visible = listed(s)
|
||||
val at = visible.indexOf(key)
|
||||
val other = visible.getOrNull(at + step) ?: return
|
||||
val next = order.toMutableList()
|
||||
val i = next.indexOf(key)
|
||||
val j = next.indexOf(other)
|
||||
next[i] = other
|
||||
next[j] = key
|
||||
order = next
|
||||
SessionPrefs.setNavTabOrder(context, next)
|
||||
}
|
||||
|
||||
fun setPlace(context: Context, key: String, place: TabPlace) {
|
||||
shelved = if (place == TabPlace.MORE) shelved + key else shelved - key
|
||||
hidden = if (place == TabPlace.HIDDEN && hideable(key) && key !in FEATURES) hidden + key else hidden - key
|
||||
SessionPrefs.setNavTabShelved(context, shelved)
|
||||
SessionPrefs.setNavTabHidden(context, hidden)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import androidx.compose.foundation.LocalIndication
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.hoverable
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.relocation.BringIntoViewRequester
|
||||
import androidx.compose.foundation.relocation.bringIntoViewRequester
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.KeyboardArrowDown
|
||||
import androidx.compose.material.icons.outlined.KeyboardArrowUp
|
||||
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.key
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.alpha
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.Role
|
||||
import androidx.compose.ui.semantics.contentDescription
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.agent.AgentTab
|
||||
|
||||
@OptIn(androidx.compose.foundation.ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
internal fun TabsSettingsGroup(host: MenuHost, s: FrontEndState, a: FrontEndActions) {
|
||||
val ctx = LocalContext.current
|
||||
val reveal = remember { BringIntoViewRequester() }
|
||||
LaunchedEffect(Unit) {
|
||||
if (!SetupTabs.focusTabs) return@LaunchedEffect
|
||||
SetupTabs.focusTabs = false
|
||||
androidx.compose.runtime.withFrameNanos { }
|
||||
reveal.bringIntoView()
|
||||
}
|
||||
val shown = stringResource(R.string.tabs_place_bar)
|
||||
val more = stringResource(R.string.tabs_place_more)
|
||||
val hidden = stringResource(R.string.tabs_place_hidden)
|
||||
val keys = NavTabs.listed(s)
|
||||
fun pick(key: String, place: TabPlace) {
|
||||
when (key) {
|
||||
"stores" -> if ((place != TabPlace.HIDDEN) != s.gameStoresEnabled) a.onGameStoresEnabled(place != TabPlace.HIDDEN)
|
||||
"soundtracks" -> if ((place != TabPlace.HIDDEN) != s.soundtracksEnabled) a.onSoundtracksEnabled(place != TabPlace.HIDDEN)
|
||||
"agent" -> if ((place != TabPlace.HIDDEN) != AgentTab.shown) AgentTab.set(ctx, place != TabPlace.HIDDEN)
|
||||
}
|
||||
NavTabs.setPlace(ctx, key, place)
|
||||
}
|
||||
Box(Modifier.bringIntoViewRequester(reveal)) {
|
||||
SettingsGroup(stringResource(R.string.setup_group_tabs)) {
|
||||
keys.forEachIndexed { index, tab ->
|
||||
key(tab) {
|
||||
val options = buildList {
|
||||
add(TabPlace.BAR to shown)
|
||||
add(TabPlace.MORE to more)
|
||||
if (NavTabs.hideable(tab)) add(TabPlace.HIDDEN to hidden)
|
||||
}
|
||||
TabRow(
|
||||
host, tab, NavTabs.place(s, tab), options,
|
||||
canUp = index > 0, canDown = index < keys.lastIndex,
|
||||
onMove = { step -> NavTabs.move(ctx, s, tab, step) },
|
||||
onPick = { pick(tab, it) },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun TabRow(
|
||||
host: MenuHost, tab: String, place: TabPlace, options: List<Pair<TabPlace, String>>,
|
||||
canUp: Boolean, canDown: Boolean, onMove: (Int) -> Unit, onPick: (TabPlace) -> Unit,
|
||||
) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val pal = LocalPalette.current
|
||||
val (labelRes, icon) = railLabelIcon(tab)
|
||||
val label = stringResource(labelRes)
|
||||
val open = host.open == "tab-$tab"
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(6.dp),
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
.background(if (open) pal.signal.copy(alpha = 0.10f) else androidx.compose.ui.graphics.Color.Transparent)
|
||||
.padding(start = 14.dp, end = 10.dp, top = 6.dp, bottom = 6.dp),
|
||||
) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier.weight(1f).alpha(if (place == TabPlace.HIDDEN) 0.5f else 1f),
|
||||
) {
|
||||
Icon(icon, contentDescription = null, tint = colors.onSurfaceVariant, modifier = Modifier.size(20.dp))
|
||||
Spacer(Modifier.width(12.dp))
|
||||
Text(label, fontSize = 15.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
||||
}
|
||||
MoveButton(Icons.Outlined.KeyboardArrowUp, stringResource(R.string.tabs_move_up, label), canUp, "tab-up-$tab") { onMove(-1) }
|
||||
MoveButton(Icons.Outlined.KeyboardArrowDown, stringResource(R.string.tabs_move_down, label), canDown, "tab-down-$tab") { onMove(1) }
|
||||
ChoiceChip(host, "tab-$tab", label, options, place, onPick = onPick)
|
||||
}
|
||||
Box(Modifier.fillMaxWidth().height(1.dp).background(pal.line))
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun MoveButton(icon: ImageVector, description: String, enabled: Boolean, tag: String, onClick: () -> Unit) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val pal = LocalPalette.current
|
||||
val src = remember { MutableInteractionSource() }
|
||||
val hot = rememberHot(src)
|
||||
Box(
|
||||
contentAlignment = Alignment.Center,
|
||||
modifier = Modifier.testTag(tag).size(40.dp).clip(CircleShape)
|
||||
.background(colors.surfaceVariant)
|
||||
.glideBorder(hot, CircleShape, pal.signal, pal.line2)
|
||||
.alpha(if (enabled) 1f else 0.35f)
|
||||
.hoverable(src)
|
||||
.clickable(interactionSource = src, indication = LocalIndication.current, role = Role.Button) { if (enabled) onClick() }
|
||||
.controllerConfirm { if (enabled) onClick() }
|
||||
.semantics { contentDescription = description },
|
||||
) { Icon(icon, contentDescription = null, tint = if (hot) pal.signal else colors.onBackground, modifier = Modifier.size(20.dp)) }
|
||||
}
|
||||
Reference in new issue
Block a user