mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 20:36:04 +00:00
feat: merge Games and store libraries into one Library and one game page (#1460)
This commit is contained in:
1 parent
0cf5b42788
commit
2a69505199
62 files changed
+3240
-1803
No files matched your search
@@ -172,7 +172,6 @@ class FrontEndActivity : ComponentActivity() {
|
||||
private var launcherIcon by mutableStateOf(LauncherIcon.DARK)
|
||||
private var gameStoresEnabled by mutableStateOf(true)
|
||||
private var gameStoresSpeedTier by mutableStateOf("fast")
|
||||
private var storesOpenTab by mutableStateOf(SessionPrefs.STORES_OPEN_LIBRARY)
|
||||
private var navRequest by mutableStateOf<String?>(null)
|
||||
private var storesShowMature by mutableStateOf(false)
|
||||
private var storesSort by mutableStateOf(SessionPrefs.STORES_SORTS.first())
|
||||
@@ -773,7 +772,6 @@ class FrontEndActivity : ComponentActivity() {
|
||||
launcherIcon = LauncherIcon.current(this)
|
||||
gameStoresEnabled = SessionPrefs.gameStoresEnabled(this)
|
||||
gameStoresSpeedTier = SessionPrefs.gameStoresSpeedTier(this)
|
||||
storesOpenTab = SessionPrefs.storesOpenTab(this)
|
||||
storesShowMature = SessionPrefs.storesShowMature(this)
|
||||
storesSort = SessionPrefs.storesSort(this)
|
||||
storesView = SessionPrefs.storesView(this)
|
||||
@@ -837,7 +835,6 @@ class FrontEndActivity : ComponentActivity() {
|
||||
launcherIcon = launcherIcon,
|
||||
gameStoresEnabled = gameStoresEnabled,
|
||||
gameStoresSpeedTier = gameStoresSpeedTier,
|
||||
storesOpenTab = storesOpenTab,
|
||||
navigate = navRequest,
|
||||
addedGamesArt = addedGamesArt,
|
||||
sgdbUserKey = sgdbUserKey,
|
||||
@@ -1012,7 +1009,6 @@ class FrontEndActivity : ComponentActivity() {
|
||||
applyLauncherFullscreen()
|
||||
},
|
||||
onGameStoresSpeedTier = { tier -> SessionPrefs.setGameStoresSpeedTier(this, tier); gameStoresSpeedTier = tier },
|
||||
onStoresOpenTab = { tab -> SessionPrefs.setStoresOpenTab(this, tab); storesOpenTab = tab },
|
||||
onNavigated = { navRequest = null },
|
||||
onStoresShowMature = { show -> SessionPrefs.setStoresShowMature(this, show); storesShowMature = show },
|
||||
onStoresSort = { sort -> SessionPrefs.setStoresSort(this, sort); storesSort = sort },
|
||||
|
||||
@@ -91,13 +91,6 @@ object SessionPrefs {
|
||||
*/
|
||||
fun storesEpicMode(context: Context): String = prefs(context).getString("storesEpicMode", "adaptive") ?: "adaptive"
|
||||
|
||||
fun storesOpenTab(context: Context): String =
|
||||
prefs(context).getString("storesOpenTab", STORES_OPEN_LIBRARY)?.takeIf { it == STORES_OPEN_STORE } ?: STORES_OPEN_LIBRARY
|
||||
|
||||
fun setStoresOpenTab(context: Context, tab: String) {
|
||||
prefs(context).edit().putString("storesOpenTab", if (tab == STORES_OPEN_STORE) STORES_OPEN_STORE else STORES_OPEN_LIBRARY).apply()
|
||||
}
|
||||
|
||||
fun storesShowMature(context: Context): Boolean = prefs(context).getBoolean("storesShowMature", false)
|
||||
|
||||
fun setStoresShowMature(context: Context, show: Boolean) {
|
||||
@@ -135,9 +128,6 @@ object SessionPrefs {
|
||||
val STORES_SORTS = listOf("lastPlayed", "recentlyInstalled", "titleAsc", "titleDesc", "sizeDesc", "sizeAsc", "releaseDateDesc")
|
||||
val STORES_VIEWS = listOf("cards", "capsules", "list")
|
||||
|
||||
const val STORES_OPEN_LIBRARY = "library"
|
||||
const val STORES_OPEN_STORE = "store"
|
||||
|
||||
fun storesInstallTarget(context: Context): String = prefs(context).getString("storesInstallTarget", "") ?: ""
|
||||
|
||||
fun setStoresInstallTarget(context: Context, path: String) {
|
||||
|
||||
@@ -61,33 +61,38 @@ fun installedCards(store: Store, installed: List<InstalledStoreGame>, library: L
|
||||
}.distinctBy { it.id }.sortedBy { it.title.lowercase() }
|
||||
}
|
||||
|
||||
private fun releaseDateValue(item: CatalogItem): Long =
|
||||
item.releaseDate.take(10).takeIf { it.length == 10 }?.let { raw ->
|
||||
runCatching { java.time.LocalDate.parse(raw).toEpochDay() }.getOrDefault(0L)
|
||||
private fun releaseDateValue(raw: String): Long =
|
||||
raw.take(10).takeIf { it.length == 10 }?.let { day ->
|
||||
runCatching { java.time.LocalDate.parse(day).toEpochDay() }.getOrDefault(0L)
|
||||
} ?: 0L
|
||||
|
||||
fun sortCatalogItems(
|
||||
items: List<CatalogItem>,
|
||||
fun <T> sortGames(
|
||||
items: List<T>,
|
||||
sort: String,
|
||||
lastPlayed: (CatalogItem) -> Long = { 0L },
|
||||
installedAt: (CatalogItem) -> Long = { 0L },
|
||||
size: (CatalogItem) -> Long = { it.sizeBytes },
|
||||
): List<CatalogItem> = when (sort) {
|
||||
"lastPlayed" -> items.sortedWith(compareByDescending(lastPlayed).thenBy { it.title.lowercase() })
|
||||
"recentlyInstalled" -> items.sortedWith(compareByDescending(installedAt).thenBy { it.title.lowercase() })
|
||||
"titleAsc" -> items.sortedBy { it.title.lowercase() }
|
||||
"titleDesc" -> items.sortedByDescending { it.title.lowercase() }
|
||||
"sizeDesc" -> items.sortedWith(compareByDescending(size).thenBy { it.title.lowercase() })
|
||||
"sizeAsc" -> items.sortedWith(compareBy<CatalogItem> { size(it).takeIf { b -> b > 0 } ?: Long.MAX_VALUE }.thenBy { it.title.lowercase() })
|
||||
"releaseDateDesc" -> items.sortedWith(compareByDescending(::releaseDateValue).thenBy { it.title.lowercase() })
|
||||
else -> items
|
||||
title: (T) -> String,
|
||||
releaseDate: (T) -> String,
|
||||
lastPlayed: (T) -> Long = { 0L },
|
||||
installedAt: (T) -> Long = { 0L },
|
||||
size: (T) -> Long = { 0L },
|
||||
): List<T> {
|
||||
val byTitle = compareBy<T> { title(it).lowercase() }
|
||||
return when (sort) {
|
||||
"lastPlayed" -> items.sortedWith(compareByDescending(lastPlayed).then(byTitle))
|
||||
"recentlyInstalled" -> items.sortedWith(compareByDescending(installedAt).then(byTitle))
|
||||
"titleAsc" -> items.sortedWith(byTitle)
|
||||
"titleDesc" -> items.sortedWith(byTitle.reversed())
|
||||
"sizeDesc" -> items.sortedWith(compareByDescending(size).then(byTitle))
|
||||
"sizeAsc" -> items.sortedWith(compareBy<T> { size(it).takeIf { b -> b > 0 } ?: Long.MAX_VALUE }.then(byTitle))
|
||||
"releaseDateDesc" -> items.sortedWith(compareByDescending<T> { releaseDateValue(releaseDate(it)) }.then(byTitle))
|
||||
else -> items
|
||||
}
|
||||
}
|
||||
|
||||
internal fun retainCatalogOrder(items: List<CatalogItem>, previous: List<CatalogItem>): List<CatalogItem> {
|
||||
internal fun <T> retainOrder(items: List<T>, previous: List<T>, key: (T) -> String): List<T> {
|
||||
if (items.size != previous.size) return items
|
||||
val byKey = items.associateBy { it.key }
|
||||
if (previous.any { it.key !in byKey }) return items
|
||||
return previous.map { byKey.getValue(it.key) }
|
||||
val byKey = items.associateBy(key)
|
||||
if (previous.any { key(it) !in byKey }) return items
|
||||
return previous.map { byKey.getValue(key(it)) }
|
||||
}
|
||||
|
||||
/** A detail page opens for search results too; the library wins when it already knows the product. */
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.droiddeck.launcher.stores.download.DownloadEntry
|
||||
object StoresState {
|
||||
private const val TAG = "Stores"
|
||||
private const val SEARCH_DELAY_MS = 400L
|
||||
private const val LIBRARY_RETRY_MS = 60_000L
|
||||
private val main = Handler(Looper.getMainLooper())
|
||||
|
||||
val accounts = mutableStateMapOf<Store, String>()
|
||||
@@ -85,7 +86,7 @@ object StoresState {
|
||||
main.post {
|
||||
androidx.compose.runtime.snapshots.Snapshot.withMutableSnapshot {
|
||||
val restored = found.toMap()
|
||||
accounts.keys.toList().filter { it !in restored }.forEach { accounts.remove(it) }
|
||||
accounts.keys.toList().filter { it !in restored }.forEach { accounts.remove(it); libraryAsked.remove(it) }
|
||||
accounts.putAll(restored)
|
||||
installed = onDisk
|
||||
unfinished = partial
|
||||
@@ -139,6 +140,18 @@ object StoresState {
|
||||
if (force || !shelves.containsKey(store)) backend.loadShelves(app, force)
|
||||
}
|
||||
|
||||
private val libraryAsked = java.util.concurrent.ConcurrentHashMap<Store, Long>()
|
||||
|
||||
/** Once per store, again after a minute when the last sync never produced a library (offline, expired sign-in). */
|
||||
fun loadLibrary(context: Context, store: Store) {
|
||||
if (!isSignedIn(store) || library.containsKey(store)) return
|
||||
val now = android.os.SystemClock.elapsedRealtime()
|
||||
val asked = libraryAsked[store]
|
||||
if (asked != null && now - asked < LIBRARY_RETRY_MS) return
|
||||
libraryAsked[store] = now
|
||||
backends[store]?.syncLibrary(context.applicationContext, false)
|
||||
}
|
||||
|
||||
fun preview(context: Context, store: Store) {
|
||||
if (!shelves.containsKey(store)) backends[store]?.loadShelves(context.applicationContext, false)
|
||||
}
|
||||
@@ -165,6 +178,7 @@ object StoresState {
|
||||
|
||||
fun signIn(context: Context, store: Store) {
|
||||
expired.remove(store)
|
||||
libraryAsked.remove(store)
|
||||
backends[store]?.signIn(context) ?: logLine("${store.label}: this build has no sign-in for it yet")
|
||||
}
|
||||
|
||||
@@ -177,7 +191,7 @@ object StoresState {
|
||||
else if (store != Store.XBOX || backend == null) StoreAccounts.clear(app, store)
|
||||
main.post {
|
||||
if (store == Store.XBOX && StoreAccounts.signedInAs(app, store) != null) return@post
|
||||
accounts.remove(store); library.remove(store); status.remove(store); problems.remove(store)
|
||||
accounts.remove(store); library.remove(store); status.remove(store); problems.remove(store); libraryAsked.remove(store)
|
||||
logLine("${store.label}: signed out")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +47,8 @@ object EpicBackend : StoreBackend, EpicLaunchSupport {
|
||||
if (!quiet) StoresState.status[store] = app.getString(R.string.stores_sync_library)
|
||||
}
|
||||
val result = EpicLibrary.sync(app, force) { line -> if (!quiet) StoresState.post { StoresState.status[store] = line } }
|
||||
// Throttled means the cache is fresh, possibly written by another sync after this one read it.
|
||||
val fresh = if (result == EpicLibrary.SyncResult.Throttled) EpicLibrary.cached(app).map { EpicLibrary.toCatalogItem(app, it) } else cached
|
||||
StoresState.post {
|
||||
StoresState.status.remove(store)
|
||||
when (result) {
|
||||
@@ -56,7 +58,7 @@ object EpicBackend : StoreBackend, EpicLaunchSupport {
|
||||
}
|
||||
is EpicLibrary.SyncResult.Failed -> StoresState.problems[store] = result.message
|
||||
EpicLibrary.SyncResult.NotLoggedIn -> StoresState.problems[store] = StoresState.notSignedInLine(store)
|
||||
EpicLibrary.SyncResult.Throttled -> if (!StoresState.library.containsKey(store)) StoresState.library[store] = cached
|
||||
EpicLibrary.SyncResult.Throttled -> if (fresh.isNotEmpty()) StoresState.library[store] = mergeItems(StoresState.library[store], fresh)
|
||||
EpicLibrary.SyncResult.Busy -> {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,12 +227,6 @@ object EpicClient {
|
||||
)
|
||||
}
|
||||
|
||||
fun withLauncher(games: List<Library.SteamGame>, launcher: Library.SteamGame?): List<Library.SteamGame> {
|
||||
if (launcher == null) return games
|
||||
val at = games.indexOfFirst { it.source == Store.EPIC.id }.takeIf { it >= 0 } ?: games.size
|
||||
return games.subList(0, at) + launcher + games.subList(at, games.size)
|
||||
}
|
||||
|
||||
private fun steamSession(): Boolean =
|
||||
SessionState.running && !SessionState.stopRequested && SessionState.mode == SessionService.MODE_STEAM
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ object XboxBackend : StoreBackend {
|
||||
if (current == generation) {
|
||||
if (cached != null) StoresState.library[store] = mergeItems(StoresState.library[store], cached.games)
|
||||
StoresState.problems.remove(store)
|
||||
if (cached == null || force) StoresState.status[store] = "Syncing Xbox library…"
|
||||
if (cached == null || force) StoresState.status[store] = app.getString(com.droiddeck.launcher.R.string.stores_sync_library)
|
||||
else StoresState.status.remove(store)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
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.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. */
|
||||
@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) }
|
||||
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() }
|
||||
.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(),
|
||||
) { 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() }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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,160 +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) }
|
||||
}
|
||||
LaunchedEffect(Unit) { com.droiddeck.launcher.stores.xbox.XboxCloudGames.load(pageContext) }
|
||||
val cloudGames = com.droiddeck.launcher.stores.xbox.XboxCloudGames.entries.toList()
|
||||
val games = remember(s.steamGames, s.shortcutPicker, epic, launcherName, launcherArt, cloudGames) {
|
||||
val sorted = s.steamGames.sortedByDescending { it.lastPlayed }
|
||||
if (s.shortcutPicker) sorted else {
|
||||
val installedXbox = s.steamGames.filter { it.source == com.droiddeck.launcher.stores.Store.XBOX.id }.mapNotNull { it.storeId }.toSet()
|
||||
EpicClient.withLauncher(sorted, EpicClient.launcherEntry(pageContext, launcherName, epic, launcherArt)) +
|
||||
com.droiddeck.launcher.stores.xbox.XboxCloudGames.rows(pageContext, installedXbox)
|
||||
}
|
||||
}
|
||||
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 ->
|
||||
when (g.library) {
|
||||
Library.EPIC_LAUNCHER -> a.onEpicLauncher()
|
||||
Library.XBOX_CLOUD -> com.droiddeck.launcher.stores.xbox.XboxCloudGames.stream(pageContext, g.storeId.orEmpty(), g.name)
|
||||
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))
|
||||
}
|
||||
}
|
||||
if (current.library != Library.XBOX_CLOUD) {
|
||||
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)
|
||||
}
|
||||
if (current.library != Library.XBOX_CLOUD) {
|
||||
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) {
|
||||
@@ -181,48 +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) {
|
||||
val context = androidx.compose.ui.platform.LocalContext.current
|
||||
if (g.library == Library.XBOX_CLOUD) {
|
||||
androidx.compose.runtime.LaunchedEffect(g.gameId) { com.droiddeck.launcher.stores.xbox.XboxCloudGames.prefetch(context) }
|
||||
Actions {
|
||||
PrimaryButton("Stream", enabled = !s.busy, main = true, icon = Icons.Filled.PlayArrow) { launch(g) }
|
||||
SecondaryButton("Download") { com.droiddeck.launcher.stores.StoresState.openGameRequest = "${com.droiddeck.launcher.stores.Store.XBOX.id}:${g.storeId}" }
|
||||
SecondaryButton("Remove from Games", compact = true) { com.droiddeck.launcher.stores.xbox.XboxCloudGames.remove(context, g.storeId.orEmpty()) }
|
||||
BusyChip(s)
|
||||
}
|
||||
return
|
||||
}
|
||||
val xboxStream by androidx.compose.runtime.produceState(false, g.gameId) {
|
||||
value = g.source == com.droiddeck.launcher.stores.Store.XBOX.id && !g.storeId.isNullOrEmpty() && !s.shortcutPicker &&
|
||||
kotlinx.coroutines.withContext(kotlinx.coroutines.Dispatchers.IO) { com.droiddeck.launcher.stores.xbox.XboxCloudGames.streams(context, g.storeId!!) }
|
||||
}
|
||||
androidx.compose.runtime.LaunchedEffect(xboxStream) { if (xboxStream) com.droiddeck.launcher.stores.xbox.XboxCloudGames.prefetch(context) }
|
||||
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 (xboxStream) SecondaryButton("Stream") { com.droiddeck.launcher.stores.xbox.XboxCloudGames.stream(context, g.storeId.orEmpty(), g.name) }
|
||||
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) {
|
||||
@@ -237,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 {
|
||||
@@ -318,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) }
|
||||
}
|
||||
|
||||
@@ -451,7 +105,7 @@ 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
|
||||
@@ -505,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() }
|
||||
@@ -586,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(
|
||||
@@ -656,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,
|
||||
@@ -668,38 +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) } ?: ""
|
||||
g.library == Library.XBOX_CLOUD -> "Xbox Cloud Gaming"
|
||||
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)
|
||||
}
|
||||
}
|
||||
@@ -141,7 +141,6 @@ class FrontEndState(
|
||||
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,
|
||||
@@ -217,7 +216,6 @@ class FrontEndActions(
|
||||
val onDownloadPrefix: (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 = {},
|
||||
@@ -440,7 +438,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 +551,8 @@ 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) } }
|
||||
StepsLayer(screenAt)
|
||||
|
||||
appToChooseDisplay?.let { app ->
|
||||
|
||||
@@ -508,7 +508,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
|
||||
@@ -527,7 +527,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 ->
|
||||
@@ -570,18 +570,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
|
||||
@@ -595,7 +588,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(
|
||||
@@ -609,9 +632,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) {
|
||||
@@ -686,6 +706,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
|
||||
|
||||
@@ -0,0 +1,830 @@
|
||||
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.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) }
|
||||
}
|
||||
}
|
||||
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.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.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 != 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()) StoreAbout(description, AboutHeight, Modifier.fillMaxWidth())
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,690 @@
|
||||
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) { 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) }
|
||||
}
|
||||
@@ -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)) {
|
||||
|
||||
@@ -1,329 +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.xbox.xboxCloud
|
||||
import com.droiddeck.launcher.stores.xbox.xboxPc
|
||||
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 && item?.xboxCloud == true) XboxStreamButton(item)
|
||||
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)
|
||||
}
|
||||
}
|
||||
store == Store.XBOX && item != null && !item.xboxPc && item.xboxCloud -> {
|
||||
XboxStreamButton(item, main = true, modifier = leadOn)
|
||||
XboxAddToGamesButton(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)
|
||||
XboxAddToGamesButton(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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun XboxStreamButton(item: com.droiddeck.launcher.stores.CatalogItem, main: Boolean = false, modifier: Modifier = Modifier) {
|
||||
val ctx = LocalContext.current
|
||||
androidx.compose.runtime.LaunchedEffect(Unit) { com.droiddeck.launcher.stores.xbox.XboxCloudGames.prefetch(ctx) }
|
||||
val stream = { com.droiddeck.launcher.stores.xbox.XboxCloudGames.stream(ctx, item.id, item.title) }
|
||||
if (main) PrimaryButton("Stream", main = true, icon = Icons.Filled.PlayArrow, modifier = modifier) { stream() }
|
||||
else SecondaryButton("Stream", modifier = modifier) { stream() }
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun XboxAddToGamesButton(item: com.droiddeck.launcher.stores.CatalogItem) {
|
||||
val ctx = LocalContext.current
|
||||
androidx.compose.runtime.LaunchedEffect(Unit) { com.droiddeck.launcher.stores.xbox.XboxCloudGames.load(ctx) }
|
||||
// Add and Remove replace each other; the controller focus moves to the new button instead of getting lost.
|
||||
val slot = remember { androidx.compose.ui.focus.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 (com.droiddeck.launcher.stores.xbox.XboxCloudGames.isAdded(item.id)) {
|
||||
ActionChip("In Games", ok = true)
|
||||
SecondaryButton("Remove from Games", compact = true, modifier = Modifier.focusRequester(slot)) {
|
||||
com.droiddeck.launcher.stores.xbox.XboxCloudGames.remove(ctx, item.id); refocus()
|
||||
}
|
||||
} else SecondaryButton("Add to Games", modifier = Modifier.focusRequester(slot)) { com.droiddeck.launcher.stores.xbox.XboxCloudGames.add(ctx, item); refocus() }
|
||||
}
|
||||
@@ -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
Reference in new issue
Block a user