mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-21 05:46:03 +00:00
Merge upstream main and close diagnostic publication races
This commit is contained in:
473 files changed
+36063
-3507
No files matched your search
@@ -308,6 +308,7 @@ internal fun AppDialog(
|
||||
width: Dp? = null, fitContent: Boolean = false,
|
||||
back: (() -> Unit)? = null,
|
||||
scrollable: Boolean = true,
|
||||
scrollState: androidx.compose.foundation.ScrollState = rememberScrollState(),
|
||||
content: @Composable ColumnScope.() -> Unit,
|
||||
) {
|
||||
val pal = LocalPalette.current
|
||||
@@ -345,7 +346,7 @@ internal fun AppDialog(
|
||||
.blockTouches()
|
||||
.controllerBack(back ?: close)
|
||||
.then(modifier)
|
||||
.then(if (scrollable) Modifier.verticalScroll(rememberScrollState()) else Modifier)
|
||||
.then(if (scrollable) Modifier.verticalScroll(scrollState) else Modifier)
|
||||
.padding(horizontal = 18.dp, vertical = 16.dp),
|
||||
content = content,
|
||||
)
|
||||
|
||||
@@ -676,14 +676,15 @@ private fun MoviePreview(url: String, modifier: Modifier = Modifier) {
|
||||
|
||||
/** A dialog with one text box, for a search term or a page number; the Android keyboard comes up with it. */
|
||||
@Composable
|
||||
private fun TextEntryDialog(
|
||||
internal fun TextEntryDialog(
|
||||
title: String, initial: String, number: Boolean, confirm: String, onSubmit: (String) -> Unit, onDismiss: () -> Unit,
|
||||
id: String = "boot-movie-entry",
|
||||
) {
|
||||
val shown = rememberShown(onDismiss)
|
||||
val close = { shown.targetState = false }
|
||||
var text by remember { mutableStateOf(initial) }
|
||||
val submit = { onSubmit(text.trim()); close() }
|
||||
AppDialog(shown, close, "boot-movie-entry", wide = false, maxWidth = 460.dp) {
|
||||
AppDialog(shown, close, id, wide = false, maxWidth = 460.dp) {
|
||||
DialogTitleRow(title, close)
|
||||
AdbTextField(
|
||||
value = text, onValueChange = { text = it }, label = "", keyboardType = if (number) KeyboardType.Number else KeyboardType.Text,
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import androidx.compose.animation.core.animateFloatAsState
|
||||
import androidx.compose.foundation.ScrollState
|
||||
import androidx.compose.foundation.focusGroup
|
||||
import androidx.compose.foundation.gestures.detectTapGestures
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.compositionLocalOf
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberUpdatedState
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clipToBounds
|
||||
import androidx.compose.ui.draw.drawWithContent
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusProperties
|
||||
import androidx.compose.ui.focus.onFocusChanged
|
||||
import androidx.compose.ui.geometry.Offset
|
||||
import androidx.compose.ui.graphics.Brush
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.graphicsLayer
|
||||
import androidx.compose.ui.input.pointer.pointerInput
|
||||
import androidx.compose.ui.layout.onGloballyPositioned
|
||||
import androidx.compose.ui.layout.positionInRoot
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.unit.dp
|
||||
import kotlinx.coroutines.delay
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.runtime.getValue
|
||||
|
||||
/** A grid of cards with a game page that floods out of the opened card and drains back into it. */
|
||||
internal val LocalDetailFloor = compositionLocalOf<() -> Float> { { Float.MAX_VALUE } }
|
||||
|
||||
@OptIn(androidx.compose.ui.ExperimentalComposeUiApi::class)
|
||||
@Composable
|
||||
internal fun CardDetailHost(
|
||||
open: String?,
|
||||
detailScroll: ScrollState,
|
||||
gridScrolled: () -> Boolean,
|
||||
onDetailFocus: (Boolean) -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
wrap: @Composable (key: String, content: @Composable () -> Unit) -> Unit = { _, content -> content() },
|
||||
grid: @Composable () -> Unit,
|
||||
detail: @Composable (key: String) -> Unit,
|
||||
) {
|
||||
val ctx = LocalContext.current
|
||||
val ff = LocalFrontFocus.current
|
||||
val density = LocalDensity.current
|
||||
var shown by remember { mutableStateOf<String?>(null) }
|
||||
var leaving by remember { mutableStateOf(false) }
|
||||
var from by remember { mutableStateOf<Origin?>(null) }
|
||||
var art by remember { mutableStateOf<String?>(null) }
|
||||
var viewportAt by remember { mutableStateOf(Offset.Zero) }
|
||||
var viewportH by remember { mutableStateOf(0) }
|
||||
LaunchedEffect(open) {
|
||||
if (open != null) {
|
||||
val mark = StoresMotion.takeCard(open)
|
||||
from = mark?.let { Origin(it.bounds.translate(-viewportAt), it.corner) }
|
||||
art = mark?.art
|
||||
StoresMotion.heroLands = mark != null
|
||||
leaving = false
|
||||
shown = open
|
||||
} else if (shown != null) {
|
||||
if (from != null) {
|
||||
leaving = true
|
||||
delay(Motion.ms(PAGE_RETURN_MS).toLong())
|
||||
}
|
||||
shown = null
|
||||
leaving = false
|
||||
from = null
|
||||
}
|
||||
}
|
||||
LaunchedEffect(shown) { detailScroll.scrollTo(0) }
|
||||
val covering = shown != null && !leaving
|
||||
val coveringNow = rememberUpdatedState(covering)
|
||||
val gridScale by animateFloatAsState(if (covering) 0.95f else 1f, if (covering) Motion.tw(480) else Motion.tw(460, 40), label = "gridSink")
|
||||
val gridAlpha by animateFloatAsState(if (covering) 0f else 1f, if (covering) Motion.tw(320, 80) else Motion.tw(300, 100), label = "gridFade")
|
||||
val fade = with(density) { 14.dp.toPx() }
|
||||
Box(
|
||||
modifier.clipToBounds()
|
||||
.onGloballyPositioned { viewportAt = it.positionInRoot(); viewportH = it.size.height }
|
||||
.graphicsLayer { compositingStrategy = androidx.compose.ui.graphics.CompositingStrategy.Offscreen }
|
||||
.drawWithContent {
|
||||
drawContent()
|
||||
val scrolled = if (shown != null) detailScroll.value > 0 else gridScrolled()
|
||||
if (scrolled && size.height > fade) drawRect(
|
||||
Brush.verticalGradient(0f to Color.Transparent, fade / size.height to Color.Black),
|
||||
blendMode = androidx.compose.ui.graphics.BlendMode.DstIn,
|
||||
)
|
||||
},
|
||||
) {
|
||||
CompositionLocalProvider(LocalFrontFocus provides if (covering) null else ff) {
|
||||
Column(
|
||||
modifier = Modifier.fillMaxSize()
|
||||
.graphicsLayer { scaleX = gridScale; scaleY = gridScale; alpha = gridAlpha }
|
||||
.focusProperties { enter = { if (coveringNow.value) FocusRequester.Cancel else FocusRequester.Default } }
|
||||
.focusGroup(),
|
||||
) { grid() }
|
||||
}
|
||||
shown?.let { key ->
|
||||
wrap(key) {
|
||||
val body: @Composable () -> Unit = {
|
||||
Column(
|
||||
Modifier.fillMaxSize().pointerInput(Unit) { detectTapGestures { } }
|
||||
.verticalScroll(detailScroll).padding(top = 4.dp, bottom = 16.dp),
|
||||
) {
|
||||
Column(
|
||||
Modifier.fillMaxWidth()
|
||||
.onFocusChanged { onDetailFocus(it.hasFocus) }
|
||||
.focusProperties { exit = { if (coveringNow.value && Steps.step == null && StoresMotion.step == null) FocusRequester.Cancel else FocusRequester.Default } }
|
||||
.focusGroup(),
|
||||
) {
|
||||
val floor = { viewportAt.y + viewportH - with(density) { 16.dp.toPx() } - detailScroll.value }
|
||||
CompositionLocalProvider(LocalDetailFloor provides floor) { detail(key) }
|
||||
}
|
||||
}
|
||||
}
|
||||
val origin = from
|
||||
if (origin == null) body()
|
||||
else {
|
||||
val painter = art?.let { url ->
|
||||
coil.compose.rememberAsyncImagePainter(
|
||||
remember(url) {
|
||||
coil.request.ImageRequest.Builder(ctx).data(url).size(1280, 720)
|
||||
.placeholderMemoryCacheKey(url).build()
|
||||
},
|
||||
)
|
||||
}
|
||||
PageFlood(origin, leaving, painter, onto = { StoresMotion.heroAt }, ontoCorner = 16.dp) { body() }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.runtime.Composable
|
||||
@@ -70,12 +71,15 @@ internal fun ColorPickerDialog(title: String, initial: Int, onDismiss: () -> Uni
|
||||
var hexText by remember { mutableStateOf(ThemeColors.hex(initial)) }
|
||||
val current = ThemeColors.fromHsv(hue, sat, value)
|
||||
val first = remember { FocusRequester() }
|
||||
val scroll = rememberScrollState()
|
||||
var typingHex by remember { mutableStateOf(false) }
|
||||
LaunchedEffect(Unit) { focusSoon { first } }
|
||||
LaunchedEffect(typingHex, scroll.maxValue) { if (typingHex) scroll.animateScrollTo(scroll.maxValue) }
|
||||
fun picked(h: Float = hue, s: Float = sat, v: Float = value) {
|
||||
hue = h.coerceIn(0f, 360f); sat = s.coerceIn(0f, 1f); value = v.coerceIn(0f, 1f)
|
||||
hexText = ThemeColors.hex(ThemeColors.fromHsv(hue, sat, value))
|
||||
}
|
||||
AppDialog(shown, close, "colorPicker", wide = false, maxWidth = 460.dp) {
|
||||
AppDialog(shown, close, "colorPicker", wide = false, maxWidth = 460.dp, scrollState = scroll) {
|
||||
DialogTitleRow(title, close)
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(14.dp), verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth()) {
|
||||
ColorWheel(hue, sat, value) { h, s -> picked(h = h, s = s) }
|
||||
@@ -95,6 +99,7 @@ internal fun ColorPickerDialog(title: String, initial: Int, onDismiss: () -> Uni
|
||||
ThemeColors.parseHex(text)?.let { argb -> ThemeColors.toHsv(argb).let { hsv -> hue = hsv.h; sat = hsv.s; value = hsv.v } }
|
||||
},
|
||||
label = "", keyboardType = KeyboardType.Ascii, imeAction = ImeAction.Done, placeholder = stringResource(R.string.theme_color_hex),
|
||||
onFocusChange = { typingHex = it },
|
||||
onDone = { ThemeColors.parseHex(hexText)?.let { onApply(it); close() } },
|
||||
)
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(8.dp), modifier = Modifier.fillMaxWidth()) {
|
||||
|
||||
@@ -70,6 +70,7 @@ import androidx.compose.ui.graphics.graphicsLayer
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.layout.boundsInRoot
|
||||
import androidx.compose.ui.layout.onGloballyPositioned
|
||||
import androidx.compose.ui.platform.LocalConfiguration
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.res.painterResource
|
||||
@@ -102,6 +103,7 @@ internal fun DesktopPage(s: FrontEndState, a: FrontEndActions, modifier: Modifie
|
||||
val ctx = LocalContext.current
|
||||
val density = LocalDensity.current
|
||||
val narrow = LocalNarrowPane.current
|
||||
val short = compactDesktop()
|
||||
val colors = MaterialTheme.colorScheme
|
||||
LaunchedEffect(Unit) { UserAppsState.refresh(ctx) }
|
||||
LaunchedEffect(s.ready) { com.droiddeck.launcher.store.StoreState.refresh(ctx) }
|
||||
@@ -120,7 +122,7 @@ internal fun DesktopPage(s: FrontEndState, a: FrontEndActions, modifier: Modifie
|
||||
key = "desktop", tabs = tabs,
|
||||
onOpen = a.onDesktopSettings, onPrimary = a.onDesktop,
|
||||
modifier = modifier.clipToBounds(),
|
||||
start = if (narrow) 20.dp else 44.dp, bottom = if (narrow) 20.dp else 44.dp,
|
||||
start = if (narrow) 20.dp else 44.dp, bottom = 44.dp,
|
||||
background = {
|
||||
DesktopWall(installed.map { it.iconRes } + apps.mapNotNull { it.icon })
|
||||
},
|
||||
@@ -132,8 +134,8 @@ internal fun DesktopPage(s: FrontEndState, a: FrontEndActions, modifier: Modifie
|
||||
},
|
||||
words = {
|
||||
Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
Text(
|
||||
stringResource(R.string.rail_desktop), fontSize = if (narrow) 30.sp else 42.sp, lineHeight = if (narrow) 34.sp else 46.sp,
|
||||
if (LocalConfiguration.current.screenHeightDp >= 400) Text(
|
||||
stringResource(R.string.rail_desktop), fontSize = if (short) 30.sp else 42.sp, lineHeight = if (short) 34.sp else 46.sp,
|
||||
fontWeight = FontWeight.Black, color = colors.onBackground,
|
||||
)
|
||||
BusyChip(s)
|
||||
@@ -143,11 +145,12 @@ internal fun DesktopPage(s: FrontEndState, a: FrontEndActions, modifier: Modifie
|
||||
PrimaryButton(open, enabled = !s.busy, main = true, large = true, icon = Icons.Outlined.DesktopWindows, onClick = click)
|
||||
},
|
||||
beside = {
|
||||
Column(verticalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||
HeroIconButton(Icons.Outlined.Storefront, stringResource(R.string.flathub_name), FlathubTeal, "desktop:flathub") { at -> openFrom(at, null, "store") }
|
||||
HeroIconButton(Icons.Filled.Add, stringResource(R.string.user_apps_add), null, "desktop:add") { if (!s.busy) adding = true }
|
||||
}
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.spacedBy(10.dp), verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier.horizontalScroll(rememberScrollState()),
|
||||
) {
|
||||
HeroIconButton(Icons.Outlined.Storefront, stringResource(R.string.flathub_name), FlathubTeal, "desktop:flathub") { at -> openFrom(at, null, "store") }
|
||||
HeroIconButton(Icons.Filled.Add, stringResource(R.string.user_apps_add), null, "desktop:add") { if (!s.busy) adding = true }
|
||||
if (s.desktopPresent) UninstallDesktop(enabled = !s.runtimeActionsBlocked, onUninstall = a.onRemoveDesktop)
|
||||
}
|
||||
},
|
||||
@@ -159,6 +162,9 @@ internal fun DesktopPage(s: FrontEndState, a: FrontEndActions, modifier: Modifie
|
||||
if (adding && !s.busy) AddAppDialog(s.ready, onDismiss = { adding = false }) { request, label -> UserAppsState.add(ctx, request, label) }
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun compactDesktop() = LocalNarrowPane.current || LocalConfiguration.current.screenHeightDp < 600
|
||||
|
||||
@Composable
|
||||
private fun DesktopDock(
|
||||
s: FrontEndState, a: FrontEndActions, installed: List<Library.Emulator>, apps: List<UserApps.App>,
|
||||
@@ -177,7 +183,7 @@ private fun DesktopDock(
|
||||
LaunchedEffect(Unit) { mounted[0] = true }
|
||||
val scroll = rememberScrollState()
|
||||
if (keys.isEmpty() && available.isEmpty() && UserAppsState.working == null && UserAppsState.lastError == null) return
|
||||
Column(Modifier.fillMaxWidth().padding(top = if (narrow) 14.dp else 22.dp)) {
|
||||
Column(Modifier.fillMaxWidth().padding(top = if (compactDesktop()) 14.dp else 22.dp)) {
|
||||
Text(
|
||||
stringResource(R.string.user_apps_section).uppercase(), fontSize = 11.sp, fontWeight = FontWeight.Bold, letterSpacing = 1.6.sp,
|
||||
color = colors.onSurfaceVariant, modifier = Modifier.padding(start = if (narrow) 20.dp else 44.dp, bottom = 8.dp),
|
||||
|
||||
@@ -27,6 +27,8 @@ import androidx.compose.material.icons.outlined.Image
|
||||
import androidx.compose.material.icons.outlined.InsertDriveFile
|
||||
import androidx.compose.material.icons.outlined.SdCard
|
||||
import androidx.compose.material.icons.outlined.Smartphone
|
||||
import androidx.compose.material.icons.outlined.Visibility
|
||||
import androidx.compose.material.icons.outlined.VisibilityOff
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
@@ -81,8 +83,8 @@ internal class PickFolder(val dir: File, val readable: Boolean)
|
||||
|
||||
internal class PickListing(val folders: List<PickFolder>, val files: List<File>)
|
||||
|
||||
internal fun pickListing(dir: File, kind: PickKind): PickListing {
|
||||
val all = dir.listFiles()?.filter { !it.name.startsWith(".") }.orEmpty().sortedBy { it.name.lowercase() }
|
||||
internal fun pickListing(dir: File, kind: PickKind, showHidden: Boolean = false): PickListing {
|
||||
val all = dir.listFiles()?.filter { showHidden || !it.name.startsWith(".") }.orEmpty().sortedBy { it.name.lowercase() }
|
||||
return PickListing(
|
||||
all.filter { it.isDirectory }.map { PickFolder(it, it.canRead() && it.list() != null) },
|
||||
all.filter { it.isFile && it.extension.lowercase() in kind.extensions },
|
||||
@@ -92,11 +94,13 @@ internal fun pickListing(dir: File, kind: PickKind): PickListing {
|
||||
@Composable
|
||||
internal fun ExePickerDialog(
|
||||
title: String, kind: PickKind = PickKind.EXE, start: File? = null,
|
||||
onAddAll: ((File) -> Unit)? = null, onPick: (File) -> Unit, onDismiss: () -> Unit,
|
||||
onAddAll: ((File, Boolean) -> Unit)? = null, onPick: (File) -> Unit, onDismiss: () -> Unit,
|
||||
) {
|
||||
val ctx = LocalContext.current
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val density = LocalDensity.current
|
||||
val prefs = remember(ctx) { ctx.getSharedPreferences("game_picker", Context.MODE_PRIVATE) }
|
||||
var showHidden by remember { mutableStateOf(prefs.getBoolean("show_hidden", false)) }
|
||||
val shown = rememberShown(onDismiss)
|
||||
val close = { shown.targetState = false }
|
||||
val volumes = remember { pickVolumes(ctx) }
|
||||
@@ -107,14 +111,23 @@ internal fun ExePickerDialog(
|
||||
val back = { if (dir == null) close() else up() }
|
||||
val first = remember(dir) { FocusRequester() }
|
||||
LaunchedEffect(dir) { focusWithinFrames({ false }) { first } }
|
||||
val listing = remember(dir) { dir?.let { pickListing(it, kind) } }
|
||||
val listing = remember(dir, showHidden) { dir?.let { pickListing(it, kind, showHidden) } }
|
||||
var locked by remember { mutableStateOf<Dp?>(null) }
|
||||
AppDialog(
|
||||
shown, close, "filePicker", wide = false, maxWidth = 520.dp, width = locked, fitContent = locked == null, back = back,
|
||||
modifier = Modifier.onSizeChanged { if (locked == null && it.width > 0) locked = with(density) { it.width.toDp() } },
|
||||
) {
|
||||
Column(verticalArrangement = Arrangement.spacedBy(6.dp), modifier = Modifier.fillMaxWidth()) {
|
||||
DialogTitleRow(title, onClose = close)
|
||||
DialogTitleRow(title, onClose = close, leading = {
|
||||
SmallIconButton(
|
||||
if (showHidden) Icons.Outlined.VisibilityOff else Icons.Outlined.Visibility,
|
||||
stringResource(if (showHidden) R.string.fm_hide_hidden else R.string.fm_show_hidden),
|
||||
if (showHidden) colors.primary else colors.onSurfaceVariant,
|
||||
) {
|
||||
showHidden = !showHidden
|
||||
prefs.edit().putBoolean("show_hidden", showHidden).apply()
|
||||
}
|
||||
})
|
||||
if (dir != null && volume != null) {
|
||||
val crumbs = listOf(volume.label) + dir!!.path.removePrefix(volume.root.path).split('/').filter { it.isNotEmpty() }
|
||||
Text(crumbs.joinToString(" › "), fontSize = 12.sp, color = colors.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
||||
@@ -135,7 +148,7 @@ internal fun ExePickerDialog(
|
||||
val shownListing = listing ?: PickListing(emptyList(), emptyList())
|
||||
PickerRow(Icons.AutoMirrored.Outlined.ArrowBack, "..", null, focus = first, onClick = up)
|
||||
if (onAddAll != null && shownListing.folders.any { it.readable }) {
|
||||
PickerRow(Icons.Filled.Add, stringResource(R.string.games_add_all), null, accent = true) { onAddAll(dir!!); close() }
|
||||
PickerRow(Icons.Filled.Add, stringResource(R.string.games_add_all), null, accent = true) { onAddAll(dir!!, showHidden); close() }
|
||||
}
|
||||
for (f in shownListing.folders) key(f.dir.path) {
|
||||
PickerRow(Icons.Outlined.Folder, f.dir.name, null, enabled = f.readable) { dir = f.dir }
|
||||
|
||||
@@ -254,7 +254,7 @@ private fun Content(
|
||||
return
|
||||
}
|
||||
if (selected == "games" || selected.startsWith("app:")) {
|
||||
GamesPage(s, a, selected, onSelect, modifier)
|
||||
LibraryPage(s, a, selected, onSelect, modifier)
|
||||
return
|
||||
}
|
||||
if (selected == "desktop") {
|
||||
|
||||
@@ -5,7 +5,6 @@ import com.droiddeck.launcher.R
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.foundation.LocalIndication
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.hoverable
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
@@ -13,144 +12,39 @@ import androidx.compose.foundation.interaction.collectIsFocusedAsState
|
||||
import androidx.compose.foundation.interaction.collectIsHoveredAsState
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.runtime.key
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.BoxScope
|
||||
import androidx.compose.foundation.layout.ColumnScope
|
||||
import androidx.compose.foundation.layout.RowScope
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxHeight
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.layout.widthIn
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.Delete
|
||||
import androidx.compose.material.icons.outlined.Edit
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.material.icons.filled.Add
|
||||
import androidx.compose.material.icons.filled.PlayArrow
|
||||
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.remember
|
||||
import kotlinx.coroutines.flow.first
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.alpha
|
||||
import androidx.compose.ui.draw.blur
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Brush
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.graphicsLayer
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.semantics.contentDescription
|
||||
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 coil.compose.AsyncImage
|
||||
import com.droiddeck.launcher.frontend.Library
|
||||
import com.droiddeck.launcher.stores.epic.EpicClient
|
||||
import kotlinx.coroutines.launch
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.runtime.getValue
|
||||
|
||||
|
||||
@Composable
|
||||
internal fun GamesPage(s: FrontEndState, a: FrontEndActions, selected: String, onSelect: (String) -> Unit, modifier: Modifier) {
|
||||
val pageContext = androidx.compose.ui.platform.LocalContext.current
|
||||
LaunchedEffect(Unit) { EpicClient.refresh(pageContext) }
|
||||
val launcherName = stringResource(R.string.epic_client_title)
|
||||
val epic = EpicClient.status
|
||||
val launcherArt by androidx.compose.runtime.produceState<java.io.File?>(null, epic.version) {
|
||||
value = kotlinx.coroutines.withContext(kotlinx.coroutines.Dispatchers.IO) { EpicClient.icon(pageContext, epic.version) }
|
||||
}
|
||||
val games = remember(s.steamGames, s.shortcutPicker, epic, launcherName, launcherArt) {
|
||||
val sorted = s.steamGames.sortedByDescending { it.lastPlayed }
|
||||
if (s.shortcutPicker) sorted else EpicClient.withLauncher(sorted, EpicClient.launcherEntry(pageContext, launcherName, epic, launcherArt))
|
||||
}
|
||||
val gameCount = games.count { it.library != Library.EPIC_LAUNCHER }
|
||||
val narrow = LocalNarrowPane.current
|
||||
val current = games.firstOrNull { "app:${it.appId}" == selected } ?: games.firstOrNull()
|
||||
GamesDialogs(a, s.steamGames)
|
||||
val onAdd: (() -> Unit)? = if (s.shortcutPicker) null else ({ GamesDialogState.adding = true })
|
||||
val launch: (Library.SteamGame) -> Unit = { g -> if (g.library == Library.EPIC_LAUNCHER) a.onEpicLauncher() else a.onSteamGame(g) }
|
||||
val onEdit: (Library.SteamGame) -> Unit = { g ->
|
||||
g.gameFiles?.let { GamesDialogState.editing = EditRequest(it.path, openTarget = false, fromSummary = false, preview = EditPreview.of(pageContext, g, it.path)) }
|
||||
}
|
||||
if (current == null || gameCount == 0) {
|
||||
Column(modifier = modifier.padding(horizontal = if (narrow) 16.dp else 22.dp, vertical = if (narrow) 12.dp else 18.dp)) {
|
||||
Rise(0) {
|
||||
PageHeader(stringResource(R.string.content_games)) {
|
||||
if (s.steamGamesX64) ClientTag()
|
||||
onAdd?.let { AddGameButton(it) }
|
||||
}
|
||||
}
|
||||
Rise(1) { Note(stringResource(if (s.shortcutPicker && s.shortcutLibraryScanning) R.string.game_shortcut_scanning else R.string.games_empty)) }
|
||||
if (!s.shortcutPicker) Rise(2) {
|
||||
Actions {
|
||||
PrimaryButton(stringResource(R.string.games_play_steam), enabled = !s.busy, main = true, icon = Icons.Filled.PlayArrow, modifier = Modifier.padding(top = 12.dp).testTag("play-steam"), onClick = a.onPlay)
|
||||
games.firstOrNull { it.library == Library.EPIC_LAUNCHER }?.let { SecondaryButton(it.name, enabled = !s.busy, modifier = Modifier.padding(top = 12.dp)) { a.onEpicLauncher() } }
|
||||
}
|
||||
}
|
||||
GameFileFolderActions(s, a)
|
||||
}
|
||||
return
|
||||
}
|
||||
val host = rememberMenuHost()
|
||||
if (games.size == 1) {
|
||||
Column(modifier = modifier.verticalScroll(rememberScrollState()).padding(horizontal = if (narrow) 16.dp else 22.dp, vertical = if (narrow) 12.dp else 18.dp)) {
|
||||
if (onAdd != null) Rise(0) { GamesHeader(gameCount, s.steamGamesX64, onAdd, Modifier.padding(bottom = 10.dp)) }
|
||||
Rise(0) {
|
||||
Row(verticalAlignment = Alignment.Bottom) {
|
||||
GameHero(current, Modifier.weight(1f).heightIn(min = if (narrow) 190.dp else 250.dp), corner = { GameRemoveButton(current, s, a) }) {
|
||||
GameHeroCopy(current, if (narrow) 28.sp else 38.sp)
|
||||
GameActions(current, s, a, onEdit, launch)
|
||||
}
|
||||
if (!narrow) Poster(current.art, current.name, Modifier.width(168.dp))
|
||||
}
|
||||
}
|
||||
Rise(1) { SectionTitle(stringResource(R.string.games_launch_settings), null) }
|
||||
Rise(2) { LaunchSettings(s, a, host, current) }
|
||||
Rise(3) { GameFileFolderActions(s, a) }
|
||||
}
|
||||
return
|
||||
}
|
||||
val pal = LocalPalette.current
|
||||
Row(modifier = modifier) {
|
||||
GameList(games, gameCount, s.steamGamesX64, current, onSelect = { onSelect("app:${it.appId}") }, onLaunch = launch, onAdd = onAdd,
|
||||
modifier = Modifier.width(if (narrow) 168.dp else 250.dp).fillMaxHeight())
|
||||
Box(Modifier.width(1.dp).fillMaxHeight().background(pal.line))
|
||||
Column(
|
||||
modifier = Modifier.weight(1f).fillMaxHeight().verticalScroll(rememberScrollState())
|
||||
.padding(horizontal = if (narrow) 14.dp else 20.dp, vertical = 16.dp),
|
||||
) {
|
||||
GameHero(current, Modifier.fillMaxWidth().heightIn(min = if (narrow) 170.dp else 200.dp), corner = { GameRemoveButton(current, s, a) }) {
|
||||
GameHeroCopy(current, if (narrow) 24.sp else 32.sp)
|
||||
GameActions(current, s, a, onEdit, launch)
|
||||
}
|
||||
SectionTitle(stringResource(R.string.games_launch_settings), null)
|
||||
LaunchSettings(s, a, host, current)
|
||||
GameFileFolderActions(s, a)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun GameFileFolderActions(s: FrontEndState, a: FrontEndActions) {
|
||||
internal fun GameFileFolderActions(s: FrontEndState, a: FrontEndActions) {
|
||||
if (s.shortcutPicker) return
|
||||
var open by remember { androidx.compose.runtime.mutableStateOf(false) }
|
||||
Box(Modifier.padding(top = 12.dp)) {
|
||||
Box {
|
||||
SecondaryButton(stringResource(R.string.game_frontend_files), compact = true) { open = !open }
|
||||
AnchoredMenu(open, onDismiss = { open = false }, title = s.gameSyncFolder ?: stringResource(R.string.game_frontend_files)) { first ->
|
||||
MenuItem(stringResource(R.string.game_file_sync), checked = false, focusRequester = first) {
|
||||
@@ -165,31 +59,7 @@ private fun GameFileFolderActions(s: FrontEndState, a: FrontEndActions) {
|
||||
|
||||
|
||||
@Composable
|
||||
private fun GameActions(g: Library.SteamGame, s: FrontEndState, a: FrontEndActions, onEdit: (Library.SteamGame) -> Unit, launch: (Library.SteamGame) -> Unit) {
|
||||
Actions {
|
||||
PrimaryButton(stringResource(if (s.shortcutPicker) R.string.game_shortcut_choose else R.string.games_launch), enabled = !s.busy, main = true, icon = Icons.Filled.PlayArrow) { launch(g) }
|
||||
if (g.library == Library.EPIC_LAUNCHER) {
|
||||
if (!s.shortcutPicker) UninstallEpicLauncher(s, a)
|
||||
BusyChip(s)
|
||||
return@Actions
|
||||
}
|
||||
g.gameFiles?.takeIf { it.isDirectory }?.let { dir ->
|
||||
SecondaryButton(stringResource(R.string.games_files), compact = true) { a.onBrowseFiles(dir) }
|
||||
}
|
||||
g.protonPrefix?.takeIf { it.isDirectory }?.let { dir ->
|
||||
SecondaryButton(stringResource(R.string.games_prefix), compact = true) { a.onBrowseFiles(dir) }
|
||||
if (g.library == Library.ADDED) ManageSaves(g, dir, a)
|
||||
}
|
||||
if (!s.shortcutPicker) GameShortcutMenu(g, a)
|
||||
if (!s.shortcutPicker && g.library == Library.ADDED && g.source == Library.ADDED && g.gameFiles != null) EditGameButton { onEdit(g) }
|
||||
else if (!s.shortcutPicker && g.library != Library.ADDED && g.source == Library.SOURCE_STEAM) EditGameButton { GamesDialogState.steamArt = g }
|
||||
else if (!s.shortcutPicker && g.library == Library.ADDED && g.source != Library.ADDED && g.gameFiles != null) EditGameButton { GamesDialogState.storeArt = g }
|
||||
BusyChip(s)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun UninstallEpicLauncher(s: FrontEndState, a: FrontEndActions) {
|
||||
internal fun UninstallEpicLauncher(s: FrontEndState, a: FrontEndActions) {
|
||||
var asking by remember { androidx.compose.runtime.mutableStateOf(false) }
|
||||
SecondaryButton(stringResource(R.string.common_uninstall), enabled = !s.busy, compact = true) { asking = true }
|
||||
if (asking) {
|
||||
@@ -204,71 +74,6 @@ private fun UninstallEpicLauncher(s: FrontEndState, a: FrontEndActions) {
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun GameShortcutMenu(g: Library.SteamGame, a: FrontEndActions) {
|
||||
var open by remember(g.gameId) { androidx.compose.runtime.mutableStateOf(false) }
|
||||
Box {
|
||||
SecondaryButton(stringResource(R.string.game_shortcut), compact = true) { open = !open }
|
||||
AnchoredMenu(open, onDismiss = { open = false }, title = stringResource(R.string.game_shortcut)) { first ->
|
||||
MenuItem(stringResource(R.string.game_shortcut_add), checked = false, focusRequester = first) {
|
||||
open = false; a.onGameShortcut(g)
|
||||
}
|
||||
MenuItem(stringResource(R.string.game_file_export), checked = false) {
|
||||
open = false; a.onExportGameFile(g)
|
||||
}
|
||||
MenuItem(stringResource(R.string.game_link_copy), checked = false) {
|
||||
open = false; a.onCopyGameLink(g)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ManageSaves(g: Library.SteamGame, prefix: java.io.File, a: FrontEndActions) {
|
||||
var open by remember(g.gameId) { androidx.compose.runtime.mutableStateOf(false) }
|
||||
val saves by androidx.compose.runtime.produceState<List<com.droiddeck.launcher.session.GameSaves.SaveDir>?>(null, g.gameId, open) {
|
||||
if (open) value = kotlinx.coroutines.withContext(kotlinx.coroutines.Dispatchers.IO) {
|
||||
runCatching { com.droiddeck.launcher.session.GameSaves.locate(prefix, g) }.getOrDefault(emptyList())
|
||||
}
|
||||
}
|
||||
val found = saves
|
||||
val summary = when {
|
||||
found == null -> stringResource(R.string.games_saves_looking)
|
||||
found.isEmpty() -> stringResource(R.string.games_saves_none)
|
||||
else -> {
|
||||
val mb = found.sumOf { it.bytes } / 1048576.0
|
||||
stringResource(
|
||||
R.string.games_saves_summary,
|
||||
if (found.size == 1) found[0].relPath else stringResource(R.string.games_saves_folders, found.size),
|
||||
found.sumOf { it.files },
|
||||
if (mb < 1) stringResource(R.string.games_kb, (mb * 1024).toInt()) else stringResource(R.string.common_size_mb, mb),
|
||||
)
|
||||
}
|
||||
}
|
||||
Box {
|
||||
val cloudGame = com.droiddeck.launcher.stores.Store.byId(g.source).let { it == com.droiddeck.launcher.stores.Store.GOG || it == com.droiddeck.launcher.stores.Store.EPIC }
|
||||
val label = stringResource(if (cloudGame) R.string.store_cloud_saves else R.string.games_manage_saves)
|
||||
SecondaryButton(label, compact = true) { open = !open }
|
||||
AnchoredMenu(open, onDismiss = { open = false }, title = if (cloudGame) label else stringResource(R.string.games_saves), note = summary) { first ->
|
||||
if (cloudGame) CloudRows(g, open, first)
|
||||
MenuItem(stringResource(R.string.games_import_saves), checked = false, focusRequester = if (cloudGame) null else first) {
|
||||
open = false; a.onSaveImport(g)
|
||||
}
|
||||
MenuItem(stringResource(R.string.games_export_gamehub), checked = false) {
|
||||
open = false; a.onSaveExport(g, com.droiddeck.launcher.session.GameSaves.Layout.GAMEHUB)
|
||||
}
|
||||
MenuItem(stringResource(R.string.games_export_winlator), checked = false) {
|
||||
open = false; a.onSaveExport(g, com.droiddeck.launcher.session.GameSaves.Layout.WINLATOR)
|
||||
}
|
||||
found?.firstOrNull()?.let { d ->
|
||||
MenuItem(stringResource(R.string.games_open_save_folder), checked = false, detail = d.relPath) {
|
||||
open = false; a.onBrowseFiles(java.io.File(prefix, "drive_c/users/steamuser/" + d.relPath))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** A skipped sync is not a success: "0 files" used to show for a signed-out store or cloud saves turned off. */
|
||||
internal fun cloudMessage(context: android.content.Context, r: com.droiddeck.launcher.stores.CloudSaves.Result): String = when (r.result) {
|
||||
"ok" -> when {
|
||||
@@ -285,125 +90,7 @@ internal fun cloudMessage(context: android.content.Context, r: com.droiddeck.lau
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun CloudRows(g: Library.SteamGame, open: Boolean, first: androidx.compose.ui.focus.FocusRequester) {
|
||||
val store = com.droiddeck.launcher.stores.Store.byId(g.source)?.takeIf { it != com.droiddeck.launcher.stores.Store.AMAZON } ?: return
|
||||
val id = g.storeId ?: return
|
||||
val context = androidx.compose.ui.platform.LocalContext.current.applicationContext
|
||||
var busy by remember(g.gameId) { androidx.compose.runtime.mutableStateOf<String?>(null) }
|
||||
var tick by remember(g.gameId) { androidx.compose.runtime.mutableStateOf(0) }
|
||||
val status by androidx.compose.runtime.produceState<com.droiddeck.launcher.stores.CloudSaves.Status?>(null, g.gameId, open, tick) {
|
||||
if (open) value = kotlinx.coroutines.withContext(kotlinx.coroutines.Dispatchers.IO) {
|
||||
runCatching { com.droiddeck.launcher.stores.CloudSaves.status(context, store, id) }.getOrNull()
|
||||
}
|
||||
}
|
||||
val folder = g.gameFiles
|
||||
var enabled by remember(g.gameId, open) { androidx.compose.runtime.mutableStateOf(folder?.let { com.droiddeck.launcher.stores.StoreGameSidecar.read(it)?.cloud } ?: true) }
|
||||
val st = status
|
||||
val supported = st?.supported ?: true
|
||||
val conflict = st != null && st.conflicts.isNotEmpty()
|
||||
fun sync(up: Boolean, force: Boolean = false) {
|
||||
if (busy != null) return
|
||||
busy = if (up) "up" else "down"
|
||||
Thread({
|
||||
val r = if (up) com.droiddeck.launcher.stores.CloudSaves.upload(context, store, id, force) else com.droiddeck.launcher.stores.CloudSaves.download(context, store, id, force)
|
||||
com.droiddeck.launcher.stores.StoresState.post { busy = null; tick++; android.widget.Toast.makeText(context, cloudMessage(context, r), android.widget.Toast.LENGTH_SHORT).show() }
|
||||
}, "cloud-manual").start()
|
||||
}
|
||||
MenuItem(stringResource(R.string.store_cloud_saves), checked = enabled && supported, enabled = supported, focusRequester = first,
|
||||
detail = if (!supported) stringResource(R.string.cloud_none) else null) {
|
||||
val f = folder ?: return@MenuItem
|
||||
val next = !enabled
|
||||
Thread({
|
||||
val written = runCatching { com.droiddeck.launcher.stores.StoreGameSidecar.updateCloud(f, next) }.getOrNull()
|
||||
com.droiddeck.launcher.stores.StoresState.post { enabled = written?.cloud ?: enabled }
|
||||
}, "cloud-switch").start()
|
||||
}
|
||||
val ready = st != null && supported && enabled && busy == null
|
||||
val pending = stringResource(R.string.cloud_pending)
|
||||
val summary = when {
|
||||
st == null || busy != null -> pending
|
||||
!supported -> stringResource(R.string.cloud_none)
|
||||
conflict -> stringResource(R.string.cloud_conflict_files, st.conflicts.size)
|
||||
st.lastSync > 0 -> stringResource(R.string.cloud_last_sync, android.text.format.DateUtils.getRelativeTimeSpanString(st.lastSync).toString())
|
||||
else -> stringResource(R.string.cloud_never)
|
||||
}
|
||||
MenuItem(stringResource(if (conflict) R.string.cloud_keep_local else R.string.cloud_upload), checked = false, enabled = ready, detail = summary) { sync(up = true, force = conflict) }
|
||||
MenuItem(stringResource(if (conflict) R.string.cloud_keep_cloud else R.string.cloud_download), checked = false, enabled = ready, detail = if (st == null || busy != null) pending else null) { sync(up = false, force = conflict) }
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ColumnScope.GameHeroCopy(g: Library.SteamGame, titleSize: androidx.compose.ui.unit.TextUnit) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
SourceChip(g.source)
|
||||
val eyebrow = lastPlayedText(g.lastPlayed) ?: libraryLabel(g)
|
||||
if (eyebrow.isNotEmpty()) Text(
|
||||
eyebrow.uppercase(),
|
||||
fontSize = 12.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 1.2.sp, color = LocalPalette.current.signal,
|
||||
maxLines = 1, overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
}
|
||||
GameTitle(g, titleSize)
|
||||
Spacer(Modifier.height(8.dp))
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun GameTitle(g: Library.SteamGame, titleSize: androidx.compose.ui.unit.TextUnit) {
|
||||
val logo = g.logo
|
||||
var failed by remember(logo) { androidx.compose.runtime.mutableStateOf(false) }
|
||||
if (logo != null && !failed) {
|
||||
AsyncImage(
|
||||
model = logo, contentDescription = g.name, contentScale = ContentScale.Fit, alignment = Alignment.CenterStart,
|
||||
onError = { failed = true },
|
||||
modifier = Modifier.padding(vertical = 4.dp).height((titleSize.value * 2.2f).dp).widthIn(max = (titleSize.value * 9f).dp).testTag("game-logo"),
|
||||
)
|
||||
} else Text(
|
||||
g.name, fontSize = titleSize, lineHeight = titleSize * 1.15f, fontWeight = FontWeight.Bold,
|
||||
color = MaterialTheme.colorScheme.onBackground, maxLines = 2, overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun GameList(
|
||||
games: List<Library.SteamGame>, count: Int, x64: Boolean, current: Library.SteamGame,
|
||||
onSelect: (Library.SteamGame) -> Unit, onLaunch: (Library.SteamGame) -> Unit, onAdd: (() -> Unit)?, modifier: Modifier,
|
||||
) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(2.dp),
|
||||
modifier = modifier.verticalScroll(rememberScrollState()).padding(start = 12.dp, end = 10.dp, top = 16.dp, bottom = 16.dp),
|
||||
) {
|
||||
GamesHeader(count, x64, onAdd, Modifier.padding(start = 6.dp, bottom = 10.dp))
|
||||
val seen = remember { HashSet<Int>() }
|
||||
var settled by remember { androidx.compose.runtime.mutableStateOf(false) }
|
||||
for (g in games) key(g.appId) {
|
||||
Box(Modifier.arriveIn(settled && g.appId !in seen)) {
|
||||
GameRow(g, g.appId == current.appId, onSelect = { onSelect(g) }, onLaunch = { onLaunch(g) })
|
||||
}
|
||||
}
|
||||
androidx.compose.runtime.SideEffect {
|
||||
seen.addAll(games.map { it.appId })
|
||||
if (games.isNotEmpty()) settled = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun GamesHeader(count: Int, x64: Boolean, onAdd: (() -> Unit)?, modifier: Modifier) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val narrow = LocalNarrowPane.current
|
||||
Column(modifier) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
Text(stringResource(R.string.content_games), fontSize = 22.sp, fontWeight = FontWeight.Bold, color = colors.onBackground, maxLines = 1)
|
||||
Text(count.toString(), fontSize = 13.sp, color = colors.onSurfaceVariant)
|
||||
if (x64 && !narrow) ClientTag()
|
||||
if (onAdd != null) AddGameButton(onAdd)
|
||||
}
|
||||
if (x64 && narrow) Box(Modifier.padding(top = 4.dp)) { ClientTag() }
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ClientTag() {
|
||||
internal fun ClientTag() {
|
||||
Box(Modifier.testTag("games-client-x64")) { StateChip(stringResource(R.string.mode_client_arch_x64), ChipTone.PLAIN) }
|
||||
}
|
||||
|
||||
@@ -418,13 +105,13 @@ internal object GamesDialogState {
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun GamesDialogs(a: FrontEndActions, games: List<Library.SteamGame>) {
|
||||
internal fun GamesDialogs(a: FrontEndActions, games: List<Library.SteamGame>) {
|
||||
val ctx = androidx.compose.ui.platform.LocalContext.current
|
||||
val scope = androidx.compose.runtime.rememberCoroutineScope()
|
||||
val st = GamesDialogState
|
||||
if (st.adding) ExePickerDialog(
|
||||
stringResource(R.string.games_add_title),
|
||||
onAddAll = { dir ->
|
||||
onAddAll = { dir, showHidden ->
|
||||
st.summary = emptyList<com.droiddeck.launcher.frontend.AddedGames.Game>() to 0
|
||||
st.checking = dir.name
|
||||
scope.launch {
|
||||
@@ -433,6 +120,7 @@ private fun GamesDialogs(a: FrontEndActions, games: List<Library.SteamGame>) {
|
||||
ctx.applicationContext, dir,
|
||||
onGame = { g -> scope.launch { st.summary?.let { (list, n) -> st.summary = (list + g) to n } } },
|
||||
onChecking = { name -> scope.launch { st.checking = name } },
|
||||
showHidden = showHidden,
|
||||
)
|
||||
}
|
||||
st.checking = null
|
||||
@@ -471,68 +159,7 @@ private fun GamesDialogs(a: FrontEndActions, games: List<Library.SteamGame>) {
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun GameRemoveButton(g: Library.SteamGame, s: FrontEndState, a: FrontEndActions) {
|
||||
val kind = com.droiddeck.launcher.frontend.GameRemoval.kind(g)
|
||||
if (s.shortcutPicker || kind == com.droiddeck.launcher.frontend.GameRemoval.Kind.LAUNCHER) return
|
||||
if (g.gameFiles?.isDirectory != true) return
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val pal = LocalPalette.current
|
||||
val src = remember { MutableInteractionSource() }
|
||||
val hot = rememberHot(src)
|
||||
var asking by remember(g.gameId) { androidx.compose.runtime.mutableStateOf(false) }
|
||||
val shortcut = kind == com.droiddeck.launcher.frontend.GameRemoval.Kind.SHORTCUT
|
||||
val label = stringResource(if (shortcut) R.string.edit_remove else R.string.common_uninstall)
|
||||
val title = if (shortcut) stringResource(R.string.games_remove_title, g.name) else stringResource(R.string.stores_uninstall_title, g.name)
|
||||
val body = when {
|
||||
shortcut -> stringResource(R.string.games_remove_body)
|
||||
g.library == Library.ADDED -> stringResource(R.string.stores_uninstall_body)
|
||||
else -> stringResource(R.string.games_uninstall_body)
|
||||
}
|
||||
Box(
|
||||
contentAlignment = Alignment.Center,
|
||||
modifier = Modifier.paneItem("game:remove").downToFirstTile().size(44.dp).clip(Shape12)
|
||||
.background(if (hot) colors.error.copy(alpha = 0.22f) else Color.Black.copy(alpha = 0.34f))
|
||||
.glideBorder(hot, Shape12, colors.error, pal.line2)
|
||||
.hoverable(src).clickable(interactionSource = src, indication = LocalIndication.current, role = androidx.compose.ui.semantics.Role.Button) { asking = true }
|
||||
.controllerConfirm { asking = true }
|
||||
.semantics { contentDescription = label },
|
||||
) {
|
||||
androidx.compose.material3.Icon(
|
||||
Icons.Outlined.Delete, contentDescription = null,
|
||||
tint = if (hot) colors.error else Color.White, modifier = Modifier.size(18.dp),
|
||||
)
|
||||
}
|
||||
if (asking) ConfirmDialog(
|
||||
title = title,
|
||||
text = body,
|
||||
confirm = label,
|
||||
onConfirm = { a.onGameRemoved(g) },
|
||||
onDismiss = { asking = false },
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun EditGameButton(onClick: () -> Unit) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val pal = LocalPalette.current
|
||||
val src = remember { MutableInteractionSource() }
|
||||
val hot = rememberHot(src)
|
||||
val label = stringResource(R.string.common_edit)
|
||||
Box(
|
||||
contentAlignment = Alignment.Center,
|
||||
modifier = Modifier.paneItem("game:edit").downToFirstTile().size(44.dp).clip(Shape12)
|
||||
.background(if (hot) pal.signal.copy(alpha = 0.14f) else Color.White.copy(alpha = 0.03f))
|
||||
.glideBorder(hot, Shape12, pal.signal, pal.line2)
|
||||
.hoverable(src).clickable(interactionSource = src, indication = LocalIndication.current, role = androidx.compose.ui.semantics.Role.Button, onClick = onClick)
|
||||
.controllerConfirm(onClick = onClick)
|
||||
.semantics { contentDescription = label },
|
||||
) {
|
||||
androidx.compose.material3.Icon(Icons.Outlined.Edit, contentDescription = null, tint = colors.onBackground, modifier = Modifier.size(18.dp))
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun AddGameButton(onClick: () -> Unit) {
|
||||
internal fun AddGameButton(onClick: () -> Unit) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val pal = LocalPalette.current
|
||||
val src = remember { MutableInteractionSource() }
|
||||
@@ -552,48 +179,6 @@ private fun AddGameButton(onClick: () -> Unit) {
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun Modifier.arriveIn(arriving: Boolean): Modifier {
|
||||
val t = remember { androidx.compose.animation.core.Animatable(if (arriving) 0f else 1f) }
|
||||
LaunchedEffect(Unit) { if (t.value < 1f) t.animateTo(1f, Motion.tw(280)) }
|
||||
return graphicsLayer { alpha = t.value; translationY = (1f - t.value) * 12.dp.toPx() }
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun GameRow(g: Library.SteamGame, selected: Boolean, onSelect: () -> Unit, onLaunch: () -> Unit) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val pal = LocalPalette.current
|
||||
val src = remember { MutableInteractionSource() }
|
||||
val focused by src.collectIsFocusedAsState()
|
||||
val hovered by src.collectIsHoveredAsState()
|
||||
LaunchedEffect(focused) { if (focused && !selected) onSelect() }
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||
modifier = Modifier.fillMaxWidth().paneItem("game:${g.appId}")
|
||||
.clip(Shape12)
|
||||
.background(if (selected) pal.signal.copy(alpha = 0.14f) else if (hovered) Color.White.copy(alpha = 0.05f) else Color.Transparent)
|
||||
.glideBorder(focused, Shape12, pal.signal)
|
||||
.hoverable(src).clickable(role = androidx.compose.ui.semantics.Role.Button, interactionSource = src, indication = LocalIndication.current, onClick = onSelect)
|
||||
.controllerConfirm(onClick = onLaunch)
|
||||
.padding(horizontal = 10.dp, vertical = 6.dp),
|
||||
) {
|
||||
Box(Modifier.width(30.dp).height(45.dp).clip(RoundedCornerShape(5.dp)).background(artBrush(hueOf(g.name)))) {
|
||||
if (g.art != null) AsyncImage(model = g.art, contentDescription = null, contentScale = ContentScale.Crop, modifier = Modifier.matchParentSize())
|
||||
}
|
||||
Column(modifier = Modifier.weight(1f)) {
|
||||
Text(g.name, fontSize = 14.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
||||
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||
SourceChip(g.source, small = true)
|
||||
Text(
|
||||
if (g.library == Library.EPIC_LAUNCHER) libraryLabel(g)
|
||||
else playedSpan(g.lastPlayed)?.replaceFirstChar { it.uppercase() } ?: stringResource(R.string.games_never_played),
|
||||
fontSize = 12.sp, color = colors.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun PageHeader(title: String, trailing: @Composable RowScope.() -> Unit = {}) {
|
||||
Row(
|
||||
@@ -622,11 +207,7 @@ internal fun RuntimeChip(s: FrontEndState) = when {
|
||||
else -> Chip(stringResource(R.string.games_runtime_ready), ok = true)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun lastPlayedText(lastPlayed: Long): String? =
|
||||
playedSpan(lastPlayed)?.let { stringResource(R.string.games_last_played, it.replaceFirstChar { c -> c.lowercase() }) }
|
||||
|
||||
private fun playedSpan(lastPlayed: Long): String? {
|
||||
internal fun playedSpan(lastPlayed: Long): String? {
|
||||
if (lastPlayed <= 0L) return null
|
||||
return android.text.format.DateUtils.getRelativeTimeSpanString(
|
||||
lastPlayed * 1000L, System.currentTimeMillis(), android.text.format.DateUtils.MINUTE_IN_MILLIS,
|
||||
@@ -634,37 +215,9 @@ private fun playedSpan(lastPlayed: Long): String? {
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun libraryLabel(g: Library.SteamGame): String = when {
|
||||
g.library == Library.EPIC_LAUNCHER -> EpicClient.status.version?.substringBefore('+')?.let { stringResource(R.string.epic_client_version, it) } ?: ""
|
||||
internal fun libraryLabel(g: Library.SteamGame): String = when {
|
||||
g.library == Library.XBOX_CLOUD -> stringResource(R.string.xbox_cloud_gaming)
|
||||
g.library != Library.ADDED -> if (g.library == "internal") stringResource(R.string.games_internal) else g.library
|
||||
g.source != Library.ADDED -> stringResource(R.string.games_store_storage)
|
||||
else -> ""
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun GameHero(g: Library.SteamGame, modifier: Modifier, corner: @Composable BoxScope.() -> Unit = {}, content: @Composable ColumnScope.() -> Unit) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
Box(modifier = modifier.clip(Shape16).background(artBrush(hueOf(g.name)))) {
|
||||
val image = g.hero ?: g.art.takeIf { g.library != Library.EPIC_LAUNCHER }
|
||||
if (image != null) AsyncImage(
|
||||
model = image, contentDescription = null, contentScale = ContentScale.Crop,
|
||||
modifier = Modifier.matchParentSize()
|
||||
.then(if (g.hero == null) Modifier.blur(24.dp).graphicsLayer { scaleX = 1.3f; scaleY = 1.3f } else Modifier),
|
||||
)
|
||||
Spacer(
|
||||
Modifier.matchParentSize().background(
|
||||
Brush.horizontalGradient(
|
||||
0f to colors.background.copy(alpha = 0.92f),
|
||||
0.55f to colors.background.copy(alpha = 0.6f),
|
||||
1f to Color.Transparent,
|
||||
),
|
||||
),
|
||||
)
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(4.dp),
|
||||
modifier = Modifier.align(Alignment.BottomStart).padding(horizontal = 22.dp, vertical = 18.dp),
|
||||
content = content,
|
||||
)
|
||||
Box(Modifier.align(Alignment.TopEnd).padding(12.dp), content = corner)
|
||||
}
|
||||
}
|
||||
@@ -102,6 +102,10 @@ class FrontEndState(
|
||||
val gameDebugLogsNeedsRestart: Boolean = false,
|
||||
val vacDiagnostics: Boolean = false,
|
||||
val agentCommands: Boolean = false,
|
||||
val clearCachedApps: Boolean = false,
|
||||
val adbPaired: Boolean = false,
|
||||
val backgroundAppLimit: Int = -1,
|
||||
val memoryHud: String = "off",
|
||||
val steamGames: List<Library.SteamGame>,
|
||||
val steamGamesX64: Boolean = false,
|
||||
val emulators: List<Library.Emulator>,
|
||||
@@ -126,6 +130,7 @@ class FrontEndState(
|
||||
val packageStage: String? = null,
|
||||
val packagePercent: Int = -1,
|
||||
val sessionRunning: Boolean = false,
|
||||
val battleNetInstalled: Boolean = false,
|
||||
val removalPending: Boolean = false,
|
||||
val runtimeActionsBlocked: Boolean = false,
|
||||
val backActionsInverted: Boolean = false,
|
||||
@@ -134,16 +139,16 @@ class FrontEndState(
|
||||
val controller: com.droiddeck.launcher.input.ControllerPrefs.Settings? = null,
|
||||
val phantomProcessStatus: PhantomProcessStatus = PhantomProcessStatus.NOT_APPLICABLE,
|
||||
val showPhantomGate: Boolean = false,
|
||||
val orientation: Int = android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
|
||||
val orientation: Int = android.content.pm.ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE,
|
||||
val launcherFullscreen: Boolean = true,
|
||||
val downloadSource: String = DownloadSource.MODE_AUTO,
|
||||
val downloadMirror: String = "",
|
||||
val downloadPrefix: String = "",
|
||||
val downloadProxy: String = "",
|
||||
val animationsEnabled: Boolean = true,
|
||||
val launcherIcon: String = com.droiddeck.launcher.LauncherIcon.DARK,
|
||||
val gameStoresEnabled: Boolean = true,
|
||||
val gameStoresSpeedTier: String = "fast",
|
||||
val storesOpenTab: String = SessionPrefs.STORES_OPEN_LIBRARY,
|
||||
val navigate: String? = null,
|
||||
val addedGamesArt: Boolean = true,
|
||||
val sgdbUserKey: Boolean = false,
|
||||
@@ -178,6 +183,7 @@ class FrontEndActions(
|
||||
val onEmulator: (Library.Emulator) -> Unit,
|
||||
val onFlatpakApp: (String, String) -> Unit = { _, _ -> },
|
||||
val onUserApp: (com.droiddeck.launcher.runtime.UserApps.App) -> Unit = {},
|
||||
val onBattleNet: () -> Unit = {},
|
||||
val onRom: (Library.Rom) -> Unit,
|
||||
val onResume: () -> Unit,
|
||||
val onSteamSettings: () -> Unit,
|
||||
@@ -203,6 +209,9 @@ class FrontEndActions(
|
||||
val onGameDebugLogs: () -> Unit = {},
|
||||
val onVacDiagnostics: () -> Unit = {},
|
||||
val onAgentCommands: () -> Unit = {},
|
||||
val onClearCachedApps: (Boolean) -> Unit = {},
|
||||
val onMemoryHud: (String) -> Unit = {},
|
||||
val onBackgroundAppLimit: (Int) -> Unit = {},
|
||||
val onShareLogs: () -> Unit = {},
|
||||
val onClearLogs: () -> Unit = {},
|
||||
val onResetSettings: () -> Unit = {},
|
||||
@@ -218,9 +227,9 @@ class FrontEndActions(
|
||||
val onDownloadSource: (String) -> Unit = {},
|
||||
val onDownloadMirror: (String) -> Unit = {},
|
||||
val onDownloadPrefix: (String) -> Unit = {},
|
||||
val onDownloadProxy: (String) -> Unit = {},
|
||||
val onGameStoresEnabled: (Boolean) -> Unit = {},
|
||||
val onGameStoresSpeedTier: (String) -> Unit = {},
|
||||
val onStoresOpenTab: (String) -> Unit = {},
|
||||
val onNavigated: () -> Unit = {},
|
||||
val onStoresShowMature: (Boolean) -> Unit = {},
|
||||
val onStoresSort: (String) -> Unit = {},
|
||||
@@ -259,6 +268,12 @@ internal object Motion {
|
||||
if (scale == 0f) snap() else spring(damping, stiffness)
|
||||
}
|
||||
|
||||
internal object Ambient {
|
||||
var poked by mutableStateOf(0L)
|
||||
private set
|
||||
fun poke() { poked = android.os.SystemClock.uptimeMillis() }
|
||||
}
|
||||
|
||||
private val Shape10 = RoundedCornerShape(10.dp)
|
||||
|
||||
internal val Shape12 = RoundedCornerShape(12.dp)
|
||||
@@ -398,6 +413,9 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
|
||||
}
|
||||
a.onNavigated()
|
||||
}
|
||||
LaunchedEffect(com.droiddeck.launcher.stores.StoresState.openGameRequest) {
|
||||
if (com.droiddeck.launcher.stores.StoresState.openGameRequest != null) selected = "stores"
|
||||
}
|
||||
var showWirelessAdbFix by rememberSaveable { mutableStateOf(false) }
|
||||
var showDeveloperDisplayChoice by rememberSaveable { mutableStateOf(false) }
|
||||
var wirelessAdbDesiredEnabled by rememberSaveable { mutableStateOf(false) }
|
||||
@@ -440,7 +458,7 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
|
||||
}
|
||||
LaunchedEffect(s.isHomeApp) { if (!s.isHomeApp && selected == "android-apps") selected = "steam" }
|
||||
LaunchedEffect(s.steamGames.isEmpty()) {
|
||||
if (s.steamGames.isEmpty() && selected.startsWith("app:")) selected = "games"
|
||||
if (s.steamGames.isEmpty() && selected.startsWith("app:") && GameRef.parse(selected).appId != null) selected = "games"
|
||||
}
|
||||
remember { Motion.refresh(ctx); true }
|
||||
|
||||
@@ -553,6 +571,9 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
|
||||
|
||||
}
|
||||
FlightsLayer(screenAt)
|
||||
GamesDialogs(a, s.steamGames)
|
||||
com.droiddeck.launcher.stores.StoresState.pendingInstall?.let { item -> StoreTheme(item.store) { InstallWhere(item) } }
|
||||
com.droiddeck.launcher.stores.StoresState.itchPicking?.let { item -> StoreTheme(item.store) { ItchBuildPicker(item) { com.droiddeck.launcher.stores.StoresState.itchPicking = null } } }
|
||||
StepsLayer(screenAt)
|
||||
|
||||
appToChooseDisplay?.let { app ->
|
||||
|
||||
@@ -21,6 +21,7 @@ import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.interaction.collectIsPressedAsState
|
||||
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.IntrinsicSize
|
||||
import androidx.compose.foundation.layout.Row
|
||||
@@ -174,6 +175,7 @@ internal fun SetupPanel(
|
||||
var showLimitDetails by rememberSaveable { mutableStateOf(false) }
|
||||
var editSgdbKey by remember { mutableStateOf(false) }
|
||||
var editDownloadPrefix by remember { mutableStateOf(false) }
|
||||
var editDownloadProxy by remember { mutableStateOf(false) }
|
||||
if (editSgdbKey) SgdbKeyDialog(s.sgdbUserKey, onSave = { a.onSgdbKey(it); editSgdbKey = false }, onDismiss = { editSgdbKey = false })
|
||||
|
||||
if (editDownloadPrefix) TextEntryDialog(
|
||||
@@ -181,6 +183,11 @@ internal fun SetupPanel(
|
||||
onDismiss = { editDownloadPrefix = false },
|
||||
onSave = { a.onDownloadPrefix(it); editDownloadPrefix = false },
|
||||
)
|
||||
if (editDownloadProxy) TextEntryDialog(
|
||||
stringResource(R.string.setup_download_proxy), s.downloadProxy,
|
||||
onDismiss = { editDownloadProxy = false },
|
||||
onSave = { a.onDownloadProxy(it); editDownloadProxy = false },
|
||||
)
|
||||
val tabs = listOf(stringResource(R.string.setup_tab_overview), stringResource(R.string.setup_tab_controller), stringResource(R.string.setup_tab_launcher), stringResource(R.string.setup_tab_storage), stringResource(R.string.setup_tab_diagnostics), stringResource(R.string.setup_tab_glasses))
|
||||
var tab by rememberSaveable { mutableStateOf(if (SetupTabs.openLauncher) LAUNCHER_TAB else 0) }
|
||||
SetupTabs.openLauncher = false
|
||||
@@ -200,7 +207,6 @@ internal fun SetupPanel(
|
||||
runCatching { chipFocus[tab].requestFocus() }
|
||||
}
|
||||
}
|
||||
val wide = !LocalNarrowPane.current
|
||||
val runtimeOk = s.ready && !s.busy && !s.removalPending
|
||||
val checks = listOf(gpuOk, runtimeOk, !limitBlocks, signedIn)
|
||||
val passing = checks.count { it }
|
||||
@@ -359,6 +365,7 @@ internal fun SetupPanel(
|
||||
}
|
||||
}
|
||||
}
|
||||
if (s.theme == Themes.INNER_GAMER) RgbSpeedRow()
|
||||
if (s.theme == Themes.GRADIENT) GradientColorRows()
|
||||
ChoiceRow(
|
||||
host, "app-scale", stringResource(R.string.setup_app_scale), stringResource(R.string.setup_app_scale_hint),
|
||||
@@ -438,12 +445,20 @@ internal fun SetupPanel(
|
||||
onClick = { editDownloadPrefix = true },
|
||||
)
|
||||
}
|
||||
ActionRow(
|
||||
stringResource(R.string.setup_download_proxy),
|
||||
s.downloadProxy.takeIf { it.isNotEmpty() },
|
||||
stringResource(R.string.mode_sgdb_edit),
|
||||
onClick = { editDownloadProxy = true },
|
||||
)
|
||||
}
|
||||
}
|
||||
if (wide) Row(horizontalArrangement = Arrangement.spacedBy(16.dp), verticalAlignment = Alignment.Top) {
|
||||
Column(Modifier.weight(1f)) { look() }
|
||||
Column(Modifier.weight(1f)) { device(); art(); download() }
|
||||
} else { look(); device(); art(); download() }
|
||||
BoxWithConstraints(Modifier.fillMaxWidth()) {
|
||||
if (maxWidth >= 840.dp && !LocalNarrowPane.current) Row(horizontalArrangement = Arrangement.spacedBy(16.dp), verticalAlignment = Alignment.Top) {
|
||||
Column(Modifier.weight(1f)) { look() }
|
||||
Column(Modifier.weight(1f)) { device(); art(); download() }
|
||||
} else Column { look(); device(); art(); download() }
|
||||
}
|
||||
}
|
||||
STORAGE_TAB -> StoragePanel(s, a)
|
||||
4 -> {
|
||||
@@ -463,6 +478,38 @@ internal fun SetupPanel(
|
||||
ActionRow(stringResource(R.string.setup_reset_settings), stringResource(R.string.setup_reset_settings_hint),
|
||||
stringResource(R.string.setup_reset_settings_button), a.onResetSettings)
|
||||
}
|
||||
SettingsGroup(stringResource(R.string.setup_group_memory)) {
|
||||
ToggleRow(
|
||||
host, "clear-cached-apps", stringResource(R.string.setup_clear_cached),
|
||||
stringResource(if (s.adbPaired) R.string.setup_clear_cached_hint else R.string.setup_clear_cached_unpaired),
|
||||
s.clearCachedApps, enabled = s.adbPaired || s.clearCachedApps,
|
||||
) { a.onClearCachedApps(it) }
|
||||
ChoiceRow(
|
||||
host, "background-app-limit", stringResource(R.string.setup_bg_limit),
|
||||
stringResource(if (s.adbPaired) R.string.setup_bg_limit_hint else R.string.setup_clear_cached_unpaired),
|
||||
listOf(
|
||||
com.droiddeck.launcher.core.BackgroundAppLimit.OFF to stringResource(R.string.game_env_off),
|
||||
4 to stringResource(R.string.setup_bg_limit_4),
|
||||
1 to stringResource(R.string.setup_bg_limit_1),
|
||||
0 to stringResource(R.string.setup_bg_limit_0),
|
||||
),
|
||||
s.backgroundAppLimit, enabled = s.adbPaired || s.backgroundAppLimit != com.droiddeck.launcher.core.BackgroundAppLimit.OFF,
|
||||
onPick = a.onBackgroundAppLimit,
|
||||
)
|
||||
ChoiceRow(
|
||||
host, "memory-hud", stringResource(R.string.setup_memory_hud), stringResource(R.string.setup_memory_hud_hint),
|
||||
listOf(
|
||||
com.droiddeck.launcher.session.SessionPrefs.MEMORY_HUD_OFF to stringResource(R.string.game_env_off),
|
||||
com.droiddeck.launcher.session.SessionPrefs.MEMORY_HUD_SIMPLE to stringResource(R.string.setup_memory_hud_simple),
|
||||
com.droiddeck.launcher.session.SessionPrefs.MEMORY_HUD_ADVANCED to stringResource(R.string.setup_memory_hud_advanced),
|
||||
),
|
||||
s.memoryHud, onPick = a.onMemoryHud,
|
||||
)
|
||||
if (!s.adbPaired) ActionRow(
|
||||
stringResource(R.string.setup_adb_pair), stringResource(R.string.setup_adb_pair_hint),
|
||||
stringResource(R.string.setup_adb_pair_button), { onRequestWirelessAdb(false) },
|
||||
)
|
||||
}
|
||||
}
|
||||
GLASSES_TAB -> GlassesSetupPanel()
|
||||
}
|
||||
@@ -513,7 +560,7 @@ private fun FrameGenMenu(s: FrontEndState, a: FrontEndActions, host: MenuHost) {
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun LaunchSettings(s: FrontEndState, a: FrontEndActions, host: MenuHost, game: com.droiddeck.launcher.frontend.Library.SteamGame? = null) {
|
||||
internal fun LaunchSettings(s: FrontEndState, a: FrontEndActions, host: MenuHost, game: com.droiddeck.launcher.frontend.Library.SteamGame? = null, hopRail: String = "games") {
|
||||
val columns = if (LocalNarrowPane.current) 2 else 3
|
||||
val controller = a.controller
|
||||
val context = androidx.compose.ui.platform.LocalContext.current
|
||||
@@ -532,7 +579,7 @@ internal fun LaunchSettings(s: FrontEndState, a: FrontEndActions, host: MenuHost
|
||||
val at = Hops.sources["card:components"]
|
||||
val open = { if (game == null) a.onComponents(true) else a.onGameComponents(game) }
|
||||
if (at == null) open()
|
||||
else Hops.go(HopOrigin("games", HOP_SURFACE_GAMES, null, "card:components", at, back, dest = "components", page = "components"), open)
|
||||
else Hops.go(HopOrigin(hopRail, HOP_SURFACE_GAMES, null, "card:components", at, back, dest = "components", page = "components"), open)
|
||||
}
|
||||
}
|
||||
add { m ->
|
||||
@@ -575,18 +622,11 @@ internal fun LaunchSettings(s: FrontEndState, a: FrontEndActions, host: MenuHost
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun GameSettingsCard(host: MenuHost, game: com.droiddeck.launcher.frontend.Library.SteamGame, scope: String) {
|
||||
val appContext = androidx.compose.ui.platform.LocalContext.current.applicationContext
|
||||
val colors = MaterialTheme.colorScheme
|
||||
var config by remember(scope) { mutableStateOf(runCatching { com.droiddeck.launcher.session.GameEnvironmentStore.read(appContext) }.getOrNull()) }
|
||||
var saving by remember(scope) { mutableStateOf(false) }
|
||||
val current = config
|
||||
val noSteam = current != null && com.droiddeck.launcher.core.GameEnvironment.gameNoSteam(current, scope)
|
||||
val fex = current?.let { runCatching { com.droiddeck.launcher.core.GameEnvironment.gameFexPreset(it, scope) }.getOrNull() }
|
||||
val sync = current?.let { runCatching { com.droiddeck.launcher.core.GameEnvironment.gameSync(it, scope) }.getOrNull() }
|
||||
val ready = current != null && !saving
|
||||
val launcher = game.library == com.droiddeck.launcher.frontend.Library.EPIC_LAUNCHER
|
||||
internal class GameSettingsState(private val appContext: android.content.Context, val scope: String) {
|
||||
var config by mutableStateOf(runCatching { com.droiddeck.launcher.session.GameEnvironmentStore.read(appContext) }.getOrNull())
|
||||
var saving by mutableStateOf(false)
|
||||
val noSteam: Boolean get() = config?.let { com.droiddeck.launcher.core.GameEnvironment.gameNoSteam(it, scope) } == true
|
||||
|
||||
fun save(change: (android.content.Context) -> com.droiddeck.launcher.core.GameEnvironment.Config?) {
|
||||
if (saving) return
|
||||
saving = true
|
||||
@@ -600,7 +640,37 @@ private fun GameSettingsCard(host: MenuHost, game: com.droiddeck.launcher.fronte
|
||||
}
|
||||
}, "game-settings").start()
|
||||
}
|
||||
val key = "game-settings"
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun rememberGameSettings(scope: String): GameSettingsState {
|
||||
val appContext = androidx.compose.ui.platform.LocalContext.current.applicationContext
|
||||
return remember(scope) { GameSettingsState(appContext, scope) }
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun GameSettingsCard(host: MenuHost, game: com.droiddeck.launcher.frontend.Library.SteamGame, scope: String) {
|
||||
val state = rememberGameSettings(scope)
|
||||
SettingCard(stringResource(R.string.game_settings_card), stringResource(if (state.noSteam) R.string.game_steam_without else R.string.game_steam_with), "card:$GAME_SETTINGS_MENU", Modifier.fillMaxSize()) {
|
||||
host.open = if (host.open == GAME_SETTINGS_MENU) null else GAME_SETTINGS_MENU
|
||||
}
|
||||
GameSettingsMenus(host, game, state)
|
||||
}
|
||||
|
||||
/** The per-game settings menus, opened by setting [MenuHost.open] to [GAME_SETTINGS_MENU]. */
|
||||
@Composable
|
||||
internal fun GameSettingsMenus(host: MenuHost, game: com.droiddeck.launcher.frontend.Library.SteamGame, state: GameSettingsState) {
|
||||
val appContext = androidx.compose.ui.platform.LocalContext.current.applicationContext
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val scope = state.scope
|
||||
val current = state.config
|
||||
val noSteam = state.noSteam
|
||||
val fex = current?.let { runCatching { com.droiddeck.launcher.core.GameEnvironment.gameFexPreset(it, scope) }.getOrNull() }
|
||||
val sync = current?.let { runCatching { com.droiddeck.launcher.core.GameEnvironment.gameSync(it, scope) }.getOrNull() }
|
||||
val ready = current != null && !state.saving
|
||||
val launcher = game.library == com.droiddeck.launcher.frontend.Library.EPIC_LAUNCHER
|
||||
fun save(change: (android.content.Context) -> com.droiddeck.launcher.core.GameEnvironment.Config?) = state.save(change)
|
||||
val key = GAME_SETTINGS_MENU
|
||||
val fexKey = "game-settings-fex"
|
||||
val syncKey = "game-settings-sync"
|
||||
val syncLabels = mapOf(
|
||||
@@ -614,9 +684,6 @@ private fun GameSettingsCard(host: MenuHost, game: com.droiddeck.launcher.fronte
|
||||
val custom = stringResource(R.string.comp_game_fex_custom)
|
||||
val customSync = stringResource(R.string.game_sync_custom)
|
||||
val resetDone = stringResource(R.string.comp_game_reset_done, game.name)
|
||||
SettingCard(stringResource(R.string.game_settings_card), stringResource(if (noSteam) R.string.game_steam_without else R.string.game_steam_with), "card:$key", Modifier.fillMaxSize()) {
|
||||
host.open = if (host.open == key) null else key
|
||||
}
|
||||
AnchoredMenu(host.open == key, onDismiss = { if (host.open == key) host.open = null }, title = stringResource(R.string.game_settings_menu_title, game.name)) { first ->
|
||||
MenuItem(stringResource(R.string.game_no_steam_title), checked = noSteam, enabled = ready,
|
||||
detail = stringResource(R.string.game_no_steam_detail), focusRequester = first) {
|
||||
@@ -691,6 +758,8 @@ private fun GameSettingsCard(host: MenuHost, game: com.droiddeck.launcher.fronte
|
||||
}
|
||||
}
|
||||
|
||||
internal const val GAME_SETTINGS_MENU = "game-settings"
|
||||
|
||||
private const val EPIC_RESOLVE_URL = "https://www.epicgames.com/id/login?redirectUrl=https%3A%2F%2Fwww.epicgames.com%2Faccount%2Fpersonal"
|
||||
|
||||
@Composable
|
||||
@@ -798,6 +867,13 @@ private fun LanguageRow(host: MenuHost, chosen: String, onPick: (String) -> Unit
|
||||
}
|
||||
}
|
||||
|
||||
/** How fast Inner Gamer cycles its colours. */
|
||||
@Composable
|
||||
private fun RgbSpeedRow() {
|
||||
val ctx = androidx.compose.ui.platform.LocalContext.current.applicationContext
|
||||
SliderRow(stringResource(R.string.theme_rgb_speed), stringResource(R.string.theme_rgb_speed_hint), Themes.rgbSpeed, 1..Themes.RGB_SPEEDS) { Themes.setRgbSpeed(ctx, it) }
|
||||
}
|
||||
|
||||
/** The two colours of the Gradient theme, each a small square that opens the colour picker. */
|
||||
@Composable
|
||||
private fun GradientColorRows() {
|
||||
|
||||
@@ -0,0 +1,845 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import androidx.compose.foundation.LocalIndication
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.focusable
|
||||
import androidx.compose.foundation.gestures.animateScrollBy
|
||||
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.BoxScope
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.ColumnScope
|
||||
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.heightIn
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.layout.widthIn
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.PlayArrow
|
||||
import androidx.compose.material.icons.outlined.Delete
|
||||
import androidx.compose.material.icons.outlined.Edit
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.SideEffect
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.produceState
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.alpha
|
||||
import androidx.compose.ui.draw.blur
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.focus.onFocusChanged
|
||||
import androidx.compose.ui.graphics.Brush
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.graphicsLayer
|
||||
import androidx.compose.ui.input.key.onPreviewKeyEvent
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.layout.boundsInRoot
|
||||
import androidx.compose.ui.layout.onGloballyPositioned
|
||||
import androidx.compose.ui.layout.positionInRoot
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.platform.LocalConfiguration
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.res.stringResource
|
||||
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.TextUnit
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import coil.compose.AsyncImage
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.frontend.GameRemoval
|
||||
import com.droiddeck.launcher.frontend.Library
|
||||
import com.droiddeck.launcher.session.GameSaves
|
||||
import com.droiddeck.launcher.stores.CatalogItem
|
||||
import com.droiddeck.launcher.stores.CloudSaves
|
||||
import com.droiddeck.launcher.stores.InstalledStoreGame
|
||||
import com.droiddeck.launcher.stores.Lookup
|
||||
import com.droiddeck.launcher.stores.Store
|
||||
import com.droiddeck.launcher.stores.StoreAchievements
|
||||
import com.droiddeck.launcher.stores.StoreGameSidecar
|
||||
import com.droiddeck.launcher.stores.StoreInstallRoot
|
||||
import com.droiddeck.launcher.stores.StoreLanguage
|
||||
import com.droiddeck.launcher.stores.StoreSizes
|
||||
import com.droiddeck.launcher.stores.StoresState
|
||||
import com.droiddeck.launcher.stores.download.DownloadQueue
|
||||
import com.droiddeck.launcher.stores.download.DownloadState
|
||||
import com.droiddeck.launcher.stores.formatBytes
|
||||
import com.droiddeck.launcher.stores.xbox.XboxBackend
|
||||
import com.droiddeck.launcher.stores.xbox.XboxCloudGames
|
||||
import com.droiddeck.launcher.stores.xbox.XboxContent
|
||||
import com.droiddeck.launcher.stores.xbox.xboxCloud
|
||||
import com.droiddeck.launcher.stores.xbox.xboxPc
|
||||
import com.droiddeck.launcher.stores.xbox.XboxRuntime
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.io.File
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.runtime.getValue
|
||||
|
||||
/** What a game page shows: `app:<appId>` for a game in the library, `[app:]<store>:<id>` for a store product. */
|
||||
internal class GameRef(val appId: Int?, val store: Store?, val storeId: String?) {
|
||||
fun game(games: List<Library.SteamGame>): Library.SteamGame? = when {
|
||||
appId != null -> games.firstOrNull { it.appId == appId }
|
||||
store != null && storeId != null -> games.firstOrNull { it.source == store.id && it.storeId == storeId }
|
||||
else -> null
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun parse(key: String): GameRef {
|
||||
val rest = key.removePrefix("app:")
|
||||
rest.toIntOrNull()?.let { return GameRef(it, null, null) }
|
||||
val store = Store.byId(rest.substringBefore(':'))
|
||||
return GameRef(null, store, rest.substringAfter(':', "").takeIf { store != null && it.isNotEmpty() })
|
||||
}
|
||||
|
||||
fun key(game: Library.SteamGame) = "app:${game.appId}"
|
||||
fun key(item: CatalogItem) = "app:${item.key}"
|
||||
}
|
||||
}
|
||||
|
||||
internal enum class GameTab { ABOUT, ACHIEVEMENTS, LAUNCH, SAVES, INSTALL }
|
||||
|
||||
@Composable
|
||||
internal fun GameDetail(
|
||||
key: String, s: FrontEndState, a: FrontEndActions, lead: FocusRequester, backLabel: String, hopRail: String?, onBack: () -> Unit,
|
||||
) {
|
||||
val narrow = LocalNarrowPane.current
|
||||
val stacked = narrow || LocalConfiguration.current.screenWidthDp < 700
|
||||
val ref = remember(key) { GameRef.parse(key) }
|
||||
val games = s.steamGames + rememberXboxCloudRows(s)
|
||||
val found = ref.game(games)
|
||||
val known = remember(key) { arrayOfNulls<Pair<Store, String>>(1) }
|
||||
val store = ref.store ?: Store.byId(found?.source) ?: known[0]?.first
|
||||
val id = ref.storeId ?: found?.storeId ?: known[0]?.second
|
||||
SideEffect { if (store != null && id != null) known[0] = store to id }
|
||||
val game = found ?: if (store != null && id != null) s.steamGames.firstOrNull { it.source == store.id && it.storeId == id } else null
|
||||
val item = if (store != null && id != null) StoresState.detailItem(store, id) else null
|
||||
val installed = if (store != null && id != null) StoresState.installedGame(store, id) else null
|
||||
val rawDownload = if (store != null && id != null) StoresState.download("${store.id}:$id") else null
|
||||
val download = rawDownload?.takeIf { it.isActive }
|
||||
val failed = rawDownload?.takeIf { it.state == DownloadState.FAILED }
|
||||
val nothing = game == null && store == null
|
||||
LaunchedEffect(nothing) { if (nothing) onBack() }
|
||||
if (nothing) return
|
||||
val source = game?.source ?: store?.id ?: Library.SOURCE_STEAM
|
||||
val title = game?.name ?: item?.title ?: installed?.sidecar?.title ?: id.orEmpty()
|
||||
val scores = if (source != Library.ADDED) rememberGameScores(title.takeIf { it.isNotBlank() && it != id }) else null
|
||||
val achievements = remember(store, id, item?.accessible, installed) {
|
||||
when {
|
||||
store == null || StoreAchievements.forSource(store.id) == null -> null
|
||||
item?.accessible == true -> StoreAchievements.Game.of(item)
|
||||
installed != null -> StoreAchievements.Game.of(installed.sidecar)
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
val achievementState = rememberAchievements(achievements)
|
||||
val listed = if (store == null) null else (StoresState.found[store].orEmpty() + StoresState.shelves[store]?.all.orEmpty()).firstOrNull { it.id == id }
|
||||
val developer = item?.developer?.ifBlank { null } ?: listed?.developer.orEmpty()
|
||||
val publisher = item?.publisher?.ifBlank { null } ?: listed?.publisher.orEmpty()
|
||||
val releaseDate = item?.releaseDate?.ifBlank { null } ?: listed?.releaseDate.orEmpty()
|
||||
val description = item?.let { com.droiddeck.launcher.stores.cleanStoreText(it.description) }.orEmpty()
|
||||
.takeUnless { it.trim().equals(title.trim(), ignoreCase = true) }.orEmpty()
|
||||
val scored = scores != null && (scores.metacritic != Lookup.None || scores.hltb != Lookup.None)
|
||||
val prefix = game?.protonPrefix?.takeIf { it.isDirectory }
|
||||
val tabs = buildList {
|
||||
if (description.isNotBlank() || developer.isNotBlank() || publisher.isNotBlank() || releaseDate.isNotBlank() || (scored && stacked)) add(GameTab.ABOUT)
|
||||
if (achievementState != null) add(GameTab.ACHIEVEMENTS)
|
||||
val cloud = game?.library == Library.XBOX_CLOUD
|
||||
if (game != null && !cloud) add(GameTab.LAUNCH)
|
||||
if (game != null && game.library == Library.ADDED && prefix != null) add(GameTab.SAVES)
|
||||
if ((game != null && !cloud) || installed != null) add(GameTab.INSTALL)
|
||||
}
|
||||
var picked by remember(key) { mutableStateOf<GameTab?>(null) }
|
||||
val tab = picked?.takeIf { it in tabs } ?: tabs.firstOrNull()
|
||||
val tabFocus = remember(key) { GameTab.entries.associateWith { FocusRequester() } }
|
||||
var inPanel by remember(key) { mutableStateOf(false) }
|
||||
var inPage by remember(key) { mutableStateOf(false) }
|
||||
var onStrip by remember(key) { mutableStateOf(false) }
|
||||
var dropped by remember(key) { mutableStateOf(0) }
|
||||
// A tab's content is swapped or refreshed under the focused row; focus goes back to the tabs, not to the rail.
|
||||
LaunchedEffect(dropped) {
|
||||
if (dropped == 0) return@LaunchedEffect
|
||||
androidx.compose.runtime.withFrameNanos { }
|
||||
val t = tab ?: return@LaunchedEffect
|
||||
if (!inPage) focusWithinFrames({ onStrip }) { tabFocus.getValue(t) }
|
||||
}
|
||||
fun cycle(step: Int) {
|
||||
if (tabs.size < 2) return
|
||||
val at = tabs.indexOf(tab).coerceAtLeast(0)
|
||||
picked = tabs[(at + step + tabs.size) % tabs.size]
|
||||
}
|
||||
Column(Modifier.fillMaxWidth().onFocusChanged { inPage = it.hasFocus }.bumpers(onPrevious = { cycle(-1) }, onNext = { cycle(1) })) {
|
||||
Rise(0) {
|
||||
Box(Modifier.padding(bottom = 12.dp)) { BackLink(backLabel, compact = true, onClick = onBack) }
|
||||
}
|
||||
val hero: @Composable () -> Unit = {
|
||||
DisposableEffect(Unit) { onDispose { StoresMotion.heroAt = null } }
|
||||
GameHero(
|
||||
title, item, installed, game,
|
||||
Modifier.fillMaxWidth().heightIn(min = if (narrow) 170.dp else 210.dp).onGloballyPositioned { StoresMotion.heroAt = it.boundsInRoot() },
|
||||
corner = { if (!s.shortcutPicker) RemoveButton(title, game, installed, a) },
|
||||
scores = scores.takeIf { !stacked },
|
||||
) {
|
||||
HeroEyebrow(source, game, item, installed, download?.location ?: failed?.location)
|
||||
GameTitle(title, game?.logo ?: item?.logoUrl, if (narrow) 26.sp else 34.sp)
|
||||
if (!failed?.error.isNullOrBlank()) Text(
|
||||
failed!!.error!!, fontSize = 13.sp, lineHeight = 17.sp, fontWeight = FontWeight.Medium,
|
||||
color = MaterialTheme.colorScheme.error, maxLines = 3, overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
Spacer(Modifier.height(4.dp))
|
||||
GameActions(store, id, game, item, installed, s, a, Modifier.focusRequester(lead))
|
||||
}
|
||||
}
|
||||
if (StoresMotion.heroLands) hero() else Rise(1) { hero() }
|
||||
if (tab != null) Rise(2) {
|
||||
Column(Modifier.fillMaxWidth().padding(top = 14.dp), verticalArrangement = Arrangement.spacedBy(12.dp)) {
|
||||
val labels = tabs.map { t ->
|
||||
when (t) {
|
||||
GameTab.ABOUT -> stringResource(R.string.game_tab_about)
|
||||
GameTab.ACHIEVEMENTS -> achievementState?.list?.takeIf { it.isNotEmpty() }?.let { list ->
|
||||
stringResource(R.string.game_tab_achievements_count, stringResource(R.string.achievements_title), achievementState.done, list.size)
|
||||
} ?: stringResource(R.string.achievements_title)
|
||||
GameTab.LAUNCH -> stringResource(R.string.game_tab_launch)
|
||||
GameTab.SAVES -> stringResource(if (Store.byId(source).let { it == Store.GOG || it == Store.EPIC }) R.string.game_tab_saves_cloud else R.string.games_saves)
|
||||
GameTab.INSTALL -> stringResource(R.string.game_tab_install)
|
||||
}
|
||||
}
|
||||
TabStrip(
|
||||
labels, tabs.indexOf(tab), { picked = tabs[it] }, Modifier.onFocusChanged { onStrip = it.hasFocus },
|
||||
focusRequesters = tabs.map { tabFocus.getValue(it) }, bumpers = tabs.size > 1, compact = narrow,
|
||||
)
|
||||
Box(Modifier.fillMaxWidth().onFocusChanged { if (inPanel && !it.hasFocus) dropped++; inPanel = it.hasFocus }.testTag("game-tab-${tab.name.lowercase()}")) {
|
||||
when (tab) {
|
||||
GameTab.ABOUT -> AboutTab(developer, publisher, releaseDate, description, scores, stacked)
|
||||
GameTab.ACHIEVEMENTS -> achievementState?.let { st -> AchievementsTab(StoreAchievements.forSource(store?.id)?.label.orEmpty(), st) }
|
||||
GameTab.LAUNCH -> if (game != null) LaunchTab(game, s, a, hopRail)
|
||||
GameTab.SAVES -> if (game != null && prefix != null) SavesTab(game, prefix, a)
|
||||
GameTab.INSTALL -> InstallTab(game, installed, item, store)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun GameHero(
|
||||
title: String, item: CatalogItem?, installed: InstalledStoreGame?, game: Library.SteamGame?, modifier: Modifier,
|
||||
corner: @Composable BoxScope.() -> Unit, scores: GameScores?, content: @Composable ColumnScope.() -> Unit,
|
||||
) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
Box(modifier.clip(Shape16).background(artBrush(hueOf(title)))) {
|
||||
val wide: Any? = game?.hero ?: item?.imageUrl ?: installed?.sidecar?.hero ?: installed?.sidecar?.cover
|
||||
if (wide != null) {
|
||||
// The card it came from keeps its own bitmap under the hero until the wide art is decoded.
|
||||
val request = if (wide is String) cardArtRequest(wide, item?.tallImageUrl) else wide
|
||||
AsyncImage(model = request, contentDescription = null, contentScale = ContentScale.Crop, modifier = Modifier.matchParentSize())
|
||||
} else game?.art?.let { art ->
|
||||
AsyncImage(
|
||||
model = art, contentDescription = null, contentScale = ContentScale.Crop,
|
||||
modifier = Modifier.matchParentSize().blur(24.dp).graphicsLayer { scaleX = 1.3f; scaleY = 1.3f },
|
||||
)
|
||||
}
|
||||
Spacer(Modifier.matchParentSize().background(Brush.horizontalGradient(0f to colors.background.copy(alpha = 0.94f), 0.55f to colors.background.copy(alpha = 0.58f), 1f to Color.Transparent)))
|
||||
if (scores != null) {
|
||||
Spacer(Modifier.matchParentSize().background(Brush.horizontalGradient(0.45f to Color.Transparent, 1f to colors.background.copy(alpha = 0.75f))))
|
||||
HeroScores(scores, Modifier.align(Alignment.BottomEnd).padding(end = 16.dp, bottom = 18.dp))
|
||||
}
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(6.dp),
|
||||
modifier = Modifier.align(Alignment.BottomStart).padding(horizontal = 22.dp, vertical = 18.dp),
|
||||
content = content,
|
||||
)
|
||||
Box(Modifier.align(Alignment.TopEnd).padding(12.dp), content = corner)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun HeroEyebrow(source: String, game: Library.SteamGame?, item: CatalogItem?, installed: InstalledStoreGame?, downloadAt: String?) {
|
||||
val ctx = LocalContext.current
|
||||
val pal = LocalPalette.current
|
||||
val folder = installed?.folder ?: game?.gameFiles
|
||||
val passName = item?.includedWith.orEmpty()
|
||||
val state = when {
|
||||
installed != null -> listOf(stringResource(R.string.stores_eyebrow_installed), StoreInstallRoot.labelFor(ctx, installed.folder))
|
||||
game?.library == Library.XBOX_CLOUD -> listOf(libraryLabel(game))
|
||||
game != null -> listOf(stringResource(R.string.stores_eyebrow_installed), libraryLabel(game))
|
||||
!downloadAt.isNullOrBlank() -> listOf(stringResource(R.string.stores_eyebrow_library), downloadAt)
|
||||
item?.owned == true -> listOf(stringResource(R.string.stores_eyebrow_library))
|
||||
item?.subscription == true -> listOf(passName.ifBlank { stringResource(R.string.stores_game_pass) })
|
||||
passName.isNotBlank() -> listOf(stringResource(R.string.stores_eyebrow_pass, passName))
|
||||
item?.accessible == true -> listOf(stringResource(R.string.stores_eyebrow_library))
|
||||
else -> listOf(stringResource(R.string.stores_eyebrow_store))
|
||||
}
|
||||
val size = if (folder != null && (installed != null || game != null)) diskSize(installed, folder) else (item?.sizeBytes ?: 0L).takeIf { it > 0 }
|
||||
val line = (state + listOfNotNull(size?.let { formatBytes(it) })).filter { it.isNotBlank() }.joinToString(" · ")
|
||||
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
SourceChip(source)
|
||||
Text(line.uppercase(), fontSize = 12.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 1.2.sp, color = pal.signal, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun GameTitle(title: String, logo: Any?, titleSize: TextUnit) {
|
||||
var failed by remember(logo) { mutableStateOf(false) }
|
||||
if (logo != null && !failed) AsyncImage(
|
||||
model = logo, contentDescription = title, contentScale = ContentScale.Fit, alignment = Alignment.CenterStart,
|
||||
onError = { failed = true },
|
||||
modifier = Modifier.padding(vertical = 4.dp).height((titleSize.value * 2.2f).dp).widthIn(max = (titleSize.value * 9f).dp).testTag("game-logo"),
|
||||
) else Text(
|
||||
title, fontSize = titleSize, lineHeight = titleSize * 1.12f, fontWeight = FontWeight.Black,
|
||||
color = MaterialTheme.colorScheme.onBackground, maxLines = 2, overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun GameActions(
|
||||
store: Store?, id: String?, game: Library.SteamGame?, item: CatalogItem?, installed: InstalledStoreGame?,
|
||||
s: FrontEndState, a: FrontEndActions, leadOn: Modifier,
|
||||
) {
|
||||
val ctx = LocalContext.current
|
||||
val storeKey = if (store != null && id != null) "${store.id}:$id" else null
|
||||
val rawDownload = storeKey?.let { StoresState.download(it) }
|
||||
val download = rawDownload?.takeIf { it.isActive }
|
||||
val failed = rawDownload?.takeIf { it.state == DownloadState.FAILED }
|
||||
Actions {
|
||||
when {
|
||||
s.shortcutPicker && game != null -> {
|
||||
PrimaryButton(stringResource(R.string.game_shortcut_choose), enabled = !s.busy, main = true, icon = Icons.Filled.PlayArrow, modifier = leadOn) { a.onSteamGame(game) }
|
||||
FileButtons(game, a)
|
||||
}
|
||||
game?.library == Library.XBOX_CLOUD -> {
|
||||
val cloudId = game.storeId.orEmpty()
|
||||
XboxStreamButton(cloudId, game.name, main = true, modifier = leadOn)
|
||||
if (download != null) ActionChip(downloadLabel(download), ok = false)
|
||||
else if (item?.installable == true) SecondaryButton(
|
||||
if (item.sizeBytes > 0) stringResource(R.string.stores_install_size, formatBytes(item.sizeBytes)) else stringResource(R.string.stores_install),
|
||||
) { StoresState.requestInstall(ctx, item) }
|
||||
XboxLibraryButton(cloudId, item)
|
||||
}
|
||||
game != null || installed != null -> {
|
||||
val gone = storeKey?.let { StoresState.uninstalling[it] }
|
||||
val xboxBusy = store == Store.XBOX && id != null && XboxContent.busy(id)
|
||||
PrimaryButton(
|
||||
stringResource(R.string.stores_play), enabled = !s.busy && gone == null && download == null && !xboxBusy,
|
||||
main = true, icon = Icons.Filled.PlayArrow, modifier = leadOn,
|
||||
) {
|
||||
if (game != null) a.onSteamGame(game) else if (store != null && id != null) launchStoreGame(ctx, store, id, s, a)
|
||||
}
|
||||
if ((game?.source ?: store?.id) != Library.SOURCE_STEAM) ActionChip(stringResource(R.string.stores_in_steam), ok = true)
|
||||
if (game != null) {
|
||||
FileButtons(game, a)
|
||||
GameShortcutMenu(game, a)
|
||||
EditArtButton(game)
|
||||
}
|
||||
if (store == Store.XBOX && id != null) XboxInstalledStream(id, game?.name ?: item?.title.orEmpty(), item)
|
||||
if (store == Store.XBOX && installed != null && id != null) {
|
||||
SecondaryButton(stringResource(R.string.stores_xbox_update), enabled = download == null && !XboxRuntime.isActive(id)) {
|
||||
runCatching { XboxBackend.update(ctx, installed) }
|
||||
.onFailure { StoresState.problems[Store.XBOX] = it.message ?: ctx.getString(R.string.stores_xbox_close_first) }
|
||||
}
|
||||
SecondaryButton(stringResource(R.string.stores_xbox_manage), enabled = download == null) { XboxContent.manage(ctx, installed) }
|
||||
}
|
||||
if (store == Store.BATTLENET) SecondaryButton(stringResource(R.string.bnet_open)) { a.onBattleNet() }
|
||||
}
|
||||
download != null -> {
|
||||
ActionChip(downloadLabel(download), ok = false)
|
||||
if (download.state != DownloadState.PAUSED) SecondaryButton(stringResource(R.string.stores_dl_pause), modifier = leadOn) { DownloadQueue.pause(download.key) }
|
||||
else PrimaryButton(stringResource(R.string.stores_dl_resume), main = true, modifier = leadOn) { DownloadQueue.resume(ctx, download.key) }
|
||||
ConfirmButton(stringResource(R.string.stores_dl_cancel), stringResource(R.string.stores_dl_cancel_confirm)) { DownloadQueue.cancel(ctx, download.key) }
|
||||
}
|
||||
failed != null -> {
|
||||
ActionChip(stringResource(R.string.stores_dl_failed), ok = false)
|
||||
PrimaryButton(stringResource(R.string.stores_dl_resume), main = true, modifier = leadOn) {
|
||||
if (item != null) StoresState.requestInstall(ctx, item) else DownloadQueue.retry(ctx, failed.key)
|
||||
}
|
||||
ConfirmButton(stringResource(R.string.stores_dl_clear), stringResource(R.string.stores_dl_cancel_confirm), compact = true) { DownloadQueue.clear(ctx, failed.key) }
|
||||
}
|
||||
store == Store.BATTLENET && item != null -> InstallButton(stringResource(R.string.stores_install), leadOn) { StoresState.requestInstall(ctx, item) }
|
||||
store == Store.XBOX && item != null && !item.xboxPc && item.xboxCloud -> {
|
||||
XboxStreamButton(item.id, item.title, main = true, modifier = leadOn)
|
||||
XboxLibraryButton(item.id, item)
|
||||
}
|
||||
item?.installable == true && StoresState.isUnfinished(item) -> {
|
||||
InstallButton(stringResource(R.string.stores_resume_install), leadOn) { StoresState.requestInstall(ctx, item) }
|
||||
ConfirmButton(stringResource(R.string.stores_dl_clear), stringResource(R.string.stores_dl_cancel_confirm), compact = true) { StoresState.clearUnfinished(ctx, item) }
|
||||
}
|
||||
item?.installable == true -> {
|
||||
InstallButton(
|
||||
if (item.sizeBytes > 0) stringResource(R.string.stores_install_size, formatBytes(item.sizeBytes)) else stringResource(R.string.stores_install),
|
||||
leadOn,
|
||||
) { StoresState.requestInstall(ctx, item) }
|
||||
if (store == Store.XBOX && item.xboxCloud) {
|
||||
XboxStreamButton(item.id, item.title)
|
||||
XboxLibraryButton(item.id, item)
|
||||
}
|
||||
if (!item.accessible) SecondaryButton(buyLabel(item)) { openStoreUrl(ctx, item) }
|
||||
}
|
||||
item != null && item.store == Store.ITCH && item.isFree -> {
|
||||
InstallButton(stringResource(R.string.stores_install), leadOn) { StoresState.requestInstall(ctx, item) }
|
||||
SecondaryButton(stringResource(R.string.stores_view_on, item.store.shortLabel)) { openStoreUrl(ctx, item) }
|
||||
}
|
||||
item != null && item.isFree -> PrimaryButton(stringResource(R.string.stores_get_free), main = true, modifier = leadOn) { openStoreUrl(ctx, item) }
|
||||
item != null -> PrimaryButton(buyLabel(item), main = true, modifier = leadOn) { openStoreUrl(ctx, item) }
|
||||
}
|
||||
BusyChip(s)
|
||||
}
|
||||
}
|
||||
|
||||
/** Xbox Cloud Gaming rows the user added to the Library, for games not installed here. */
|
||||
@Composable
|
||||
internal fun rememberXboxCloudRows(s: FrontEndState): List<Library.SteamGame> {
|
||||
val ctx = LocalContext.current
|
||||
LaunchedEffect(Unit) { XboxCloudGames.load(ctx) }
|
||||
if (s.shortcutPicker) return emptyList()
|
||||
val added = XboxCloudGames.entries.toList()
|
||||
return remember(added, s.steamGames) {
|
||||
val installedXbox = s.steamGames.filter { it.source == Store.XBOX.id }.mapNotNull { it.storeId }.toSet()
|
||||
XboxCloudGames.rows(ctx, installedXbox)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun XboxStreamButton(id: String, title: String, main: Boolean = false, modifier: Modifier = Modifier) {
|
||||
val ctx = LocalContext.current
|
||||
LaunchedEffect(Unit) { XboxCloudGames.prefetch(ctx) }
|
||||
val label = stringResource(R.string.game_stream)
|
||||
if (main) PrimaryButton(label, main = true, icon = Icons.Filled.PlayArrow, modifier = modifier) { XboxCloudGames.stream(ctx, id, title) }
|
||||
else SecondaryButton(label, modifier = modifier) { XboxCloudGames.stream(ctx, id, title) }
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun XboxInstalledStream(id: String, title: String, item: CatalogItem?) {
|
||||
val ctx = LocalContext.current
|
||||
val streams by produceState(item?.xboxCloud == true, id) {
|
||||
if (!value) value = withContext(Dispatchers.IO) { XboxCloudGames.streams(ctx, id) }
|
||||
}
|
||||
if (streams) XboxStreamButton(id, title)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun XboxLibraryButton(id: String, item: CatalogItem?) {
|
||||
val ctx = LocalContext.current
|
||||
LaunchedEffect(Unit) { XboxCloudGames.load(ctx) }
|
||||
// Add and Remove replace each other; the controller focus moves to the new button instead of getting lost.
|
||||
val slot = remember { FocusRequester() }
|
||||
val inputMode = androidx.compose.ui.platform.LocalInputModeManager.current
|
||||
val scope = rememberCoroutineScope()
|
||||
fun refocus() { if (inputMode.inputMode == androidx.compose.ui.input.InputMode.Keyboard) scope.launch { focusSoon { slot } } }
|
||||
if (XboxCloudGames.isAdded(id)) {
|
||||
ActionChip(stringResource(R.string.library_in), ok = true)
|
||||
SecondaryButton(stringResource(R.string.library_remove), compact = true, modifier = Modifier.focusRequester(slot)) { XboxCloudGames.remove(ctx, id); refocus() }
|
||||
} else if (item != null) SecondaryButton(stringResource(R.string.library_add), modifier = Modifier.focusRequester(slot)) { XboxCloudGames.add(ctx, item); refocus() }
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun buyLabel(item: CatalogItem): String = when {
|
||||
item.isFree -> stringResource(R.string.stores_get_free)
|
||||
item.hasPrice && item.finalPrice.isNotBlank() -> stringResource(R.string.stores_buy_price, item.finalPrice)
|
||||
else -> stringResource(R.string.stores_view_on, item.store.shortLabel)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun FileButtons(game: Library.SteamGame, a: FrontEndActions) {
|
||||
game.gameFiles?.takeIf { it.isDirectory }?.let { dir -> SecondaryButton(stringResource(R.string.games_files), compact = true) { a.onBrowseFiles(dir) } }
|
||||
game.protonPrefix?.takeIf { it.isDirectory }?.let { dir -> SecondaryButton(stringResource(R.string.games_prefix), compact = true) { a.onBrowseFiles(dir) } }
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun GameShortcutMenu(g: Library.SteamGame, a: FrontEndActions) {
|
||||
var open by remember(g.gameId) { mutableStateOf(false) }
|
||||
Box {
|
||||
SecondaryButton(stringResource(R.string.game_shortcut), compact = true) { open = !open }
|
||||
AnchoredMenu(open, onDismiss = { open = false }, title = stringResource(R.string.game_shortcut)) { first ->
|
||||
MenuItem(stringResource(R.string.game_shortcut_add), checked = false, focusRequester = first) { open = false; a.onGameShortcut(g) }
|
||||
MenuItem(stringResource(R.string.game_file_export), checked = false) { open = false; a.onExportGameFile(g) }
|
||||
MenuItem(stringResource(R.string.game_link_copy), checked = false) { open = false; a.onCopyGameLink(g) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** The pencil opens the editor each kind of game always had: the shortcut editor for added games, art for the rest. */
|
||||
@Composable
|
||||
private fun EditArtButton(g: Library.SteamGame) {
|
||||
val ctx = LocalContext.current
|
||||
val folder = g.gameFiles
|
||||
val open: (() -> Unit)? = when {
|
||||
g.library == Library.ADDED && g.source == Library.ADDED && folder != null -> {
|
||||
{ GamesDialogState.editing = EditRequest(folder.path, openTarget = false, fromSummary = false, preview = EditPreview.of(ctx, g, folder.path)) }
|
||||
}
|
||||
g.library != Library.ADDED && g.source == Library.SOURCE_STEAM -> { { GamesDialogState.steamArt = g } }
|
||||
g.library == Library.ADDED && g.source != Library.ADDED && folder != null -> { { GamesDialogState.storeArt = g } }
|
||||
else -> null
|
||||
}
|
||||
if (open != null) IconAction(Icons.Outlined.Edit, stringResource(R.string.common_edit), "game:edit", onClick = open)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun IconAction(icon: androidx.compose.ui.graphics.vector.ImageVector, label: String, id: String, danger: Boolean = false, enabled: Boolean = true, onClick: () -> Unit) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val pal = LocalPalette.current
|
||||
val src = remember { MutableInteractionSource() }
|
||||
val hot = rememberHot(src) && enabled
|
||||
val accent = if (danger) colors.error else pal.signal
|
||||
Box(
|
||||
contentAlignment = Alignment.Center,
|
||||
modifier = Modifier.paneItem(id).downToFirstTile().size(44.dp).clip(Shape12)
|
||||
.background(if (hot) accent.copy(alpha = if (danger) 0.22f else 0.14f) else if (danger) Color.Black.copy(alpha = 0.34f) else Color.White.copy(alpha = 0.03f))
|
||||
.glideBorder(hot, Shape12, accent, pal.line2)
|
||||
.alpha(if (enabled) 1f else 0.45f)
|
||||
.hoverable(src).clickable(interactionSource = src, indication = LocalIndication.current, role = androidx.compose.ui.semantics.Role.Button, enabled = enabled, onClick = onClick)
|
||||
.controllerConfirm(enabled = enabled, onClick = onClick)
|
||||
.semantics { contentDescription = label },
|
||||
) {
|
||||
Icon(icon, contentDescription = null, tint = if (danger && hot) colors.error else if (danger) Color.White else colors.onBackground, modifier = Modifier.size(18.dp))
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun RemoveButton(title: String, game: Library.SteamGame?, installed: InstalledStoreGame?, a: FrontEndActions) {
|
||||
val ctx = LocalContext.current
|
||||
val colors = MaterialTheme.colorScheme
|
||||
if ((installed?.sidecar?.store?.id ?: game?.source) == Store.BATTLENET.id) return
|
||||
if (installed != null) {
|
||||
val key = installed.key
|
||||
val gone = StoresState.uninstalling[key]
|
||||
if (gone != null) {
|
||||
val uninstalling = stringResource(R.string.stores_uninstalling)
|
||||
Box(contentAlignment = Alignment.Center, modifier = Modifier.size(44.dp).clip(Shape12).background(Color.Black.copy(alpha = 0.34f)).semantics { contentDescription = uninstalling }) {
|
||||
if (gone > 0f) CircularProgressIndicator(progress = { gone }, strokeWidth = 2.dp, color = colors.error, trackColor = colors.error.copy(alpha = 0.22f), modifier = Modifier.size(20.dp))
|
||||
else CircularProgressIndicator(strokeWidth = 2.dp, color = colors.error, modifier = Modifier.size(20.dp))
|
||||
}
|
||||
return
|
||||
}
|
||||
val heading = stringResource(R.string.stores_uninstall_title, title)
|
||||
val size = StoreSizes.onDisk[key]
|
||||
val body = if (size != null && size > 0) stringResource(R.string.stores_uninstall_body_size, formatBytes(size)) else stringResource(R.string.stores_uninstall_body)
|
||||
val keep = stringResource(R.string.stores_notification_keep)
|
||||
val remove = stringResource(R.string.stores_uninstall)
|
||||
val busy = StoresState.download(key)?.isActive == true || (installed.sidecar.store == Store.XBOX && XboxContent.busy(installed.sidecar.id))
|
||||
val placed = remember { arrayOfNulls<androidx.compose.ui.layout.LayoutCoordinates>(1) }
|
||||
Box(Modifier.onGloballyPositioned { placed[0] = it }) {
|
||||
IconAction(Icons.Outlined.Delete, remove, "game:remove", danger = true, enabled = !busy) {
|
||||
val at = placed[0]?.takeIf { it.isAttached }?.boundsInRoot() ?: return@IconAction
|
||||
var confirmed = false
|
||||
Steps.ask(StepAsk(anchor = at, side = StepSide.Left, accent = colors.error, items = 3, pillCorner = 12.dp, maxWidth = 340.dp,
|
||||
onDismiss = { if (confirmed) StoresState.uninstall(ctx, installed) { StoresState.refresh(ctx); a.onLibraryChanged() } },
|
||||
handle = { Icon(Icons.Outlined.Delete, null, tint = colors.error, modifier = Modifier.size(18.dp)) }) {
|
||||
StepTitle(heading)
|
||||
Text(body, fontSize = 13.sp, lineHeight = 18.sp, color = colors.onSurfaceVariant, modifier = Modifier.stepItem(1).padding(start = 4.dp, bottom = 12.dp))
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(8.dp, Alignment.End), modifier = Modifier.fillMaxWidth().stepItem(2)) {
|
||||
StepChoice(keep, enabled = open, modifier = Modifier.focusRequester(first)) { Steps.fold() }
|
||||
StepChoice(remove, danger = true, enabled = open) { confirmed = true; Steps.fold() }
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
val g = game ?: return
|
||||
val kind = GameRemoval.kind(g)
|
||||
if (kind == GameRemoval.Kind.LAUNCHER || g.gameFiles?.isDirectory != true) return
|
||||
var asking by remember(g.gameId) { mutableStateOf(false) }
|
||||
val shortcut = kind == GameRemoval.Kind.SHORTCUT
|
||||
val label = stringResource(if (shortcut) R.string.edit_remove else R.string.common_uninstall)
|
||||
IconAction(Icons.Outlined.Delete, label, "game:remove", danger = true) { asking = true }
|
||||
if (asking) ConfirmDialog(
|
||||
title = if (shortcut) stringResource(R.string.games_remove_title, g.name) else stringResource(R.string.stores_uninstall_title, g.name),
|
||||
text = when {
|
||||
shortcut -> stringResource(R.string.games_remove_body)
|
||||
g.library == Library.ADDED -> stringResource(R.string.stores_uninstall_body)
|
||||
else -> stringResource(R.string.games_uninstall_body)
|
||||
},
|
||||
confirm = label,
|
||||
onConfirm = { a.onGameRemoved(g) },
|
||||
onDismiss = { asking = false },
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun InstallButton(label: String, modifier: Modifier = Modifier, onInstall: () -> Unit) {
|
||||
val placed = remember { arrayOfNulls<androidx.compose.ui.layout.LayoutCoordinates>(1) }
|
||||
Box(Modifier.onGloballyPositioned { placed[0] = it }) {
|
||||
PrimaryButton(label, main = true, modifier = modifier) {
|
||||
StoresMotion.markInstall(placed[0]?.takeIf { it.isAttached }?.boundsInRoot(), label)
|
||||
onInstall()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun AboutTab(developer: String, publisher: String, releaseDate: String, description: String, scores: GameScores?, stacked: Boolean) {
|
||||
Column(verticalArrangement = Arrangement.spacedBy(10.dp), modifier = Modifier.fillMaxWidth().tabPanel()) {
|
||||
if (scores != null) Box(Modifier.readable()) { StoreGameFacts(developer, publisher, releaseDate, scores, scoresInHero = !stacked) }
|
||||
else if (developer.isNotBlank() || publisher.isNotBlank() || releaseDate.isNotBlank()) {
|
||||
val parts = listOf(developer, publisher, com.droiddeck.launcher.stores.GameFacts.releaseLabel(releaseDate).orEmpty()).filter { it.isNotBlank() }.distinct()
|
||||
Text(parts.joinToString(" · "), fontSize = 13.sp, color = MaterialTheme.colorScheme.onSurfaceVariant, modifier = Modifier.readable())
|
||||
}
|
||||
if (description.isNotBlank()) {
|
||||
val floor = LocalDetailFloor.current
|
||||
val density = LocalDensity.current
|
||||
var room by remember { mutableStateOf(AboutHeight) }
|
||||
val fill = Modifier.onGloballyPositioned { c -> room = maxOf(AboutHeight, with(density) { (floor() - c.positionInRoot().y).toDp() - 14.dp }) }
|
||||
StoreAbout(description, room, Modifier.fillMaxWidth().then(fill))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val AboutHeight = 260.dp
|
||||
|
||||
@Composable
|
||||
internal fun Modifier.tabPanel(): Modifier {
|
||||
val shape = RoundedCornerShape(16.dp)
|
||||
return clip(shape).background(MaterialTheme.colorScheme.surface).border(1.dp, LocalPalette.current.line, shape).padding(horizontal = 16.dp, vertical = 14.dp)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun StoreAbout(text: String, height: Dp, modifier: Modifier = Modifier) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val pal = LocalPalette.current
|
||||
val scroll = rememberScrollState()
|
||||
val scope = rememberCoroutineScope()
|
||||
val src = remember { MutableInteractionSource() }
|
||||
val hot = rememberHot(src)
|
||||
val shape = RoundedCornerShape(12.dp)
|
||||
Box(
|
||||
modifier.heightIn(max = height).clip(shape)
|
||||
.glideBorder(hot, shape, pal.signal, restColor = Color.Transparent)
|
||||
.paneItem("about")
|
||||
.focusable(interactionSource = src)
|
||||
.onPreviewKeyEvent { e ->
|
||||
val step = when (e.nativeKeyEvent.keyCode) {
|
||||
android.view.KeyEvent.KEYCODE_DPAD_DOWN -> if (scroll.value < scroll.maxValue) 120f else return@onPreviewKeyEvent false
|
||||
android.view.KeyEvent.KEYCODE_DPAD_UP -> if (scroll.value > 0) -120f else return@onPreviewKeyEvent false
|
||||
else -> return@onPreviewKeyEvent false
|
||||
}
|
||||
if (e.nativeKeyEvent.action == android.view.KeyEvent.ACTION_DOWN) scope.launch { scroll.animateScrollBy(step) }
|
||||
true
|
||||
},
|
||||
) {
|
||||
Text(text, fontSize = 14.sp, lineHeight = 21.sp, color = colors.onSurfaceVariant, modifier = Modifier.verticalScroll(scroll).padding(horizontal = 4.dp, vertical = 6.dp))
|
||||
if (scroll.value < scroll.maxValue) Box(
|
||||
Modifier.align(Alignment.BottomCenter).fillMaxWidth().height(28.dp)
|
||||
.background(Brush.verticalGradient(listOf(Color.Transparent, colors.surface))),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun LaunchTab(game: Library.SteamGame, s: FrontEndState, a: FrontEndActions, hopRail: String?) {
|
||||
val host = rememberMenuHost()
|
||||
Column(verticalArrangement = Arrangement.spacedBy(12.dp), modifier = Modifier.fillMaxWidth()) {
|
||||
LaunchSettings(s, a, host, game, hopRail ?: GameRef.key(game))
|
||||
val folder = game.gameFiles
|
||||
if (game.library == Library.ADDED && game.source == Library.ADDED && !s.shortcutPicker && folder != null) ShortcutFields(game, folder)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ShortcutFields(game: Library.SteamGame, folder: File) {
|
||||
val ctx = LocalContext.current
|
||||
val preview = remember(game.gameId, game.name, GamesDialogState.editing) { EditPreview.of(ctx, game, folder.path) }
|
||||
fun edit(target: Boolean) { GamesDialogState.editing = EditRequest(folder.path, openTarget = target, fromSummary = false, preview = EditPreview.of(ctx, game, folder.path)) }
|
||||
Column(Modifier.fillMaxWidth().tabPanel(), verticalArrangement = Arrangement.spacedBy(2.dp)) {
|
||||
SectionLabel(stringResource(R.string.game_launch_shortcut))
|
||||
MenuItem(stringResource(R.string.edit_name), checked = false, detail = preview.name) { edit(false) }
|
||||
MenuItem(stringResource(R.string.edit_target), checked = false, detail = preview.exeName ?: "—") { edit(true) }
|
||||
MenuItem(stringResource(R.string.edit_start_in), checked = false, detail = preview.startIn ?: "—") { edit(false) }
|
||||
MenuItem(stringResource(R.string.edit_launch_options), checked = false, detail = preview.launchOptions.ifEmpty { "—" }) { edit(false) }
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SavesTab(g: Library.SteamGame, prefix: File, a: FrontEndActions) {
|
||||
val saves by produceState<List<GameSaves.SaveDir>?>(null, g.gameId) {
|
||||
value = withContext(Dispatchers.IO) { runCatching { GameSaves.locate(prefix, g) }.getOrDefault(emptyList()) }
|
||||
}
|
||||
val found = saves
|
||||
val summary = when {
|
||||
found == null -> stringResource(R.string.games_saves_looking)
|
||||
found.isEmpty() -> stringResource(R.string.games_saves_none)
|
||||
else -> {
|
||||
val mb = found.sumOf { it.bytes } / 1048576.0
|
||||
stringResource(
|
||||
R.string.games_saves_summary,
|
||||
if (found.size == 1) found[0].relPath else stringResource(R.string.games_saves_folders, found.size),
|
||||
found.sumOf { it.files },
|
||||
if (mb < 1) stringResource(R.string.games_kb, (mb * 1024).toInt()) else stringResource(R.string.common_size_mb, mb),
|
||||
)
|
||||
}
|
||||
}
|
||||
Column(Modifier.fillMaxWidth().tabPanel(), verticalArrangement = Arrangement.spacedBy(2.dp)) {
|
||||
Text(summary, fontSize = 13.sp, color = MaterialTheme.colorScheme.onSurfaceVariant, modifier = Modifier.padding(bottom = 6.dp).readable().padding(4.dp))
|
||||
if (Store.byId(g.source).let { it == Store.GOG || it == Store.EPIC }) {
|
||||
SectionLabel(stringResource(R.string.store_cloud_saves))
|
||||
CloudRows(g)
|
||||
SectionLabel(stringResource(R.string.games_saves))
|
||||
}
|
||||
MenuItem(stringResource(R.string.games_import_saves), checked = false) { a.onSaveImport(g) }
|
||||
MenuItem(stringResource(R.string.games_export_gamehub), checked = false) { a.onSaveExport(g, GameSaves.Layout.GAMEHUB) }
|
||||
MenuItem(stringResource(R.string.games_export_winlator), checked = false) { a.onSaveExport(g, GameSaves.Layout.WINLATOR) }
|
||||
found?.firstOrNull()?.let { d ->
|
||||
MenuItem(stringResource(R.string.games_open_save_folder), checked = false, detail = d.relPath) {
|
||||
a.onBrowseFiles(File(prefix, "drive_c/users/steamuser/" + d.relPath))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun CloudRows(g: Library.SteamGame) {
|
||||
val store = Store.byId(g.source)?.takeIf { it != Store.AMAZON } ?: return
|
||||
val id = g.storeId ?: return
|
||||
val context = LocalContext.current.applicationContext
|
||||
var busy by remember(g.gameId) { mutableStateOf<String?>(null) }
|
||||
var tick by remember(g.gameId) { mutableStateOf(0) }
|
||||
val status by produceState<CloudSaves.Status?>(null, g.gameId, tick) {
|
||||
value = withContext(Dispatchers.IO) { runCatching { CloudSaves.status(context, store, id) }.getOrNull() }
|
||||
}
|
||||
val folder = g.gameFiles
|
||||
var enabled by remember(g.gameId) { mutableStateOf(folder?.let { StoreGameSidecar.read(it)?.cloud } ?: true) }
|
||||
val st = status
|
||||
val supported = st?.supported ?: true
|
||||
val conflict = st != null && st.conflicts.isNotEmpty()
|
||||
fun sync(up: Boolean, force: Boolean = false) {
|
||||
if (busy != null) return
|
||||
busy = if (up) "up" else "down"
|
||||
Thread({
|
||||
val r = if (up) CloudSaves.upload(context, store, id, force) else CloudSaves.download(context, store, id, force)
|
||||
StoresState.post { busy = null; tick++; android.widget.Toast.makeText(context, cloudMessage(context, r), android.widget.Toast.LENGTH_SHORT).show() }
|
||||
}, "cloud-manual").start()
|
||||
}
|
||||
MenuItem(stringResource(R.string.store_cloud_saves), checked = enabled && supported, enabled = supported,
|
||||
detail = if (!supported) stringResource(R.string.cloud_none) else null) {
|
||||
val f = folder ?: return@MenuItem
|
||||
val next = !enabled
|
||||
Thread({
|
||||
val written = runCatching { StoreGameSidecar.updateCloud(f, next) }.getOrNull()
|
||||
StoresState.post { enabled = written?.cloud ?: enabled }
|
||||
}, "cloud-switch").start()
|
||||
}
|
||||
val ready = st != null && supported && enabled && busy == null
|
||||
val pending = stringResource(R.string.cloud_pending)
|
||||
val summary = when {
|
||||
st == null || busy != null -> pending
|
||||
!supported -> stringResource(R.string.cloud_none)
|
||||
conflict -> stringResource(R.string.cloud_conflict_files, st.conflicts.size)
|
||||
st.lastSync > 0 -> stringResource(R.string.cloud_last_sync, android.text.format.DateUtils.getRelativeTimeSpanString(st.lastSync).toString())
|
||||
else -> stringResource(R.string.cloud_never)
|
||||
}
|
||||
MenuItem(stringResource(if (conflict) R.string.cloud_keep_local else R.string.cloud_upload), checked = false, enabled = ready, detail = summary) { sync(up = true, force = conflict) }
|
||||
MenuItem(stringResource(if (conflict) R.string.cloud_keep_cloud else R.string.cloud_download), checked = false, enabled = ready, detail = if (st == null || busy != null) pending else null) { sync(up = false, force = conflict) }
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun InstallTab(game: Library.SteamGame?, installed: InstalledStoreGame?, item: CatalogItem?, store: Store?) {
|
||||
val ctx = LocalContext.current
|
||||
val folder = installed?.folder ?: game?.gameFiles
|
||||
val sidecar = installed?.sidecar
|
||||
val size = folder?.let { diskSize(installed, it) }
|
||||
val rows = buildList {
|
||||
add(stringResource(R.string.game_install_location) to when {
|
||||
installed != null -> StoreInstallRoot.labelFor(ctx, installed.folder)
|
||||
game != null -> libraryLabel(game).ifBlank { stringResource(R.string.games_internal) }
|
||||
else -> ""
|
||||
})
|
||||
if (folder != null) {
|
||||
add(stringResource(R.string.game_install_folder) to folder.path)
|
||||
add(stringResource(R.string.game_install_size) to (size?.let { formatBytes(it) } ?: stringResource(R.string.cloud_pending)))
|
||||
}
|
||||
sidecar?.extra?.get(StoreLanguage.EXTRA)?.takeIf { it.isNotBlank() }?.let { add(stringResource(R.string.stores_install_language) to StoreLanguage.displayName(it)) }
|
||||
sidecar?.installVersion?.takeIf { it.isNotBlank() }?.let { add(stringResource(R.string.game_install_version) to it) }
|
||||
sidecar?.installedAt?.takeIf { it > 0 }?.let {
|
||||
add(stringResource(R.string.game_install_date) to java.text.DateFormat.getDateInstance(java.text.DateFormat.MEDIUM).format(java.util.Date(it)))
|
||||
}
|
||||
if (game != null) add(stringResource(R.string.game_install_played) to (playedSpan(game.lastPlayed)?.replaceFirstChar { it.uppercase() } ?: stringResource(R.string.games_never_played)))
|
||||
if (store == Store.XBOX) {
|
||||
val access = sidecar?.extra?.get("access") ?: if (item?.subscription == true) "gamepass" else if (item?.owned == true) "owned" else null
|
||||
if (access != null) add(stringResource(R.string.game_install_access) to stringResource(if (access == "gamepass") R.string.stores_game_pass else R.string.game_install_access_owned))
|
||||
}
|
||||
}.filter { it.second.isNotBlank() }
|
||||
Column(Modifier.fillMaxWidth().tabPanel(), verticalArrangement = Arrangement.spacedBy(2.dp)) {
|
||||
for ((label, value) in rows) FactRow(label, value)
|
||||
}
|
||||
}
|
||||
|
||||
/** Text a controller has to land on to bring it into view: focusable, with the focus ring. */
|
||||
@Composable
|
||||
internal fun Modifier.readable(): Modifier {
|
||||
val pal = LocalPalette.current
|
||||
val src = remember { MutableInteractionSource() }
|
||||
val hot = rememberHot(src)
|
||||
val shape = RoundedCornerShape(8.dp)
|
||||
return clip(shape).glideBorder(hot, shape, pal.signal, restColor = Color.Transparent).focusable(interactionSource = src)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun FactRow(label: String, value: String) {
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.spacedBy(16.dp),
|
||||
modifier = Modifier.fillMaxWidth().readable().padding(horizontal = 8.dp, vertical = 7.dp),
|
||||
) {
|
||||
Text(label, fontSize = 13.sp, color = MaterialTheme.colorScheme.onSurfaceVariant, modifier = Modifier.width(150.dp))
|
||||
Text(value, fontSize = 13.sp, fontWeight = FontWeight.SemiBold, color = MaterialTheme.colorScheme.onBackground, modifier = Modifier.weight(1f), maxLines = 2, overflow = TextOverflow.Ellipsis)
|
||||
}
|
||||
}
|
||||
|
||||
/** Store installs are measured by [StoreSizes]; Steam and added games by walking their folder once. */
|
||||
@Composable
|
||||
internal fun diskSize(installed: InstalledStoreGame?, folder: File): Long? {
|
||||
val ctx = LocalContext.current
|
||||
if (installed != null) {
|
||||
LaunchedEffect(installed.key) { StoreSizes.requestDisk(ctx, installed.key, installed) }
|
||||
return StoreSizes.onDisk[installed.key]
|
||||
}
|
||||
LaunchedEffect(folder.path) { FolderSizes.request(folder) }
|
||||
return FolderSizes.known[folder.path]
|
||||
}
|
||||
|
||||
internal object FolderSizes {
|
||||
val known = androidx.compose.runtime.mutableStateMapOf<String, Long>()
|
||||
private val asked = java.util.Collections.synchronizedSet(HashSet<String>())
|
||||
|
||||
fun request(folder: File) {
|
||||
if (!asked.add(folder.path)) return
|
||||
Thread({
|
||||
var total = 0L
|
||||
val walked = runCatching {
|
||||
java.nio.file.Files.walkFileTree(folder.toPath(), object : java.nio.file.SimpleFileVisitor<java.nio.file.Path>() {
|
||||
override fun visitFile(file: java.nio.file.Path, attrs: java.nio.file.attribute.BasicFileAttributes): java.nio.file.FileVisitResult {
|
||||
if (attrs.isRegularFile) total += attrs.size()
|
||||
return java.nio.file.FileVisitResult.CONTINUE
|
||||
}
|
||||
override fun visitFileFailed(file: java.nio.file.Path, exc: java.io.IOException): java.nio.file.FileVisitResult = java.nio.file.FileVisitResult.CONTINUE
|
||||
})
|
||||
}.isSuccess
|
||||
if (walked) StoresState.post { known[folder.path] = total } else asked.remove(folder.path)
|
||||
}, "folder-size").start()
|
||||
}
|
||||
}
|
||||
@@ -101,7 +101,8 @@ internal fun GameEnvironmentEditor(byPad: Boolean, initialScope: String = "", on
|
||||
LaunchedEffect(Unit) {
|
||||
runCatching {
|
||||
withContext(Dispatchers.IO) {
|
||||
GameEnvironmentStore.read(context) to Library.steamGames(context).map { it.appId.toString() to it.name }
|
||||
GameEnvironmentStore.read(context) to Library.steamGames(context).map { it.appId.toString() to it.name } +
|
||||
listOfNotNull(com.droiddeck.launcher.runtime.BattleNet.profile(context))
|
||||
}
|
||||
}.onSuccess { (settings, installed) -> config = settings; games = installed }
|
||||
.onFailure { error = true }
|
||||
|
||||
@@ -23,6 +23,7 @@ import androidx.compose.ui.platform.LocalClipboardManager
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.text.AnnotatedString
|
||||
import com.droiddeck.launcher.gpu.DeviceInfo
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
@@ -128,6 +129,8 @@ class GpuDriversState(
|
||||
val runtime: DriverSlot = DriverSlot(),
|
||||
val canRestart: Boolean = true,
|
||||
val checkedAt: Long = 0L,
|
||||
val tpUbwcMode: String? = null,
|
||||
val tpUbwcRestartRequired: Boolean = false,
|
||||
) {
|
||||
val activePair: PairRow? get() = pairs.firstOrNull { it.active }
|
||||
}
|
||||
@@ -147,6 +150,7 @@ class GpuDriversActions(
|
||||
val onRestoreBundled: () -> Unit = {},
|
||||
val onMode: (String) -> Unit = {},
|
||||
val onRestart: () -> Unit = {},
|
||||
val onTpUbwcMode: (String) -> Unit = {},
|
||||
)
|
||||
|
||||
@Composable
|
||||
@@ -259,6 +263,27 @@ internal fun GpuDriversBody(
|
||||
GPU_MODE_PAIR -> PairBody(gpu, actions)
|
||||
else -> MixBody(single, actions, slotFocus, onOpenSlot)
|
||||
}
|
||||
gpu.tpUbwcMode?.let { selected ->
|
||||
var advanced by rememberSaveable { mutableStateOf(false) }
|
||||
SecondaryButton(stringResource(R.string.gpu_advanced) + if (advanced) " ▴" else " ▾", modifier = Modifier.fillMaxWidth()) { advanced = !advanced }
|
||||
AnimatedVisibility(advanced) {
|
||||
Column(verticalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||
ChoiceRow(
|
||||
rememberMenuHost(), "tp-ubwc", stringResource(R.string.gpu_ubwc_title),
|
||||
stringResource(R.string.gpu_ubwc_hint),
|
||||
listOf(
|
||||
SessionPrefs.TP_UBWC_AUTO to stringResource(R.string.common_auto),
|
||||
SessionPrefs.TP_UBWC_ON to stringResource(R.string.widgets_on),
|
||||
SessionPrefs.TP_UBWC_OFF to stringResource(R.string.widgets_off),
|
||||
), selected, onPick = actions.onTpUbwcMode,
|
||||
)
|
||||
if (gpu.tpUbwcRestartRequired) {
|
||||
Text(stringResource(R.string.gpu_ubwc_restart), fontSize = 13.sp, color = AttentionAmber)
|
||||
if (gpu.canRestart) SecondaryButton(stringResource(R.string.gpu_restart_now), onClick = actions.onRestart)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import androidx.compose.foundation.LocalIndication
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.horizontalScroll
|
||||
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.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.selection.selectable
|
||||
import androidx.compose.foundation.selection.selectableGroup
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.LinearProgressIndicator
|
||||
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
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.Role
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.stores.itch.ItchBrowse
|
||||
import com.droiddeck.launcher.stores.itch.ItchBrowseState
|
||||
|
||||
@Composable
|
||||
internal fun ItchBrowseBar() {
|
||||
val ctx = LocalContext.current
|
||||
val query = ItchBrowseState.query
|
||||
var picking by remember { mutableStateOf(false) }
|
||||
Column(Modifier.fillMaxWidth().padding(top = 6.dp, bottom = 8.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||
ChipRow {
|
||||
for (sort in ItchBrowse.sorts) BrowseChip(sortLabel(sort), query.sort == sort) { ItchBrowseState.choose(ctx, query.copy(sort = sort)) }
|
||||
}
|
||||
ChipRow {
|
||||
for (price in ItchBrowse.prices) BrowseChip(priceLabel(price), query.price == price) { ItchBrowseState.choose(ctx, query.copy(price = price)) }
|
||||
}
|
||||
ChipRow {
|
||||
BrowseChip(stringResource(R.string.stores_itch_platform_any), query.platforms.isEmpty()) { ItchBrowseState.choose(ctx, query.copy(platforms = emptySet())) }
|
||||
for (platform in ItchBrowse.platformNames) {
|
||||
val on = platform in query.platforms
|
||||
BrowseChip(platformLabel(platform), on) { ItchBrowseState.choose(ctx, query.copy(platforms = if (on) query.platforms - platform else query.platforms + platform)) }
|
||||
}
|
||||
}
|
||||
ChipRow {
|
||||
for (tag in query.tags) BrowseChip("$tag ✕", true) { ItchBrowseState.choose(ctx, query.copy(tags = query.tags - tag)) }
|
||||
BrowseChip(stringResource(R.string.stores_itch_tag_add), false) { picking = true }
|
||||
}
|
||||
}
|
||||
if (picking) TextEntryDialog(
|
||||
stringResource(R.string.stores_itch_tag_title), "", number = false, confirm = stringResource(R.string.common_ok),
|
||||
onSubmit = { value -> ItchBrowse.tagSlug(value).takeIf { it.isNotEmpty() }?.let { ItchBrowseState.choose(ctx, query.copy(tags = (query.tags + it).distinct())) } },
|
||||
onDismiss = { picking = false }, id = "itch-tag",
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun ItchLoadMore() {
|
||||
val ctx = LocalContext.current
|
||||
val count = ItchBrowseState.items.size
|
||||
LaunchedEffect(Unit) { ItchBrowseState.more(ctx) }
|
||||
if (ItchBrowseState.loading) LinearProgressIndicator(Modifier.fillMaxWidth().padding(vertical = 12.dp))
|
||||
else if (ItchBrowseState.failed) Box(Modifier.fillMaxWidth().padding(vertical = 8.dp), contentAlignment = Alignment.Center) {
|
||||
BrowseChip(stringResource(R.string.stores_dl_retry), false) { ItchBrowseState.more(ctx, retry = true) }
|
||||
}
|
||||
else if (!ItchBrowseState.ended && count > 0) Box(Modifier.fillMaxWidth().padding(vertical = 8.dp), contentAlignment = Alignment.Center) {
|
||||
BrowseChip(stringResource(R.string.stores_itch_load_more), false) { ItchBrowseState.more(ctx) }
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ChipRow(content: @Composable () -> Unit) {
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.spacedBy(6.dp), verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier.fillMaxWidth().horizontalScroll(rememberScrollState()).selectableGroup(),
|
||||
) { content() }
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun BrowseChip(label: String, selected: Boolean, onClick: () -> Unit) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val pal = LocalPalette.current
|
||||
val shape = RoundedCornerShape(8.dp)
|
||||
val src = remember { MutableInteractionSource() }
|
||||
val hot = rememberHot(src)
|
||||
Text(
|
||||
label, fontSize = 13.sp, fontWeight = FontWeight.SemiBold, maxLines = 1,
|
||||
color = if (selected) pal.onSignal else if (hot) colors.onBackground else colors.onSurfaceVariant,
|
||||
modifier = Modifier.clip(shape).background(if (selected) pal.signal else colors.surfaceVariant)
|
||||
.glideBorder(hot, shape, pal.signal)
|
||||
.hoverable(src).selectable(selected = selected, interactionSource = src, indication = LocalIndication.current, role = Role.Tab, onClick = onClick)
|
||||
.controllerConfirm(onClick = onClick)
|
||||
.padding(horizontal = 12.dp, vertical = 7.dp),
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun sortLabel(sort: String): String = stringResource(
|
||||
when (sort) {
|
||||
ItchBrowse.SORT_NEW_POPULAR -> R.string.stores_itch_sort_new_popular
|
||||
ItchBrowse.SORT_TOP_SELLERS -> R.string.stores_itch_sort_top_sellers
|
||||
ItchBrowse.SORT_TOP_RATED -> R.string.stores_itch_sort_top_rated
|
||||
ItchBrowse.SORT_NEWEST -> R.string.stores_itch_sort_new
|
||||
else -> R.string.stores_itch_sort_popular
|
||||
},
|
||||
)
|
||||
|
||||
@Composable
|
||||
private fun platformLabel(platform: String): String = stringResource(
|
||||
when (platform) {
|
||||
"windows" -> R.string.stores_itch_platform_windows
|
||||
"osx" -> R.string.stores_itch_platform_macos
|
||||
"linux" -> R.string.stores_itch_platform_linux
|
||||
"android" -> R.string.stores_itch_platform_android
|
||||
"ios" -> R.string.stores_itch_platform_ios
|
||||
"web" -> R.string.stores_itch_platform_web
|
||||
else -> R.string.stores_itch_platform_mobile_web
|
||||
},
|
||||
)
|
||||
|
||||
@Composable
|
||||
private fun priceLabel(price: String): String = stringResource(
|
||||
when (price) {
|
||||
ItchBrowse.PRICE_FREE -> R.string.stores_itch_price_free
|
||||
ItchBrowse.PRICE_SALE -> R.string.stores_itch_price_sale
|
||||
ItchBrowse.PRICE_PAID -> R.string.stores_itch_price_paid
|
||||
ItchBrowse.PRICE_UNDER_5 -> R.string.stores_itch_price_under_5
|
||||
ItchBrowse.PRICE_UNDER_15 -> R.string.stores_itch_price_under_15
|
||||
else -> R.string.stores_itch_price_any
|
||||
},
|
||||
)
|
||||
@@ -0,0 +1,117 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.LinearProgressIndicator
|
||||
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.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.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
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.stores.CatalogItem
|
||||
import com.droiddeck.launcher.stores.StoresState
|
||||
import com.droiddeck.launcher.stores.formatBytes
|
||||
import com.droiddeck.launcher.stores.itch.ItchApi
|
||||
import com.droiddeck.launcher.stores.itch.ItchAuth
|
||||
import com.droiddeck.launcher.stores.itch.ItchBuild
|
||||
import com.droiddeck.launcher.stores.itch.ItchGame
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
private class BuildList(val gameId: String, val builds: List<ItchBuild>)
|
||||
|
||||
@Composable
|
||||
internal fun ItchBuildPicker(item: CatalogItem, onDismiss: () -> Unit) {
|
||||
val ctx = LocalContext.current
|
||||
val app = ctx.applicationContext
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val shown = rememberShown(onDismiss)
|
||||
val close = { shown.targetState = false }
|
||||
var loaded by remember(item) { mutableStateOf<BuildList?>(null) }
|
||||
var failed by remember(item) { mutableStateOf(false) }
|
||||
|
||||
val install: (BuildList, ItchBuild) -> Unit = install@{ list, build ->
|
||||
if (!shown.targetState) return@install
|
||||
val tagged = item.copy(
|
||||
extra = item.extra + mapOf("gameId" to list.gameId, "uploadId" to build.uploadId),
|
||||
sizeBytes = build.size.takeIf { it > 0 } ?: item.sizeBytes,
|
||||
)
|
||||
close()
|
||||
StoresState.requestInstall(ctx, tagged)
|
||||
}
|
||||
|
||||
LaunchedEffect(item) {
|
||||
val result = withContext(Dispatchers.IO) {
|
||||
val key = ItchAuth.key(app)
|
||||
val id = if (key.isBlank()) null else ItchGame.resolveId(item)
|
||||
val uploads = id?.let { ItchApi.uploads(key, it, item.extra["downloadKeyId"].orEmpty()) }
|
||||
if (id == null || uploads == null) null else BuildList(id, ItchGame.builds(uploads))
|
||||
}
|
||||
if (result == null) { failed = true; return@LaunchedEffect }
|
||||
loaded = result
|
||||
if (shown.targetState) result.builds.singleOrNull()?.takeIf { it.installable }?.let { install(result, it) }
|
||||
}
|
||||
|
||||
AppDialog(shown, close, "itchBuilds", wide = false, maxWidth = 460.dp) {
|
||||
DialogTitleRow(stringResource(R.string.stores_itch_pick_title), close)
|
||||
Text(item.title, fontSize = 12.sp, color = colors.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
||||
val list = loaded
|
||||
when {
|
||||
failed -> Text(stringResource(R.string.stores_itch_pick_failed), fontSize = 13.sp, color = colors.onSurfaceVariant)
|
||||
list == null -> LinearProgressIndicator(Modifier.fillMaxWidth().padding(vertical = 8.dp))
|
||||
list.builds.isEmpty() -> Text(stringResource(R.string.stores_itch_pick_none), fontSize = 13.sp, color = colors.onSurfaceVariant)
|
||||
else -> Column(verticalArrangement = Arrangement.spacedBy(8.dp), modifier = Modifier.fillMaxWidth()) {
|
||||
for (build in list.builds) key(build.uploadId) { BuildRow(item, build) { install(list, build) } }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun BuildRow(item: CatalogItem, build: ItchBuild, onInstall: () -> Unit) {
|
||||
val ctx = LocalContext.current
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val linux = "linux" in build.platforms && !build.installable
|
||||
val detail = listOfNotNull(
|
||||
build.platforms.map { platformName(it) }.joinToString(", "),
|
||||
build.size.takeIf { it > 0 }?.let { formatBytes(it) },
|
||||
build.updatedAt.take(10).takeIf { it.isNotBlank() },
|
||||
if (build.demo) stringResource(R.string.stores_itch_build_demo) else null,
|
||||
).joinToString(" · ")
|
||||
ListRow(enabled = !linux, onClick = { if (build.installable) onInstall() else openStoreUrl(ctx, item) }) {
|
||||
Column(Modifier.weight(1f)) {
|
||||
Text(build.filename.ifBlank { item.title }, fontSize = 13.sp, color = colors.onBackground, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
||||
Text(detail, fontSize = 11.sp, color = colors.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
||||
}
|
||||
val label = when {
|
||||
build.installable -> stringResource(R.string.stores_install)
|
||||
linux -> stringResource(R.string.stores_itch_build_linux_soon)
|
||||
else -> stringResource(R.string.stores_itch_build_open)
|
||||
}
|
||||
Text(label, fontSize = 12.sp, color = colors.onSurfaceVariant, maxLines = 1)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun platformName(platform: String): String = stringResource(
|
||||
when (platform) {
|
||||
"windows" -> R.string.stores_itch_build_windows
|
||||
"linux" -> R.string.stores_itch_build_linux
|
||||
"osx" -> R.string.stores_itch_build_macos
|
||||
"android" -> R.string.stores_itch_build_android
|
||||
else -> R.string.stores_itch_build_web
|
||||
},
|
||||
)
|
||||
@@ -0,0 +1,691 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import android.view.KeyEvent
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.compose.animation.core.Spring
|
||||
import androidx.compose.animation.core.animateFloatAsState
|
||||
import androidx.compose.foundation.LocalIndication
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.focusGroup
|
||||
import androidx.compose.foundation.horizontalScroll
|
||||
import androidx.compose.foundation.hoverable
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.interaction.collectIsPressedAsState
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.lazy.grid.GridCells
|
||||
import androidx.compose.foundation.lazy.grid.GridItemSpan
|
||||
import androidx.compose.foundation.lazy.grid.LazyGridScope
|
||||
import androidx.compose.foundation.lazy.grid.LazyGridState
|
||||
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
|
||||
import androidx.compose.foundation.lazy.grid.items
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.selection.selectable
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.FilterList
|
||||
import androidx.compose.material.icons.filled.GridView
|
||||
import androidx.compose.material.icons.filled.PlayArrow
|
||||
import androidx.compose.material.icons.filled.Sort
|
||||
import androidx.compose.material.icons.filled.ViewList
|
||||
import androidx.compose.material.icons.filled.ViewModule
|
||||
import androidx.compose.material.icons.outlined.Download
|
||||
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.SideEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.ui.Alignment
|
||||
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.focus.onFocusChanged
|
||||
import androidx.compose.ui.geometry.Rect
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.graphicsLayer
|
||||
import androidx.compose.ui.input.key.onPreviewKeyEvent
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.layout.boundsInRoot
|
||||
import androidx.compose.ui.layout.onGloballyPositioned
|
||||
import androidx.compose.ui.layout.onSizeChanged
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.res.pluralStringResource
|
||||
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 coil.compose.AsyncImage
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.frontend.Library
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import com.droiddeck.launcher.stores.CatalogItem
|
||||
import com.droiddeck.launcher.stores.Store
|
||||
import com.droiddeck.launcher.stores.StoreSizes
|
||||
import com.droiddeck.launcher.stores.StoresState
|
||||
import com.droiddeck.launcher.stores.download.DownloadEntry
|
||||
import com.droiddeck.launcher.stores.formatBytes
|
||||
import com.droiddeck.launcher.stores.retainOrder
|
||||
import com.droiddeck.launcher.stores.xbox.XboxLibraryFilter
|
||||
import com.droiddeck.launcher.stores.sortGames
|
||||
import kotlinx.coroutines.launch
|
||||
import androidx.compose.runtime.setValue
|
||||
|
||||
/** One owned game: installed ones carry their [game], store products not installed yet only their [item]. */
|
||||
internal class LibraryEntry(
|
||||
val key: String, val source: String, val title: String,
|
||||
val game: Library.SteamGame?, val item: CatalogItem?, val installed: Boolean,
|
||||
) {
|
||||
val storeKey: String? get() = item?.key ?: game?.storeId?.let { "${game.source}:$it" }
|
||||
}
|
||||
|
||||
/** Installed games first claim their store product, so a game owned and installed shows once. */
|
||||
internal fun libraryEntries(
|
||||
games: List<Library.SteamGame>, owned: Map<Store, List<CatalogItem>>, installedStore: Set<String>,
|
||||
): List<LibraryEntry> {
|
||||
val claimed = HashSet<String>()
|
||||
val out = ArrayList<LibraryEntry>()
|
||||
for (g in games) {
|
||||
if (g.library == Library.EPIC_LAUNCHER) continue
|
||||
val storeKey = g.storeId?.let { "${g.source}:$it" }
|
||||
val item = storeKey?.let { k -> Store.byId(g.source)?.let { st -> owned[st]?.firstOrNull { it.key == k } } }
|
||||
if (storeKey != null) claimed += storeKey
|
||||
out += LibraryEntry(GameRef.key(g), g.source, g.name, g, item, installed = true)
|
||||
}
|
||||
for (store in Store.entries) for (item in owned[store].orEmpty()) {
|
||||
if (!claimed.add(item.key)) continue
|
||||
out += LibraryEntry(GameRef.key(item), store.id, item.title, null, item, installed = item.key in installedStore)
|
||||
}
|
||||
return out.distinctBy { it.key }
|
||||
}
|
||||
|
||||
internal fun installedFirst(entries: List<LibraryEntry>): List<LibraryEntry> = entries.partition { it.installed }.let { (on, off) -> on + off }
|
||||
|
||||
internal const val LIBRARY_ALL = "all"
|
||||
internal val LIBRARY_SOURCES = listOf(Library.SOURCE_STEAM) + Store.entries.map { it.id } + Library.ADDED
|
||||
|
||||
/** Survives leaving the page, so Stores can open the Library on one store's owned games. */
|
||||
internal object LibraryView {
|
||||
var source by mutableStateOf(LIBRARY_ALL)
|
||||
var query by mutableStateOf("")
|
||||
var focusFirst = false
|
||||
|
||||
fun showOwned(store: Store) {
|
||||
source = store.id
|
||||
query = ""
|
||||
focusFirst = true
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun LibraryPage(s: FrontEndState, a: FrontEndActions, selected: String, onSelect: (String) -> Unit, modifier: Modifier) {
|
||||
val ctx = LocalContext.current
|
||||
val narrow = LocalNarrowPane.current
|
||||
val ff = LocalFrontFocus.current
|
||||
val focusManager = androidx.compose.ui.platform.LocalFocusManager.current
|
||||
val inputMode = androidx.compose.ui.platform.LocalInputModeManager.current
|
||||
LaunchedEffect(Unit) { StoresState.refresh(ctx) }
|
||||
val stores = s.gameStoresEnabled && !s.shortcutPicker
|
||||
val signedIn = Store.entries.filter { StoresState.isSignedIn(it) }
|
||||
LaunchedEffect(stores, signedIn) { if (stores) signedIn.forEach { StoresState.loadLibrary(ctx, it) } }
|
||||
val owned = if (stores) signedIn.associateWith { StoresState.library[it].orEmpty() } else emptyMap()
|
||||
val installedStore = StoresState.installed.map { it.key }.toSet()
|
||||
val syncing = if (stores) signedIn.mapNotNull { st -> StoresState.status[st]?.let { st to it } } else emptyList()
|
||||
val cloudRows = rememberXboxCloudRows(s)
|
||||
val all = remember(s.steamGames, cloudRows, owned, installedStore) { libraryEntries(s.steamGames + cloudRows, owned, installedStore) }
|
||||
LaunchedEffect(Unit) { XboxLibraryFilter.load(ctx) }
|
||||
val sources = LIBRARY_SOURCES.filter { src -> all.any { it.source == src } }
|
||||
val source = LibraryView.source.takeIf { it == LIBRARY_ALL || it in sources } ?: LIBRARY_ALL
|
||||
val q = LibraryView.query.trim().lowercase()
|
||||
val xboxFilter = if (source == Store.XBOX.id) XboxLibraryFilter.current else XboxLibraryFilter.ALL
|
||||
val candidates = all.filter {
|
||||
(source == LIBRARY_ALL || it.source == source) && (q.isEmpty() || it.title.lowercase().contains(q)) && keepsXbox(xboxFilter, it)
|
||||
}
|
||||
val sort = s.storesSort
|
||||
val sizeSort = sort == "sizeAsc" || sort == "sizeDesc"
|
||||
val installedAt = StoresState.installed.associate { it.key to it.sidecar.installedAt }
|
||||
val lastPlayed = s.steamGames.filter { it.storeId != null }.associate { "${it.source}:${it.storeId}" to it.lastPlayed }
|
||||
fun sizeOf(e: LibraryEntry): Long? {
|
||||
val key = e.storeKey
|
||||
return when {
|
||||
key != null && key in installedStore -> StoreSizes.onDisk[key]
|
||||
e.game?.gameFiles != null -> FolderSizes.known[e.game.gameFiles.path]
|
||||
e.item != null -> StoreSizes.size(e.item).takeIf { it > 0 }
|
||||
else -> 0L
|
||||
}
|
||||
}
|
||||
LaunchedEffect(sizeSort, candidates.map { it.key }) {
|
||||
if (!sizeSort) return@LaunchedEffect
|
||||
for (e in candidates) {
|
||||
val key = e.storeKey
|
||||
val inst = key?.let { k -> StoresState.installed.firstOrNull { it.key == k } }
|
||||
when {
|
||||
inst != null -> StoreSizes.requestDisk(ctx, inst.key, inst)
|
||||
e.game?.gameFiles != null -> FolderSizes.request(e.game.gameFiles)
|
||||
e.item != null && e.item.accessible -> StoreSizes.request(ctx, e.item)
|
||||
}
|
||||
}
|
||||
}
|
||||
var sizesWaited by remember(sizeSort) { mutableStateOf(false) }
|
||||
LaunchedEffect(sizeSort) { if (sizeSort) { kotlinx.coroutines.delay(8_000); sizesWaited = true } }
|
||||
val sizesPending = sizeSort && !sizesWaited && candidates.any { sizeOf(it) == null }
|
||||
val sorted = sortGames(
|
||||
candidates, sort, title = { it.title }, releaseDate = { it.item?.releaseDate.orEmpty() },
|
||||
lastPlayed = { e -> e.game?.lastPlayed ?: e.storeKey?.let { lastPlayed[it] } ?: 0L },
|
||||
installedAt = { e -> e.storeKey?.let { installedAt[it] } ?: 0L },
|
||||
size = { e -> sizeOf(e) ?: 0L },
|
||||
)
|
||||
var stable by remember { mutableStateOf(emptyList<LibraryEntry>()) }
|
||||
val ordered = if (sizesPending) retainOrder(candidates, stable) { it.key } else sorted
|
||||
SideEffect { if (!sizesPending) stable = sorted }
|
||||
val visible = installedFirst(ordered)
|
||||
val split = visible.count { it.installed }.takeIf { it in 1 until visible.size } ?: 0
|
||||
|
||||
val open = selected.takeIf { it.startsWith("app:") }
|
||||
val back = { onSelect("games") }
|
||||
BackHandler(enabled = open == null && LibraryView.query.isNotEmpty()) { LibraryView.query = "" }
|
||||
BackHandler(enabled = open != null) { back() }
|
||||
val lead = remember { FocusRequester() }
|
||||
var detailFocused by remember { mutableStateOf(false) }
|
||||
var lastOpened by remember { mutableStateOf<String?>(null) }
|
||||
val wasOpen = remember { booleanArrayOf(false) }
|
||||
val backLabel = stringResource(R.string.rail_games)
|
||||
LaunchedEffect(open) {
|
||||
val closing = open == null && wasOpen[0]
|
||||
wasOpen[0] = open != null
|
||||
if (open != null) lastOpened = open
|
||||
else if (!closing) return@LaunchedEffect
|
||||
if (inputMode.inputMode != androidx.compose.ui.input.InputMode.Keyboard || ff == null) return@LaunchedEffect
|
||||
repeat(60) { if (!HeldKeys.confirm) return@repeat; androidx.compose.runtime.withFrameNanos { } }
|
||||
if (open != null) {
|
||||
val backId = "back:$backLabel"
|
||||
repeat(45) { n ->
|
||||
androidx.compose.runtime.withFrameNanos { }
|
||||
if (detailFocused) return@LaunchedEffect
|
||||
val req = if (n < 20) lead else ff.items[backId]?.takeIf { (ff.attached[backId] ?: 0) > 0 } ?: lead
|
||||
runCatching { req.requestFocus() }
|
||||
}
|
||||
return@LaunchedEffect
|
||||
}
|
||||
val id = lastOpened?.let { "card:$it" }
|
||||
repeat(45) {
|
||||
androidx.compose.runtime.withFrameNanos { }
|
||||
if (id != null && ff.last == id) return@LaunchedEffect
|
||||
val card = id?.let { ff.items[it] }?.takeIf { (ff.attached[id] ?: 0) > 0 }
|
||||
if (card != null) runCatching { card.requestFocus() }
|
||||
else if (ff.firstTileAttached > 0 && runCatching { ff.firstTile.requestFocus() }.isSuccess) return@LaunchedEffect
|
||||
}
|
||||
}
|
||||
LaunchedEffect(Unit) {
|
||||
if (!LibraryView.focusFirst || ff == null) return@LaunchedEffect
|
||||
LibraryView.focusFirst = false
|
||||
if (inputMode.inputMode != androidx.compose.ui.input.InputMode.Keyboard) return@LaunchedEffect
|
||||
kotlinx.coroutines.delay(Motion.ms(240).toLong())
|
||||
focusWithinFrames({ ff.last?.startsWith("card:") == true }) { if (ff.firstTileAttached > 0) ff.firstTile else FocusRequester.Default }
|
||||
}
|
||||
if (all.isEmpty() && open == null) {
|
||||
LibraryEmpty(s, a, modifier)
|
||||
return
|
||||
}
|
||||
val grid = remember { LazyGridState() }
|
||||
val detailScroll = rememberScrollState()
|
||||
var cycled by remember { mutableIntStateOf(0) }
|
||||
var gridFocused by remember { mutableStateOf(false) }
|
||||
LaunchedEffect(source, sort) { grid.scrollToItem(0) }
|
||||
LaunchedEffect(cycled) {
|
||||
if (cycled == 0 || ff == null || inputMode.inputMode != androidx.compose.ui.input.InputMode.Keyboard) return@LaunchedEffect
|
||||
focusWithinFrames({ gridFocused }) {
|
||||
if (ff.firstTileAttached > 0) ff.firstTile else ff.items["libchip:$source"] ?: FocusRequester.Default
|
||||
}
|
||||
}
|
||||
CardDetailHost(
|
||||
open, detailScroll,
|
||||
gridScrolled = { grid.firstVisibleItemIndex > 0 || grid.firstVisibleItemScrollOffset > 0 },
|
||||
onDetailFocus = { detailFocused = it },
|
||||
modifier = modifier.padding(horizontal = if (narrow) 14.dp else 22.dp, vertical = if (narrow) 10.dp else 14.dp),
|
||||
wrap = { key, content -> StoreTheme(GameRef.parse(key).let { r -> r.store ?: r.game(s.steamGames)?.source?.let { Store.byId(it) } }) { content() } },
|
||||
grid = {
|
||||
LibraryGrid(
|
||||
s, a, grid, visible, split, all.size, sources, source, sizesPending, syncing,
|
||||
onSource = { LibraryView.source = it },
|
||||
onCycle = { step ->
|
||||
val ids = listOf(LIBRARY_ALL) + sources
|
||||
LibraryView.source = ids[(ids.indexOf(source).coerceAtLeast(0) + step + ids.size) % ids.size]
|
||||
cycled++
|
||||
},
|
||||
onOpen = { focusManager.clearFocus(force = true); onSelect(it) },
|
||||
searchCleared = open != null,
|
||||
onFocus = { gridFocused = it },
|
||||
)
|
||||
},
|
||||
) { key -> GameDetail(key, s, a, lead, backLabel, hopRail = "games", onBack = back) }
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun LibraryEmpty(s: FrontEndState, a: FrontEndActions, modifier: Modifier) {
|
||||
val narrow = LocalNarrowPane.current
|
||||
Column(modifier = modifier.padding(horizontal = if (narrow) 16.dp else 22.dp, vertical = if (narrow) 12.dp else 18.dp)) {
|
||||
Rise(0) {
|
||||
PageHeader(stringResource(R.string.rail_games)) {
|
||||
if (s.steamGamesX64) ClientTag()
|
||||
if (!s.shortcutPicker) AddGameButton { GamesDialogState.adding = true }
|
||||
}
|
||||
}
|
||||
Rise(1) { Note(stringResource(if (s.shortcutPicker && s.shortcutLibraryScanning) R.string.game_shortcut_scanning else R.string.games_empty)) }
|
||||
if (!s.shortcutPicker) Rise(2) {
|
||||
Actions {
|
||||
PrimaryButton(stringResource(R.string.games_play_steam), enabled = !s.busy, main = true, icon = Icons.Filled.PlayArrow, modifier = Modifier.padding(top = 12.dp).testTag("play-steam"), onClick = a.onPlay)
|
||||
}
|
||||
}
|
||||
Box(Modifier.padding(top = 12.dp)) { GameFileFolderActions(s, a) }
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun LibraryGrid(
|
||||
s: FrontEndState, a: FrontEndActions, grid: LazyGridState, visible: List<LibraryEntry>, split: Int, total: Int,
|
||||
sources: List<String>, source: String, sizesPending: Boolean, syncing: List<Pair<Store, String>>,
|
||||
onSource: (String) -> Unit, onCycle: (Int) -> Unit, onOpen: (String) -> Unit, onFocus: (Boolean) -> Unit, searchCleared: Boolean,
|
||||
) {
|
||||
val listMode = s.storesView == "list"
|
||||
val capsules = s.storesView == "capsules"
|
||||
val tileWidth = if (capsules) CapsuleWidth else CardWidth
|
||||
val focus = LocalFrontFocus.current
|
||||
val scope = rememberCoroutineScope()
|
||||
val density = androidx.compose.ui.platform.LocalDensity.current
|
||||
var columns by remember { mutableIntStateOf(1) }
|
||||
val headerItems = 2 + (if (sizesPending) 1 else 0) + syncing.size
|
||||
val tile: @Composable (LibraryEntry) -> Unit = { e ->
|
||||
val first = e.key == visible.firstOrNull()?.key
|
||||
val navigation = if (focus == null) Modifier else Modifier.onPreviewKeyEvent { event ->
|
||||
val key = event.nativeKeyEvent
|
||||
val direction = when (key.keyCode) {
|
||||
KeyEvent.KEYCODE_DPAD_DOWN -> 1
|
||||
KeyEvent.KEYCODE_DPAD_UP -> -1
|
||||
else -> 0
|
||||
}
|
||||
val index = visible.indexOfFirst { it.key == e.key }
|
||||
val next = storeGridNeighbor(index, visible.size, if (listMode) 1 else columns, direction, split)
|
||||
when {
|
||||
direction == 0 || index < 0 -> false
|
||||
next == null -> direction > 0
|
||||
else -> {
|
||||
if (key.action == KeyEvent.ACTION_DOWN) {
|
||||
val target = "card:${visible[next].key}"
|
||||
val targetIndex = headerItems + next + if (split == 0) 0 else if (next < split) 1 else 2
|
||||
val shown = grid.layoutInfo.visibleItemsInfo.any { it.index == targetIndex }
|
||||
if (!shown || (focus.attached[target] ?: 0) == 0 ||
|
||||
runCatching { focus.items.getValue(target).requestFocus() }.isFailure) scope.launch {
|
||||
grid.scrollToItem(targetIndex)
|
||||
focusWithinFrames({ focus.last == target }) { focus.items[target] ?: FocusRequester.Default }
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
val picker = s.shortcutPicker && e.game != null
|
||||
val choose = if (picker) ({ a.onSteamGame(e.game!!) }) else null
|
||||
if (listMode) LibraryRow(e, first, navigation, choose, onOpen) else LibraryTile(e, capsules, first, navigation, choose, onOpen)
|
||||
}
|
||||
LazyVerticalGrid(
|
||||
columns = if (listMode) GridCells.Fixed(1) else GridCells.Adaptive(tileWidth), state = grid,
|
||||
modifier = Modifier.fillMaxSize().onFocusChanged { onFocus(it.hasFocus) }.focusGroup().bumpers(onPrevious = { onCycle(-1) }, onNext = { onCycle(1) }).onSizeChanged {
|
||||
val gap = with(density) { 10.dp.roundToPx() }
|
||||
val minimum = with(density) { (if (listMode) CardWidth * 2 else tileWidth).roundToPx() }
|
||||
columns = ((it.width + gap) / (minimum + gap)).coerceAtLeast(1)
|
||||
},
|
||||
horizontalArrangement = Arrangement.spacedBy(10.dp), verticalArrangement = Arrangement.spacedBy(10.dp),
|
||||
contentPadding = PaddingValues(top = 4.dp, bottom = 16.dp),
|
||||
) {
|
||||
item(key = "header", span = { GridItemSpan(maxLineSpan) }) { Rise(0) { LibraryHeader(s, a, total, searchCleared, xbox = source == Store.XBOX.id) } }
|
||||
item(key = "filters", span = { GridItemSpan(maxLineSpan) }) {
|
||||
Rise(1) { LibraryFilters(sources, source, onSource) }
|
||||
}
|
||||
for ((store, line) in syncing) item(key = "sync-${store.id}", span = { GridItemSpan(maxLineSpan) }) {
|
||||
Column(verticalArrangement = Arrangement.spacedBy(4.dp), modifier = Modifier.fillMaxWidth()) {
|
||||
Text(store.shortLabel + " · " + line, fontSize = 12.sp, color = MaterialTheme.colorScheme.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
||||
if (syncCount(line) != null) SyncBar(line)
|
||||
else androidx.compose.material3.LinearProgressIndicator(Modifier.fillMaxWidth().padding(bottom = 8.dp).height(3.dp))
|
||||
}
|
||||
}
|
||||
if (sizesPending) item(key = "size-sort-progress", span = { GridItemSpan(maxLineSpan) }) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp), modifier = Modifier.fillMaxWidth().padding(bottom = 4.dp)) {
|
||||
androidx.compose.material3.LinearProgressIndicator(Modifier.weight(1f).height(3.dp))
|
||||
Text(stringResource(R.string.store_section_loading), fontSize = 11.sp, color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
}
|
||||
}
|
||||
val empty = R.string.stores_nothing_matches
|
||||
if (split == 0) libraryGrid(visible, empty, tile)
|
||||
else {
|
||||
item(key = "installed-label", span = { GridItemSpan(maxLineSpan) }) { SectionLabel(stringResource(R.string.stores_section_installed)) }
|
||||
libraryGrid(visible.take(split), empty, tile)
|
||||
item(key = "not-installed-label", span = { GridItemSpan(maxLineSpan) }) { SectionLabel(stringResource(R.string.stores_section_not_installed)) }
|
||||
libraryGrid(visible.drop(split), empty, tile)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun LazyGridScope.libraryGrid(entries: List<LibraryEntry>, empty: Int, tile: @Composable (LibraryEntry) -> Unit) {
|
||||
if (entries.isEmpty()) item(key = "empty", span = { GridItemSpan(maxLineSpan) }) {
|
||||
Box(Modifier.padding(vertical = 32.dp).fillMaxWidth(), contentAlignment = Alignment.Center) {
|
||||
Text(stringResource(empty), fontSize = 13.sp, color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
}
|
||||
}
|
||||
else items(entries, key = { it.key }, contentType = { "game" }) { tile(it) }
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun LibraryHeader(s: FrontEndState, a: FrontEndActions, total: Int, searchCleared: Boolean, xbox: Boolean) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val narrow = LocalNarrowPane.current
|
||||
ModeHeader(
|
||||
stringResource(R.string.rail_games), LibraryView.query, { LibraryView.query = it },
|
||||
placeholder = stringResource(R.string.stores_search_library),
|
||||
clearSearchFocus = searchCleared,
|
||||
lead = {
|
||||
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp), modifier = Modifier.padding(start = 2.dp, end = 4.dp)) {
|
||||
Text(stringResource(R.string.rail_games), fontSize = if (narrow) 20.sp else 24.sp, fontWeight = FontWeight.Bold, color = colors.onBackground, maxLines = 1)
|
||||
Text(pluralStringResource(R.plurals.mode_added_count, total, total), fontSize = 13.sp, color = colors.onSurfaceVariant, maxLines = 1)
|
||||
if (s.steamGamesX64 && !narrow) ClientTag()
|
||||
}
|
||||
},
|
||||
) {
|
||||
if (xbox) XboxFilterButton()
|
||||
SortButton(s, a)
|
||||
ViewButton(s, a)
|
||||
GameFileFolderActions(s, a)
|
||||
if (!s.shortcutPicker) AddGameButton { GamesDialogState.adding = true }
|
||||
}
|
||||
if (s.steamGamesX64 && narrow) Box(Modifier.padding(top = 4.dp)) { ClientTag() }
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun LibraryFilters(sources: List<String>, source: String, onSource: (String) -> Unit) {
|
||||
if (sources.size < 2) return
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp), verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier.fillMaxWidth().horizontalScroll(rememberScrollState()).padding(top = 4.dp, bottom = 2.dp),
|
||||
) {
|
||||
SourceFilterChip(LIBRARY_ALL, stringResource(R.string.stores_tab_all), source == LIBRARY_ALL, dot = null) { onSource(LIBRARY_ALL) }
|
||||
for (src in sources) {
|
||||
val store = Store.byId(src)
|
||||
val dot = when {
|
||||
store != null -> sourceColours(src).dot.copy(alpha = if (StoresState.isSignedIn(store) && StoresState.expired[store] != true) 1f else 0.35f)
|
||||
src == Library.SOURCE_STEAM -> sourceColours(src).dot
|
||||
else -> null
|
||||
}
|
||||
SourceFilterChip(src, if (src == Library.ADDED) stringResource(R.string.library_filter_added) else store?.shortLabel ?: sourceLabel(src), source == src, dot) { onSource(src) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SourceFilterChip(key: String, label: String, on: Boolean, dot: Color?, onClick: () -> Unit) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val pal = LocalPalette.current
|
||||
val src = remember { MutableInteractionSource() }
|
||||
val hot = rememberHot(src)
|
||||
val shape = RoundedCornerShape(99.dp)
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(7.dp),
|
||||
modifier = Modifier.paneItem("libchip:$key").testTag("library-source-$key").heightIn(min = 40.dp).clip(shape)
|
||||
.background(if (on) pal.signal.copy(alpha = 0.16f) else colors.surface)
|
||||
.glideBorder(hot, shape, pal.signal, if (on) pal.signal else pal.line)
|
||||
.hoverable(src).selectable(selected = on, interactionSource = src, indication = LocalIndication.current, role = Role.Tab, onClick = onClick)
|
||||
.controllerConfirm(onClick = onClick)
|
||||
.padding(horizontal = 14.dp, vertical = 8.dp),
|
||||
) {
|
||||
if (dot != null) Box(Modifier.size(9.dp).background(dot, CircleShape))
|
||||
Text(label, fontSize = 13.sp, fontWeight = FontWeight.Bold, color = if (on || hot) colors.onBackground else colors.onSurfaceVariant, maxLines = 1)
|
||||
}
|
||||
}
|
||||
|
||||
private fun entryArt(e: LibraryEntry, tall: Boolean): Any? {
|
||||
val inst = e.storeKey?.let { k -> StoresState.installed.firstOrNull { it.key == k } }
|
||||
val wide: Any? = e.game?.hero ?: e.item?.imageUrl ?: inst?.sidecar?.hero ?: inst?.sidecar?.cover
|
||||
val portrait: Any? = e.game?.art ?: e.item?.tallImageUrl ?: inst?.sidecar?.cover
|
||||
return if (tall) portrait ?: wide else wide ?: portrait
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun LibraryTile(e: LibraryEntry, capsule: Boolean, first: Boolean, navigation: Modifier, choose: (() -> Unit)?, onOpen: (String) -> Unit) {
|
||||
val pal = LocalPalette.current
|
||||
val src = remember { MutableInteractionSource() }
|
||||
val hot = rememberHot(src)
|
||||
val pressed by src.collectIsPressedAsState()
|
||||
val scale by animateFloatAsState(if (pressed) 0.985f else 1f, Motion.sp(0.5f, Spring.StiffnessMedium), label = "tileScale")
|
||||
val download = e.storeKey?.let { StoresState.download(it) }?.takeIf { it.isActive }
|
||||
val placed = remember { arrayOfNulls<androidx.compose.ui.layout.LayoutCoordinates>(1) }
|
||||
val corner = with(androidx.compose.ui.platform.LocalDensity.current) { 10.dp.toPx() }
|
||||
val wide = entryArt(e, tall = false)
|
||||
val tall = entryArt(e, tall = true)
|
||||
RequestSize(e)
|
||||
val open = {
|
||||
val art = if (capsule) tall else wide
|
||||
placed[0]?.takeIf { it.isAttached }?.let { StoresMotion.markCard(CardMark(e.key, it.boundsInRoot(), corner, (art as? java.io.File)?.path ?: art as? String)) }
|
||||
onOpen(e.key)
|
||||
}
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth().onGloballyPositioned { placed[0] = it }
|
||||
.then(navigation).paneItem("card:${e.key}").then(if (first) Modifier.firstTile().paneEntry() else Modifier).graphicsLayer { scaleX = scale; scaleY = scale }
|
||||
.clip(RoundedCornerShape(10.dp)).glideBorder(hot, RoundedCornerShape(10.dp), pal.signal, pal.line)
|
||||
.hoverable(src).clickable(role = Role.Button, interactionSource = src, indication = LocalIndication.current, onClick = open)
|
||||
.controllerConfirm(onClick = choose ?: open),
|
||||
) {
|
||||
CardFace(e.title, wide, tall, download, hot, capsule, dim = !e.installed && download == null,
|
||||
badge = { SourceChip(e.source, small = true, modifier = Modifier.align(Alignment.TopStart).padding(6.dp)) }) {
|
||||
LibraryMarker(e, download)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun RequestSize(e: LibraryEntry) {
|
||||
val ctx = LocalContext.current
|
||||
val item = e.item?.takeIf { !e.installed && it.accessible && it.sizeBytes <= 0 } ?: return
|
||||
LaunchedEffect(item.key) { StoreSizes.request(ctx, item) }
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun LibraryMarker(e: LibraryEntry, download: DownloadEntry?) {
|
||||
val pal = LocalPalette.current
|
||||
when {
|
||||
download != null -> Text("${download.percent}%", fontSize = 10.sp, fontWeight = FontWeight.Bold, color = pal.signal, maxLines = 1)
|
||||
e.installed -> Unit
|
||||
e.item != null && StoresState.isUnfinished(e.item) -> Text(stringResource(R.string.stores_resume), fontSize = 10.sp, fontWeight = FontWeight.Bold, color = pal.signal, maxLines = 1)
|
||||
else -> Icon(Icons.Outlined.Download, stringResource(R.string.stores_section_not_installed), tint = Color.White, modifier = Modifier.size(12.dp))
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun LibraryRow(e: LibraryEntry, first: Boolean, navigation: Modifier, choose: (() -> Unit)?, onOpen: (String) -> Unit) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val pal = LocalPalette.current
|
||||
val src = remember { MutableInteractionSource() }
|
||||
val hot = rememberHot(src)
|
||||
val download = e.storeKey?.let { StoresState.download(it) }?.takeIf { it.isActive }
|
||||
val placed = remember { arrayOfNulls<androidx.compose.ui.layout.LayoutCoordinates>(1) }
|
||||
val corner = with(androidx.compose.ui.platform.LocalDensity.current) { 10.dp.toPx() }
|
||||
val wide = entryArt(e, tall = false)
|
||||
val open = {
|
||||
placed[0]?.takeIf { it.isAttached }?.let { StoresMotion.markCard(CardMark(e.key, it.boundsInRoot(), corner, (wide as? java.io.File)?.path ?: wide as? String)) }
|
||||
onOpen(e.key)
|
||||
}
|
||||
RequestSize(e)
|
||||
val inst = e.storeKey?.let { k -> StoresState.installed.firstOrNull { it.key == k } }
|
||||
val folder = inst?.folder ?: e.game?.gameFiles
|
||||
val size = if (e.installed && folder != null) diskSize(inst, folder) else e.item?.let { StoreSizes.size(it) }?.takeIf { it > 0 }
|
||||
val status = when {
|
||||
download != null -> downloadLabel(download)
|
||||
!e.installed -> stringResource(R.string.stores_section_not_installed)
|
||||
e.game != null -> playedSpan(e.game.lastPlayed)?.replaceFirstChar { it.uppercase() } ?: stringResource(R.string.games_never_played)
|
||||
else -> stringResource(R.string.stores_installed_chip)
|
||||
}
|
||||
val meta = listOfNotNull(status, size?.let { formatBytes(it) }?.takeIf { it.isNotEmpty() })
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||
modifier = Modifier.fillMaxWidth().heightIn(min = 64.dp).onGloballyPositioned { placed[0] = it }.then(navigation).paneItem("card:${e.key}")
|
||||
.then(if (first) Modifier.firstTile().paneEntry() else Modifier)
|
||||
.clip(RoundedCornerShape(10.dp)).glideBorder(hot, RoundedCornerShape(10.dp), pal.signal, pal.line)
|
||||
.hoverable(src).clickable(role = Role.Button, interactionSource = src, indication = LocalIndication.current, onClick = open)
|
||||
.controllerConfirm(onClick = choose ?: open)
|
||||
.padding(horizontal = 10.dp, vertical = 8.dp),
|
||||
) {
|
||||
Box(Modifier.width(96.dp).height(54.dp).clip(RoundedCornerShape(8.dp)).background(artBrush(hueOf(e.title))).graphicsLayer { alpha = if (e.installed || download != null) 1f else 0.55f }) {
|
||||
if (wide != null) AsyncImage(model = wide, contentDescription = null, contentScale = ContentScale.Crop, modifier = Modifier.matchParentSize())
|
||||
}
|
||||
Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(3.dp)) {
|
||||
Text(e.title, fontSize = 14.sp, fontWeight = FontWeight.Bold, color = colors.onBackground, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
||||
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||
SourceChip(e.source, small = true)
|
||||
Text(meta.joinToString(" · "), fontSize = 12.sp, color = colors.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
||||
}
|
||||
}
|
||||
if (download != null) Text("${download.percent}%", fontSize = 11.sp, fontWeight = FontWeight.Bold, color = pal.signal, maxLines = 1)
|
||||
else if (!e.installed) Icon(Icons.Outlined.Download, null, tint = colors.onSurfaceVariant, modifier = Modifier.size(16.dp))
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun HeaderIconButton(description: String, icon: androidx.compose.ui.graphics.vector.ImageVector, key: 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.paneItem("btn:$key").size(32.dp).clip(CircleShape).background(if (hot) pal.signal.copy(alpha = 0.14f) else Color.Transparent)
|
||||
.glideBorder(hot, CircleShape, pal.signal)
|
||||
.hoverable(src).clickable(interactionSource = src, indication = LocalIndication.current, role = Role.Button, onClick = onClick)
|
||||
.controllerConfirm(onClick = onClick)
|
||||
.semantics { contentDescription = description },
|
||||
) { Icon(icon, null, tint = if (hot) pal.signal else colors.onSurfaceVariant, modifier = Modifier.size(18.dp)) }
|
||||
}
|
||||
|
||||
/** Choosing Library in the rail lands on the first game, as Play Steam does on the Steam page. */
|
||||
@Composable
|
||||
private fun Modifier.paneEntry(): Modifier {
|
||||
val ff = LocalFrontFocus.current ?: return this
|
||||
androidx.compose.runtime.DisposableEffect(ff) {
|
||||
ff.primaryAttached++
|
||||
onDispose { ff.primaryAttached-- }
|
||||
}
|
||||
return focusRequester(ff.primary)
|
||||
}
|
||||
|
||||
internal fun keepsXbox(filter: String, e: LibraryEntry): Boolean = when {
|
||||
filter == XboxLibraryFilter.ALL || e.source != Store.XBOX.id -> true
|
||||
e.game?.library == Library.XBOX_CLOUD -> filter == XboxLibraryFilter.CLOUD
|
||||
else -> e.item?.let { XboxLibraryFilter.keeps(filter, it) } == true
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun xboxFilterLabel(filter: String): String = when (filter) {
|
||||
XboxLibraryFilter.OWNED -> stringResource(R.string.game_install_access_owned)
|
||||
XboxLibraryFilter.GAME_PASS -> stringResource(R.string.xbox_filter_game_pass)
|
||||
XboxLibraryFilter.CLOUD -> stringResource(R.string.xbox_filter_cloud)
|
||||
else -> stringResource(R.string.stores_tab_all)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun XboxFilterButton() {
|
||||
val pal = LocalPalette.current
|
||||
val ctx = LocalContext.current
|
||||
val title = stringResource(R.string.xbox_filter_show)
|
||||
var at by remember { mutableStateOf<Rect?>(null) }
|
||||
Box(Modifier.onGloballyPositioned { at = it.boundsInRoot() }) {
|
||||
HeaderIconButton(title + " · " + xboxFilterLabel(XboxLibraryFilter.current), Icons.Filled.FilterList, "xbox-filter") {
|
||||
val from = at ?: return@HeaderIconButton
|
||||
Steps.ask(StepAsk(
|
||||
anchor = from, side = StepSide.Left, accent = pal.signal, pillCorner = 8.dp, items = XboxLibraryFilter.ALL_FILTERS.size,
|
||||
handle = { Text(title, fontSize = 12.sp, fontWeight = FontWeight.SemiBold, color = pal.signal, maxLines = 1, overflow = TextOverflow.Ellipsis) },
|
||||
) {
|
||||
StepTitle(title)
|
||||
StepList {
|
||||
XboxLibraryFilter.ALL_FILTERS.forEachIndexed { i, filter ->
|
||||
StepChoice(
|
||||
xboxFilterLabel(filter), selected = filter == XboxLibraryFilter.current, enabled = open,
|
||||
modifier = Modifier.fillMaxWidth().stepItem(i).then(if (filter == XboxLibraryFilter.current) Modifier.focusRequester(first) else Modifier),
|
||||
) {
|
||||
XboxLibraryFilter.set(ctx, filter)
|
||||
Steps.fold()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SortButton(s: FrontEndState, a: FrontEndActions) {
|
||||
val pal = LocalPalette.current
|
||||
val title = stringResource(R.string.stores_sort)
|
||||
var at by remember { mutableStateOf<Rect?>(null) }
|
||||
Box(Modifier.onGloballyPositioned { at = it.boundsInRoot() }) {
|
||||
HeaderIconButton(title, Icons.Filled.Sort, "sort") {
|
||||
val from = at ?: return@HeaderIconButton
|
||||
Steps.ask(StepAsk(
|
||||
anchor = from, side = StepSide.Left, accent = pal.signal, pillCorner = 8.dp, items = SessionPrefs.STORES_SORTS.size,
|
||||
handle = { Text(title, fontSize = 12.sp, fontWeight = FontWeight.SemiBold, color = pal.signal, maxLines = 1, overflow = TextOverflow.Ellipsis) },
|
||||
) {
|
||||
StepTitle(title)
|
||||
StepList {
|
||||
SessionPrefs.STORES_SORTS.forEachIndexed { i, sort ->
|
||||
val label = when (sort) {
|
||||
"lastPlayed" -> stringResource(R.string.stores_sort_last_played)
|
||||
"recentlyInstalled" -> stringResource(R.string.stores_sort_recently_installed)
|
||||
"titleAsc" -> stringResource(R.string.stores_sort_title_asc)
|
||||
"titleDesc" -> stringResource(R.string.stores_sort_title_desc)
|
||||
"sizeDesc" -> stringResource(R.string.stores_sort_size_desc)
|
||||
"sizeAsc" -> stringResource(R.string.stores_sort_size_asc)
|
||||
else -> stringResource(R.string.stores_sort_release_date)
|
||||
}
|
||||
StepChoice(
|
||||
label, selected = sort == s.storesSort, enabled = open,
|
||||
modifier = Modifier.fillMaxWidth().stepItem(i).then(if (sort == s.storesSort) Modifier.focusRequester(first) else Modifier),
|
||||
) {
|
||||
a.onStoresSort(sort)
|
||||
Steps.fold()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ViewButton(s: FrontEndState, a: FrontEndActions) {
|
||||
val views = SessionPrefs.STORES_VIEWS
|
||||
val next = views[(views.indexOf(s.storesView) + 1) % views.size]
|
||||
HeaderIconButton(
|
||||
stringResource(when (next) { "capsules" -> R.string.stores_view_capsules; "list" -> R.string.stores_view_list; else -> R.string.stores_view_cards }),
|
||||
when (next) { "capsules" -> Icons.Filled.ViewModule; "list" -> Icons.Filled.ViewList; else -> Icons.Filled.GridView },
|
||||
"view",
|
||||
) { a.onStoresView(next) }
|
||||
}
|
||||
@@ -641,11 +641,7 @@ internal fun LiftHero(
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun Handle(height: Dp, above: Boolean = false) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val pal = LocalPalette.current
|
||||
val shape = if (above) RoundedCornerShape(topStart = 12.dp, topEnd = 12.dp) else RoundedCornerShape(bottomStart = 12.dp, bottomEnd = 12.dp)
|
||||
val still = Motion.scale == 0f
|
||||
private fun handleBob(): Float {
|
||||
val bob = androidx.compose.animation.core.rememberInfiniteTransition(label = "handle")
|
||||
val lift by bob.animateFloat(
|
||||
0f, 0f,
|
||||
@@ -660,6 +656,16 @@ internal fun Handle(height: Dp, above: Boolean = false) {
|
||||
),
|
||||
label = "handleBob",
|
||||
)
|
||||
return lift
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun Handle(height: Dp, above: Boolean = false) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val pal = LocalPalette.current
|
||||
val shape = if (above) RoundedCornerShape(topStart = 12.dp, topEnd = 12.dp) else RoundedCornerShape(bottomStart = 12.dp, bottomEnd = 12.dp)
|
||||
val still = Motion.scale == 0f || !ambientAwake()
|
||||
val lift = if (still) 0f else handleBob()
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(4.dp),
|
||||
modifier = Modifier.height(height).clip(shape).background(colors.surface)
|
||||
|
||||
@@ -60,6 +60,7 @@ class ModeSettings(
|
||||
val hdrReason: String?,
|
||||
val gpuDrivers: String? = null,
|
||||
val fpsLimit: Int = 0,
|
||||
val performanceMode: Boolean = false,
|
||||
val upscaler: Int = 0,
|
||||
val upscaleSharpness: Int = 75,
|
||||
val touchMode: String,
|
||||
@@ -82,6 +83,8 @@ class ModeSettings(
|
||||
val steamClientArch: String? = null,
|
||||
/** Steam only: a game launched from the front end returns there when it closes; null hides the row. */
|
||||
val returnAfterGame: Boolean? = null,
|
||||
/** Steam only: the client's Shader Pre-Caching setting; null hides the row. */
|
||||
val shaderPrecache: Boolean? = null,
|
||||
val steamRepairQueued: Boolean = false,
|
||||
val mangoapp: Boolean = true,
|
||||
val steamController: String? = null,
|
||||
@@ -114,6 +117,7 @@ class ModeSettingsActions(
|
||||
val onHdr: (Boolean) -> Unit,
|
||||
val onGpuDrivers: () -> Unit = {},
|
||||
val onFpsLimit: (Int) -> Unit = {},
|
||||
val onPerformanceMode: (Boolean) -> Unit = {},
|
||||
val onUpscaler: (Int) -> Unit = {},
|
||||
val onUpscaleSharpness: (Int) -> Unit = {},
|
||||
val onTouch: (String) -> Unit,
|
||||
@@ -136,6 +140,7 @@ class ModeSettingsActions(
|
||||
val onSteamClientArch: (String) -> Unit = {},
|
||||
val onMangoapp: (Boolean) -> Unit = {},
|
||||
val onReturnAfterGame: (Boolean) -> Unit = {},
|
||||
val onShaderPrecache: (Boolean) -> Unit = {},
|
||||
val onSteamController: (String) -> Unit = {},
|
||||
val onUnfoldedControls: (Boolean) -> Unit = {},
|
||||
val onUnfoldedControlsWithController: (Boolean) -> Unit = {},
|
||||
@@ -218,7 +223,8 @@ fun ModeSheetRows(s: ModeSettings, a: ModeSettingsActions, tab: String, extras:
|
||||
}
|
||||
if (s.stretch16x9 != null && (com.droiddeck.launcher.session.SessionDisplay.canStretch16x9(s.panelSize) ||
|
||||
com.droiddeck.launcher.session.SessionDisplay.canStretch16x9(displaySize))) {
|
||||
val canStretch = com.droiddeck.launcher.session.SessionDisplay.canStretch16x9(displaySize)
|
||||
val canStretch = s.resolution != com.droiddeck.launcher.session.SessionDisplay.FOLLOW_SCREEN &&
|
||||
com.droiddeck.launcher.session.SessionDisplay.canStretch16x9(displaySize)
|
||||
ChoiceRow(host, "game-fit", stringResource(R.string.display_game_fit),
|
||||
stringResource(if (canStretch) R.string.display_game_fit_hint else R.string.display_game_fit_unavailable),
|
||||
listOf(false to stringResource(R.string.display_preserve), true to stringResource(R.string.display_stretch)),
|
||||
@@ -237,6 +243,8 @@ fun ModeSheetRows(s: ModeSettings, a: ModeSettingsActions, tab: String, extras:
|
||||
)
|
||||
}
|
||||
SettingsGroup(stringResource(R.string.display_frame_rate)) {
|
||||
ToggleRow(host, "performance", stringResource(R.string.mode_performance), stringResource(R.string.mode_performance_hint),
|
||||
s.performanceMode, onChange = a.onPerformanceMode)
|
||||
ChoiceRow(host, "fps", stringResource(R.string.mode_fps), stringResource(R.string.common_applies_next_session),
|
||||
SessionPrefs.fpsLimitChoices(LocalContext.current), s.fpsLimit, note = stringResource(R.string.mode_fps_note), onPick = a.onFpsLimit)
|
||||
}
|
||||
@@ -478,6 +486,11 @@ fun ModeSheetRows(s: ModeSettings, a: ModeSettingsActions, tab: String, extras:
|
||||
stringResource(R.string.mode_return_after_game_hint),
|
||||
s.returnAfterGame, onChange = a.onReturnAfterGame,
|
||||
)
|
||||
if (s.shaderPrecache != null) ToggleRow(
|
||||
host, "shaderprecache", stringResource(R.string.mode_shader_precache),
|
||||
stringResource(R.string.mode_shader_precache_hint),
|
||||
s.shaderPrecache, onChange = a.onShaderPrecache,
|
||||
)
|
||||
SettingsRow(
|
||||
stringResource(R.string.mode_steam_repair),
|
||||
stringResource(if (s.steamRepairQueued) R.string.mode_steam_repair_queued else R.string.mode_steam_repair_hint),
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import com.droiddeck.launcher.R
|
||||
import androidx.annotation.StringRes
|
||||
import com.droiddeck.launcher.input.PC_KEY_ROWS
|
||||
import com.droiddeck.launcher.input.PC_MODIFIERS
|
||||
import com.droiddeck.launcher.input.PcKey
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import android.view.KeyEvent
|
||||
import androidx.compose.animation.animateColorAsState
|
||||
@@ -54,46 +56,6 @@ import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
|
||||
private data class PcKey(val label: String, val code: Int, val weight: Float = 1f, val shifted: String? = null, @StringRes val labelRes: Int = 0)
|
||||
|
||||
private fun k(label: String, code: Int, weight: Float = 1f, shifted: String? = null) = PcKey(label, code, weight, shifted)
|
||||
|
||||
private fun k(@StringRes labelRes: Int, code: Int, weight: Float = 1f) = PcKey("", code, weight, null, labelRes)
|
||||
|
||||
private val ROWS: List<List<PcKey>> = listOf(
|
||||
listOf(
|
||||
k(R.string.pckb_key_esc, 1), k("F1", 59), k("F2", 60), k("F3", 61), k("F4", 62), k("F5", 63), k("F6", 64),
|
||||
k("F7", 65), k("F8", 66), k("F9", 67), k("F10", 68), k("F11", 87), k("F12", 88),
|
||||
k(R.string.pckb_key_ins, 110), k(R.string.pckb_key_del, 111), k(R.string.pckb_key_home, 102), k(R.string.pckb_key_end, 107), k(R.string.pckb_key_pgup, 104), k(R.string.pckb_key_pgdn, 109),
|
||||
),
|
||||
listOf(
|
||||
k("`", 41, shifted = "~"), k("1", 2, shifted = "!"), k("2", 3, shifted = "@"), k("3", 4, shifted = "#"),
|
||||
k("4", 5, shifted = "$"), k("5", 6, shifted = "%"), k("6", 7, shifted = "^"), k("7", 8, shifted = "&"),
|
||||
k("8", 9, shifted = "*"), k("9", 10, shifted = "("), k("0", 11, shifted = ")"), k("-", 12, shifted = "_"),
|
||||
k("=", 13, shifted = "+"), k(R.string.pckb_key_backspace, 14, 2f),
|
||||
),
|
||||
listOf(
|
||||
k(R.string.pckb_key_tab, 15, 1.5f), k("q", 16), k("w", 17), k("e", 18), k("r", 19), k("t", 20), k("y", 21),
|
||||
k("u", 22), k("i", 23), k("o", 24), k("p", 25), k("[", 26, shifted = "{"), k("]", 27, shifted = "}"),
|
||||
k("\\", 43, 1.5f, shifted = "|"),
|
||||
),
|
||||
listOf(
|
||||
k(R.string.pckb_key_caps, 58, 1.75f), k("a", 30), k("s", 31), k("d", 32), k("f", 33), k("g", 34), k("h", 35),
|
||||
k("j", 36), k("k", 37), k("l", 38), k(";", 39, shifted = ":"), k("'", 40, shifted = "\""),
|
||||
k(R.string.pckb_key_enter, 28, 2.25f),
|
||||
),
|
||||
listOf(
|
||||
k(R.string.pckb_key_shift, 42, 2.25f), k("z", 44), k("x", 45), k("c", 46), k("v", 47), k("b", 48), k("n", 49),
|
||||
k("m", 50), k(",", 51, shifted = "<"), k(".", 52, shifted = ">"), k("/", 53, shifted = "?"),
|
||||
k(R.string.pckb_key_shift, 54, 1.75f), k("↑", 103),
|
||||
),
|
||||
listOf(
|
||||
k(R.string.pckb_key_ctrl, 29, 1.5f), k(R.string.pckb_key_super, 125, 1.25f), k(R.string.pckb_key_alt, 56, 1.25f), k(R.string.pckb_key_space, 57, 6.25f),
|
||||
k(R.string.pckb_key_altgr, 100, 1.25f), k(R.string.pckb_key_ctrl, 97, 1.25f), k("←", 105), k("↓", 108), k("→", 106),
|
||||
),
|
||||
)
|
||||
|
||||
private val MODIFIERS = setOf(42, 54, 29, 97, 56, 100, 125)
|
||||
private const val MOD_OFF = 0
|
||||
private const val MOD_ONCE = 1
|
||||
private const val MOD_LOCKED = 2
|
||||
@@ -115,7 +77,7 @@ fun PcKeyboard(
|
||||
for ((code, state) in mods.toMap()) if (state == MOD_ONCE) { sendKey(code, false); mods[code] = MOD_OFF }
|
||||
}
|
||||
fun press(key: PcKey) {
|
||||
if (key.code in MODIFIERS) {
|
||||
if (key.code in PC_MODIFIERS) {
|
||||
when (mods[key.code] ?: MOD_OFF) {
|
||||
MOD_OFF -> { sendKey(key.code, true); mods[key.code] = MOD_ONCE }
|
||||
MOD_ONCE -> mods[key.code] = MOD_LOCKED
|
||||
@@ -126,7 +88,7 @@ fun PcKeyboard(
|
||||
sendKey(key.code, true)
|
||||
}
|
||||
fun release(key: PcKey) {
|
||||
if (key.code in MODIFIERS) return
|
||||
if (key.code in PC_MODIFIERS) return
|
||||
sendKey(key.code, false)
|
||||
if (key.code == 58) capsOn = !capsOn
|
||||
releaseOnceModifiers()
|
||||
@@ -153,7 +115,7 @@ fun PcKeyboard(
|
||||
Spacer(Modifier.width(8.dp))
|
||||
HeaderButton(stringResource(R.string.pckb_hide), onClose)
|
||||
}
|
||||
ROWS.forEachIndexed { r, row ->
|
||||
PC_KEY_ROWS.forEachIndexed { r, row ->
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(3.dp), modifier = Modifier.fillMaxWidth().height(rowHeight)) {
|
||||
row.forEachIndexed { i, key ->
|
||||
val state = mods[key.code] ?: MOD_OFF
|
||||
|
||||
@@ -28,6 +28,8 @@ import com.droiddeck.launcher.session.SessionPrefs
|
||||
|
||||
class CoreRow(val core: Int, val label: String)
|
||||
|
||||
private const val MEMORY_CAP_STEP_MB = 256
|
||||
|
||||
@Composable
|
||||
fun PerformancePage(
|
||||
cores: List<CoreRow>,
|
||||
@@ -44,8 +46,14 @@ fun PerformancePage(
|
||||
fsyncFirst: Boolean,
|
||||
gamescopeRealtime: Boolean,
|
||||
gpuClockPin: Boolean,
|
||||
ramCapMb: Int,
|
||||
zramClient: Boolean,
|
||||
vramCapMb: Int,
|
||||
deviceRamMb: Int,
|
||||
ramCapAvailable: Boolean,
|
||||
prootNoSeccomp: Boolean,
|
||||
prootFastPath: Boolean,
|
||||
cursorComposite: Boolean,
|
||||
guestHostname: String,
|
||||
phantomWarning: String?,
|
||||
onClientOverride: (Boolean) -> Unit,
|
||||
@@ -59,8 +67,12 @@ fun PerformancePage(
|
||||
onFsyncFirst: (Boolean) -> Unit,
|
||||
onGamescopeRealtime: (Boolean) -> Unit,
|
||||
onGpuClockPin: (Boolean) -> Unit,
|
||||
onRamCapMb: (Int) -> Unit,
|
||||
onZramClient: (Boolean) -> Unit,
|
||||
onVramCapMb: (Int) -> Unit,
|
||||
onProotNoSeccomp: (Boolean) -> Unit,
|
||||
onProotFastPath: (Boolean) -> Unit,
|
||||
onCursorComposite: (Boolean) -> Unit,
|
||||
onGuestHostname: (String) -> Unit,
|
||||
onClientCore: (Int, Boolean) -> Unit,
|
||||
onGameCore: (Int, Boolean) -> Unit,
|
||||
@@ -121,6 +133,27 @@ fun PerformancePage(
|
||||
gpuClockPin, onChange = onGpuClockPin,
|
||||
)
|
||||
}
|
||||
SettingsGroup(stringResource(R.string.perf_memory)) {
|
||||
val top = (deviceRamMb / MEMORY_CAP_STEP_MB * MEMORY_CAP_STEP_MB).coerceAtLeast(MEMORY_CAP_STEP_MB)
|
||||
val off = stringResource(R.string.perf_cap_off)
|
||||
val auto = stringResource(R.string.perf_cap_auto)
|
||||
ToggleRow(
|
||||
host, "zramclient", stringResource(R.string.perf_zram_client),
|
||||
if (ramCapAvailable) stringResource(R.string.perf_zram_client_hint) else stringResource(R.string.perf_ram_cap_unavailable),
|
||||
zramClient && ramCapAvailable, enabled = ramCapAvailable, onChange = onZramClient,
|
||||
)
|
||||
SliderRow(
|
||||
stringResource(R.string.perf_ram_cap),
|
||||
if (ramCapAvailable) stringResource(R.string.perf_ram_cap_hint) else stringResource(R.string.perf_ram_cap_unavailable),
|
||||
ramCapMb.coerceAtMost(top), 0..top, step = MEMORY_CAP_STEP_MB, enabled = ramCapAvailable,
|
||||
format = { if (it == 0) off else "$it MB" }, onChange = onRamCapMb,
|
||||
)
|
||||
SliderRow(
|
||||
stringResource(R.string.perf_vram_cap), stringResource(R.string.perf_vram_cap_hint),
|
||||
vramCapMb.coerceAtMost(top), 0..top, step = MEMORY_CAP_STEP_MB,
|
||||
format = { if (it == 0) auto else "$it MB" }, onChange = onVramCapMb,
|
||||
)
|
||||
}
|
||||
SettingsGroup(stringResource(R.string.perf_fixes)) {
|
||||
ToggleRow(
|
||||
host, "sysmem", stringResource(R.string.perf_sysmem),
|
||||
@@ -158,6 +191,11 @@ fun PerformancePage(
|
||||
else stringResource(R.string.perf_fastpath_hint),
|
||||
prootFastPath && !prootNoSeccomp, enabled = !prootNoSeccomp, onChange = onProotFastPath,
|
||||
)
|
||||
ToggleRow(
|
||||
host, "cursorcomposite", stringResource(R.string.perf_cursor_composite),
|
||||
stringResource(R.string.perf_cursor_composite_hint),
|
||||
cursorComposite, onChange = onCursorComposite,
|
||||
)
|
||||
}
|
||||
SettingsGroup(stringResource(R.string.perf_identity)) {
|
||||
var draft by remember(guestHostname) { mutableStateOf(guestHostname) }
|
||||
|
||||
@@ -0,0 +1,368 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import android.net.Uri
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.foundation.BorderStroke
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.gestures.detectDragGestures
|
||||
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.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.offset
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.systemBarsPadding
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.layout.widthIn
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.text.BasicTextField
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Close
|
||||
import androidx.compose.material.icons.filled.Delete
|
||||
import androidx.compose.material.icons.filled.DragIndicator
|
||||
import androidx.compose.material.icons.filled.Image
|
||||
import androidx.compose.material.icons.filled.Keyboard
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Slider
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Switch
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.geometry.Offset
|
||||
import androidx.compose.ui.focus.onFocusChanged
|
||||
import androidx.compose.ui.input.pointer.pointerInput
|
||||
import androidx.compose.ui.platform.LocalConfiguration
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.input.ImeAction
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.IntOffset
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.input.SCREEN_KEY_CIRCLE
|
||||
import com.droiddeck.launcher.input.SCREEN_KEY_DPAD
|
||||
import com.droiddeck.launcher.input.SCREEN_KEY_PILL
|
||||
import com.droiddeck.launcher.input.SCREEN_KEY_RECT
|
||||
import com.droiddeck.launcher.input.SCREEN_KEY_ROUND
|
||||
import com.droiddeck.launcher.input.SCREEN_KEY_STICK
|
||||
import com.droiddeck.launcher.input.SCREEN_KEY_TRIGGER
|
||||
import com.droiddeck.launcher.input.ScreenKeys
|
||||
import com.droiddeck.launcher.input.pcKeyLabel
|
||||
import com.droiddeck.launcher.input.screenKeyDirections
|
||||
import java.io.File
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
private val PANEL_WIDTH = 600.dp
|
||||
private val CHIP_PADDING = androidx.compose.foundation.layout.PaddingValues(horizontal = 6.dp, vertical = 2.dp)
|
||||
|
||||
@Composable
|
||||
fun ScreenKeyEditor(
|
||||
codes: List<Int>,
|
||||
keyY: Float,
|
||||
size: Int,
|
||||
opacity: Float,
|
||||
shape: Int,
|
||||
toggle: Boolean,
|
||||
labels: Boolean,
|
||||
text: String,
|
||||
hasImage: Boolean,
|
||||
onResize: (Int) -> Unit,
|
||||
onOpacity: (Float) -> Unit,
|
||||
onShape: (Int) -> Unit,
|
||||
onToggle: (Boolean) -> Unit,
|
||||
onLabels: (Boolean) -> Unit,
|
||||
onText: (String) -> Unit,
|
||||
onImage: (String) -> Unit,
|
||||
onClearImage: () -> Unit,
|
||||
onBind: () -> Unit,
|
||||
onTextFocus: () -> Unit,
|
||||
onTextBlur: () -> Unit,
|
||||
onDirection: (Int) -> Unit,
|
||||
onRemove: () -> Unit,
|
||||
onDismiss: () -> Unit,
|
||||
) {
|
||||
val p = LocalPalette.current
|
||||
val context = LocalContext.current
|
||||
var offset by remember(codes) { mutableStateOf(Offset.Zero) }
|
||||
val density = LocalDensity.current
|
||||
val screen = LocalConfiguration.current
|
||||
val panelWidthPx = with(density) { PANEL_WIDTH.toPx() }
|
||||
val screenWidthPx = screen.screenWidthDp * density.density
|
||||
val screenHeightPx = screen.screenHeightDp * density.density
|
||||
val atTop = keyY > 0.45f
|
||||
val button = shape <= SCREEN_KEY_RECT
|
||||
val directions = screenKeyDirections(shape)
|
||||
val pickImage = rememberLauncherForActivityResult(ActivityResultContracts.GetContent()) { uri ->
|
||||
if (uri != null) importImage(context, uri, codes)?.let(onImage)
|
||||
}
|
||||
Box(
|
||||
Modifier.fillMaxSize().systemBarsPadding().padding(horizontal = 10.dp, vertical = 6.dp),
|
||||
contentAlignment = if (atTop) Alignment.TopCenter else Alignment.BottomCenter,
|
||||
) {
|
||||
Surface(
|
||||
Modifier.widthIn(max = PANEL_WIDTH).fillMaxWidth()
|
||||
.offset { IntOffset(offset.x.roundToInt(), offset.y.roundToInt()) },
|
||||
shape = RoundedCornerShape(18.dp),
|
||||
color = p.background, contentColor = p.onBackground, border = BorderStroke(1.dp, p.line2),
|
||||
) {
|
||||
Column(Modifier.padding(start = 10.dp, end = 6.dp, top = 2.dp, bottom = 6.dp)) {
|
||||
Row(Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) {
|
||||
Icon(
|
||||
Icons.Default.DragIndicator, null,
|
||||
tint = p.onBackground.copy(alpha = 0.45f),
|
||||
modifier = Modifier.pointerInput(panelWidthPx, screenWidthPx, screenHeightPx) {
|
||||
detectDragGestures { change, drag ->
|
||||
change.consume()
|
||||
offset = Offset(
|
||||
(offset.x + drag.x).coerceIn(
|
||||
-(screenWidthPx - panelWidthPx) / 2f + 8f,
|
||||
(screenWidthPx - panelWidthPx) / 2f - 8f,
|
||||
),
|
||||
(offset.y + drag.y).coerceIn(
|
||||
-screenHeightPx * if (atTop) 0f else 0.75f,
|
||||
screenHeightPx * if (atTop) 0.75f else 0f,
|
||||
),
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
Box(
|
||||
Modifier.weight(1f).height(36.dp)
|
||||
.background(p.line2.copy(alpha = 0.24f), RoundedCornerShape(9.dp))
|
||||
.padding(horizontal = 10.dp),
|
||||
contentAlignment = Alignment.CenterStart,
|
||||
) {
|
||||
BasicTextField(
|
||||
value = text,
|
||||
onValueChange = { onText(it.take(24)) },
|
||||
singleLine = true,
|
||||
textStyle = TextStyle(
|
||||
color = p.onBackground, fontSize = 13.sp,
|
||||
fontWeight = FontWeight.Medium,
|
||||
),
|
||||
cursorBrush = androidx.compose.ui.graphics.SolidColor(p.primary),
|
||||
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),
|
||||
modifier = Modifier.fillMaxWidth().onFocusChanged {
|
||||
if (it.isFocused) onTextFocus() else onTextBlur()
|
||||
},
|
||||
)
|
||||
if (text.isEmpty()) {
|
||||
Text(
|
||||
stringResource(R.string.screen_key_text),
|
||||
color = p.onBackground.copy(alpha = 0.4f),
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
)
|
||||
}
|
||||
}
|
||||
if (button) {
|
||||
IconButton(onClick = onBind, modifier = Modifier.width(38.dp)) {
|
||||
Icon(
|
||||
Icons.Default.Keyboard, stringResource(R.string.screen_key_bind),
|
||||
tint = p.onBackground.copy(alpha = 0.8f),
|
||||
)
|
||||
}
|
||||
}
|
||||
IconButton(onClick = { pickImage.launch("image/*") }, modifier = Modifier.width(38.dp)) {
|
||||
Icon(
|
||||
Icons.Default.Image, stringResource(R.string.screen_key_image),
|
||||
tint = p.onBackground.copy(alpha = 0.8f),
|
||||
)
|
||||
}
|
||||
if (hasImage) IconButton(onClick = onClearImage, modifier = Modifier.width(34.dp)) {
|
||||
Icon(Icons.Default.Close, stringResource(R.string.screen_key_image_clear), tint = p.error)
|
||||
}
|
||||
IconButton(onClick = onRemove, modifier = Modifier.width(38.dp)) {
|
||||
Icon(Icons.Default.Delete, stringResource(R.string.common_delete), tint = p.error)
|
||||
}
|
||||
IconButton(onClick = onDismiss, modifier = Modifier.width(34.dp)) {
|
||||
Icon(Icons.Default.Close, null, tint = p.onBackground)
|
||||
}
|
||||
}
|
||||
Row(
|
||||
Modifier.fillMaxWidth().padding(vertical = 2.dp),
|
||||
horizontalArrangement = Arrangement.spacedBy(4.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
listOf<Pair<Int?, Int>>(
|
||||
(if (button) SCREEN_KEY_PILL else null) to R.string.screen_key_type_button,
|
||||
SCREEN_KEY_TRIGGER to R.string.screen_key_shape_trigger,
|
||||
SCREEN_KEY_DPAD to R.string.touch_dpad,
|
||||
SCREEN_KEY_STICK to R.string.deck_surface_stick,
|
||||
).forEach { (value, label) ->
|
||||
val selected = if (value == null) button else shape == value
|
||||
Chip(stringResource(label), selected, Modifier.weight(1f)) {
|
||||
onShape(if (value == null) (if (button) shape else SCREEN_KEY_PILL) else value)
|
||||
}
|
||||
}
|
||||
Box(Modifier.width(1.dp).height(20.dp).background(p.line2))
|
||||
listOf(
|
||||
SCREEN_KEY_PILL to R.string.screen_key_shape_pill,
|
||||
SCREEN_KEY_ROUND to R.string.screen_key_shape_round,
|
||||
SCREEN_KEY_CIRCLE to R.string.screen_key_shape_circle,
|
||||
SCREEN_KEY_RECT to R.string.screen_key_shape_rect,
|
||||
).forEach { (value, label) ->
|
||||
Chip(
|
||||
stringResource(label), button && shape == value, Modifier.weight(1f), enabled = button,
|
||||
) { onShape(value) }
|
||||
}
|
||||
Box(Modifier.width(1.dp).height(20.dp).background(p.line2))
|
||||
Text(
|
||||
stringResource(R.string.screen_key_toggle), Modifier.padding(start = 6.dp, end = 2.dp),
|
||||
style = MaterialTheme.typography.bodySmall, maxLines = 1,
|
||||
)
|
||||
Switch(checked = toggle, onCheckedChange = onToggle, modifier = Modifier.height(30.dp))
|
||||
}
|
||||
if (directions.isNotEmpty()) {
|
||||
Row(
|
||||
Modifier.fillMaxWidth().padding(vertical = 2.dp),
|
||||
horizontalArrangement = Arrangement.spacedBy(4.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
directions.forEachIndexed { index, arrow ->
|
||||
val code = codes.getOrNull(index) ?: 0
|
||||
Chip(
|
||||
if (code == 0) arrow else "$arrow ${pcKeyLabel(context, code)}",
|
||||
code != 0, Modifier.weight(1f),
|
||||
) { onDirection(index) }
|
||||
}
|
||||
Text(
|
||||
stringResource(R.string.screen_key_text), Modifier.padding(start = 6.dp, end = 2.dp),
|
||||
style = MaterialTheme.typography.bodySmall, maxLines = 1,
|
||||
)
|
||||
Switch(checked = labels, onCheckedChange = onLabels, modifier = Modifier.height(30.dp))
|
||||
}
|
||||
}
|
||||
Row(
|
||||
Modifier.fillMaxWidth().padding(top = 2.dp),
|
||||
horizontalArrangement = Arrangement.spacedBy(6.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
KeySlider(
|
||||
label = stringResource(R.string.screen_key_size),
|
||||
value = "$size",
|
||||
current = size.toFloat(),
|
||||
min = ScreenKeys.MIN_SIZE.toFloat(),
|
||||
max = ScreenKeys.MAX_SIZE.toFloat(),
|
||||
modifier = Modifier.weight(1f),
|
||||
) { onResize(it.roundToInt()) }
|
||||
KeySlider(
|
||||
label = stringResource(R.string.screen_key_opacity),
|
||||
value = "${(opacity * 100).roundToInt()}%",
|
||||
current = opacity,
|
||||
min = 0.2f,
|
||||
max = 1f,
|
||||
modifier = Modifier.weight(1f),
|
||||
onChange = onOpacity,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun KeySlider(
|
||||
label: String,
|
||||
value: String,
|
||||
current: Float,
|
||||
min: Float,
|
||||
max: Float,
|
||||
modifier: Modifier,
|
||||
onChange: (Float) -> Unit,
|
||||
) {
|
||||
Row(modifier, verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(label, style = MaterialTheme.typography.bodySmall, maxLines = 1)
|
||||
Slider(current, onChange, Modifier.weight(1f).height(28.dp), valueRange = min..max)
|
||||
Text(
|
||||
value, Modifier.width(32.dp), style = MaterialTheme.typography.bodySmall,
|
||||
fontWeight = FontWeight.SemiBold, maxLines = 1,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun Chip(
|
||||
label: String,
|
||||
selected: Boolean,
|
||||
modifier: Modifier = Modifier,
|
||||
enabled: Boolean = true,
|
||||
onClick: () -> Unit,
|
||||
) {
|
||||
val p = LocalPalette.current
|
||||
Box(
|
||||
modifier
|
||||
.background(
|
||||
if (selected) p.primary.copy(alpha = 0.18f) else p.line2.copy(alpha = 0.28f),
|
||||
CircleShape,
|
||||
)
|
||||
.clickable(enabled = enabled, onClick = onClick)
|
||||
.padding(vertical = 6.dp),
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
Text(
|
||||
label, style = MaterialTheme.typography.labelSmall, maxLines = 1, overflow = TextOverflow.Ellipsis,
|
||||
color = when {
|
||||
!enabled -> p.onBackground.copy(alpha = 0.28f)
|
||||
selected -> p.primary
|
||||
else -> p.onBackground.copy(alpha = 0.7f)
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun importImage(context: Context, uri: Uri, codes: List<Int>): String? {
|
||||
val dir = File(context.filesDir, ScreenKeys.IMAGE_DIR).apply { mkdirs() }
|
||||
val name = "key_" + codes.joinToString("_") + "_" + System.currentTimeMillis() + ".png"
|
||||
val longest = (ScreenKeys.MAX_SIZE * context.resources.displayMetrics.density).toInt()
|
||||
return runCatching {
|
||||
val bounds = BitmapFactory.Options().apply { inJustDecodeBounds = true }
|
||||
context.contentResolver.openInputStream(uri)?.use { BitmapFactory.decodeStream(it, null, bounds) }
|
||||
val source = maxOf(bounds.outWidth, bounds.outHeight)
|
||||
if (source <= 0) return@runCatching null
|
||||
var sample = 1
|
||||
while (source / (sample * 2) >= longest) sample *= 2
|
||||
val bitmap = context.contentResolver.openInputStream(uri)?.use {
|
||||
BitmapFactory.decodeStream(it, null, BitmapFactory.Options().apply { inSampleSize = sample })
|
||||
} ?: return@runCatching null
|
||||
val scale = longest.toFloat() / maxOf(bitmap.width, bitmap.height)
|
||||
val scaled = if (scale < 1f) {
|
||||
Bitmap.createScaledBitmap(
|
||||
bitmap,
|
||||
(bitmap.width * scale).toInt().coerceAtLeast(1),
|
||||
(bitmap.height * scale).toInt().coerceAtLeast(1),
|
||||
true,
|
||||
)
|
||||
} else {
|
||||
bitmap
|
||||
}
|
||||
try {
|
||||
val saved = File(dir, name).outputStream().use { scaled.compress(Bitmap.CompressFormat.PNG, 100, it) }
|
||||
if (saved) name else null
|
||||
} finally {
|
||||
if (scaled !== bitmap) bitmap.recycle()
|
||||
scaled.recycle()
|
||||
}
|
||||
}.getOrNull().also { if (it == null) File(dir, name).delete() }
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import androidx.compose.foundation.BorderStroke
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.horizontalScroll
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxHeight
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.systemBarsPadding
|
||||
import androidx.compose.foundation.layout.widthIn
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Close
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
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 androidx.compose.ui.window.Dialog
|
||||
import androidx.compose.ui.window.DialogProperties
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.input.PC_KEYS
|
||||
import com.droiddeck.launcher.input.PC_KEY_ROWS
|
||||
import com.droiddeck.launcher.input.PC_MODIFIERS
|
||||
import com.droiddeck.launcher.input.PcKey
|
||||
import com.droiddeck.launcher.input.pcKeyLabel
|
||||
|
||||
@Composable
|
||||
fun ScreenKeyPicker(
|
||||
onDismiss: () -> Unit,
|
||||
onAdd: (List<Int>) -> Unit,
|
||||
initial: List<Int> = emptyList(),
|
||||
sequence: Boolean = false,
|
||||
sequenceLimit: Int = 4,
|
||||
slots: List<String> = emptyList(),
|
||||
) {
|
||||
var picked by remember { mutableStateOf(initial) }
|
||||
val p = LocalPalette.current
|
||||
val toggle: (Int) -> Unit = { code ->
|
||||
picked = if (sequence) {
|
||||
if (code in picked) picked - code else (picked + code).take(sequenceLimit)
|
||||
} else if (code in PC_MODIFIERS) {
|
||||
if (code in picked) picked - code else picked + code
|
||||
} else {
|
||||
picked.filter { it in PC_MODIFIERS } + code
|
||||
}
|
||||
}
|
||||
val rows = remember {
|
||||
val functionRow = PC_KEY_ROWS[0]
|
||||
val nav = listOfNotNull(PC_KEYS[110], PC_KEYS[111], PC_KEYS[102], PC_KEYS[107], PC_KEYS[104], PC_KEYS[109]) +
|
||||
listOfNotNull(PC_KEYS[103], PC_KEYS[105], PC_KEYS[108], PC_KEYS[106])
|
||||
listOf(functionRow.take(13), nav) + PC_KEY_ROWS.drop(1)
|
||||
}
|
||||
val unit = remember { rows.maxOf { row -> row.fold(0f) { sum, key -> sum + key.weight } } }
|
||||
Dialog(onDismissRequest = onDismiss, properties = DialogProperties(usePlatformDefaultWidth = false)) {
|
||||
Box(Modifier.fillMaxSize().systemBarsPadding().padding(10.dp), contentAlignment = Alignment.Center) {
|
||||
Surface(
|
||||
Modifier.widthIn(max = 820.dp).fillMaxWidth().fillMaxHeight(), shape = RoundedCornerShape(20.dp),
|
||||
color = p.background, contentColor = p.onBackground, border = BorderStroke(1.dp, p.line2),
|
||||
) {
|
||||
Column {
|
||||
Row(Modifier.fillMaxWidth().padding(start = 16.dp, end = 6.dp), verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(stringResource(R.string.screen_keys_add), Modifier.weight(1f), style = MaterialTheme.typography.titleMedium, fontWeight = FontWeight.SemiBold)
|
||||
IconButton(onClick = onDismiss) { Icon(Icons.Default.Close, null) }
|
||||
}
|
||||
Row(
|
||||
Modifier.fillMaxWidth().heightIn(min = 26.dp).horizontalScroll(rememberScrollState()).padding(horizontal = 16.dp),
|
||||
horizontalArrangement = Arrangement.spacedBy(6.dp), verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
if (sequence && slots.size >= sequenceLimit) {
|
||||
slots.take(sequenceLimit).forEachIndexed { index, arrow ->
|
||||
val code = picked.getOrNull(index)
|
||||
Surface(
|
||||
shape = RoundedCornerShape(8.dp),
|
||||
color = if (code == null) p.line2.copy(alpha = 0.2f) else p.primary.copy(alpha = 0.16f),
|
||||
modifier = if (code == null) Modifier else Modifier.clickable { picked = picked - code },
|
||||
) {
|
||||
Text(
|
||||
if (code == null) arrow else "$arrow ${pcKeyLabel(LocalContext.current, code)}",
|
||||
Modifier.padding(horizontal = 8.dp, vertical = 2.dp),
|
||||
style = MaterialTheme.typography.labelMedium,
|
||||
)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
picked.forEach { code ->
|
||||
Surface(
|
||||
shape = RoundedCornerShape(8.dp), color = p.primary.copy(alpha = 0.16f),
|
||||
modifier = Modifier.clickable { picked = picked - code },
|
||||
) {
|
||||
Text(pcKeyLabel(LocalContext.current, code), Modifier.padding(horizontal = 8.dp, vertical = 2.dp), style = MaterialTheme.typography.labelMedium)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
LazyColumn(Modifier.weight(1f).fillMaxWidth(), contentPadding = PaddingValues(vertical = 6.dp), verticalArrangement = Arrangement.spacedBy(4.dp)) {
|
||||
items(rows.size) { index ->
|
||||
val row = rows[index]
|
||||
Row(
|
||||
Modifier.fillMaxWidth().padding(horizontal = 16.dp),
|
||||
horizontalArrangement = Arrangement.spacedBy(4.dp),
|
||||
) {
|
||||
row.forEach { key -> KeyCell(key, key.code in picked, Modifier.weight(key.weight)) { toggle(key.code) } }
|
||||
if (row.sumOf { it.weight.toDouble() } < unit) {
|
||||
Spacer(Modifier.weight(unit - row.fold(0f) { sum, key -> sum + key.weight }))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Row(Modifier.fillMaxWidth().padding(horizontal = 16.dp, vertical = 8.dp), horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
Button(
|
||||
onClick = { onAdd(picked) },
|
||||
enabled = picked.isNotEmpty(),
|
||||
modifier = Modifier.weight(1f),
|
||||
) {
|
||||
Text(stringResource(R.string.screen_keys_add))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun KeyCell(key: PcKey, selected: Boolean, modifier: Modifier, onClick: () -> Unit) {
|
||||
val p = LocalPalette.current
|
||||
val label = pcKeyLabel(LocalContext.current, key.code)
|
||||
Surface(
|
||||
shape = RoundedCornerShape(8.dp),
|
||||
color = if (selected) p.primary.copy(alpha = 0.2f) else p.surface,
|
||||
border = BorderStroke(1.dp, if (selected) p.primary else p.line),
|
||||
modifier = modifier.height(36.dp).clickable(onClick = onClick),
|
||||
) {
|
||||
Box(Modifier.fillMaxSize().padding(horizontal = 2.dp), contentAlignment = Alignment.Center) {
|
||||
Text(
|
||||
label, style = MaterialTheme.typography.labelMedium, maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
fontSize = if (label.length > 4) 10.sp else 12.sp,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.foundation.BorderStroke
|
||||
import androidx.compose.foundation.clickable
|
||||
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.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.systemBarsPadding
|
||||
import androidx.compose.foundation.layout.widthIn
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Close
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.input.ImeAction
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.window.Dialog
|
||||
import androidx.compose.ui.window.DialogProperties
|
||||
import com.droiddeck.launcher.R
|
||||
|
||||
@Composable
|
||||
fun ScreenLayoutPanel(
|
||||
layouts: List<String>,
|
||||
onSave: (String) -> Unit,
|
||||
onLoad: (String) -> Unit,
|
||||
onDelete: (String) -> Unit,
|
||||
onImport: (String) -> Unit,
|
||||
exportText: () -> String,
|
||||
onDismiss: () -> Unit,
|
||||
) {
|
||||
val p = LocalPalette.current
|
||||
val context = LocalContext.current
|
||||
var naming by remember { mutableStateOf(false) }
|
||||
var name by remember { mutableStateOf("") }
|
||||
|
||||
val importer = rememberLauncherForActivityResult(ActivityResultContracts.OpenDocument()) { uri ->
|
||||
if (uri == null) return@rememberLauncherForActivityResult
|
||||
val text = runCatching {
|
||||
context.contentResolver.openInputStream(uri)?.use { it.readBytes().toString(Charsets.UTF_8) }
|
||||
}.getOrNull()
|
||||
if (text != null) onImport(text)
|
||||
}
|
||||
val exporter = rememberLauncherForActivityResult(ActivityResultContracts.CreateDocument("application/json")) { uri ->
|
||||
if (uri == null) return@rememberLauncherForActivityResult
|
||||
runCatching { context.contentResolver.openOutputStream(uri)?.use { it.write(exportText().toByteArray()) } }
|
||||
}
|
||||
|
||||
Dialog(onDismissRequest = onDismiss, properties = DialogProperties(usePlatformDefaultWidth = false)) {
|
||||
Box(Modifier.fillMaxSize().systemBarsPadding().padding(16.dp), contentAlignment = Alignment.Center) {
|
||||
Surface(
|
||||
Modifier.widthIn(max = 520.dp).fillMaxWidth(), shape = RoundedCornerShape(22.dp),
|
||||
color = p.background, contentColor = p.onBackground, border = BorderStroke(1.dp, p.line2),
|
||||
) {
|
||||
Column(Modifier.padding(start = 20.dp, end = 8.dp, top = 6.dp, bottom = 12.dp)) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(
|
||||
stringResource(R.string.screen_key_layout), Modifier.weight(1f),
|
||||
style = MaterialTheme.typography.titleMedium, fontWeight = FontWeight.SemiBold,
|
||||
)
|
||||
IconButton(onClick = onDismiss) { Icon(Icons.Default.Close, null) }
|
||||
}
|
||||
Row(Modifier.fillMaxWidth().padding(end = 12.dp), horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
TextButton(onClick = { naming = true }) { Text(stringResource(R.string.screen_key_layout_save)) }
|
||||
TextButton(onClick = { importer.launch(arrayOf("application/json", "text/plain", "*/*")) }) {
|
||||
Text(stringResource(R.string.boot_movie_import))
|
||||
}
|
||||
TextButton(onClick = { exporter.launch("droiddeck-layout.icp") }) {
|
||||
Text(stringResource(R.string.screen_key_layout_export))
|
||||
}
|
||||
}
|
||||
Column(Modifier.padding(end = 12.dp).heightIn(max = 320.dp).verticalScroll(rememberScrollState())) {
|
||||
layouts.forEach { layout ->
|
||||
Row(Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(
|
||||
layout, Modifier.weight(1f).clickable { onLoad(layout) }.padding(vertical = 14.dp),
|
||||
style = MaterialTheme.typography.bodyLarge,
|
||||
)
|
||||
TextButton(onClick = { onDelete(layout) }) {
|
||||
Text(stringResource(R.string.common_delete), color = p.error)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (naming) {
|
||||
Dialog(onDismissRequest = { naming = false }, properties = DialogProperties(usePlatformDefaultWidth = false)) {
|
||||
Box(Modifier.fillMaxSize().systemBarsPadding().padding(16.dp), contentAlignment = Alignment.Center) {
|
||||
Surface(
|
||||
Modifier.widthIn(max = 520.dp).fillMaxWidth(), shape = RoundedCornerShape(22.dp),
|
||||
color = p.background, contentColor = p.onBackground, border = BorderStroke(1.dp, p.line2),
|
||||
) {
|
||||
Column(Modifier.padding(20.dp), verticalArrangement = Arrangement.spacedBy(12.dp)) {
|
||||
OutlinedTextField(
|
||||
name, { name = it.take(24) }, Modifier.fillMaxWidth(), singleLine = true,
|
||||
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),
|
||||
)
|
||||
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.End) {
|
||||
TextButton(onClick = { naming = false }) { Text(stringResource(R.string.common_cancel)) }
|
||||
Button(onClick = { onSave(name.trim()); naming = false }, enabled = name.isNotBlank()) {
|
||||
Text(stringResource(R.string.screen_key_layout_save))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,6 @@ import androidx.compose.animation.core.FastOutSlowInEasing
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.material.icons.filled.Pause
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.foundation.Canvas
|
||||
@@ -223,7 +222,7 @@ fun LoadingOverlay(
|
||||
.background(colors.background)
|
||||
.blockTouches(),
|
||||
) {
|
||||
CapsuleWall(games, driftMs = 65_000, modifier = Modifier.alpha(0.3f))
|
||||
CapsuleWall(games, driftMs = 65_000, modifier = Modifier.alpha(0.3f), pauseWhenIdle = false)
|
||||
Box(
|
||||
Modifier.fillMaxSize().drawBehind {
|
||||
drawRect(
|
||||
@@ -345,37 +344,3 @@ private fun CancelHint(onCancel: () -> Unit, modifier: Modifier = Modifier) {
|
||||
Text(stringResource(R.string.common_cancel), fontSize = 13.sp, color = colors.onSurfaceVariant)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun SessionPausedOverlay(title: String = stringResource(R.string.load_steam_paused), onResume: () -> Unit) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val pal = LocalPalette.current
|
||||
val resumeFocus = remember { FocusRequester() }
|
||||
LaunchedEffect(Unit) {
|
||||
androidx.compose.runtime.withFrameNanos { }
|
||||
runCatching { resumeFocus.requestFocus() }
|
||||
}
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.background(pal.background.copy(alpha = 0.94f))
|
||||
.blockTouches(),
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.spacedBy(10.dp),
|
||||
modifier = Modifier.widthIn(max = 440.dp).padding(32.dp),
|
||||
) {
|
||||
Box(contentAlignment = Alignment.Center, modifier = Modifier.padding(bottom = 6.dp).size(64.dp).border(2.dp, pal.line2, CircleShape)) {
|
||||
Icon(Icons.Filled.Pause, contentDescription = null, tint = colors.onBackground, modifier = Modifier.size(30.dp))
|
||||
}
|
||||
Text(title, fontSize = 28.sp, fontWeight = FontWeight.Bold, color = colors.onBackground, textAlign = TextAlign.Center)
|
||||
PrimaryButton(
|
||||
stringResource(R.string.resume_session),
|
||||
modifier = Modifier.padding(top = 14.dp).focusRequester(resumeFocus).controllerConfirm(onClick = onResume),
|
||||
onClick = onResume,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -193,6 +193,7 @@ private class DrawerFocus {
|
||||
|
||||
class DrawerActions(
|
||||
val steam: Boolean,
|
||||
val direct: Boolean = false,
|
||||
val title: String? = null,
|
||||
val isHomeApp: Boolean,
|
||||
val androidApps: List<HomeApp.LaunchableApp>,
|
||||
@@ -208,6 +209,9 @@ class DrawerActions(
|
||||
val onScreenButtonsVisible: Boolean,
|
||||
val suspendPolicy: String,
|
||||
val steamDownloadsInBackground: Boolean = false,
|
||||
val micAvailable: Boolean = false,
|
||||
val micEnabled: Boolean = false,
|
||||
val onMicEnabled: (Boolean) -> Unit = {},
|
||||
val backActionsInverted: Boolean,
|
||||
val padType: String? = null,
|
||||
val onPadType: (String) -> Unit = {},
|
||||
@@ -258,6 +262,10 @@ class DrawerActions(
|
||||
val onLowLatencyTouch: (Boolean) -> Unit = {},
|
||||
val onTouch: (String) -> Unit,
|
||||
val onGestureSettings: () -> Unit = {},
|
||||
val onScreenKeys: (() -> Unit)? = null,
|
||||
val onScreenLayouts: (() -> Unit)? = null,
|
||||
val screenKeysShown: Boolean = true,
|
||||
val onScreenKeysShown: (Boolean) -> Unit = {},
|
||||
val onFexPreset: (String) -> Unit,
|
||||
val onUpscaler: (Int) -> Unit = {},
|
||||
val onUpscaleSharpness: (Int) -> Unit = {},
|
||||
@@ -423,7 +431,10 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
|
||||
) {
|
||||
Text(a.title ?: if (a.steam) stringResource(R.string.drawer_steam) else stringResource(R.string.drawer_desktop), fontSize = if (short) 18.sp else 20.sp, fontWeight = FontWeight.Bold,
|
||||
color = colors.onBackground, maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f))
|
||||
if (a.onSteamMenu != null && a.onQam != null) {
|
||||
if (a.pipSupported) SteamActionPill(
|
||||
stringResource(R.string.pip_title), Icons.Outlined.PictureInPictureAlt, focus.track(page, "pip"),
|
||||
) { host.open = null; a.onPip() }
|
||||
if (a.steam && a.onSteamMenu != null && a.onQam != null) {
|
||||
val qamInteraction = remember { MutableInteractionSource() }
|
||||
var qamStartedOnPress by remember { mutableStateOf(false) }
|
||||
LaunchedEffect(qamInteraction) {
|
||||
@@ -435,13 +446,13 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
|
||||
}
|
||||
}
|
||||
}
|
||||
SteamActionPill(stringResource(R.string.drawer_steam_menu), Icons.Outlined.Home, focus.track(page, "steam")) {
|
||||
SteamActionPill(stringResource(R.string.drawer_steam_menu), Icons.Outlined.Home, focus.track(page, "steam"), shortcut = "⧉") {
|
||||
host.open = null
|
||||
a.onSteamMenu.invoke()
|
||||
}
|
||||
SteamActionPill(
|
||||
stringResource(R.string.drawer_open_qam), Icons.Outlined.MoreHoriz, focus.track(page, "qam"),
|
||||
interactionSource = qamInteraction,
|
||||
interactionSource = qamInteraction, shortcut = "☰",
|
||||
onConfirm = { host.open = null; a.onQam.invoke() },
|
||||
) {
|
||||
host.open = null
|
||||
@@ -549,6 +560,23 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
|
||||
ActionRow(stringResource(R.string.gesture_settings), stringResource(R.string.gesture_settings_hint),
|
||||
stringResource(R.string.ctrl_edit), a.onGestureSettings,
|
||||
modifier = focus.track(page, "gesture-settings"))
|
||||
if (a.onScreenKeys != null) {
|
||||
SettingsRow(stringResource(R.string.screen_keys), null) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(10.dp),
|
||||
) {
|
||||
SecondaryButton(stringResource(R.string.ctrl_edit),
|
||||
modifier = focus.track(page, "screen-keys"), onClick = a.onScreenKeys)
|
||||
a.onScreenLayouts?.let { open ->
|
||||
SecondaryButton(stringResource(R.string.screen_key_layout),
|
||||
modifier = focus.track(page, "screen-key-layouts"), onClick = open)
|
||||
}
|
||||
ToggleSwitch(a.screenKeysShown, true,
|
||||
modifier = focus.track(page, "screen-keys-shown"), onChange = a.onScreenKeysShown)
|
||||
}
|
||||
}
|
||||
}
|
||||
ChoiceRow(host, "osc", stringResource(R.string.mode_osc), null,
|
||||
if (a.steam) listOf(SessionPrefs.OSC_AUTO to stringResource(R.string.common_auto), SessionPrefs.OSC_ALWAYS to stringResource(R.string.common_always), SessionPrefs.OSC_STEAM_TOUCH to stringResource(R.string.osc_steam_touch), SessionPrefs.OSC_STEAM_QAM to stringResource(R.string.mode_osc_qam), SessionPrefs.OSC_NEVER to stringResource(R.string.common_never))
|
||||
else listOf(SessionPrefs.OSC_AUTO to stringResource(R.string.common_auto), SessionPrefs.OSC_ALWAYS to stringResource(R.string.common_always), SessionPrefs.OSC_NEVER to stringResource(R.string.common_never)),
|
||||
@@ -613,11 +641,11 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
|
||||
steamVr = { SteamVrRow(a) })
|
||||
}
|
||||
SessionDrawerPage.GAMES -> {
|
||||
if (a.steam) SelectedGameProfileGroup(host, a) { key -> focus.track(page, key) }
|
||||
if (a.steam || a.direct) SelectedGameProfileGroup(host, a) { key -> focus.track(page, key) }
|
||||
Text(stringResource(R.string.fex_next_launch), fontSize = 12.sp,
|
||||
color = colors.onSurfaceVariant, modifier = Modifier.padding(horizontal = 14.dp, vertical = 8.dp))
|
||||
TextureFilteringGroup(host, a) { key -> focus.track(page, key) }
|
||||
if (a.steam) SettingsGroup(stringResource(R.string.game_settings_title)) {
|
||||
if (a.steam || a.direct) SettingsGroup(stringResource(R.string.game_settings_title)) {
|
||||
DrawerFexPresetRow(host, a, focus.track(page, "fex"))
|
||||
DrawerNoSteamRow(host, a, focus.track(page, "no-steam"))
|
||||
GameEnvironmentRow(
|
||||
@@ -669,6 +697,9 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
|
||||
}
|
||||
}
|
||||
SettingsGroup(stringResource(R.string.drawer_session_behavior)) {
|
||||
if (a.micAvailable) ToggleRow(host, "microphone", stringResource(R.string.mode_mic),
|
||||
stringResource(R.string.drawer_mic_hint), a.micEnabled,
|
||||
chipModifier = focus.track(page, "microphone"), onChange = a.onMicEnabled)
|
||||
ChoiceRow(
|
||||
host, "suspend", stringResource(R.string.mode_suspend),
|
||||
null,
|
||||
@@ -705,8 +736,6 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
|
||||
a.pipAutoEnter, onChange = a.onPipAutoEnter)
|
||||
}
|
||||
Column(Modifier.fillMaxWidth().padding(top = 12.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
if (a.pipSupported) DrawerActionButton(stringResource(R.string.pip_title), Icons.Outlined.PictureInPictureAlt,
|
||||
modifier = focus.track(page, "pip")) { host.open = null; a.onPip() }
|
||||
if (!a.isHomeApp) DrawerActionButton(stringResource(R.string.drawer_background), Icons.AutoMirrored.Outlined.ExitToApp,
|
||||
modifier = focus.track(page, "background")) { host.open = null; a.onBackground() }
|
||||
}
|
||||
@@ -812,6 +841,7 @@ private fun SteamActionPill(
|
||||
description: String, icon: androidx.compose.ui.graphics.vector.ImageVector, modifier: Modifier,
|
||||
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
|
||||
onConfirm: (() -> Unit)? = null,
|
||||
shortcut: String? = null,
|
||||
onClick: () -> Unit,
|
||||
) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
@@ -820,7 +850,7 @@ private fun SteamActionPill(
|
||||
val shape = RoundedCornerShape(22.dp)
|
||||
Box(
|
||||
contentAlignment = Alignment.Center,
|
||||
modifier = modifier.size(width = 52.dp, height = 44.dp).semantics { contentDescription = description }
|
||||
modifier = modifier.size(44.dp).semantics { contentDescription = description }
|
||||
.clip(shape).background(if (hot) pal.signal.copy(alpha = 0.14f) else Color.Transparent)
|
||||
.glideBorder(hot, shape, pal.signal, pal.line)
|
||||
.hoverable(interactionSource)
|
||||
@@ -828,6 +858,10 @@ private fun SteamActionPill(
|
||||
.controllerConfirm(onClick = onConfirm ?: onClick),
|
||||
) {
|
||||
Icon(icon, contentDescription = null, tint = if (hot) pal.signal else colors.onBackground, modifier = Modifier.size(20.dp))
|
||||
if (shortcut != null) Text(
|
||||
shortcut, fontSize = 8.sp, lineHeight = 9.sp, color = colors.onSurfaceVariant,
|
||||
modifier = Modifier.align(Alignment.BottomEnd).padding(end = 8.dp, bottom = 6.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,276 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import android.os.Build
|
||||
import androidx.compose.animation.core.Animatable
|
||||
import androidx.compose.animation.core.CubicBezierEasing
|
||||
import androidx.compose.animation.core.FastOutLinearInEasing
|
||||
import androidx.compose.animation.core.LinearEasing
|
||||
import androidx.compose.animation.core.LinearOutSlowInEasing
|
||||
import androidx.compose.animation.core.Spring
|
||||
import androidx.compose.animation.core.animateFloat
|
||||
import androidx.compose.animation.core.animateFloatAsState
|
||||
import androidx.compose.animation.core.infiniteRepeatable
|
||||
import androidx.compose.animation.core.keyframes
|
||||
import androidx.compose.animation.core.rememberInfiniteTransition
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.BoxScope
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.offset
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.rounded.PlayArrow
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.State
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberUpdatedState
|
||||
import androidx.compose.runtime.snapshotFlow
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.runtime.withFrameNanos
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.blur
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.draw.drawWithContent
|
||||
import androidx.compose.ui.draw.drawBehind
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.geometry.Offset
|
||||
import androidx.compose.ui.geometry.Size
|
||||
import androidx.compose.ui.graphics.Brush
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.ColorFilter
|
||||
import androidx.compose.ui.graphics.ColorMatrix
|
||||
import androidx.compose.ui.graphics.ImageBitmap
|
||||
import androidx.compose.ui.graphics.StrokeCap
|
||||
import androidx.compose.ui.graphics.drawscope.Stroke
|
||||
import androidx.compose.ui.graphics.drawscope.rotate
|
||||
import androidx.compose.ui.graphics.graphicsLayer
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
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.unit.IntOffset
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.droiddeck.launcher.R
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withTimeoutOrNull
|
||||
|
||||
/** The last game frame, captured as the session left the screen, and where it sat in the overlay. */
|
||||
class PausedFrame(val image: ImageBitmap, val bounds: android.graphics.Rect)
|
||||
|
||||
private const val CARD_SCALE = 0.82f
|
||||
private const val FRAME_WAIT_MS = 600L
|
||||
|
||||
private fun tone(saturation: Float, brightness: Float): ColorMatrix =
|
||||
ColorMatrix().apply {
|
||||
setToSaturation(saturation)
|
||||
timesAssign(ColorMatrix().apply { setToScale(brightness, brightness, brightness, 1f) })
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun SessionPausedOverlay(
|
||||
suspended: Boolean,
|
||||
engaged: Boolean,
|
||||
failures: Int,
|
||||
frame: PausedFrame?,
|
||||
title: String,
|
||||
onResume: () -> Unit,
|
||||
onFrameNeeded: () -> Unit,
|
||||
onHidden: () -> Unit,
|
||||
) {
|
||||
val currentFrame by rememberUpdatedState(frame)
|
||||
var shown by remember { mutableStateOf(suspended) }
|
||||
val lift = remember { Animatable(if (suspended) 1f else 0f) }
|
||||
val orb = remember { Animatable(if (suspended) 1f else 0f) }
|
||||
val press = remember { Animatable(1f) }
|
||||
val ring = remember { Animatable(0f) }
|
||||
val shake = remember { Animatable(0f) }
|
||||
|
||||
LaunchedEffect(suspended, engaged) {
|
||||
when {
|
||||
suspended && !engaged -> {
|
||||
if (!shown) {
|
||||
if (currentFrame == null) {
|
||||
onFrameNeeded()
|
||||
withTimeoutOrNull(FRAME_WAIT_MS) { snapshotFlow { currentFrame }.first { it != null } }
|
||||
}
|
||||
// Pausing mostly happens while the screen is off or the app is away, so it appears already settled.
|
||||
press.snapTo(1f)
|
||||
ring.snapTo(0f)
|
||||
lift.snapTo(1f)
|
||||
orb.snapTo(1f)
|
||||
shown = true
|
||||
return@LaunchedEffect
|
||||
}
|
||||
launch { press.animateTo(1f, Motion.sp(0.5f, Spring.StiffnessMedium)) }
|
||||
launch { ring.animateTo(0f, Motion.tw(200)) }
|
||||
orb.animateTo(1f, Motion.tw(200))
|
||||
}
|
||||
suspended -> {
|
||||
if (!shown) return@LaunchedEffect
|
||||
launch { orb.animateTo(1f, Motion.tw(200)) }
|
||||
launch { press.animateTo(0.92f, Motion.tw(140)) }
|
||||
ring.animateTo(0.25f, Motion.tw(140))
|
||||
ring.animateTo(0.8f, Motion.tw(650, easing = CubicBezierEasing(0.1f, 0.6f, 0.3f, 1f)))
|
||||
ring.animateTo(0.92f, Motion.tw(2000, easing = LinearOutSlowInEasing))
|
||||
}
|
||||
shown -> {
|
||||
ring.animateTo(1f, Motion.tw(110))
|
||||
coroutineScope {
|
||||
launch { orb.animateTo(0f, Motion.tw(220, easing = FastOutLinearInEasing)) }
|
||||
lift.animateTo(0f, Motion.sp(0.62f, 380f))
|
||||
}
|
||||
shown = false
|
||||
ring.snapTo(0f)
|
||||
press.snapTo(1f)
|
||||
onHidden()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val seenFailures = remember { mutableIntStateOf(failures) }
|
||||
LaunchedEffect(failures) {
|
||||
if (failures == seenFailures.intValue) return@LaunchedEffect
|
||||
seenFailures.intValue = failures
|
||||
if (!shown || Motion.scale == 0f) return@LaunchedEffect
|
||||
shake.animateTo(0f, keyframes {
|
||||
durationMillis = Motion.ms(360)
|
||||
10f at Motion.ms(60)
|
||||
-8f at Motion.ms(140)
|
||||
5f at Motion.ms(220)
|
||||
-2f at Motion.ms(300)
|
||||
})
|
||||
}
|
||||
|
||||
if (!shown) return
|
||||
|
||||
val presence = lift.value.coerceIn(0f, 1f)
|
||||
val idle = suspended && !engaged
|
||||
val focus = remember { FocusRequester() }
|
||||
LaunchedEffect(Unit) {
|
||||
withFrameNanos { }
|
||||
runCatching { focus.requestFocus() }
|
||||
}
|
||||
val resumeLabel = stringResource(R.string.resume_session)
|
||||
Box(
|
||||
contentAlignment = Alignment.Center,
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.semantics { contentDescription = title }
|
||||
.focusRequester(focus)
|
||||
.controllerConfirm(enabled = idle, onClick = onResume)
|
||||
.clickable(
|
||||
interactionSource = remember { MutableInteractionSource() },
|
||||
indication = null,
|
||||
role = Role.Button,
|
||||
onClickLabel = resumeLabel,
|
||||
) { if (idle) onResume() },
|
||||
) {
|
||||
if (frame != null) {
|
||||
PausedCard(frame, lift.value, presence)
|
||||
} else {
|
||||
Box(Modifier.fillMaxSize().graphicsLayer { alpha = presence }.background(Color.Black.copy(alpha = 0.55f)))
|
||||
}
|
||||
ResumeOrb(orb.value, press.value, ring.value, shake.value, idle)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun BoxScope.PausedCard(frame: PausedFrame, lift: Float, presence: Float) {
|
||||
val density = LocalDensity.current
|
||||
val bounds = frame.bounds
|
||||
val ambient = remember { ColorFilter.colorMatrix(tone(0.1f, 0.3f)) }
|
||||
Box(Modifier.fillMaxSize().graphicsLayer { alpha = presence }.background(Color.Black)) {
|
||||
Image(
|
||||
frame.image, contentDescription = null, contentScale = ContentScale.Crop, colorFilter = ambient,
|
||||
modifier = Modifier.fillMaxSize().then(if (Build.VERSION.SDK_INT >= 31) Modifier.blur(32.dp) else Modifier),
|
||||
)
|
||||
}
|
||||
Image(
|
||||
frame.image, contentDescription = null, contentScale = ContentScale.FillBounds,
|
||||
colorFilter = ColorFilter.colorMatrix(tone(1f - 0.92f * presence, 1f - 0.45f * presence)),
|
||||
modifier = Modifier
|
||||
.align(Alignment.TopStart)
|
||||
.offset { IntOffset(bounds.left, bounds.top) }
|
||||
.size(with(density) { bounds.width().toDp() }, with(density) { bounds.height().toDp() })
|
||||
.graphicsLayer {
|
||||
val scale = 1f - (1f - CARD_SCALE) * lift
|
||||
scaleX = scale
|
||||
scaleY = scale
|
||||
shape = RoundedCornerShape((20f * presence).dp)
|
||||
clip = true
|
||||
shadowElevation = 24.dp.toPx() * presence
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ResumeOrb(presence: Float, press: Float, ring: Float, shake: Float, idle: Boolean) {
|
||||
val glintAlpha by animateFloatAsState(if (idle) 1f else 0f, Motion.tw(160), label = "glintAlpha")
|
||||
val glint: State<Float>? = if (Motion.scale > 0f) {
|
||||
rememberInfiniteTransition(label = "glint").animateFloat(
|
||||
0f, 360f, infiniteRepeatable(tween(Motion.ms(3600), easing = LinearEasing)), label = "glintAngle",
|
||||
)
|
||||
} else null
|
||||
Box(
|
||||
contentAlignment = Alignment.Center,
|
||||
modifier = Modifier
|
||||
.size(96.dp)
|
||||
.graphicsLayer {
|
||||
val scale = press * (0.4f + 0.6f * presence)
|
||||
scaleX = scale
|
||||
scaleY = scale
|
||||
alpha = presence.coerceIn(0f, 1f)
|
||||
translationX = shake.dp.toPx()
|
||||
}
|
||||
.drawBehind {
|
||||
val halo = size.minDimension * 0.8f
|
||||
drawCircle(Brush.radialGradient(0.6f to Color.Black.copy(alpha = 0.35f), 1f to Color.Transparent, radius = halo), radius = halo)
|
||||
}
|
||||
.clip(CircleShape)
|
||||
.background(Color.White.copy(alpha = 0.08f))
|
||||
.drawWithContent {
|
||||
drawContent()
|
||||
val stroke = 2.5.dp.toPx()
|
||||
val radius = size.minDimension / 2f * 0.92f
|
||||
if (glint != null && glintAlpha > 0f) {
|
||||
rotate(glint.value) {
|
||||
drawCircle(
|
||||
Brush.sweepGradient(
|
||||
0f to Color.Transparent,
|
||||
0.083f to Color.White.copy(alpha = 0.4f * glintAlpha),
|
||||
0.166f to Color.Transparent,
|
||||
1f to Color.Transparent,
|
||||
),
|
||||
radius = radius, style = Stroke(stroke),
|
||||
)
|
||||
}
|
||||
}
|
||||
if (ring > 0f) {
|
||||
drawArc(
|
||||
Color.White, startAngle = -90f, sweepAngle = 360f * ring.coerceAtMost(1f), useCenter = false,
|
||||
topLeft = Offset(center.x - radius, center.y - radius), size = Size(radius * 2f, radius * 2f),
|
||||
style = Stroke(stroke, cap = StrokeCap.Round),
|
||||
)
|
||||
}
|
||||
},
|
||||
) {
|
||||
Icon(Icons.Rounded.PlayArrow, contentDescription = null, tint = Color.White, modifier = Modifier.size(48.dp))
|
||||
}
|
||||
}
|
||||
@@ -5,12 +5,6 @@ import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import com.droiddeck.launcher.R
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.animation.core.FastOutSlowInEasing
|
||||
import androidx.compose.animation.core.RepeatMode
|
||||
import androidx.compose.runtime.State
|
||||
import androidx.compose.animation.core.animateFloat
|
||||
import androidx.compose.animation.core.infiniteRepeatable
|
||||
import androidx.compose.animation.core.rememberInfiniteTransition
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
@@ -76,6 +70,38 @@ private const val WALL_MIN_GAMES = 4
|
||||
private const val WALL_DISTINCT = 40
|
||||
|
||||
private const val DRIFT_STEP_NS = 15_000_000L
|
||||
private const val AMBIENT_IDLE_NS = 20_000_000_000L
|
||||
|
||||
@Composable
|
||||
internal fun ambientAwake(): Boolean {
|
||||
val poked = Ambient.poked
|
||||
var awake by remember { mutableStateOf(true) }
|
||||
LaunchedEffect(poked) {
|
||||
awake = true
|
||||
kotlinx.coroutines.delay(AMBIENT_IDLE_NS / 1_000_000)
|
||||
awake = false
|
||||
}
|
||||
return awake
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun AmbientFrames(pauseWhenIdle: Boolean = true, step: (Long) -> Unit) {
|
||||
val onStep = androidx.compose.runtime.rememberUpdatedState(step)
|
||||
val poked = if (pauseWhenIdle) Ambient.poked else 0L
|
||||
if (Motion.scale != 0f) LaunchedEffect(poked, pauseWhenIdle) {
|
||||
var shown = 0L
|
||||
var end = Long.MAX_VALUE
|
||||
while (shown < end) withFrameNanos { now ->
|
||||
if (shown == 0L) {
|
||||
shown = now
|
||||
if (pauseWhenIdle) end = now + AMBIENT_IDLE_NS
|
||||
} else if (now - shown >= DRIFT_STEP_NS) {
|
||||
onStep.value(now - shown)
|
||||
shown = now
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun SteamHome(s: FrontEndState, a: FrontEndActions, modifier: Modifier) {
|
||||
@@ -179,6 +205,7 @@ internal fun CapsuleWall(
|
||||
modifier: Modifier = Modifier,
|
||||
owned: List<Pair<Int, java.io.File>> = emptyList(),
|
||||
featured: List<com.droiddeck.launcher.frontend.SteamFeatured.Game> = emptyList(),
|
||||
pauseWhenIdle: Boolean = true,
|
||||
) {
|
||||
val pal = LocalPalette.current
|
||||
val blank = remember(pal) { WallCapsule(Brush.linearGradient(listOf(pal.surface, pal.background)), edge = pal.line) }
|
||||
@@ -188,7 +215,7 @@ internal fun CapsuleWall(
|
||||
val store = if (owned.isEmpty()) featured.filter { shown.add(it.appId) }.map { it.name to it.art } else emptyList()
|
||||
(library + store).take((WALL_DISTINCT - games.size).coerceAtLeast(0))
|
||||
}
|
||||
TiltedWall(games.size + padding.size, driftMs, modifier) { i ->
|
||||
TiltedWall(games.size + padding.size, driftMs, modifier, pauseWhenIdle = pauseWhenIdle) { i ->
|
||||
when {
|
||||
i < games.size -> WallCapsule(artBrush(hueOf(games[i].name)), games[i].art)
|
||||
i - games.size < padding.size -> padding[i - games.size].let { (seed, art) -> WallCapsule(artBrush(hueOf(seed)), art) }
|
||||
@@ -208,20 +235,13 @@ internal fun TiltedWall(
|
||||
capH: androidx.compose.ui.unit.Dp = 168.dp,
|
||||
gap: androidx.compose.ui.unit.Dp = 14.dp,
|
||||
corner: androidx.compose.ui.unit.Dp = 10.dp,
|
||||
pauseWhenIdle: Boolean = true,
|
||||
capsule: (index: Int) -> WallCapsule,
|
||||
) {
|
||||
val still = Motion.scale == 0f
|
||||
val drift = remember { mutableFloatStateOf(0f) }
|
||||
val period = androidx.compose.runtime.rememberUpdatedState(driftMs)
|
||||
if (!still) LaunchedEffect(Unit) {
|
||||
var shown = 0L
|
||||
while (true) withFrameNanos { now ->
|
||||
if (shown == 0L) shown = now
|
||||
else if (now - shown >= DRIFT_STEP_NS) {
|
||||
drift.floatValue = ((drift.floatValue + (now - shown) / (period.value * 1_000_000.0 * Motion.scale)) % 1.0).toFloat()
|
||||
shown = now
|
||||
}
|
||||
}
|
||||
AmbientFrames(pauseWhenIdle) { dt ->
|
||||
drift.floatValue = ((drift.floatValue + dt / (driftMs * 1_000_000.0 * Motion.scale)) % 1.0).toFloat()
|
||||
}
|
||||
val density = LocalDensity.current
|
||||
BoxWithConstraints(modifier.fillMaxSize()) {
|
||||
@@ -307,10 +327,9 @@ private fun DrawScope.drawCapsule(look: WallCapsule, art: Painter?, radius: Floa
|
||||
private fun CapsuleFan(games: List<Library.SteamGame>) {
|
||||
val pal = LocalPalette.current
|
||||
val density = LocalDensity.current
|
||||
val transition = rememberInfiniteTransition(label = "fan")
|
||||
val floats = listOf(9_000, 11_000, 13_000).map { ms ->
|
||||
transition.animateFloat(0f, 1f, infiniteRepeatable(tween(ms, easing = FastOutSlowInEasing), RepeatMode.Reverse), label = "float")
|
||||
}
|
||||
val clock = remember { androidx.compose.runtime.mutableLongStateOf(0L) }
|
||||
AmbientFrames { clock.longValue += it }
|
||||
val floatMs = listOf(9_000, 11_000, 13_000)
|
||||
val still = Motion.scale == 0f
|
||||
val slots = listOf(
|
||||
FanSlot(0.54f, 0.14f, 0.62f, -9f),
|
||||
@@ -331,7 +350,7 @@ private fun CapsuleFan(games: List<Library.SteamGame>) {
|
||||
for (i in games.indices.reversed()) {
|
||||
val slot = slots[i]
|
||||
val h = maxHeight * slot.height
|
||||
val v: State<Float> = floats[i]
|
||||
val ms = floatMs[i]
|
||||
val look = WallCapsule(artBrush(hueOf(games[i].name)), games[i].art)
|
||||
val art = look.art?.let { rememberCapsuleArt(it, with(density) { Size((h * 2f / 3f).toPx(), h.toPx()) }, radius) }
|
||||
Spacer(
|
||||
@@ -339,7 +358,10 @@ private fun CapsuleFan(games: List<Library.SteamGame>) {
|
||||
.offset(x = maxWidth * slot.x, y = maxHeight * slot.y)
|
||||
.size(h * 2f / 3f, h)
|
||||
.graphicsLayer {
|
||||
val t = if (still) 0f else v.value
|
||||
val t = if (still) 0f else {
|
||||
val phase = (clock.longValue / (ms * 1_000_000.0 * Motion.scale)) % 2.0
|
||||
FastOutSlowInEasing.transform((if (phase < 1.0) phase else 2.0 - phase).toFloat())
|
||||
}
|
||||
rotationZ = slot.lean + 2f * t
|
||||
translationY = -12.dp.toPx() * t
|
||||
shadowElevation = 24.dp.toPx()
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import android.app.Activity
|
||||
import android.widget.Toast
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.animation.core.Spring
|
||||
import androidx.compose.animation.core.animateFloatAsState
|
||||
import androidx.compose.foundation.LocalIndication
|
||||
@@ -51,6 +55,7 @@ import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
@@ -65,6 +70,7 @@ import androidx.compose.ui.graphics.graphicsLayer
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.res.pluralStringResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.Role
|
||||
@@ -74,6 +80,7 @@ import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import coil.compose.AsyncImage
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.files.InAppFilePicker
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import com.droiddeck.launcher.storage.Bucket
|
||||
import com.droiddeck.launcher.storage.CleanItem
|
||||
@@ -84,6 +91,8 @@ import com.droiddeck.launcher.storage.StorageState
|
||||
import com.droiddeck.launcher.storage.ToolReason
|
||||
import com.droiddeck.launcher.storage.ToolState
|
||||
import com.droiddeck.launcher.storage.ToolUsage
|
||||
import com.droiddeck.launcher.stores.StoreInstallRoot
|
||||
import java.io.File
|
||||
import java.text.DateFormat
|
||||
import java.util.Date
|
||||
|
||||
@@ -144,6 +153,113 @@ internal fun StoragePanel(s: FrontEndState, a: FrontEndActions) {
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun DefaultStorageGroup() {
|
||||
val ctx = LocalContext.current
|
||||
var value by remember { mutableStateOf(SessionPrefs.defaultStorage(ctx)) }
|
||||
var open by remember { mutableStateOf(false) }
|
||||
var revision by remember { mutableIntStateOf(0) }
|
||||
val customPath = SessionPrefs.defaultStorageFolder(ctx)
|
||||
val customTarget = remember(customPath, revision) { StoreInstallRoot.customTarget(ctx) }
|
||||
val detected = remember(customPath, revision) { StoreInstallRoot.detectedExternalTarget(ctx) }
|
||||
val customLabel = SessionPrefs.defaultStorageFolderLabel(ctx).ifBlank {
|
||||
customPath.takeIf { it.isNotBlank() }?.let { File(it).name }.orEmpty()
|
||||
}
|
||||
val pickFolder = rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||
if (result.resultCode != Activity.RESULT_OK) return@rememberLauncherForActivityResult
|
||||
val path = InAppFilePicker.pickedPath(result.data) ?: return@rememberLauncherForActivityResult
|
||||
val problem = StoreInstallRoot.prepareDefaultFolder(ctx, File(path))
|
||||
if (problem != null) {
|
||||
Toast.makeText(ctx, ctx.getString(R.string.main_storage_not_usable, problem), Toast.LENGTH_LONG).show()
|
||||
return@rememberLauncherForActivityResult
|
||||
}
|
||||
SessionPrefs.setDefaultStorageFolder(ctx, path, StoreInstallRoot.folderLabel(ctx, File(path)))
|
||||
SessionPrefs.setDefaultStorage(ctx, SessionPrefs.DEFAULT_STORAGE_EXTERNAL)
|
||||
value = SessionPrefs.DEFAULT_STORAGE_EXTERNAL
|
||||
revision++
|
||||
open = false
|
||||
}
|
||||
fun chooseFolder() {
|
||||
open = false
|
||||
val initial = customPath.takeIf { it.isNotBlank() && File(it).isDirectory }
|
||||
?: detected?.root?.parentFile?.takeIf { it.isDirectory }?.absolutePath
|
||||
pickFolder.launch(InAppFilePicker.buildDirIntent(ctx, ctx.getString(R.string.storage_default_choose_folder), initial))
|
||||
}
|
||||
val title = stringResource(R.string.storage_default_title)
|
||||
val chip = when (value) {
|
||||
SessionPrefs.DEFAULT_STORAGE_INTERNAL -> stringResource(R.string.storage_default_internal)
|
||||
SessionPrefs.DEFAULT_STORAGE_EXTERNAL -> when {
|
||||
customPath.isNotBlank() -> customTarget?.label
|
||||
?: "$customLabel · ${stringResource(R.string.storage_default_folder_missing)}"
|
||||
detected != null -> detected.label
|
||||
else -> stringResource(R.string.storage_default_external)
|
||||
}
|
||||
else -> stringResource(R.string.storage_default_ask)
|
||||
}
|
||||
fun pick(next: String) {
|
||||
SessionPrefs.setDefaultStorage(ctx, next)
|
||||
value = next
|
||||
open = false
|
||||
}
|
||||
SettingsGroup(stringResource(R.string.storage_default_group)) {
|
||||
SettingsRow(label = title, hint = stringResource(R.string.storage_default_hint)) {
|
||||
Box {
|
||||
ValueChip(chip, open, modifier = Modifier.testTag("setting-default-storage")) { open = !open }
|
||||
AnchoredMenu(
|
||||
open, onDismiss = { open = false }, title = title,
|
||||
note = stringResource(R.string.storage_default_note),
|
||||
) { firstItemFocus ->
|
||||
MenuItem(
|
||||
stringResource(R.string.storage_default_ask), value == SessionPrefs.DEFAULT_STORAGE_ASK,
|
||||
detail = stringResource(R.string.storage_default_ask_detail),
|
||||
focusRequester = firstItemFocus,
|
||||
) { pick(SessionPrefs.DEFAULT_STORAGE_ASK) }
|
||||
MenuItem(
|
||||
stringResource(R.string.storage_default_internal), value == SessionPrefs.DEFAULT_STORAGE_INTERNAL,
|
||||
) { pick(SessionPrefs.DEFAULT_STORAGE_INTERNAL) }
|
||||
if (detected == null && customPath.isBlank()) {
|
||||
MenuItem(
|
||||
stringResource(R.string.storage_default_external), value == SessionPrefs.DEFAULT_STORAGE_EXTERNAL,
|
||||
detail = stringResource(R.string.storage_default_choose_folder_detail),
|
||||
) { chooseFolder() }
|
||||
} else {
|
||||
if (detected != null) {
|
||||
MenuItem(
|
||||
stringResource(R.string.storage_default_external),
|
||||
value == SessionPrefs.DEFAULT_STORAGE_EXTERNAL && customPath.isBlank(),
|
||||
detail = detected.let { target ->
|
||||
val free = target.freeBytes
|
||||
if (free >= 0) stringResource(R.string.storage_default_external_detail, target.label, gb(free))
|
||||
else target.label
|
||||
},
|
||||
) {
|
||||
SessionPrefs.clearDefaultStorageFolder(ctx)
|
||||
pick(SessionPrefs.DEFAULT_STORAGE_EXTERNAL)
|
||||
revision++
|
||||
}
|
||||
}
|
||||
if (customPath.isNotBlank()) {
|
||||
MenuItem(
|
||||
stringResource(R.string.storage_default_folder, customLabel),
|
||||
value == SessionPrefs.DEFAULT_STORAGE_EXTERNAL,
|
||||
detail = customTarget?.let { target ->
|
||||
val free = target.freeBytes
|
||||
if (free >= 0) stringResource(R.string.storage_default_folder_free, gb(free))
|
||||
else stringResource(R.string.storage_default_folder_missing)
|
||||
} ?: stringResource(R.string.storage_default_folder_missing),
|
||||
) { if (customTarget != null) pick(SessionPrefs.DEFAULT_STORAGE_EXTERNAL) else chooseFolder() }
|
||||
}
|
||||
MenuItem(
|
||||
stringResource(R.string.storage_default_choose_folder), checked = false,
|
||||
detail = stringResource(R.string.storage_default_choose_folder_detail),
|
||||
) { chooseFolder() }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalLayoutApi::class)
|
||||
@Composable
|
||||
private fun Overview(report: StorageReport, sessionRunning: Boolean, onCleanUp: () -> Unit, onOpen: (String) -> Unit) {
|
||||
@@ -189,6 +305,7 @@ private fun Overview(report: StorageReport, sessionRunning: Boolean, onCleanUp:
|
||||
Spacer(Modifier.height(8.dp))
|
||||
Note(stringResource(R.string.storage_session_running))
|
||||
}
|
||||
DefaultStorageGroup()
|
||||
SectionTitle(stringResource(R.string.storage_where), null)
|
||||
val unused = report.unusedTools.sumOf { it.bytes }
|
||||
val tiles = listOf<@Composable (Modifier) -> Unit>(
|
||||
|
||||
@@ -270,6 +270,23 @@ internal fun StoreAchievementsCardContent(label: String, state: AchievementsStat
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun AchievementsTab(label: String, state: AchievementsState, modifier: Modifier = Modifier) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val list = state.list
|
||||
Column(verticalArrangement = Arrangement.spacedBy(8.dp), modifier = modifier.fillMaxWidth().tabPanel()) {
|
||||
if (list.isNullOrEmpty()) {
|
||||
Text(achievementsNote(state, label).orEmpty(), fontSize = 13.sp, color = colors.onSurfaceVariant, modifier = Modifier.readable().padding(4.dp))
|
||||
return@Column
|
||||
}
|
||||
Box(Modifier.fillMaxWidth().readable().padding(4.dp)) { AchievementsProgress(state) }
|
||||
for ((group, items) in groups(list)) {
|
||||
AchievementGroupLabel(stringResource(group, items.size))
|
||||
for (a in items) androidx.compose.runtime.key(a.id) { AchievementRow(a, compact = true) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun LazyListScope.achievementItems(list: List<Achievement>, compact: Boolean, first: FocusRequester, labels: Boolean = true) {
|
||||
var index = 0
|
||||
for ((label, group) in groups(list)) {
|
||||
|
||||
@@ -31,6 +31,7 @@ internal fun sourceColours(source: String): SourceColours = when (source) {
|
||||
Store.AMAZON.id -> SourceColours(Color(0xFF3A2A0A), Color(0xFFFFC266), Color(0xFFFF9900))
|
||||
Store.XBOX.id -> SourceColours(Color(0xFF17381B), Color(0xFFC6EDC2), Color(0xFF70C850))
|
||||
Store.ITCH.id -> SourceColours(Color(0xFF3A1A1E), Color(0xFFFFB3B3), Color(0xFFFF5C5C))
|
||||
Store.BATTLENET.id -> SourceColours(Color(0xFF0A2440), Color(0xFF9DD1FF), Color(0xFF148EFF))
|
||||
Library.SOURCE_STEAM -> SourceColours(Color(0xFF16293D), Color(0xFF7CC4FF), Color(0xFF1A9FFF))
|
||||
FLATHUB -> SourceColours(Color(0xFF0B2E2B), Color(0xFF9FE3DD), FlathubTeal)
|
||||
else -> SourceColours(Color(0xFF1A1D22), Color(0xFF9AA3AF), Color(0xFF9AA3AF))
|
||||
@@ -44,6 +45,7 @@ internal fun sourceLabel(source: String): String = when (source) {
|
||||
Store.AMAZON.id -> Store.AMAZON.label
|
||||
Store.XBOX.id -> Store.XBOX.label
|
||||
Store.ITCH.id -> Store.ITCH.label
|
||||
Store.BATTLENET.id -> Store.BATTLENET.label
|
||||
else -> stringResource(R.string.source_added)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,292 +0,0 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.layout.boundsInRoot
|
||||
import androidx.compose.ui.layout.onGloballyPositioned
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.focusable
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.gestures.animateScrollBy
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.ui.input.key.onPreviewKeyEvent
|
||||
import kotlinx.coroutines.launch
|
||||
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.heightIn
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.PlayArrow
|
||||
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
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Brush
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalConfiguration
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.layout.onSizeChanged
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import coil.compose.AsyncImage
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.stores.Store
|
||||
import com.droiddeck.launcher.stores.StoreAchievements
|
||||
import com.droiddeck.launcher.stores.StoresState
|
||||
import com.droiddeck.launcher.stores.download.DownloadState
|
||||
import com.droiddeck.launcher.stores.formatBytes
|
||||
|
||||
|
||||
@Composable
|
||||
internal fun StoreGameDetail(store: Store, key: String, s: FrontEndState, a: FrontEndActions, lead: androidx.compose.ui.focus.FocusRequester, onBack: () -> Unit) {
|
||||
val leadOn = Modifier.focusRequester(lead)
|
||||
val ctx = LocalContext.current
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val pal = LocalPalette.current
|
||||
val narrow = LocalNarrowPane.current
|
||||
val stacked = narrow || LocalConfiguration.current.screenWidthDp < 700
|
||||
val id = key.substringAfter(':')
|
||||
val item = StoresState.detailItem(store, id)
|
||||
val installed = StoresState.installedGame(store, id)
|
||||
val rawDownload = StoresState.download("${store.id}:$id")
|
||||
val download = rawDownload?.takeIf { it.isActive }
|
||||
val failedDownload = rawDownload?.takeIf { it.state == DownloadState.FAILED }
|
||||
val title = item?.title ?: installed?.sidecar?.title ?: id
|
||||
Rise(0) {
|
||||
Box(Modifier.padding(bottom = 12.dp)) { BackLink(stringResource(R.string.common_back), compact = true, onClick = onBack) }
|
||||
}
|
||||
val scores = if (store == Store.GOG || store == Store.EPIC) rememberGameScores(title.takeIf { it != id }) else null
|
||||
val hero: @Composable () -> Unit = {
|
||||
androidx.compose.runtime.DisposableEffect(Unit) { onDispose { StoresMotion.heroAt = null } }
|
||||
Box(
|
||||
Modifier.fillMaxWidth().heightIn(min = if (narrow) 150.dp else 180.dp)
|
||||
.onGloballyPositioned { StoresMotion.heroAt = it.boundsInRoot() }
|
||||
.clip(Shape16).background(artBrush(hueOf(title))),
|
||||
) {
|
||||
val art = item?.imageUrl ?: installed?.sidecar?.hero ?: installed?.sidecar?.cover
|
||||
// The card it came from keeps its own bitmap under the hero until the wide art is decoded.
|
||||
val heroArt = cardArtRequest(art, item?.tallImageUrl)
|
||||
if (heroArt != null) AsyncImage(model = heroArt, contentDescription = null, contentScale = ContentScale.Crop, modifier = Modifier.matchParentSize())
|
||||
Spacer(Modifier.matchParentSize().background(Brush.horizontalGradient(0f to colors.background.copy(alpha = 0.94f), 0.5f to colors.background.copy(alpha = 0.55f), 1f to Color.Transparent)))
|
||||
if (scores != null && !stacked) {
|
||||
Spacer(Modifier.matchParentSize().background(Brush.horizontalGradient(0.45f to Color.Transparent, 1f to colors.background.copy(alpha = 0.75f))))
|
||||
HeroScores(scores, Modifier.align(Alignment.BottomEnd).padding(end = 16.dp, bottom = 18.dp))
|
||||
}
|
||||
Column(verticalArrangement = Arrangement.spacedBy(8.dp), modifier = Modifier.align(Alignment.BottomStart).padding(horizontal = 22.dp, vertical = 18.dp)) {
|
||||
val passName = item?.includedWith.orEmpty()
|
||||
val state = when {
|
||||
installed != null -> stringResource(R.string.stores_eyebrow_installed) + " · " + com.droiddeck.launcher.stores.StoreInstallRoot.labelFor(ctx, installed.folder)
|
||||
download != null && download.location.isNotBlank() -> stringResource(R.string.stores_eyebrow_library) + " · " + download.location
|
||||
failedDownload != null && failedDownload.location.isNotBlank() -> stringResource(R.string.stores_eyebrow_library) + " · " + failedDownload.location
|
||||
item?.owned == true -> stringResource(R.string.stores_eyebrow_library)
|
||||
item?.subscription == true -> passName.ifBlank { "PC Game Pass" }
|
||||
passName.isNotBlank() -> "Available with $passName"
|
||||
item?.accessible == true -> stringResource(R.string.stores_eyebrow_library)
|
||||
else -> stringResource(R.string.stores_eyebrow_store)
|
||||
}
|
||||
val size = (item?.sizeBytes ?: 0L).takeIf { it > 0 }?.let { " · " + formatBytes(it) } ?: ""
|
||||
Text((state + size).uppercase(), fontSize = 12.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 1.2.sp, color = pal.signal)
|
||||
Text(title, fontSize = if (narrow) 24.sp else 30.sp, lineHeight = if (narrow) 27.sp else 33.sp, fontWeight = FontWeight.Black, color = colors.onBackground, maxLines = 2, overflow = TextOverflow.Ellipsis)
|
||||
if (!failedDownload?.error.isNullOrBlank()) {
|
||||
Text(
|
||||
failedDownload!!.error!!,
|
||||
fontSize = 13.sp,
|
||||
lineHeight = 17.sp,
|
||||
fontWeight = FontWeight.Medium,
|
||||
color = colors.error,
|
||||
maxLines = 3,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
}
|
||||
Actions {
|
||||
when {
|
||||
installed != null -> {
|
||||
val gone = StoresState.uninstalling["${store.id}:$id"]
|
||||
PrimaryButton(stringResource(R.string.stores_play), enabled = !s.busy && gone == null && download == null && (store != Store.XBOX || !com.droiddeck.launcher.stores.xbox.XboxContent.busy(id)), main = true, icon = Icons.Filled.PlayArrow, modifier = leadOn) {
|
||||
launchStoreGame(ctx, store, id, s, a)
|
||||
}
|
||||
ActionChip(stringResource(R.string.stores_in_steam), ok = true)
|
||||
if (store == Store.XBOX) {
|
||||
SecondaryButton("Update / verify", enabled = download == null && !com.droiddeck.launcher.stores.xbox.XboxRuntime.isActive(id)) {
|
||||
runCatching { com.droiddeck.launcher.stores.xbox.XboxBackend.update(ctx, installed) }
|
||||
.onFailure { StoresState.problems[Store.XBOX] = it.message ?: "Close this Xbox game before updating it." }
|
||||
}
|
||||
SecondaryButton("Manage content", enabled = download == null) {
|
||||
com.droiddeck.launcher.stores.xbox.XboxContent.manage(ctx, installed)
|
||||
}
|
||||
}
|
||||
if (gone != null) SecondaryButton(stringResource(R.string.stores_uninstalling), enabled = false, progress = gone) {}
|
||||
else UninstallButton(title, installed, enabled = download == null && (store != Store.XBOX || !com.droiddeck.launcher.stores.xbox.XboxContent.busy(id))) {
|
||||
StoresState.uninstall(ctx, installed) { StoresState.refresh(ctx); a.onLibraryChanged() }
|
||||
}
|
||||
}
|
||||
download != null -> {
|
||||
ActionChip(downloadLabel(download), ok = false)
|
||||
if (download.state != DownloadState.PAUSED) SecondaryButton(stringResource(R.string.stores_dl_pause), modifier = leadOn) { com.droiddeck.launcher.stores.download.DownloadQueue.pause(download.key) }
|
||||
else PrimaryButton(stringResource(R.string.stores_dl_resume), main = true, modifier = leadOn) { com.droiddeck.launcher.stores.download.DownloadQueue.resume(ctx, download.key) }
|
||||
ConfirmButton(stringResource(R.string.stores_dl_cancel), stringResource(R.string.stores_dl_cancel_confirm)) { com.droiddeck.launcher.stores.download.DownloadQueue.cancel(ctx, download.key) }
|
||||
}
|
||||
failedDownload != null -> {
|
||||
ActionChip(stringResource(R.string.stores_dl_failed), ok = false)
|
||||
PrimaryButton(stringResource(R.string.stores_dl_resume), main = true, modifier = leadOn) {
|
||||
if (item != null) StoresState.requestInstall(ctx, item)
|
||||
else com.droiddeck.launcher.stores.download.DownloadQueue.retry(ctx, failedDownload.key)
|
||||
}
|
||||
ConfirmButton(stringResource(R.string.stores_dl_clear), stringResource(R.string.stores_dl_cancel_confirm), compact = true) {
|
||||
com.droiddeck.launcher.stores.download.DownloadQueue.clear(ctx, failedDownload.key)
|
||||
}
|
||||
}
|
||||
item?.installable == true && StoresState.isUnfinished(item) -> {
|
||||
InstallButton(stringResource(R.string.stores_resume_install), leadOn) { StoresState.requestInstall(ctx, item) }
|
||||
ConfirmButton(stringResource(R.string.stores_dl_clear), stringResource(R.string.stores_dl_cancel_confirm), compact = true) { StoresState.clearUnfinished(ctx, item) }
|
||||
}
|
||||
item?.installable == true -> {
|
||||
InstallButton(
|
||||
if (item.sizeBytes > 0) stringResource(R.string.stores_install_size, formatBytes(item.sizeBytes)) else stringResource(R.string.stores_install),
|
||||
leadOn,
|
||||
) { StoresState.requestInstall(ctx, item) }
|
||||
if (!item.accessible) {
|
||||
SecondaryButton(
|
||||
when {
|
||||
item.isFree -> stringResource(R.string.stores_get_free)
|
||||
item.hasPrice && item.finalPrice.isNotBlank() -> stringResource(R.string.stores_buy_price, item.finalPrice)
|
||||
else -> stringResource(R.string.stores_view_on, store.shortLabel)
|
||||
},
|
||||
) { openStoreUrl(ctx, item) }
|
||||
}
|
||||
}
|
||||
item != null && item.isFree -> PrimaryButton(stringResource(R.string.stores_get_free), main = true, modifier = leadOn) { openStoreUrl(ctx, item) }
|
||||
item != null -> PrimaryButton(if (item.hasPrice && item.finalPrice.isNotBlank()) stringResource(R.string.stores_buy_price, item.finalPrice) else stringResource(R.string.stores_view_on, store.shortLabel), main = true, modifier = leadOn) { openStoreUrl(ctx, item) }
|
||||
}
|
||||
BusyChip(s)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (StoresMotion.heroLands) hero() else Rise(1) { hero() }
|
||||
if (scores != null) Rise(2) {
|
||||
val listed = (StoresState.found[store].orEmpty() + StoresState.shelves[store]?.all.orEmpty()).firstOrNull { it.id == id }
|
||||
val developer = item?.developer?.ifBlank { null } ?: listed?.developer.orEmpty()
|
||||
val publisher = item?.publisher?.ifBlank { null } ?: listed?.publisher.orEmpty()
|
||||
val releaseDate = item?.releaseDate?.ifBlank { null } ?: listed?.releaseDate.orEmpty()
|
||||
StoreGameFacts(developer, publisher, releaseDate, scores, scoresInHero = !stacked)
|
||||
}
|
||||
val description = item?.let { com.droiddeck.launcher.stores.cleanStoreText(it.description) }.orEmpty()
|
||||
.takeUnless { it.trim().equals(title.trim(), ignoreCase = true) }.orEmpty()
|
||||
val achievements = remember(store, id, item?.accessible, installed) {
|
||||
when {
|
||||
StoreAchievements.forSource(store.id) == null -> null
|
||||
item?.accessible == true -> StoreAchievements.Game.of(item)
|
||||
installed != null -> StoreAchievements.Game.of(installed.sidecar)
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
if (description.isNotBlank() || achievements != null) Rise(3) {
|
||||
val about: @Composable (Modifier, Dp) -> Unit = { m, h -> if (description.isNotBlank()) StoreAbout(description, h, m) }
|
||||
val card: @Composable (Modifier) -> Unit = { m -> if (achievements != null) StoreAchievementsCard(achievements, title, m) }
|
||||
if (stacked) Column(verticalArrangement = Arrangement.spacedBy(14.dp), modifier = Modifier.fillMaxWidth().padding(top = 14.dp)) {
|
||||
about(Modifier.fillMaxWidth(), AboutHeight)
|
||||
card(Modifier.fillMaxWidth())
|
||||
} else Row(horizontalArrangement = Arrangement.spacedBy(24.dp), modifier = Modifier.fillMaxWidth().padding(top = 14.dp)) {
|
||||
val density = LocalDensity.current
|
||||
var cardHeight by remember { mutableStateOf<Dp?>(null) }
|
||||
about(Modifier.weight(1f), cardHeight ?: AboutHeight)
|
||||
card(Modifier.width(340.dp).onSizeChanged { cardHeight = with(density) { it.height.toDp() } })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val AboutHeight = 150.dp
|
||||
|
||||
@Composable
|
||||
private fun StoreAbout(text: String, height: Dp, modifier: Modifier = Modifier) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val pal = LocalPalette.current
|
||||
val scroll = rememberScrollState()
|
||||
val scope = rememberCoroutineScope()
|
||||
val src = remember { MutableInteractionSource() }
|
||||
val more = scroll.maxValue > 0
|
||||
val hot = more && rememberHot(src)
|
||||
val shape = RoundedCornerShape(12.dp)
|
||||
Box(
|
||||
modifier.heightIn(max = height).clip(shape)
|
||||
.glideBorder(hot, shape, pal.signal, restColor = Color.Transparent)
|
||||
.then(if (more) Modifier.paneItem("about") else Modifier)
|
||||
.focusable(enabled = more, interactionSource = src)
|
||||
.onPreviewKeyEvent { e ->
|
||||
val step = when (e.nativeKeyEvent.keyCode) {
|
||||
android.view.KeyEvent.KEYCODE_DPAD_DOWN -> if (scroll.value < scroll.maxValue) 120f else return@onPreviewKeyEvent false
|
||||
android.view.KeyEvent.KEYCODE_DPAD_UP -> if (scroll.value > 0) -120f else return@onPreviewKeyEvent false
|
||||
else -> return@onPreviewKeyEvent false
|
||||
}
|
||||
if (e.nativeKeyEvent.action == android.view.KeyEvent.ACTION_DOWN) scope.launch { scroll.animateScrollBy(step) }
|
||||
true
|
||||
},
|
||||
) {
|
||||
Text(text, fontSize = 14.sp, lineHeight = 21.sp, color = colors.onSurfaceVariant, modifier = Modifier.verticalScroll(scroll).padding(horizontal = 10.dp, vertical = 6.dp))
|
||||
if (scroll.value < scroll.maxValue) Box(
|
||||
Modifier.align(Alignment.BottomCenter).fillMaxWidth().height(28.dp)
|
||||
.background(Brush.verticalGradient(listOf(Color.Transparent, colors.background))),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun UninstallButton(title: String, game: com.droiddeck.launcher.stores.InstalledStoreGame, enabled: Boolean, modifier: Modifier = Modifier, onUninstall: () -> Unit) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val placed = remember { arrayOfNulls<androidx.compose.ui.layout.LayoutCoordinates>(1) }
|
||||
val heading = stringResource(R.string.stores_uninstall_title, title)
|
||||
val size = com.droiddeck.launcher.stores.StoreSizes.onDisk["${game.sidecar.store.id}:${game.sidecar.id}"]
|
||||
val body = if (size != null && size > 0) stringResource(R.string.stores_uninstall_body_size, formatBytes(size)) else stringResource(R.string.stores_uninstall_body)
|
||||
val keep = stringResource(R.string.stores_notification_keep)
|
||||
val remove = stringResource(R.string.stores_uninstall)
|
||||
Box(Modifier.onGloballyPositioned { placed[0] = it }) {
|
||||
SecondaryButton(remove, enabled = enabled, modifier = modifier) {
|
||||
val at = placed[0]?.takeIf { it.isAttached }?.boundsInRoot() ?: return@SecondaryButton
|
||||
var confirmed = false
|
||||
StoresMotion.ask(StepAsk(anchor = at, side = StepSide.Right, accent = colors.error, items = 3, pillCorner = 12.dp, maxWidth = 340.dp,
|
||||
onDismiss = { if (confirmed) onUninstall() }, handle = {
|
||||
Text(remove, fontSize = 15.sp, fontWeight = FontWeight.SemiBold, color = colors.error, maxLines = 1)
|
||||
}) {
|
||||
StepTitle(heading)
|
||||
Text(body, fontSize = 13.sp, lineHeight = 18.sp, color = colors.onSurfaceVariant, modifier = Modifier.stepItem(1).padding(start = 4.dp, bottom = 12.dp))
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(8.dp, Alignment.End), modifier = Modifier.fillMaxWidth().stepItem(2)) {
|
||||
StepChoice(keep, enabled = open, modifier = Modifier.focusRequester(first)) { StoresMotion.fold() }
|
||||
StepChoice(remove, danger = true, enabled = open) { confirmed = true; StoresMotion.fold() }
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun InstallButton(label: String, modifier: Modifier = Modifier, onInstall: () -> Unit) {
|
||||
val placed = remember { arrayOfNulls<androidx.compose.ui.layout.LayoutCoordinates>(1) }
|
||||
Box(Modifier.onGloballyPositioned { placed[0] = it }) {
|
||||
PrimaryButton(label, main = true, modifier = modifier) {
|
||||
StoresMotion.markInstall(placed[0]?.takeIf { it.isAttached }?.boundsInRoot(), label)
|
||||
onInstall()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -221,7 +221,7 @@ private fun FinishedRow(d: DownloadEntry, s: FrontEndState, a: FrontEndActions,
|
||||
ArtStrip(d.cover, d.name) {
|
||||
StripLabel(d.name, d.store.id, stringResource(if (d.state == DownloadState.INSTALLED) R.string.stores_installed_chip else R.string.stores_dl_cancelled), Color.White.copy(alpha = 0.72f))
|
||||
if (d.state == DownloadState.INSTALLED) Box(Modifier.bloomIn(bloom, GATHER_HOLD_MS + 150)) {
|
||||
RoundAction(Icons.Filled.PlayArrow, stringResource(R.string.stores_play), primary = true) { if (d.key == EpicClient.DOWNLOAD_KEY) a.onEpicLauncher() else launchStoreGame(ctx, d.store, d.id, s, a) }
|
||||
RoundAction(Icons.Filled.PlayArrow, stringResource(R.string.stores_play), primary = true) { if (d.key == EpicClient.DOWNLOAD_KEY) a.onEpicLauncher() else if (d.key == com.droiddeck.launcher.stores.battlenet.BattleNetClient.DOWNLOAD_KEY) a.onBattleNet() else launchStoreGame(ctx, d.store, d.id, s, a) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -372,7 +372,7 @@ private fun DownloadCard(d: DownloadEntry, s: FrontEndState, a: FrontEndActions)
|
||||
CancelAction { DownloadQueue.clear(ctx, d.key) }
|
||||
}
|
||||
DownloadState.INSTALLED -> Box(Modifier.bloomIn(true, 420)) {
|
||||
RoundAction(Icons.Filled.PlayArrow, stringResource(R.string.stores_play), primary = true) { if (d.key == EpicClient.DOWNLOAD_KEY) a.onEpicLauncher() else launchStoreGame(ctx, d.store, d.id, s, a) }
|
||||
RoundAction(Icons.Filled.PlayArrow, stringResource(R.string.stores_play), primary = true) { if (d.key == EpicClient.DOWNLOAD_KEY) a.onEpicLauncher() else if (d.key == com.droiddeck.launcher.stores.battlenet.BattleNetClient.DOWNLOAD_KEY) a.onBattleNet() else launchStoreGame(ctx, d.store, d.id, s, a) }
|
||||
}
|
||||
DownloadState.CANCELLED -> {}
|
||||
}
|
||||
@@ -498,16 +498,10 @@ internal fun storesSettingsStep(at: Rect, s: androidx.compose.runtime.State<Fron
|
||||
val st = s.value
|
||||
val context = androidx.compose.ui.platform.LocalContext.current
|
||||
SettingsRow(stringResource(R.string.stores_tabs_arrange), null) {
|
||||
RoundAction(Icons.Filled.SwapHoriz, stringResource(R.string.stores_tabs_arrange), size = 36.dp) {
|
||||
Box(Modifier.focusRequester(first).focusGroup()) { RoundAction(Icons.Filled.SwapHoriz, stringResource(R.string.stores_tabs_arrange), size = 36.dp) {
|
||||
StoresMotion.fold()
|
||||
onArrange()
|
||||
}
|
||||
}
|
||||
SettingsRow(stringResource(R.string.setup_stores_open_on), null, stacked = true) {
|
||||
Box(Modifier.focusRequester(first).focusGroup()) { SegmentedTabs(
|
||||
listOf(SessionPrefs.STORES_OPEN_LIBRARY to stringResource(R.string.stores_tab_library), SessionPrefs.STORES_OPEN_STORE to stringResource(R.string.stores_tab_store)),
|
||||
st.storesOpenTab,
|
||||
) { a.onStoresOpenTab(it) } }
|
||||
} }
|
||||
}
|
||||
SettingsRow(stringResource(R.string.stores_show_mature), null) {
|
||||
ToggleSwitch(st.storesShowMature, label = stringResource(R.string.stores_show_mature)) { a.onStoresShowMature(it) }
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -2,8 +2,20 @@ package com.droiddeck.launcher.ui
|
||||
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.ProvideTextStyle
|
||||
import androidx.compose.material3.Typography
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.style.TextDirection
|
||||
import androidx.compose.material3.darkColorScheme
|
||||
import androidx.compose.animation.core.LinearEasing
|
||||
import androidx.compose.animation.core.RepeatMode
|
||||
import androidx.compose.animation.core.animateFloat
|
||||
import androidx.compose.animation.core.infiniteRepeatable
|
||||
import androidx.compose.animation.core.rememberInfiniteTransition
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.key
|
||||
import androidx.compose.runtime.SideEffect
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.staticCompositionLocalOf
|
||||
import androidx.compose.runtime.getValue
|
||||
@@ -13,6 +25,7 @@ import android.content.Context
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.luminance
|
||||
import androidx.compose.ui.graphics.toArgb
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import com.droiddeck.launcher.R
|
||||
import androidx.compose.ui.platform.LocalConfiguration
|
||||
@@ -33,6 +46,7 @@ object Themes {
|
||||
const val PAPER = "paper"
|
||||
const val ICON_BLUE = "blue"
|
||||
const val ELECTRIC = "electric"
|
||||
const val INNER_GAMER = "inner_gamer"
|
||||
const val GRADIENT = "gradient"
|
||||
|
||||
const val DEFAULT_PRIMARY = 0xFF8B5CF6.toInt()
|
||||
@@ -42,10 +56,42 @@ object Themes {
|
||||
var gradientColors by mutableStateOf(DEFAULT_PRIMARY to DEFAULT_SECONDARY)
|
||||
private set
|
||||
|
||||
const val RGB_SPEEDS = 10
|
||||
const val DEFAULT_RGB_SPEED = 3
|
||||
const val RGB_HUE_STEP = 3f
|
||||
|
||||
/** How fast Inner Gamer cycles, 1 (slow) to [RGB_SPEEDS] (fast). */
|
||||
var rgbSpeed by mutableStateOf(DEFAULT_RGB_SPEED)
|
||||
private set
|
||||
|
||||
/** Where Inner Gamer is on the colour wheel, in whole [RGB_HUE_STEP] steps so the app restyles only when the colour visibly moves. */
|
||||
var rgbHue by mutableStateOf(0f)
|
||||
private set
|
||||
|
||||
fun moveRgbHue(hue: Float) {
|
||||
rgbHue = hue
|
||||
}
|
||||
|
||||
fun setRgbSpeed(context: Context, speed: Int) {
|
||||
val value = speed.coerceIn(1, RGB_SPEEDS)
|
||||
SessionPrefs.setRgbSpeed(context, value)
|
||||
rgbSpeed = value
|
||||
}
|
||||
|
||||
/** Milliseconds for one trip round the colour wheel. */
|
||||
fun rgbCycleMillis(speed: Int): Int = 30_000 / speed.coerceIn(1, RGB_SPEEDS)
|
||||
|
||||
fun loadGradient(context: Context) {
|
||||
gradientColors = SessionPrefs.gradientColors(context)
|
||||
rgbSpeed = SessionPrefs.rgbSpeed(context)
|
||||
}
|
||||
|
||||
/** The Inner Gamer palette at one point on the colour wheel. */
|
||||
fun innerGamer(hue: Float): Palette = ThemeColors.palette(
|
||||
Color.hsv(hue % 360f, 0.9f, 1f).toArgb(), Color.hsv((hue + 60f) % 360f, 0.9f, 1f).toArgb(),
|
||||
R.string.theme_inner_gamer, R.string.theme_inner_gamer_detail, INNER_GAMER,
|
||||
)
|
||||
|
||||
fun setGradient(context: Context, primary: Int, secondary: Int) {
|
||||
SessionPrefs.setGradientColors(context, primary, secondary)
|
||||
gradientColors = primary to secondary
|
||||
@@ -54,7 +100,7 @@ object Themes {
|
||||
/** The theme the person chose, with the custom colours read first; for code that is not in a composition. */
|
||||
fun current(context: Context): Palette {
|
||||
val id = SessionPrefs.theme(context)
|
||||
if (id == GRADIENT) loadGradient(context)
|
||||
if (id == GRADIENT || id == INNER_GAMER) loadGradient(context)
|
||||
return byId(id)
|
||||
}
|
||||
|
||||
@@ -87,10 +133,12 @@ object Themes {
|
||||
primary = Color(0xFF2E86FF), primary2 = Color(0xFF2684FF), onPrimary = Color(0xFF03111F), signal = Color(0xFF2E86FF),
|
||||
good = Color(0xFF4CD37F),
|
||||
),
|
||||
innerGamer(0f),
|
||||
ThemeColors.palette(DEFAULT_PRIMARY, DEFAULT_SECONDARY, R.string.theme_gradient, R.string.theme_gradient_detail),
|
||||
)
|
||||
|
||||
fun byId(id: String): Palette {
|
||||
if (id == INNER_GAMER) return innerGamer(rgbHue)
|
||||
if (id == GRADIENT) return ThemeColors.palette(gradientColors.first, gradientColors.second, R.string.theme_gradient, R.string.theme_gradient_detail)
|
||||
return all.firstOrNull { it.id == id } ?: all[0]
|
||||
}
|
||||
@@ -103,6 +151,7 @@ val Palette.onSignal: Color get() = if (signal.luminance() > 0.18f) Color(0xFF03
|
||||
@Composable
|
||||
fun DroidDeckTheme(theme: String? = null, appScale: Int = AppUiPrefs.DEFAULT_SCALE, content: @Composable () -> Unit) {
|
||||
val id = theme ?: SessionPrefs.theme(LocalContext.current)
|
||||
if (id == Themes.INNER_GAMER) InnerGamerHue(Themes.rgbSpeed)
|
||||
val p = Themes.byId(id)
|
||||
val scheme = darkColorScheme(
|
||||
primary = p.primary, onPrimary = p.onPrimary, secondary = p.onSurfaceVariant,
|
||||
@@ -119,5 +168,38 @@ fun DroidDeckTheme(theme: String? = null, appScale: Int = AppUiPrefs.DEFAULT_SCA
|
||||
LocalPalette provides p,
|
||||
LocalDensity provides density,
|
||||
LocalConfiguration provides configuration,
|
||||
) { MaterialTheme(colorScheme = scheme, content = content) }
|
||||
) {
|
||||
MaterialTheme(colorScheme = scheme, typography = ContentDirected) {
|
||||
ProvideTextStyle(TextStyle(textDirection = TextDirection.Content), content)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val ContentDirected = Typography().run {
|
||||
fun TextStyle.byContent() = copy(textDirection = TextDirection.Content)
|
||||
Typography(
|
||||
displayLarge.byContent(), displayMedium.byContent(), displaySmall.byContent(),
|
||||
headlineLarge.byContent(), headlineMedium.byContent(), headlineSmall.byContent(),
|
||||
titleLarge.byContent(), titleMedium.byContent(), titleSmall.byContent(),
|
||||
bodyLarge.byContent(), bodyMedium.byContent(), bodySmall.byContent(),
|
||||
labelLarge.byContent(), labelMedium.byContent(), labelSmall.byContent(),
|
||||
)
|
||||
}
|
||||
|
||||
/** Turns the colour wheel on the system's own animation clock; with animations off, in the app or in Android, the colour holds still. */
|
||||
@Composable
|
||||
private fun InnerGamerHue(speed: Int) {
|
||||
if (Motion.scale == 0f) return
|
||||
key(speed) { InnerGamerCycle(speed) }
|
||||
}
|
||||
|
||||
/** One run of the cycle at one speed, picking up from the colour on screen so a new speed takes over at once without a jump. */
|
||||
@Composable
|
||||
private fun InnerGamerCycle(speed: Int) {
|
||||
val start = remember { Themes.rgbHue }
|
||||
val hue by rememberInfiniteTransition(label = "innerGamer").animateFloat(
|
||||
start, start + 360f, infiniteRepeatable(tween(Themes.rgbCycleMillis(speed).coerceAtLeast(1), easing = LinearEasing), RepeatMode.Restart), label = "hue",
|
||||
)
|
||||
val stepped = ((hue % 360f) / Themes.RGB_HUE_STEP).toInt() * Themes.RGB_HUE_STEP
|
||||
SideEffect { Themes.moveRgbHue(stepped) }
|
||||
}
|
||||
@@ -132,7 +132,7 @@ internal object ThemeColors {
|
||||
}
|
||||
}
|
||||
|
||||
fun palette(primary: Int, secondary: Int, label: Int, detail: Int): Palette {
|
||||
fun palette(primary: Int, secondary: Int, label: Int, detail: Int, id: String = Themes.GRADIENT): Palette {
|
||||
val seen = readable(primary)
|
||||
val seenSecond = readable(secondary)
|
||||
val ink = inkFor(seen, seenSecond)
|
||||
@@ -146,7 +146,7 @@ internal object ThemeColors {
|
||||
second = nextSecond
|
||||
}
|
||||
return Palette(
|
||||
Themes.GRADIENT, label, detail,
|
||||
id, label, detail,
|
||||
background = tint(first, 0.50f, 0.045f), surface = tint(first, 0.45f, 0.075f), surfaceVariant = tint(first, 0.42f, 0.115f),
|
||||
line = tint(first, 0.40f, 0.16f), line2 = tint(first, 0.36f, 0.22f),
|
||||
onBackground = tint(first, 0.05f, 0.97f), onSurfaceVariant = tint(first, 0.16f, 0.68f),
|
||||
|
||||
@@ -9,6 +9,7 @@ import androidx.compose.animation.fadeIn
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.animation.shrinkVertically
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.basicMarquee
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.hoverable
|
||||
@@ -88,6 +89,7 @@ class UpdatesActions(
|
||||
val onDismissPermission: () -> Unit = {},
|
||||
)
|
||||
|
||||
@OptIn(androidx.compose.foundation.ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
internal fun UpdatesPage(s: FrontEndState, a: FrontEndActions, modifier: Modifier) {
|
||||
val u = s.updates
|
||||
@@ -95,10 +97,14 @@ internal fun UpdatesPage(s: FrontEndState, a: FrontEndActions, modifier: Modifie
|
||||
val me = remember { AppUpdates.installed() }
|
||||
val colors = MaterialTheme.colorScheme
|
||||
Column(modifier = modifier) {
|
||||
PageHeader(stringResource(R.string.upd_title)) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||
modifier = Modifier.fillMaxWidth().padding(bottom = 10.dp),
|
||||
) {
|
||||
Text(
|
||||
stringResource(R.string.upd_build, me.version, s.buildLabel), fontSize = 12.5.sp, color = colors.onSurfaceVariant,
|
||||
maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f).padding(top = 6.dp),
|
||||
maxLines = 1, modifier = Modifier.weight(1f)
|
||||
.basicMarquee(iterations = Int.MAX_VALUE, initialDelayMillis = 700, velocity = 40.dp),
|
||||
)
|
||||
val checked = u.catalog?.checkedAt?.takeIf { it > 0 }
|
||||
if (!LocalNarrowPane.current) Text(
|
||||
|
||||
@@ -56,7 +56,7 @@ import java.io.File
|
||||
private fun installable(name: String, all: Map<String, WinComponents.Component>): String = WinComponents.installable(name, all)
|
||||
|
||||
@Composable
|
||||
private fun originName(origin: String): String = stringResource(
|
||||
private fun originName(origin: String): String = if (origin == WinCompSources.Origin.XBOX.name) "Xbox" else stringResource(
|
||||
when (origin) {
|
||||
WinCompSources.Origin.GOG.name -> R.string.wincomp_src_gog
|
||||
WinCompSources.Origin.EPIC.name -> R.string.wincomp_src_epic
|
||||
@@ -71,6 +71,7 @@ private fun autoReason(r: WinComponents.AutoReason): String = when (r.kind) {
|
||||
WinCompSources.Origin.GOG.name -> stringResource(R.string.wincomp_auto_gog)
|
||||
WinCompSources.Origin.EPIC.name -> stringResource(R.string.wincomp_auto_epic)
|
||||
WinCompSources.Origin.AMAZON.name -> stringResource(R.string.wincomp_auto_amazon)
|
||||
WinCompSources.Origin.XBOX.name -> "Xbox games install it with the game (${r.args.getOrElse(0) { "VC14" }})"
|
||||
else -> ""
|
||||
}
|
||||
|
||||
|
||||
@@ -356,6 +356,7 @@ internal fun AdbTextField(
|
||||
placeholder: String? = null,
|
||||
compact: Boolean = false,
|
||||
onFocusChange: (Boolean) -> Unit = {},
|
||||
clearFocus: Boolean = false,
|
||||
onNext: (() -> Unit)? = null,
|
||||
onDone: (() -> Unit)? = null,
|
||||
focusOnShow: Boolean = false,
|
||||
@@ -444,6 +445,11 @@ internal fun AdbTextField(
|
||||
?.showSoftInput(editText, android.view.inputmethod.InputMethodManager.SHOW_IMPLICIT)
|
||||
}
|
||||
}
|
||||
if (clearFocus && editText.hasFocus()) {
|
||||
editText.clearFocus()
|
||||
(editText.context.getSystemService(android.content.Context.INPUT_METHOD_SERVICE) as? android.view.inputmethod.InputMethodManager)
|
||||
?.hideSoftInputFromWindow(editText.windowToken, 0)
|
||||
}
|
||||
editText.setTextColor(colors.onBackground.toArgb())
|
||||
editText.setHintTextColor(colors.onSurfaceVariant.toArgb())
|
||||
editText.hint = placeholder
|
||||
|
||||
Reference in new issue
Block a user