mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-20 13:26:02 +00:00
Switch the GOG store to GOG's official listing endpoint: fewer requests, the tab now opens in seconds (#786)
This commit is contained in:
1 parent
cd18e87864
commit
60043873f2
9 files changed
+334
-47
No files matched your search
@@ -85,7 +85,9 @@ internal fun StoreGameDetail(store: Store, key: String, s: FrontEndState, a: Fro
|
||||
.clip(Shape16).background(artBrush(hueOf(title))),
|
||||
) {
|
||||
val art = item?.imageUrl ?: installed?.sidecar?.hero ?: installed?.sidecar?.cover
|
||||
if (art != null) AsyncImage(model = art, contentDescription = null, contentScale = ContentScale.Crop, modifier = Modifier.matchParentSize())
|
||||
// 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))))
|
||||
|
||||
@@ -1007,8 +1007,11 @@ private fun Storefront(
|
||||
val density = androidx.compose.ui.platform.LocalDensity.current
|
||||
val focus = LocalFrontFocus.current
|
||||
val scope = rememberCoroutineScope()
|
||||
val headerItems = 1 + (if (sizeSortPending) 1 else 0) +
|
||||
(if (StoresState.status[store] != null) 1 else 0) + (if (StoresState.problems[store] != null) 1 else 0)
|
||||
// A bar only where the tab has nothing else on it: shelves, the shelf of owned games, or a grid still loading.
|
||||
val gridEmpty = if (showGrid) visible.isEmpty() else (shelves == null || shelves.isEmpty) && library.isEmpty()
|
||||
val barLine = StoresState.status[store]?.takeIf { gridEmpty && syncCount(it) != null }
|
||||
val headerItems = 1 + (if (sizeSortPending) 1 else 0) + (if (barLine != null) 1 else 0) +
|
||||
(if (StoresState.problems[store] != null) 1 else 0)
|
||||
val listMode = s.storesView == "list" && tab == "library"
|
||||
val capsules = s.storesView == "capsules" && tab == "library"
|
||||
val tileWidth = if (capsules) CapsuleWidth else CardWidth
|
||||
@@ -1091,7 +1094,7 @@ private fun Storefront(
|
||||
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) } } }
|
||||
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) } } } }
|
||||
when (tab) {
|
||||
"library" -> if (!loaded) Unit
|
||||
@@ -1480,22 +1483,35 @@ private fun GameCard(
|
||||
}
|
||||
}
|
||||
|
||||
private fun syncCount(line: String): Pair<Int, Int>? {
|
||||
val match = Regex("(\\d+)\\s*/\\s*(\\d+)").find(line) ?: return null
|
||||
val done = match.groupValues[1].toIntOrNull() ?: return null
|
||||
val total = match.groupValues[2].toIntOrNull()?.takeIf { it > 0 } ?: return null
|
||||
return done to total
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SyncBar(line: String) {
|
||||
val count = Regex("(\\d+)\\s*/\\s*(\\d+)").find(line)
|
||||
val done = count?.groupValues?.get(1)?.toIntOrNull()
|
||||
val total = count?.groupValues?.get(2)?.toIntOrNull()?.takeIf { it > 0 }
|
||||
val count = syncCount(line) ?: return
|
||||
val done = count.first
|
||||
val total = count.second
|
||||
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp), modifier = Modifier.fillMaxWidth().padding(bottom = 8.dp)) {
|
||||
Box(Modifier.weight(1f)) {
|
||||
if (done != null && total != null) androidx.compose.material3.LinearProgressIndicator(progress = { (done.toFloat() / total).coerceIn(0f, 1f) }, modifier = Modifier.fillMaxWidth().height(3.dp))
|
||||
else androidx.compose.material3.LinearProgressIndicator(modifier = Modifier.fillMaxWidth().height(3.dp))
|
||||
}
|
||||
if (done != null && total != null) Text("$done/$total", fontSize = 11.sp, color = MaterialTheme.colorScheme.onSurfaceVariant, maxLines = 1)
|
||||
Box(Modifier.weight(1f)) { androidx.compose.material3.LinearProgressIndicator(progress = { (done.toFloat() / total).coerceIn(0f, 1f) }, modifier = Modifier.fillMaxWidth().height(3.dp)) }
|
||||
Text("$done/$total", fontSize = 11.sp, color = MaterialTheme.colorScheme.onSurfaceVariant, maxLines = 1)
|
||||
}
|
||||
}
|
||||
|
||||
private val CardStrip = 26.dp
|
||||
|
||||
@Composable
|
||||
internal fun cardArtRequest(url: String?, cover: String?): coil.request.ImageRequest? {
|
||||
val ctx = LocalContext.current
|
||||
val under = cover?.takeIf { it != url }
|
||||
return remember(url, under) {
|
||||
url?.let { coil.request.ImageRequest.Builder(ctx).data(it).apply { if (under != null) placeholderMemoryCacheKey(under) }.build() }
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(androidx.compose.foundation.ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
private fun CardFace(
|
||||
@@ -1503,26 +1519,27 @@ private fun CardFace(
|
||||
marker: @Composable () -> Unit,
|
||||
) {
|
||||
val url = if (capsule) item.tallImageUrl ?: item.imageUrl else item.imageUrl ?: item.tallImageUrl
|
||||
val art = cardArtRequest(url, item.tallImageUrl)
|
||||
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(item.title))) else Modifier)) {
|
||||
if (url != null && capsule && landscape) {
|
||||
if (art != null && capsule && landscape) {
|
||||
// Stores without portrait covers (itch) would lose most of the art to a portrait crop.
|
||||
AsyncImage(model = url, contentDescription = null, contentScale = ContentScale.Crop, modifier = Modifier.matchParentSize().blur(24.dp))
|
||||
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 = url, contentDescription = null, contentScale = ContentScale.Fit, modifier = Modifier.matchParentSize().padding(bottom = CardStrip))
|
||||
} else if (url != null) AsyncImage(
|
||||
model = url, contentDescription = null, contentScale = ContentScale.Crop, modifier = Modifier.matchParentSize(),
|
||||
AsyncImage(model = art, contentDescription = null, contentScale = ContentScale.Fit, modifier = Modifier.matchParentSize().padding(bottom = CardStrip))
|
||||
} else if (art != null) AsyncImage(
|
||||
model = art, contentDescription = null, contentScale = ContentScale.Crop, modifier = Modifier.matchParentSize(),
|
||||
onSuccess = { r ->
|
||||
val art = r.result.drawable
|
||||
if (capsule && art.intrinsicWidth > 0 && art.intrinsicHeight > 0) landscape = art.intrinsicWidth > art.intrinsicHeight * 0.95f
|
||||
val drawn = r.result.drawable
|
||||
if (capsule && drawn.intrinsicWidth > 0 && drawn.intrinsicHeight > 0) landscape = drawn.intrinsicWidth > drawn.intrinsicHeight * 0.95f
|
||||
},
|
||||
)
|
||||
Box(Modifier.align(Alignment.BottomCenter).fillMaxWidth().height(CardStrip).clipToBounds()) {
|
||||
if (url != null) AsyncImage(
|
||||
model = url, contentDescription = null, contentScale = ContentScale.Crop,
|
||||
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)))
|
||||
@@ -1575,9 +1592,10 @@ private fun CardMarker(item: CatalogItem, installed: Boolean, download: com.droi
|
||||
@Composable
|
||||
internal fun CardArt(item: CatalogItem, modifier: Modifier) {
|
||||
val url = item.imageUrl ?: item.tallImageUrl
|
||||
val art = cardArtRequest(url, item.tallImageUrl)
|
||||
val colors = MaterialTheme.colorScheme
|
||||
Box(modifier.background(colors.surfaceVariant).then(if (url == null) Modifier.background(artBrush(hueOf(item.title))) else Modifier)) {
|
||||
if (url != null) AsyncImage(model = url, contentDescription = null, contentScale = ContentScale.Crop, modifier = Modifier.matchParentSize())
|
||||
if (art != null) AsyncImage(model = art, contentDescription = null, contentScale = ContentScale.Crop, modifier = Modifier.matchParentSize())
|
||||
else Text(item.title, fontSize = 10.sp, fontWeight = FontWeight.Black, color = Color.White, maxLines = 3, overflow = TextOverflow.Ellipsis, modifier = Modifier.align(Alignment.BottomStart).padding(6.dp))
|
||||
Spacer(Modifier.matchParentSize().background(androidx.compose.ui.graphics.Brush.verticalGradient(0.6f to Color.Transparent, 1f to colors.surface.copy(alpha = 0.85f))))
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user