feat: sort the store library and installed tabs, and switch between card and list views (#798)

This commit is contained in:
kingokksa authored and GitHub committed 2026-10-15 09:20:49 -04:00
1 parent e1ca869d8e
commit 47e4f25346
39 files changed
+710 -26

No files matched your search

@@ -160,6 +160,8 @@ class MainActivity : ComponentActivity() {
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())
private var storesView by mutableStateOf(SessionPrefs.STORES_VIEWS.first())
private var mic by mutableStateOf(false)
private var wifiDiscovery by mutableStateOf(false)
private var wifiDiscoveryPermission by mutableStateOf(false)
@@ -517,6 +519,8 @@ class MainActivity : ComponentActivity() {
gameStoresSpeedTier = SessionPrefs.gameStoresSpeedTier(this)
storesOpenTab = SessionPrefs.storesOpenTab(this)
storesShowMature = SessionPrefs.storesShowMature(this)
storesSort = SessionPrefs.storesSort(this)
storesView = SessionPrefs.storesView(this)
applyLauncherFullscreen()
updates.start()
setContent {
@@ -574,6 +578,8 @@ class MainActivity : ComponentActivity() {
addedGamesArt = addedGamesArt,
sgdbUserKey = sgdbUserKey,
storesShowMature = storesShowMature,
storesSort = storesSort,
storesView = storesView,
storeDownloadsActive = com.droiddeck.launcher.stores.StoresState.activeDownloads,
),
FrontEndActions(
@@ -729,6 +735,8 @@ class MainActivity : ComponentActivity() {
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 },
onStoresView = { view -> SessionPrefs.setStoresView(this, view); storesView = view },
onLibraryChanged = { refreshAddedGames(); refresh() },
onAnimationsEnabled = { on ->
SessionPrefs.setAnimationsEnabled(this, on)
@@ -104,6 +104,23 @@ object SessionPrefs {
prefs(context).edit().putBoolean("storesShowMature", show).apply()
}
fun storesSort(context: Context): String =
prefs(context).getString("storesSort", null)?.takeIf { it in STORES_SORTS } ?: STORES_SORTS.first()
fun setStoresSort(context: Context, sort: String) {
prefs(context).edit().putString("storesSort", if (sort in STORES_SORTS) sort else STORES_SORTS.first()).apply()
}
fun storesView(context: Context): String =
prefs(context).getString("storesView", null)?.takeIf { it in STORES_VIEWS } ?: STORES_VIEWS.first()
fun setStoresView(context: Context, view: String) {
prefs(context).edit().putString("storesView", if (view in STORES_VIEWS) view else STORES_VIEWS.first()).apply()
}
val STORES_SORTS = listOf("lastPlayed", "recentlyInstalled", "titleAsc", "titleDesc", "sizeDesc", "sizeAsc", "releaseDateDesc")
val STORES_VIEWS = listOf("cards", "list")
const val STORES_OPEN_LIBRARY = "library"
const val STORES_OPEN_STORE = "store"
@@ -53,6 +53,35 @@ 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)
} ?: 0L
fun sortCatalogItems(
items: List<CatalogItem>,
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
}
internal fun retainCatalogOrder(items: List<CatalogItem>, previous: List<CatalogItem>): List<CatalogItem> {
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) }
}
fun mergeItems(old: List<CatalogItem>?, new: List<CatalogItem>): List<CatalogItem> {
if (old.isNullOrEmpty()) return new
val before = old.associateBy { it.key }
@@ -12,6 +12,7 @@ import com.droiddeck.launcher.stores.epic.EpicCredentialStore
import com.droiddeck.launcher.stores.epic.EpicDownloadManager
import com.droiddeck.launcher.stores.epic.EpicInstallTags
import com.droiddeck.launcher.stores.epic.EpicPrefs
import java.util.concurrent.CompletableFuture
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.Executors
@@ -20,7 +21,8 @@ object StoreSizes {
val known = mutableStateMapOf<String, Long>()
private val asked = ConcurrentHashMap.newKeySet<String>()
private val sizeRequests = ConcurrentHashMap<String, CompletableFuture<Long?>>()
private val diskRequests = ConcurrentHashMap<String, CompletableFuture<Long?>>()
private val pool = Executors.newFixedThreadPool(3, com.droiddeck.launcher.stores.download.DownloadQueue.workerFactory("sizes"))
fun size(item: CatalogItem): Long = known[item.key] ?: item.sizeBytes
@@ -29,22 +31,35 @@ object StoreSizes {
private fun cache(context: Context, store: Store) = caches.getOrPut(store) { SizeCache.forStore(context.applicationContext.filesDir, store) }
fun request(context: Context, item: CatalogItem) {
if (!item.owned || item.sizeBytes > 0 || item.store == Store.GOG) return
if (known.containsKey(item.key) || !asked.add(item.key)) return
if (!item.owned || item.sizeBytes > 0 || item.store == Store.GOG || known.containsKey(item.key)) return
resolve(context, item).thenAccept { bytes ->
if (bytes != null) StoresState.post { known[item.key] = bytes }
}
}
fun resolve(context: Context, item: CatalogItem): CompletableFuture<Long?> {
val available = known[item.key] ?: item.sizeBytes.takeIf { it > 0 }
if (!item.owned || item.store == Store.GOG || item.sizeBytes > 0) return CompletableFuture.completedFuture(available)
if (available != null) return CompletableFuture.completedFuture(available)
val app = context.applicationContext
val version = item.extra["version"].orEmpty()
pool.execute {
val cached = cache(app, item.store).get(item.id, version)
if (cached != null) { StoresState.post { known[item.key] = cached }; return@execute }
val bytes = runCatching { fetch(app, item) }.onFailure { Log.w(TAG, "${item.key}: ${it.javaClass.simpleName}") }.getOrNull() ?: 0L
if (bytes > 0) {
cache(app, item.store).put(item.id, version, bytes)
when (item.store) {
Store.EPIC -> EpicPrefs.get(app).edit().putLong("size_${item.id}", bytes).apply()
Store.AMAZON -> AmazonPrefs.get(app).edit().putLong("size_${item.id}", bytes).apply()
Store.GOG -> {}
return sizeRequests.computeIfAbsent(item.key) {
CompletableFuture.supplyAsync({
val cached = cache(app, item.store).get(item.id, version)
val bytes = cached ?: runCatching { fetch(app, item) }
.onFailure { Log.w(TAG, "${item.key}: ${it.javaClass.simpleName}") }
.getOrNull()
bytes?.takeIf { it > 0 }?.also {
cache(app, item.store).put(item.id, version, it)
when (item.store) {
Store.EPIC -> EpicPrefs.get(app).edit().putLong("size_${item.id}", it).apply()
Store.AMAZON -> AmazonPrefs.get(app).edit().putLong("size_${item.id}", it).apply()
Store.GOG -> {}
}
}
StoresState.post { known[item.key] = bytes }
}, pool).exceptionally { error ->
Log.w(TAG, "${item.key}: size resolution failed", error)
null
}
}
}
@@ -52,14 +67,25 @@ object StoreSizes {
val onDisk = mutableStateMapOf<String, Long>()
fun requestDisk(context: Context, key: String, game: InstalledStoreGame) {
if (onDisk.containsKey(key) || !asked.add("disk:$key")) return
resolveDisk(context, key, game).thenAccept { bytes ->
if (bytes != null) StoresState.post { onDisk[key] = bytes }
}
}
fun resolveDisk(context: Context, key: String, game: InstalledStoreGame): CompletableFuture<Long?> {
onDisk[key]?.let { return CompletableFuture.completedFuture(it) }
val app = context.applicationContext
val version = "disk:${game.sidecar.installedAt}:${game.sidecar.installVersion}"
pool.execute {
val c = cache(app, game.sidecar.store)
val bytes = c.get("disk:${game.sidecar.id}", version)
?: game.folder.walkTopDown().filter { it.isFile && !it.name.startsWith(".droiddeck") }.sumOf { it.length() }.also { c.put("disk:${game.sidecar.id}", version, it) }
if (bytes > 0) StoresState.post { onDisk[key] = bytes }
return diskRequests.computeIfAbsent(key) {
CompletableFuture.supplyAsync({
val c = cache(app, game.sidecar.store)
c.get("disk:${game.sidecar.id}", version)
?: game.folder.walkTopDown().filter { it.isFile && !it.name.startsWith(".droiddeck") }
.sumOf { it.length() }.also { c.put("disk:${game.sidecar.id}", version, it) }
}, pool).thenApply { it.takeIf { bytes -> bytes > 0 } }.exceptionally { error ->
Log.w(TAG, "$key: disk size resolution failed", error)
null
}
}
}
@@ -139,6 +139,8 @@ class FrontEndState(
val addedGamesArt: Boolean = true,
val sgdbUserKey: Boolean = false,
val storesShowMature: Boolean = false,
val storesSort: String = SessionPrefs.STORES_SORTS.first(),
val storesView: String = SessionPrefs.STORES_VIEWS.first(),
val storeDownloadsActive: Int = 0,
val updates: UpdatesState = UpdatesState(),
)
@@ -199,6 +201,8 @@ class FrontEndActions(
val onStoresOpenTab: (String) -> Unit = {},
val onNavigated: () -> Unit = {},
val onStoresShowMature: (Boolean) -> Unit = {},
val onStoresSort: (String) -> Unit = {},
val onStoresView: (String) -> Unit = {},
val onLibraryChanged: () -> Unit = {},
val onHomeApp: () -> Unit = {},
val onHomeScreen: (Boolean) -> Unit = {},
@@ -85,6 +85,11 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Check
import androidx.compose.material.icons.filled.Search
import androidx.compose.material.icons.automirrored.filled.Login
import androidx.compose.material.icons.filled.GridView
import androidx.compose.material.icons.filled.Sort
import androidx.compose.material.icons.filled.ViewList
import com.droiddeck.launcher.stores.sortCatalogItems
import com.droiddeck.launcher.stores.retainCatalogOrder
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.basicMarquee
import androidx.compose.material.icons.filled.PlayArrow
@@ -95,6 +100,7 @@ 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.State
import androidx.compose.runtime.getValue
import androidx.compose.runtime.key
@@ -132,6 +138,10 @@ import com.droiddeck.launcher.stores.StoresState
import com.droiddeck.launcher.stores.download.DownloadStage
import com.droiddeck.launcher.stores.download.DownloadState
import com.droiddeck.launcher.stores.formatBytes
import java.util.concurrent.CompletableFuture
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException
import kotlinx.coroutines.suspendCancellableCoroutine
private const val DOWNLOADS = "downloads"
@@ -738,13 +748,72 @@ private fun Storefront(
val installedOnly = tab == "installed"
val loaded = StoresState.library.containsKey(store)
val showGrid = tab != "store" || q.isNotEmpty()
val visible = remember(library, installedItems, everything, tab, q, s.storesShowMature) {
val sort = s.storesSort
val lastPlayedFor = remember(s.steamGames) {
val byKey = s.steamGames.associate { "${it.source}:${it.storeId}" to it.lastPlayed }
val lookup: (CatalogItem) -> Long = { i -> byKey[i.key] ?: 0L }
lookup
}
val installedAtFor = remember(StoresState.installed) {
val byKey = StoresState.installed.associate { "${it.sidecar.store.id}:${it.sidecar.id}" to it.sidecar.installedAt }
val lookup: (CatalogItem) -> Long = { i -> byKey[i.key] ?: 0L }
lookup
}
val isSizeSort = (tab == "library" || tab == "installed") && (sort == "sizeAsc" || sort == "sizeDesc")
val candidates = remember(library, installedItems, everything, tab, q, s.storesShowMature) {
when (tab) {
"library" -> library.filter(::matches)
"installed" -> installedItems.filter(::matches)
else -> everything.filter { matches(it) && shown(it) }
}
}
val candidateKeys = remember(candidates) { candidates.map { it.key } }
var resolvedSizeSortKey by remember(store, tab) { mutableStateOf<List<String>?>(null) }
val sizeSortPending = isSizeSort && resolvedSizeSortKey != candidateKeys
var stableVisible by remember(store, tab) { mutableStateOf(emptyList<CatalogItem>()) }
val resolvedSizes = when {
!isSizeSort -> emptyMap<String, Long>()
installedOnly -> com.droiddeck.launcher.stores.StoreSizes.onDisk.toMap()
else -> com.droiddeck.launcher.stores.StoreSizes.known.toMap()
}
val sizeFor = remember(resolvedSizes, installedOnly) {
val resolved = resolvedSizes
val lookup: (CatalogItem) -> Long = { item ->
resolved[item.key] ?: if (installedOnly) 0L else item.sizeBytes
}
lookup
}
val sortedVisible = remember(candidates, tab, sort, lastPlayedFor, installedAtFor, sizeFor) {
if (tab == "library" || tab == "installed")
sortCatalogItems(candidates, sort, lastPlayed = lastPlayedFor, installedAt = installedAtFor, size = sizeFor)
else candidates
}
val visible = remember(sizeSortPending, candidates, stableVisible, sortedVisible) {
if (sizeSortPending) retainCatalogOrder(candidates, stableVisible) else sortedVisible
}
SideEffect {
if (!sizeSortPending && stableVisible != sortedVisible) stableVisible = sortedVisible
}
LaunchedEffect(store, tab, sort, candidates, candidateKeys) {
if (!isSizeSort || resolvedSizeSortKey == candidateKeys) return@LaunchedEffect
val requests = candidates.map { item ->
val future: CompletableFuture<Long?> = if (tab == "installed") {
StoresState.installedGame(store, item.id)?.let {
com.droiddeck.launcher.stores.StoreSizes.resolveDisk(ctx, item.key, it)
} ?: CompletableFuture.completedFuture<Long?>(null)
} else {
com.droiddeck.launcher.stores.StoreSizes.resolve(ctx, item)
}
item to future
}
CompletableFuture.allOf(*requests.map { it.second }.toTypedArray()).await()
requests.forEach { (item, future) ->
val bytes = future.getNow(null) ?: return@forEach
if (tab == "installed") com.droiddeck.launcher.stores.StoreSizes.onDisk[item.key] = bytes
else if (item.owned && item.sizeBytes <= 0) com.droiddeck.launcher.stores.StoreSizes.known[item.key] = bytes
}
resolvedSizeSortKey = candidateKeys
}
val empty = stringResource(when {
installedOnly -> R.string.stores_installed_empty
tab == "library" && library.isEmpty() && StoresState.status[store] != null -> R.string.stores_library_loading
@@ -755,7 +824,9 @@ private fun Storefront(
val density = androidx.compose.ui.platform.LocalDensity.current
val focus = LocalFrontFocus.current
val scope = rememberCoroutineScope()
val headerItems = 1 + (if (StoresState.status[store] != null) 1 else 0) + (if (StoresState.problems[store] != null) 1 else 0)
val headerItems = 1 + (if (sizeSortPending) 1 else 0) +
(if (StoresState.status[store] != null) 1 else 0) + (if (StoresState.problems[store] != null) 1 else 0)
val listMode = s.storesView == "list" && (tab == "library" || tab == "installed")
val card: @Composable (CatalogItem) -> Unit = { item ->
val first = if (showGrid) item.key == visible.firstOrNull()?.key else !firstPlaced
firstPlaced = true
@@ -767,7 +838,7 @@ private fun Storefront(
else -> 0
}
val index = visible.indexOfFirst { it.key == item.key }
val next = storeGridNeighbor(index, visible.size, columns, direction)
val next = storeGridNeighbor(index, visible.size, if (listMode) 1 else columns, direction)
when {
direction == 0 || index < 0 -> false
next == null -> direction > 0
@@ -786,12 +857,13 @@ private fun Storefront(
}
}
}
GameCard(item, store, s, a, installedKeys, onOpen, first, navigation)
if (listMode) GameListRow(item, store, installedKeys, onOpen, first, navigation)
else GameCard(item, store, s, a, installedKeys, onOpen, first, navigation)
}
LazyVerticalGrid(
columns = GridCells.Adaptive(CardWidth), state = grid, modifier = Modifier.fillMaxSize().focusGroup().onSizeChanged {
columns = if (listMode) GridCells.Fixed(1) else GridCells.Adaptive(CardWidth), state = grid, modifier = Modifier.fillMaxSize().focusGroup().onSizeChanged {
val gap = with(density) { 10.dp.roundToPx() }
val minimum = with(density) { CardWidth.roundToPx() }
val minimum = with(density) { (if (listMode) CardWidth * 2 else CardWidth).roundToPx() }
columns = ((it.width + gap) / (minimum + gap)).toInt().coerceAtLeast(1)
},
horizontalArrangement = Arrangement.spacedBy(10.dp), verticalArrangement = Arrangement.spacedBy(10.dp),
@@ -813,12 +885,25 @@ private fun Storefront(
else -> stringResource(R.string.stores_search_library)
},
) {
if (tab == "library" || tab == "installed") {
SortButton(s, a)
ViewButton(s, a)
}
SmallTextButton(stringResource(R.string.stores_refresh)) { StoresState.open(ctx, store, force = true) }
val name = StoresState.accounts[store] ?: ""
SignOutButton(store, name)
}
}
}
if (sizeSortPending) item(key = "size-sort-progress", span = { GridItemSpan(maxLineSpan) }) {
Row(
verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp),
modifier = Modifier.fillMaxWidth().padding(bottom = 8.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)
}
}
StoresState.status[store]?.let { line -> item(key = "sync", span = { GridItemSpan(maxLineSpan) }) { Rise(3) { SyncBar(line) } } }
StoresState.problems[store]?.let { line -> item(key = "problem", span = { GridItemSpan(maxLineSpan) }) { Rise(3) { Box(Modifier.padding(bottom = 8.dp)) { Note(line) } } } }
when (tab) {
@@ -844,6 +929,14 @@ private fun Storefront(
}
}
private suspend fun <T> CompletableFuture<T>.await(): T =
suspendCancellableCoroutine { continuation ->
whenComplete { value, error ->
if (error == null) continuation.resume(value)
else continuation.resumeWithException(error)
}
}
@Composable
internal fun ModeHeader(title: String, query: String, onQuery: (String) -> Unit, placeholder: String, trailing: @Composable () -> Unit) {
val colors = MaterialTheme.colorScheme
@@ -933,6 +1026,126 @@ private fun SmallTextButton(text: String, key: String = text, onClick: () -> Uni
)
}
@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),
) { Icon(icon, description, tint = if (hot) pal.signal else colors.onSurfaceVariant, modifier = Modifier.size(18.dp)) }
}
@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
StoresMotion.ask(StepAsk(
anchor = from, side = StepSide.Left, accent = pal.signal, pillCorner = 8.dp, items = SessionPrefs.STORES_SORTS.size,
onDismiss = {},
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)
StoresMotion.fold()
}
}
}
})
}
}
}
@Composable
private fun ViewButton(s: FrontEndState, a: FrontEndActions) {
val list = s.storesView == "list"
HeaderIconButton(
if (list) stringResource(R.string.stores_view_cards) else stringResource(R.string.stores_view_list),
if (list) Icons.Filled.GridView else Icons.Filled.ViewList,
"view",
) { a.onStoresView(if (list) "cards" else "list") }
}
@Composable
private fun GameListRow(
item: CatalogItem, store: Store, installedKeys: Set<String>, onOpen: (String) -> Unit,
first: Boolean = false, navigation: Modifier = Modifier,
) {
val colors = MaterialTheme.colorScheme
val pal = LocalPalette.current
val src = remember { MutableInteractionSource() }
val hot = rememberHot(src)
val installed = item.id in installedKeys
val download = StoresState.download("${store.id}:${item.id}")?.takeIf { it.isActive }
if (installed) {
val ctx = LocalContext.current
val game = StoresState.installedGame(store, item.id)
if (game != null) androidx.compose.runtime.LaunchedEffect(item.key) { com.droiddeck.launcher.stores.StoreSizes.requestDisk(ctx, item.key, game) }
}
val placed = remember { arrayOfNulls<androidx.compose.ui.layout.LayoutCoordinates>(1) }
val corner = with(androidx.compose.ui.platform.LocalDensity.current) { 10.dp.toPx() }
val open = {
placed[0]?.takeIf { it.isAttached }?.let { StoresMotion.markCard(CardMark(item.key, it.boundsInRoot(), corner, item.imageUrl ?: item.tallImageUrl)) }
onOpen(item.key)
}
val meta = listOfNotNull(
item.developer.takeIf { it.isNotBlank() },
item.releaseDate.take(4).takeIf { it.length == 4 },
when {
installed -> {
val bytes = com.droiddeck.launcher.stores.StoreSizes.onDisk[item.key]
?: com.droiddeck.launcher.stores.StoreSizes.size(item).takeIf { it > 0 } ?: 0L
formatBytes(bytes).takeIf { it.isNotEmpty() }
}
item.isFree -> stringResource(R.string.stores_free)
item.isDiscounted -> "-${item.discountPercent}%"
item.hasPrice -> item.finalPrice.takeIf { it.isNotBlank() }
else -> null
},
)
Row(
verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(12.dp),
modifier = Modifier.fillMaxWidth().heightIn(min = 64.dp).then(navigation).paneItem("card:${item.key}")
.then(if (first) Modifier.firstTile() else Modifier)
.clip(RoundedCornerShape(10.dp)).glideBorder(hot, RoundedCornerShape(10.dp), pal.signal, pal.line)
.hoverable(src).clickable(interactionSource = src, indication = LocalIndication.current, onClick = open).controllerConfirm(onClick = open)
.padding(horizontal = 10.dp, vertical = 8.dp),
) {
CardArt(item, Modifier.width(96.dp).height(54.dp).clip(RoundedCornerShape(8.dp)))
Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(2.dp)) {
Text(item.title, fontSize = 14.sp, fontWeight = FontWeight.Bold, color = colors.onBackground, maxLines = 1, overflow = TextOverflow.Ellipsis)
Text(meta.joinToString(" · "), fontSize = 12.sp, color = colors.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis)
}
if (installed) Icon(Icons.Filled.Check, stringResource(R.string.stores_installed_chip), tint = pal.good, modifier = Modifier.size(16.dp))
else if (download != null) Text("${download.percent}%", fontSize = 11.sp, fontWeight = FontWeight.Bold, color = pal.signal, maxLines = 1)
}
}
@Composable
private fun SignOutButton(store: Store, name: String) {
val ctx = LocalContext.current