mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 12:28:40 +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
@@ -108,6 +108,19 @@ fun mergeItems(old: List<CatalogItem>?, new: List<CatalogItem>): List<CatalogIte
|
||||
return if (merged.size == old.size && merged.indices.all { merged[it] === old[it] }) old else merged
|
||||
}
|
||||
|
||||
/**
|
||||
* [patched] over [old] by key, the way a store that fills its cards in one at a time needs it: a card
|
||||
* already on screen keeps its very object and its place, one the grid does not have yet is added where
|
||||
* its title belongs. Unlike [mergeItems] the rest of [old] is never dropped.
|
||||
*/
|
||||
fun patchItems(old: List<CatalogItem>?, patched: List<CatalogItem>): List<CatalogItem> {
|
||||
if (old.isNullOrEmpty()) return patched
|
||||
val byKey = patched.associateBy { it.key }
|
||||
val kept = old.map { byKey[it.key] ?: it }
|
||||
val added = patched.filter { n -> old.none { it.key == n.key } }
|
||||
return if (added.isEmpty()) kept else (kept + added).sortedBy { it.title.lowercase() }
|
||||
}
|
||||
|
||||
class InstalledStoreGame(val sidecar: StoreGameSidecar, val folder: java.io.File) {
|
||||
val key: String get() = "${sidecar.store.id}:${sidecar.id}"
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ internal object StoreNet {
|
||||
headers.forEach { (k, v) -> setRequestProperty(k, v) }
|
||||
}
|
||||
val code = conn.responseCode
|
||||
if (code !in 200..299) { Log.w(TAG, "GET $code ${StoreLog.redactUrl(url)}"); null } else readAll(conn)
|
||||
if (code !in 200..299) { StoresState.logLine("GET $code ${StoreLog.redactUrl(url)}"); null } else readAll(conn)
|
||||
} catch (e: Exception) {
|
||||
Log.w(TAG, "GET failed ${StoreLog.redactUrl(url)}: ${e.javaClass.simpleName}")
|
||||
null
|
||||
|
||||
@@ -37,7 +37,16 @@ object GogBackend : StoreBackend {
|
||||
if (cached.isNotEmpty()) StoresState.library[store] = com.droiddeck.launcher.stores.mergeItems(StoresState.library[store], cached)
|
||||
if (!quiet) StoresState.status[store] = app.getString(com.droiddeck.launcher.R.string.stores_sync_library)
|
||||
}
|
||||
val result = GogLibrary.sync(app, force) { line -> if (!quiet) StoresState.post { StoresState.status[store] = line } }
|
||||
val result = GogLibrary.sync(app, force, onStatus = { line -> if (!quiet) StoresState.post { StoresState.status[store] = line } }, onList = { list ->
|
||||
// Mapped here, off the main thread: the listing paints the tab before any product is asked about.
|
||||
val items = list.map { GogLibrary.toCatalogItem(app, it) }
|
||||
// An empty listing is not news: posting it would drop the cards already on screen.
|
||||
if (items.isNotEmpty()) StoresState.post { StoresState.library[store] = com.droiddeck.launcher.stores.mergeItems(StoresState.library[store], items) }
|
||||
}, onItems = { changed ->
|
||||
// Only the products that came back are touched: a card already on screen keeps its object, and a product the grid has not seen yet is added where its title belongs.
|
||||
val items = changed.map { GogLibrary.toCatalogItem(app, it) }
|
||||
StoresState.post { StoresState.library[store] = com.droiddeck.launcher.stores.patchItems(StoresState.library[store], items) }
|
||||
})
|
||||
StoresState.post {
|
||||
StoresState.status.remove(store)
|
||||
when (result) {
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.stores.CatalogItem
|
||||
import com.droiddeck.launcher.stores.Store
|
||||
import com.droiddeck.launcher.stores.StoreNet
|
||||
import com.droiddeck.launcher.stores.StoresState
|
||||
import com.droiddeck.launcher.stores.cleanStoreText
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
@@ -20,6 +21,14 @@ object GogLibrary {
|
||||
private const val LAST_SYNC_KEY = "library_synced_at"
|
||||
private const val SKIPPED_KEY = "library_skipped"
|
||||
private const val THROTTLE_MS = 6L * 60L * 60L * 1000L
|
||||
// mediaType=1 leaves the movies and soundtracks out, hiddenFlag=0 the hidden ones.
|
||||
private const val LIST_URL = "https://embed.gog.com/account/getFilteredProducts?mediaType=1&hiddenFlag=0&sortBy=title"
|
||||
private const val LIST_MAX_PAGES = 100
|
||||
// The listing's image is a bare hash, and the CDN serves it only through Galaxy's own formatters: the
|
||||
// vertical cover is the one card art it carries. The wide background only the per-game fetch knows.
|
||||
private const val COVER_SUFFIX = "_glx_vertical_cover.webp"
|
||||
// The older account endpoint: owned ids only. The fallback for a listing that cannot be read.
|
||||
private const val OWNED_URL = "https://embed.gog.com/user/data/games"
|
||||
|
||||
private val syncing = AtomicBoolean(false)
|
||||
|
||||
@@ -45,42 +54,44 @@ object GogLibrary {
|
||||
|
||||
fun sizeOf(context: Context, gameId: String): Long = GogPrefs.get(context).getLong("size_$gameId", 0L)
|
||||
|
||||
fun sync(context: Context, force: Boolean = false, onStatus: (String) -> Unit = {}): SyncResult {
|
||||
fun sync(context: Context, force: Boolean = false, onStatus: (String) -> Unit = {}, onList: (List<GogGame>) -> Unit = {}, onItems: (List<GogGame>) -> Unit = {}): SyncResult {
|
||||
if (!syncing.compareAndSet(false, true)) return SyncResult.Busy
|
||||
try {
|
||||
val app = context.applicationContext
|
||||
val p = GogPrefs.get(app)
|
||||
val token = GogAuth.validToken(app) ?: return SyncResult.NotLoggedIn
|
||||
onStatus(app.getString(R.string.stores_sync_game_list))
|
||||
val gamesJson = StoreNet.get("https://embed.gog.com/user/data/games", bearer = token, userAgent = GogAuth.GALAXY_UA)
|
||||
val listing = ownedListing(token)
|
||||
// The listing is the only source of titles: without it the owned ids still sync, just without the early paint.
|
||||
val listed: List<GogGame> = listing?.games
|
||||
?: ownedIds(token)?.map { GogGame(it, "", "", "", "", "", 1, null, "", "") }
|
||||
?: return SyncResult.Failed(app.getString(R.string.stores_sync_gog_unreachable))
|
||||
val ids = ArrayList<String>()
|
||||
val parsed = runCatching {
|
||||
val owned = JSONObject(gamesJson).optJSONArray("owned")
|
||||
if (owned != null) for (i in 0 until owned.length()) {
|
||||
val id = owned.optLong(i).toString()
|
||||
if (id != "1801418160" && id != "0") ids.add(id)
|
||||
}
|
||||
}.isSuccess
|
||||
if (!parsed) return SyncResult.Failed(app.getString(R.string.stores_sync_gog_unreadable))
|
||||
|
||||
val ownedSet = ids.toHashSet()
|
||||
val named = listing != null
|
||||
StoresState.logLine(if (named) "GOG: listing ${listed.size} games" else "GOG: listing unreadable, ${listed.size} owned ids")
|
||||
// A page that failed leaves games unnamed: they are still owned, so their cards and cached details stay.
|
||||
val ownedSet = listing?.owned ?: listed.mapTo(HashSet()) { it.gameId }
|
||||
val cachedList = cached(app)
|
||||
val stale = System.currentTimeMillis() - p.getLong(LAST_SYNC_KEY, 0L) >= THROTTLE_MS
|
||||
val heavy = force || cachedList.isEmpty() || stale
|
||||
val cachedIds = cachedList.mapTo(HashSet()) { it.gameId }
|
||||
// A product the last sync found uninstallable stays out of the list while it is re-checked.
|
||||
val skipped = java.util.Collections.newSetFromMap(java.util.concurrent.ConcurrentHashMap<String, Boolean>())
|
||||
if (!heavy) skipped.addAll(p.getStringSet(SKIPPED_KEY, emptySet()).orEmpty())
|
||||
val idsToFetch = if (heavy) ids else ids.filter { it !in cachedIds && it !in skipped }
|
||||
val fetchSet = idsToFetch.toHashSet()
|
||||
skipped.addAll(p.getStringSet(SKIPPED_KEY, emptySet()).orEmpty())
|
||||
val idsToFetch = if (heavy) ownedSet.toList() else ownedSet.filter { it !in cachedIds && it !in skipped }
|
||||
val merged = LinkedHashMap<String, GogGame>()
|
||||
for (g in cachedList) if (g.gameId in ownedSet && g.gameId !in fetchSet) merged[g.gameId] = g
|
||||
// The cache's own entry stays even when the game is re-fetched: its details beat the listing's.
|
||||
for (g in cachedList) if (g.gameId in ownedSet && g.gameId !in skipped) merged[g.gameId] = g
|
||||
// A game the sync has not reached keeps the listing's entry, so its card is there from the start.
|
||||
for (g in listed) if (g.gameId !in merged && g.gameId !in skipped) merged[g.gameId] = g
|
||||
// Only products that were asked about are cached: a bare listing entry is asked about again.
|
||||
val detailed = HashSet(cachedIds)
|
||||
if (named) onList(sorted(merged))
|
||||
if (idsToFetch.isEmpty()) {
|
||||
val list = merged.values.toList()
|
||||
skipped.retainAll(ownedSet)
|
||||
p.edit().putStringSet(SKIPPED_KEY, HashSet(skipped)).apply()
|
||||
saveCache(p, list)
|
||||
return SyncResult.Ok(list.sortedBy { it.title.lowercase() }, 0)
|
||||
saveCache(p, list.filter { it.gameId in detailed })
|
||||
return SyncResult.Ok(sorted(merged), 0)
|
||||
}
|
||||
onStatus(app.resources.getQuantityString(R.plurals.stores_sync_games, idsToFetch.size, idsToFetch.size))
|
||||
val pool = Executors.newFixedThreadPool(5)
|
||||
@@ -89,16 +100,24 @@ object GogLibrary {
|
||||
var fetched = 0
|
||||
for ((idx, f) in futures.withIndex()) {
|
||||
val g = runCatching { f.get() }.getOrNull()
|
||||
if (g != null) { merged[g.gameId] = g; fetched++ }
|
||||
if (g != null) {
|
||||
// The cover the card already shows stays, so the wide art lands over it instead of over a gap.
|
||||
val filled = g.withCover(merged[g.gameId]?.verticalCover)
|
||||
merged[g.gameId] = filled; detailed.add(g.gameId); fetched++; skipped.remove(g.gameId); onItems(listOf(filled))
|
||||
}
|
||||
if ((idx + 1) % 5 == 0) onStatus(app.getString(R.string.stores_sync_progress, idx + 1, futures.size))
|
||||
// Saved as it goes: a sync the user closes the app on still leaves a library to paint next launch.
|
||||
if ((idx + 1) % 20 == 0) saveCache(p, merged.values.filter { it.gameId in detailed })
|
||||
}
|
||||
// A product this round found uninstallable leaves when the round is over, not in the middle of it.
|
||||
for (id in skipped) merged.remove(id)
|
||||
val finalList = merged.values.toList()
|
||||
saveCache(p, finalList)
|
||||
saveCache(p, finalList.filter { it.gameId in detailed })
|
||||
skipped.retainAll(ownedSet)
|
||||
p.edit().putStringSet(SKIPPED_KEY, HashSet(skipped)).apply()
|
||||
if (heavy) p.edit().putLong(LAST_SYNC_KEY, System.currentTimeMillis()).apply()
|
||||
Log.i(TAG, "sync: owned=${ids.size} fetched=$fetched cached=${finalList.size} heavy=$heavy")
|
||||
return SyncResult.Ok(finalList.sortedBy { it.title.lowercase() }, fetched)
|
||||
Log.i(TAG, "sync: owned=${ownedSet.size} fetched=$fetched cached=${finalList.size} heavy=$heavy")
|
||||
return SyncResult.Ok(sorted(merged), fetched)
|
||||
} catch (e: Exception) {
|
||||
Log.w(TAG, "sync failed: ${e.message}")
|
||||
return SyncResult.Failed(e.message ?: context.getString(R.string.stores_sync_failed))
|
||||
@@ -107,6 +126,68 @@ object GogLibrary {
|
||||
}
|
||||
}
|
||||
|
||||
private fun ownedListing(token: String): Listing? {
|
||||
val all = ArrayList<GogGame>()
|
||||
val owned = HashSet<String>()
|
||||
var page = 1
|
||||
var pages = 1
|
||||
while (page <= pages && page <= LIST_MAX_PAGES) {
|
||||
// A page that cannot be read ends the listing; the pages already read still name most of the library.
|
||||
val listed = StoreNet.get("$LIST_URL&page=$page", bearer = token, userAgent = GogAuth.GALAXY_UA)?.let { parseListing(it) }
|
||||
if (listed == null) {
|
||||
StoresState.logLine("GOG: listing page $page of $pages unreadable")
|
||||
// The unread pages hold games too: without their ids those games would leave the library and the cache.
|
||||
owned.addAll(ownedIds(token) ?: return null)
|
||||
break
|
||||
}
|
||||
all.addAll(listed.games)
|
||||
owned.addAll(listed.games.map { it.gameId })
|
||||
pages = listed.totalPages
|
||||
page++
|
||||
}
|
||||
// Not one page read: the caller falls back to the owned ids.
|
||||
return all.ifEmpty { null }?.let { Listing(it, owned) }
|
||||
}
|
||||
|
||||
private fun ownedIds(token: String): List<String>? {
|
||||
val json = StoreNet.get(OWNED_URL, bearer = token, userAgent = GogAuth.GALAXY_UA) ?: return null
|
||||
val owned = runCatching { JSONObject(json).optJSONArray("owned") }.getOrNull() ?: return null
|
||||
val ids = ArrayList<String>(owned.length())
|
||||
for (i in 0 until owned.length()) {
|
||||
val id = owned.optLong(i).toString()
|
||||
if (id != "1801418160" && id != "0") ids.add(id)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
fun parseListing(json: String): ListingPage? = runCatching {
|
||||
val root = JSONObject(json)
|
||||
val arr = root.optJSONArray("products") ?: return@runCatching null
|
||||
val games = ArrayList<GogGame>(arr.length())
|
||||
for (i in 0 until arr.length()) {
|
||||
val o = arr.optJSONObject(i) ?: continue
|
||||
// 1801418160 is GOG's own "Galaxy" entry, in every library.
|
||||
val id = o.optLong("id", 0L).toString()
|
||||
if (id == "0" || id == "1801418160") continue
|
||||
if (o.optBoolean("isMovie", false) || !o.optBoolean("isGame", true)) continue
|
||||
val title = o.optString("title", "").trim()
|
||||
if (title.isEmpty()) continue
|
||||
val worksOn = o.optJSONObject("worksOn")
|
||||
if (worksOn != null && !worksOn.optBoolean("Windows", true)) continue
|
||||
val released = o.optJSONObject("releaseDate")?.optString("date", "").orEmpty().substringBefore(' ')
|
||||
val image = o.optString("image", "").ifBlank { null }
|
||||
games.add(GogGame(id, title, "", "", "", o.optString("category", ""), 1,
|
||||
image?.let { GogStoreCatalog.absolutize(it + COVER_SUFFIX) }, released, ""))
|
||||
}
|
||||
ListingPage(games, maxOf(1, root.optInt("totalPages", 1)))
|
||||
}.getOrNull()
|
||||
|
||||
class ListingPage(val games: List<GogGame>, val totalPages: Int)
|
||||
|
||||
private class Listing(val games: List<GogGame>, val owned: Set<String>)
|
||||
|
||||
private fun sorted(merged: Map<String, GogGame>): List<GogGame> = merged.values.sortedBy { it.title.lowercase() }
|
||||
|
||||
private fun fetchGame(prefs: SharedPreferences, id: String, token: String, skipped: MutableSet<String>): GogGame? {
|
||||
fun skip(): GogGame? { skipped.add(id); return null }
|
||||
try {
|
||||
@@ -198,6 +279,10 @@ object GogLibrary {
|
||||
}
|
||||
}
|
||||
|
||||
private fun GogGame.withCover(cover: String?): GogGame =
|
||||
if (cover.isNullOrBlank() || cover == verticalCover) this
|
||||
else GogGame(gameId, title, imageUrl, description, developer, category, generation, cover, releaseDate, publisher)
|
||||
|
||||
fun toCatalogItem(context: Context, g: GogGame): CatalogItem = CatalogItem(
|
||||
store = Store.GOG, id = g.gameId, title = g.title,
|
||||
imageUrl = GogStoreCatalog.absolutize(g.imageUrl).ifBlank { null },
|
||||
|
||||
@@ -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