mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 12:28:40 +00:00
feat: art-first store cards (#1747)
* feat: art-first store cards that share the library display settings * fix: keep price and installed state on store cards when size is hidden * fix: darken the compact store badge for contrast on light artwork
This commit is contained in:
1 parent
64950099a3
commit
2410b8c67c
2 files changed
+54
-81
No files matched your search
@@ -14,6 +14,7 @@ import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.interaction.collectIsPressedAsState
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.BoxScope
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
@@ -602,10 +603,29 @@ private fun LibraryTile(e: LibraryEntry, capsule: Boolean, first: Boolean, navig
|
||||
}
|
||||
}
|
||||
|
||||
private val LibraryCardWidth = 150.dp
|
||||
internal val LibraryCardWidth = 150.dp
|
||||
|
||||
internal fun libraryTileWidth() = LibraryCardWidth * LibraryDisplay.scales[LibraryDisplay.level]
|
||||
|
||||
@Composable
|
||||
private fun LibraryArt(e: LibraryEntry, wide: Any?, tall: Any?, download: DownloadEntry?, hot: Boolean, capsule: Boolean, showSource: Boolean) {
|
||||
val chip = when {
|
||||
download != null -> "${download.percent}%"
|
||||
e.item != null && StoresState.isUnfinished(e.item) -> stringResource(R.string.stores_resume)
|
||||
e.installed && libraryUpdateAvailable(e) -> stringResource(R.string.common_update)
|
||||
else -> null
|
||||
}
|
||||
ArtCard(
|
||||
e.title, wide, tall, download, hot, capsule, chip,
|
||||
badge = if (showSource) ({ SourceChip(e.source, small = true, modifier = Modifier.align(Alignment.TopStart).padding(6.dp)) }) else null,
|
||||
) { LibrarySize(e) }
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun ArtCard(
|
||||
title: String, wide: Any?, tall: Any?, download: DownloadEntry?, hot: Boolean, capsule: Boolean, chip: String?,
|
||||
badge: (@Composable BoxScope.() -> Unit)? = null, detail: @Composable () -> Unit,
|
||||
) {
|
||||
val url = if (capsule) tall ?: wide else wide ?: tall
|
||||
val art = cardArtRequest(url, tall)
|
||||
val ratio = if (capsule) 5f / 7f else 16f / 9f
|
||||
@@ -614,7 +634,7 @@ private fun LibraryArt(e: LibraryEntry, wide: Any?, tall: Any?, download: Downlo
|
||||
val blurs = android.os.Build.VERSION.SDK_INT >= 31
|
||||
Box(
|
||||
Modifier.fillMaxWidth().aspectRatio(ratio).background(Color(0xFF101318))
|
||||
.then(if (url == null) Modifier.background(artBrush(hueOf(e.title))) else Modifier),
|
||||
.then(if (url == null) Modifier.background(artBrush(hueOf(title))) else Modifier),
|
||||
) {
|
||||
if (art != null && offRatio) {
|
||||
AsyncImage(model = art, contentDescription = null, contentScale = ContentScale.Crop, modifier = Modifier.matchParentSize().blur(32.dp))
|
||||
@@ -631,24 +651,18 @@ private fun LibraryArt(e: LibraryEntry, wide: Any?, tall: Any?, download: Downlo
|
||||
}
|
||||
},
|
||||
)
|
||||
if (showSource) SourceChip(e.source, small = true, modifier = Modifier.align(Alignment.TopStart).padding(6.dp))
|
||||
val state = when {
|
||||
download != null -> "${download.percent}%"
|
||||
e.item != null && StoresState.isUnfinished(e.item) -> stringResource(R.string.stores_resume)
|
||||
e.installed && libraryUpdateAvailable(e) -> stringResource(R.string.common_update)
|
||||
else -> null
|
||||
}
|
||||
if (state != null) Box(Modifier.align(Alignment.TopEnd).padding(6.dp)) { StateChip(state, ChipTone.BUSY, small = true) }
|
||||
badge?.invoke(this)
|
||||
if (chip != null) Box(Modifier.align(Alignment.TopEnd).padding(6.dp)) { StateChip(chip, ChipTone.BUSY, small = true) }
|
||||
val showName = LibraryDisplay.title || hot
|
||||
val showSize = LibraryDisplay.size || hot
|
||||
if (showName || showSize) Column(
|
||||
val showDetail = LibraryDisplay.size || hot
|
||||
if (showName || showDetail) Column(
|
||||
verticalArrangement = Arrangement.spacedBy(1.dp),
|
||||
modifier = Modifier.align(Alignment.BottomCenter).fillMaxWidth()
|
||||
.background(Brush.verticalGradient(0f to Color.Transparent, 0.6f to Color.Black.copy(alpha = 0.78f), 1f to Color.Black.copy(alpha = 0.92f)))
|
||||
.padding(start = 8.dp, end = 8.dp, top = 20.dp, bottom = if (download != null) 14.dp else 6.dp),
|
||||
) {
|
||||
if (showName) Text(e.title, fontSize = 11.sp, fontWeight = FontWeight.Bold, color = Color.White, maxLines = if (hot) 2 else 1, overflow = TextOverflow.Ellipsis, lineHeight = 13.sp)
|
||||
if (showSize) LibrarySize(e)
|
||||
if (showName) Text(title, fontSize = 11.sp, fontWeight = FontWeight.Bold, color = Color.White, maxLines = if (hot) 2 else 1, overflow = TextOverflow.Ellipsis, lineHeight = 13.sp)
|
||||
if (showDetail) detail()
|
||||
}
|
||||
if (download != null) Box(Modifier.align(Alignment.BottomCenter).padding(start = 6.dp, end = 6.dp, bottom = 5.dp)) {
|
||||
ProgressBarThin(download.fraction, paused = download.state == DownloadState.PAUSED, verify = download.stage == DownloadStage.VERIFY)
|
||||
@@ -868,7 +882,7 @@ private fun CollectionsButton() {
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun DisplayButton() {
|
||||
internal fun DisplayButton() {
|
||||
val pal = LocalPalette.current
|
||||
val ctx = LocalContext.current
|
||||
val title = stringResource(R.string.library_display)
|
||||
|
||||
@@ -852,6 +852,9 @@ private fun Storefront(
|
||||
var firstPlaced = false
|
||||
var columns by remember { mutableIntStateOf(1) }
|
||||
val density = androidx.compose.ui.platform.LocalDensity.current
|
||||
val displayContext = LocalContext.current
|
||||
remember { LibraryDisplay.load(displayContext) }
|
||||
val tileWidth = libraryTileWidth()
|
||||
val focus = LocalFrontFocus.current
|
||||
val scope = rememberCoroutineScope()
|
||||
val searching = q.isNotEmpty() || browsing || catalog
|
||||
@@ -893,9 +896,9 @@ private fun Storefront(
|
||||
GameCard(item, store, installedKeys, onOpen, first, navigation)
|
||||
}
|
||||
LazyVerticalGrid(
|
||||
columns = GridCells.Adaptive(CardWidth), state = grid, modifier = Modifier.fillMaxSize().focusGroup().onSizeChanged {
|
||||
columns = GridCells.Adaptive(tileWidth), state = grid, modifier = Modifier.fillMaxSize().focusGroup().onSizeChanged {
|
||||
val gap = with(density) { 10.dp.roundToPx() }
|
||||
val minimum = with(density) { CardWidth.roundToPx() }
|
||||
val minimum = with(density) { tileWidth.roundToPx() }
|
||||
columns = ((it.width + gap) / (minimum + gap)).coerceAtLeast(1)
|
||||
},
|
||||
horizontalArrangement = Arrangement.spacedBy(10.dp), verticalArrangement = Arrangement.spacedBy(10.dp),
|
||||
@@ -903,7 +906,7 @@ private fun Storefront(
|
||||
) {
|
||||
item(key = "profile", span = { GridItemSpan(maxLineSpan) }) { Rise(1) { ProfileStrip(store, library.size, StoresState.library.containsKey(store), s, a) } }
|
||||
item(key = "search", span = { GridItemSpan(maxLineSpan) }) {
|
||||
Rise(2) { ModeHeader(store.label, query, onQuery, placeholder = stringResource(R.string.stores_search_catalog, store.label), clearSearchFocus = clearSearchFocus) {} }
|
||||
Rise(2) { ModeHeader(store.label, query, onQuery, placeholder = stringResource(R.string.stores_search_catalog, store.label), clearSearchFocus = clearSearchFocus, inlineWhenStacked = true) { DisplayButton() } }
|
||||
}
|
||||
barLine?.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) } } } }
|
||||
@@ -1253,7 +1256,7 @@ private fun Shelf(title: String, items: List<CatalogItem>?, card: @Composable (C
|
||||
if (items.isNullOrEmpty()) return
|
||||
Box(Modifier.padding(top = 10.dp, bottom = 8.dp)) { SectionLabel(title) }
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(10.dp), modifier = Modifier.fillMaxWidth().horizontalScroll(rememberScrollState()).padding(vertical = 2.dp)) {
|
||||
for (item in items.take(24)) key(item.key) { Box(Modifier.width(CardWidth)) { card(item) } }
|
||||
for (item in items.take(24)) key(item.key) { Box(Modifier.width(libraryTileWidth())) { card(item) } }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1303,7 +1306,19 @@ private fun GameCard(
|
||||
.clip(RoundedCornerShape(10.dp)).glideBorder(hot, RoundedCornerShape(10.dp), pal.signal, pal.line)
|
||||
.hoverable(src).clickable(role = androidx.compose.ui.semantics.Role.Button, interactionSource = src, indication = LocalIndication.current, onClick = open).controllerConfirm(onClick = open),
|
||||
) {
|
||||
CardFace(item.title, item.imageUrl, item.tallImageUrl, download, hot) { CardMarker(item, installed, download) }
|
||||
val chip = when {
|
||||
download != null -> "${download.percent}%"
|
||||
item.accessible && StoresState.isUnfinished(item) -> stringResource(R.string.stores_resume)
|
||||
item.store == Store.GOG && installed && com.droiddeck.launcher.stores.gog.GogMaintenance.checks[item.id]?.state == com.droiddeck.launcher.stores.gog.GogMaintenance.State.AVAILABLE -> stringResource(R.string.common_update)
|
||||
else -> null
|
||||
}
|
||||
val priced = installed || item.isFree || item.isDiscounted || item.hasPrice
|
||||
val pill: (@Composable BoxScope.() -> Unit)? = if (priced && !LibraryDisplay.size && !hot) ({
|
||||
Box(Modifier.align(Alignment.TopStart).padding(6.dp).clip(RoundedCornerShape(6.dp)).background(Color.Black.copy(alpha = 0.82f)).padding(horizontal = 6.dp, vertical = 2.dp)) {
|
||||
CardMarker(item, installed, download, compact = true, status = false)
|
||||
}
|
||||
}) else null
|
||||
ArtCard(item.title, item.imageUrl, item.tallImageUrl, download, hot, capsule = false, chip = chip, badge = pill) { CardMarker(item, installed, download, status = false) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1325,8 +1340,6 @@ internal fun SyncBar(line: String) {
|
||||
}
|
||||
}
|
||||
|
||||
private val CardStrip = 26.dp
|
||||
|
||||
@Composable
|
||||
internal fun cardArtRequest(url: Any?, cover: Any?): coil.request.ImageRequest? {
|
||||
val ctx = LocalContext.current
|
||||
@@ -1336,68 +1349,14 @@ internal fun cardArtRequest(url: Any?, cover: Any?): coil.request.ImageRequest?
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(androidx.compose.foundation.ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
internal fun CardFace(
|
||||
title: String, wide: Any?, tall: Any?, download: com.droiddeck.launcher.stores.download.DownloadEntry?, hot: Boolean, capsule: Boolean = false,
|
||||
dim: Boolean = false, badge: (@Composable BoxScope.() -> Unit)? = null, marker: @Composable () -> Unit,
|
||||
) {
|
||||
val url = if (capsule) tall ?: wide else wide ?: tall
|
||||
val art = cardArtRequest(url, tall)
|
||||
val blurs = android.os.Build.VERSION.SDK_INT >= 31
|
||||
var landscape by remember(url) { mutableStateOf(false) }
|
||||
BoxWithConstraints(Modifier.fillMaxWidth()) {
|
||||
val total = if (capsule) maxWidth * 7f / 5f + CardStrip else maxWidth * 9f / 16f + CardStrip
|
||||
Box(Modifier.fillMaxWidth().height(total).background(Color(0xFF101318)).then(if (url == null) Modifier.background(artBrush(hueOf(title))) else Modifier)) {
|
||||
if (art != null && capsule && landscape) {
|
||||
// Stores without portrait covers (itch) would lose most of the art to a portrait crop.
|
||||
AsyncImage(model = art, contentDescription = null, contentScale = ContentScale.Crop, modifier = Modifier.matchParentSize().blur(24.dp))
|
||||
Spacer(Modifier.matchParentSize().background(Color.Black.copy(alpha = if (blurs) 0.35f else 0.7f)))
|
||||
AsyncImage(model = art, contentDescription = null, contentScale = ContentScale.Fit, modifier = Modifier.matchParentSize().padding(bottom = CardStrip))
|
||||
} else if (art != null) AsyncImage(
|
||||
model = art, contentDescription = null, contentScale = if (capsule) ContentScale.Fit else ContentScale.Crop,
|
||||
modifier = Modifier.matchParentSize().padding(bottom = if (capsule) CardStrip else 0.dp),
|
||||
onSuccess = { r ->
|
||||
val drawn = r.result.drawable
|
||||
if (capsule && drawn.intrinsicWidth > 0 && drawn.intrinsicHeight > 0) landscape = drawn.intrinsicWidth > drawn.intrinsicHeight * 0.95f
|
||||
},
|
||||
)
|
||||
if (dim) Spacer(Modifier.matchParentSize().background(Color.Black.copy(alpha = 0.5f)))
|
||||
Box(Modifier.align(Alignment.BottomCenter).fillMaxWidth().height(CardStrip).clipToBounds()) {
|
||||
if (art != null) AsyncImage(
|
||||
model = art, contentDescription = null, contentScale = ContentScale.Crop,
|
||||
modifier = Modifier.fillMaxWidth().wrapContentHeight(Alignment.Bottom, unbounded = true).height(total).blur(24.dp),
|
||||
)
|
||||
Spacer(Modifier.matchParentSize().background(Color.Black.copy(alpha = if (blurs) 0.45f else 0.7f)))
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(6.dp),
|
||||
modifier = Modifier.matchParentSize().padding(horizontal = 8.dp),
|
||||
) {
|
||||
Text(
|
||||
title, fontSize = 11.sp, fontWeight = FontWeight.Bold, color = Color.White, maxLines = 1,
|
||||
overflow = if (hot) TextOverflow.Clip else TextOverflow.Ellipsis,
|
||||
modifier = Modifier.weight(1f).then(if (hot) Modifier.basicMarquee(iterations = Int.MAX_VALUE, initialDelayMillis = 700, velocity = 40.dp) else Modifier),
|
||||
)
|
||||
marker()
|
||||
}
|
||||
}
|
||||
Spacer(Modifier.align(Alignment.BottomCenter).padding(bottom = CardStrip).fillMaxWidth().height(14.dp).background(Brush.verticalGradient(0f to Color.Transparent, 1f to Color.Black.copy(alpha = 0.35f))))
|
||||
if (download != null) Box(Modifier.align(Alignment.BottomCenter).padding(start = 6.dp, end = 6.dp, bottom = CardStrip + 5.dp)) {
|
||||
ProgressBarThin(download.fraction, paused = download.state == DownloadState.PAUSED, verify = download.stage == DownloadStage.VERIFY)
|
||||
}
|
||||
badge?.invoke(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun CardMarker(item: CatalogItem, installed: Boolean, download: com.droiddeck.launcher.stores.download.DownloadEntry?, compact: Boolean = false) {
|
||||
private fun CardMarker(item: CatalogItem, installed: Boolean, download: com.droiddeck.launcher.stores.download.DownloadEntry?, compact: Boolean = false, status: Boolean = true) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val pal = LocalPalette.current
|
||||
val small = 10.sp
|
||||
when {
|
||||
item.store == Store.GOG && download != null -> Text("${download.percent}%", fontSize = small, fontWeight = FontWeight.Bold, color = pal.signal, maxLines = 1)
|
||||
item.store == Store.GOG && installed && com.droiddeck.launcher.stores.gog.GogMaintenance.checks[item.id]?.state == com.droiddeck.launcher.stores.gog.GogMaintenance.State.AVAILABLE ->
|
||||
status && item.store == Store.GOG && download != null -> Text("${download.percent}%", fontSize = small, fontWeight = FontWeight.Bold, color = pal.signal, maxLines = 1)
|
||||
status && item.store == Store.GOG && installed && com.droiddeck.launcher.stores.gog.GogMaintenance.checks[item.id]?.state == com.droiddeck.launcher.stores.gog.GogMaintenance.State.AVAILABLE ->
|
||||
Text(stringResource(R.string.common_update), fontSize = small, fontWeight = FontWeight.Bold, color = pal.signal, maxLines = 1)
|
||||
installed -> Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(3.dp)) {
|
||||
val ctx = LocalContext.current
|
||||
@@ -1406,8 +1365,8 @@ private fun CardMarker(item: CatalogItem, installed: Boolean, download: com.droi
|
||||
if (!compact) com.droiddeck.launcher.stores.StoreSizes.onDisk[item.key]?.let { Text(formatBytes(it), fontSize = 11.sp, fontWeight = FontWeight.Bold, color = Color.White, maxLines = 1) }
|
||||
Icon(Icons.Filled.Check, stringResource(R.string.stores_installed_chip), tint = pal.good, modifier = Modifier.size(11.dp))
|
||||
}
|
||||
download != null -> Text("${download.percent}%", fontSize = small, fontWeight = FontWeight.Bold, color = pal.signal, maxLines = 1)
|
||||
item.accessible && StoresState.isUnfinished(item) -> Text(stringResource(R.string.stores_resume), fontSize = small, fontWeight = FontWeight.Bold, color = pal.signal, maxLines = 1)
|
||||
status && download != null -> Text("${download.percent}%", fontSize = small, fontWeight = FontWeight.Bold, color = pal.signal, maxLines = 1)
|
||||
status && item.accessible && StoresState.isUnfinished(item) -> Text(stringResource(R.string.stores_resume), fontSize = small, fontWeight = FontWeight.Bold, color = pal.signal, maxLines = 1)
|
||||
item.accessible && compact -> Unit
|
||||
item.accessible -> com.droiddeck.launcher.stores.StoreSizes.size(item).takeIf { it > 0 }?.let { Text(formatBytes(it), fontSize = 11.sp, fontWeight = FontWeight.Bold, color = Color.White, maxLines = 1) }
|
||||
item.isFree -> Text(stringResource(R.string.stores_free), fontSize = small, fontWeight = FontWeight.Bold, color = pal.good, maxLines = 1)
|
||||
|
||||
Reference in new issue
Block a user