mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-21 05:46:03 +00:00
feat: store game pages flood onto their hero art, and downloads survive a restart (#608)
* feat: a store game's page floods out of its card onto its own hero art, and draws back from it * fix: installs interrupted by the app closing show in Downloads with Resume and Clear * feat: finished and interrupted downloads share the running card's art look, and the queue sits under what is running * fix: the download queue outlives the app: queued, running and paused downloads come back after a restart
This commit is contained in:
1 parent
1603009687
commit
4ec2146019
9 files changed
+271
-27
No files matched your search
@@ -30,7 +30,9 @@ import androidx.compose.ui.graphics.drawscope.clipPath
|
||||
import androidx.compose.ui.graphics.drawscope.translate
|
||||
import androidx.compose.ui.graphics.painter.Painter
|
||||
import androidx.compose.ui.graphics.graphicsLayer
|
||||
import androidx.compose.ui.layout.onGloballyPositioned
|
||||
import androidx.compose.ui.layout.onSizeChanged
|
||||
import androidx.compose.ui.layout.positionInRoot
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.util.lerp
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
@@ -109,6 +111,14 @@ internal fun PageFlood(
|
||||
/** What the tile shows instead of the control's fill: a game card's art, cropped to the tile as it grows. */
|
||||
art: Painter? = null,
|
||||
sinks: Boolean = false,
|
||||
/**
|
||||
* Where on the page the control's tile lands (root px), when the page has its own picture of
|
||||
* the control - a game page's hero art: the tile grows onto it instead of over the whole pane,
|
||||
* corner to corner ([ontoCorner] there), and the page comes in around it. Back leaves from it.
|
||||
* Null, or off screen: the pane, as any page.
|
||||
*/
|
||||
onto: (() -> Rect?)? = null,
|
||||
ontoCorner: androidx.compose.ui.unit.Dp = 0.dp,
|
||||
content: @Composable () -> Unit,
|
||||
) {
|
||||
val pal = LocalPalette.current
|
||||
@@ -118,6 +128,10 @@ internal fun PageFlood(
|
||||
val shown = remember { Animatable(0f) }
|
||||
val tile = remember { Animatable(1f) }
|
||||
var size by remember { mutableStateOf(Size.Zero) }
|
||||
var at by remember { mutableStateOf(Offset.Zero) }
|
||||
// Where this flood lands (in its own space), read as it opens and again as it leaves.
|
||||
var target by remember { mutableStateOf<Rect?>(null) }
|
||||
val density = androidx.compose.ui.platform.LocalDensity.current
|
||||
LaunchedEffect(size != Size.Zero, leaving, sinks) {
|
||||
if (sinks) {
|
||||
// Whatever the flood in was doing, the page is shown whole and leaves with the pane.
|
||||
@@ -128,6 +142,30 @@ internal fun PageFlood(
|
||||
}
|
||||
if (size == Size.Zero) return@LaunchedEffect
|
||||
glide?.hidden = true
|
||||
// The page lays out under the tile at once, so its picture is there within a frame or two.
|
||||
target = onto?.let { get ->
|
||||
kotlinx.coroutines.withTimeoutOrNull(300) { snapshotFlow { get() }.first { it != null } }
|
||||
}?.translate(-at)?.takeIf { it.height > 1f && it.overlaps(Rect(Offset.Zero, size)) }
|
||||
if (target != null) {
|
||||
coroutineScope {
|
||||
if (!leaving) {
|
||||
// Onto the page's picture, every edge together on one firm spring: no blob, and
|
||||
// nowhere to go past it.
|
||||
val runs = edges.map { launch { it.animateTo(1f, Motion.sp(0.85f, 320f)) } }
|
||||
snapshotFlow { edges.all { it.value >= 0.9f } }.first { it }
|
||||
launch { shown.animateTo(1f, Motion.tw(240)) }
|
||||
launch { delay(Motion.ms(140).toLong()); tile.animateTo(0f, Motion.tw(220)) }
|
||||
runs.forEach { it.join() }
|
||||
} else {
|
||||
launch { shown.animateTo(0f, Motion.tw(160)) }
|
||||
tile.animateTo(1f, Motion.tw(120))
|
||||
edges.map { launch { it.animateTo(0f, Motion.sp(0.9f, 320f)) } }.forEach { it.join() }
|
||||
tile.animateTo(0f, Motion.tw(120))
|
||||
}
|
||||
}
|
||||
glide?.hidden = false
|
||||
return@LaunchedEffect
|
||||
}
|
||||
val b = from.bounds
|
||||
val travel = listOf(b.left, b.top, size.width - b.right, size.height - b.bottom).map { it.coerceAtLeast(0f) }
|
||||
val far = travel.max().coerceAtLeast(1f)
|
||||
@@ -160,10 +198,16 @@ internal fun PageFlood(
|
||||
glide?.hidden = false
|
||||
}
|
||||
DisposableEffect(Unit) { onDispose { glide?.hidden = false } }
|
||||
Box(Modifier.fillMaxSize().clipToBounds().onSizeChanged { size = Size(it.width.toFloat(), it.height.toFloat()) }) {
|
||||
Box(Modifier.fillMaxSize().graphicsLayer { alpha = shown.value; translationY = (1f - shown.value) * 14.dp.toPx() }) { content() }
|
||||
Box(
|
||||
Modifier.fillMaxSize().clipToBounds().onSizeChanged { size = Size(it.width.toFloat(), it.height.toFloat()) }
|
||||
.onGloballyPositioned { at = it.positionInRoot() },
|
||||
) {
|
||||
// Landing on the page's picture, the page must not rise: its picture would move off the tile.
|
||||
val rise = if (onto != null) 0f else 1f
|
||||
Box(Modifier.fillMaxSize().graphicsLayer { alpha = shown.value; translationY = (1f - shown.value) * 14.dp.toPx() * rise }) { content() }
|
||||
val onCorner = with(density) { ontoCorner.toPx() }
|
||||
Canvas(Modifier.fillMaxSize()) {
|
||||
if (tile.value > 0.01f) drawTile(from, edges.map { it.value }, pal.surface, pal.line2, tile.value, art)
|
||||
if (tile.value > 0.01f) drawTile(from, edges.map { it.value }, pal.surface, pal.line2, tile.value, art, target, onCorner)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -172,22 +216,33 @@ internal fun PageFlood(
|
||||
* The control's tile with its edges [v] of the way to the pane's (left, top, right, bottom):
|
||||
* sinking with the page behind, blobby in flight, square once it fills the pane.
|
||||
*/
|
||||
private fun DrawScope.drawTile(from: Origin, v: List<Float>, fill: Color, line: Color, alpha: Float, art: Painter? = null) {
|
||||
private fun DrawScope.drawTile(
|
||||
from: Origin, v: List<Float>, fill: Color, line: Color, alpha: Float, art: Painter? = null,
|
||||
/** Lands on this instead of the pane (a page's picture of the control), corner [toCorner]. */
|
||||
to: Rect? = null, toCorner: Float = 0f,
|
||||
) {
|
||||
val (l, t, r, b) = v
|
||||
val mean = v.sumOf { it.coerceIn(0f, 1f).toDouble() }.toFloat() / 4f
|
||||
// The control sinks with the page behind it (scaled to 0.95 about the pane's centre).
|
||||
val k = 1f - 0.05f * mean
|
||||
val cx = size.width / 2f
|
||||
val cy = size.height / 2f
|
||||
val f = from.bounds
|
||||
val left = lerp(cx + (f.left - cx) * k, 0f, l)
|
||||
val top = lerp(cy + (f.top - cy) * k, 0f, t)
|
||||
val right = lerp(cx + (f.right - cx) * k, size.width, r)
|
||||
val bottom = lerp(cy + (f.bottom - cy) * k, size.height, b)
|
||||
val left: Float; val top: Float; val right: Float; val bottom: Float
|
||||
if (to != null) {
|
||||
left = lerp(f.left, to.left, l); top = lerp(f.top, to.top, t)
|
||||
right = lerp(f.right, to.right, r); bottom = lerp(f.bottom, to.bottom, b)
|
||||
} else {
|
||||
// The control sinks with the page behind it (scaled to 0.95 about the pane's centre).
|
||||
val k = 1f - 0.05f * mean
|
||||
val cx = size.width / 2f
|
||||
val cy = size.height / 2f
|
||||
left = lerp(cx + (f.left - cx) * k, 0f, l)
|
||||
top = lerp(cy + (f.top - cy) * k, 0f, t)
|
||||
right = lerp(cx + (f.right - cx) * k, size.width, r)
|
||||
bottom = lerp(cy + (f.bottom - cy) * k, size.height, b)
|
||||
}
|
||||
val w = (right - left).coerceAtLeast(0f)
|
||||
val h = (bottom - top).coerceAtLeast(0f)
|
||||
val blob = sin(PI * mean).toFloat().coerceAtLeast(0f)
|
||||
val corner = lerp(from.corner * (1f - mean), minOf(w, h) * 0.42f, blob)
|
||||
// Onto a picture it keeps a card's shape, corner to corner; over the pane it blobs in flight.
|
||||
val corner = if (to != null) lerp(from.corner, toCorner, mean).coerceAtMost(minOf(w, h) / 2f)
|
||||
else lerp(from.corner * (1f - mean), minOf(w, h) * 0.42f, sin(PI * mean).toFloat().coerceAtLeast(0f))
|
||||
drawRoundRect(fill, Offset(left, top), Size(w, h), CornerRadius(corner), alpha = alpha)
|
||||
val pic = art?.intrinsicSize?.takeIf { it.isSpecified && it.width > 0f && it.height > 0f }
|
||||
if (art != null && pic != null && w > 0f && h > 0f) {
|
||||
|
||||
@@ -61,8 +61,16 @@ internal fun StoreGameDetail(store: Store, key: String, s: FrontEndState, a: Fro
|
||||
SourceChip(store.id)
|
||||
}
|
||||
}
|
||||
Rise(1) {
|
||||
Box(Modifier.fillMaxWidth().heightIn(min = if (narrow) 150.dp else 180.dp).clip(Shape16).background(artBrush(hueOf(title)))) {
|
||||
// Out of a card, the hero holds still in its place: the card's flood lands on it, and a hero
|
||||
// still rising in sat below where the flood had measured it (the art showed twice).
|
||||
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)
|
||||
// The card it opened from floods onto this, and draws back into the card from it.
|
||||
.onGloballyPositioned { StoresMotion.heroAt = it.boundsInRoot() }
|
||||
.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())
|
||||
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)))
|
||||
@@ -110,6 +118,7 @@ internal fun StoreGameDetail(store: Store, key: String, s: FrontEndState, a: Fro
|
||||
}
|
||||
}
|
||||
}
|
||||
if (StoresMotion.heroLands) hero() else Rise(1) { hero() }
|
||||
// Plain text only, and nothing at all when the store sent a template key instead of words.
|
||||
// A description that is only the title again (some stores fill it so) is no description.
|
||||
val description = item?.let { com.droiddeck.launcher.stores.cleanStoreText(it.description) }.orEmpty()
|
||||
|
||||
@@ -111,10 +111,26 @@ private fun DownloadList(s: FrontEndState, a: FrontEndActions) {
|
||||
var clearing by remember { mutableStateOf(false) }
|
||||
// Under way on top; finished below a line whose X clears them all (rows only - a failed
|
||||
// download's kept files stay until its game page's Clear).
|
||||
val (active, finished) = entries.partition { it.isActive }
|
||||
// Under way first, then paused, then the queue in its order: a queued row sat above the one running.
|
||||
val (active, finished) = entries.partition { it.isActive }.let { (on, off) ->
|
||||
on.sortedWith(compareBy<DownloadEntry>({ when (it.state) { DownloadState.RUNNING -> 0; DownloadState.PAUSED -> 1; else -> 2 } }, { it.queuePosition })) to off
|
||||
}
|
||||
val finishedShown = if (clearing) emptyList() else finished
|
||||
// Installs that stopped without the queue knowing (the app closed or was killed): the queue
|
||||
// lives in memory, so after a restart they were only on their game's page. They resume here too.
|
||||
val queued = entries.mapTo(HashSet()) { it.key }
|
||||
// Matched against each store's library: one not read yet (Downloads opened first) is read from
|
||||
// its cache, quietly, so the rows are there without visiting the store.
|
||||
val ctx = LocalContext.current
|
||||
val missing = StoresState.unfinished.map { it.store }.filter { StoresState.library[it] == null }.toSet()
|
||||
LaunchedEffect(missing) { missing.forEach { StoresState.backend(it)?.syncLibrary(ctx, false) } }
|
||||
val interrupted = StoresState.unfinished.mapNotNull { u ->
|
||||
StoresState.library[u.store]?.firstOrNull {
|
||||
u.id == it.id || (u.id == null && u.folder.name == com.droiddeck.launcher.stores.StoreInstallRoot.folderName(it.title, it.id))
|
||||
}
|
||||
}.filter { "${it.store.id}:${it.id}" !in queued }.distinctBy { "${it.store.id}:${it.id}" }
|
||||
Column(verticalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||
AnimatedVisibility(entries.isEmpty(), enter = fadeIn(Motion.tw(300, 300)), exit = fadeOut(Motion.tw(120))) {
|
||||
AnimatedVisibility(entries.isEmpty() && interrupted.isEmpty(), enter = fadeIn(Motion.tw(300, 300)), exit = fadeOut(Motion.tw(120))) {
|
||||
Box(Modifier.fillMaxWidth().padding(vertical = 40.dp), contentAlignment = Alignment.Center) {
|
||||
Text(stringResource(R.string.stores_downloads_empty), fontSize = 13.sp, color = colors.onSurfaceVariant)
|
||||
}
|
||||
@@ -135,6 +151,11 @@ private fun DownloadList(s: FrontEndState, a: FrontEndActions) {
|
||||
else shrinkHorizontally(Motion.tw(260), shrinkTowards = Alignment.End) + shrinkVertically(Motion.tw(300, 120)) + fadeOut(Motion.tw(200, 80))
|
||||
},
|
||||
) { row, _ -> DownloadCard(StoresState.download(row.key) ?: row, s, a) }
|
||||
AnimatedRows(
|
||||
interrupted, key = { "${it.store.id}:${it.id}" },
|
||||
enter = { i, _ -> fadeIn(Motion.tw(300, 60 * i.coerceAtMost(5))) + expandVertically(Motion.tw(260)) },
|
||||
exit = { _, _, _ -> fadeOut(Motion.tw(160)) + shrinkVertically(Motion.tw(220, 60)) },
|
||||
) { item, _ -> InterruptedRow(item) }
|
||||
AnimatedVisibility(
|
||||
finishedShown.isNotEmpty(),
|
||||
enter = expandVertically(Motion.tw(260)) + fadeIn(Motion.tw(220)),
|
||||
@@ -172,21 +193,50 @@ private fun DownloadList(s: FrontEndState, a: FrontEndActions) {
|
||||
}
|
||||
}
|
||||
|
||||
/** An install that stopped before it finished, from an earlier run: Resume picks it up, Clear deletes what it had. */
|
||||
@Composable
|
||||
private fun InterruptedRow(item: com.droiddeck.launcher.stores.CatalogItem) {
|
||||
val ctx = LocalContext.current
|
||||
ArtStrip(item.imageUrl ?: item.tallImageUrl, item.title) {
|
||||
Text(item.title, fontSize = 13.sp, fontWeight = FontWeight.Bold, color = Color.White, maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f, fill = false))
|
||||
SourceChip(item.store.id, small = true)
|
||||
Text(stringResource(R.string.stores_dl_interrupted), fontSize = 12.sp, color = Color(0xFFFFC24D), maxLines = 1)
|
||||
Spacer(Modifier.weight(1f))
|
||||
RoundAction(Icons.Filled.PlayArrow, stringResource(R.string.stores_dl_resume), primary = true) { StoresState.requestInstall(ctx, item) }
|
||||
CancelAction { StoresState.clearUnfinished(ctx, item) }
|
||||
}
|
||||
}
|
||||
|
||||
/** How long a row that installed holds for its bar to gather into Play before it moves under the line. */
|
||||
private const val GATHER_HOLD_MS = 900
|
||||
|
||||
/**
|
||||
* A row in the download card's look, shorter: the game's art behind it under the same dark wash,
|
||||
* the copy in white. Finished and interrupted downloads read as the same thing as one under way.
|
||||
*/
|
||||
@Composable
|
||||
private fun ArtStrip(cover: String?, name: String, content: @Composable androidx.compose.foundation.layout.RowScope.() -> Unit) {
|
||||
val pal = LocalPalette.current
|
||||
Box(Modifier.fillMaxWidth().heightIn(min = 60.dp).clip(Shape12).background(Color(0xFF101318)).border(1.dp, pal.line, Shape12)) {
|
||||
if (!cover.isNullOrEmpty()) AsyncImage(model = cover, contentDescription = null, contentScale = ContentScale.Crop, modifier = Modifier.matchParentSize())
|
||||
else Spacer(Modifier.matchParentSize().background(artBrush(hueOf(name))))
|
||||
Spacer(Modifier.matchParentSize().background(Brush.horizontalGradient(0f to Color.Black.copy(alpha = 0.92f), 0.5f to Color.Black.copy(alpha = 0.72f), 1f to Color.Black.copy(alpha = 0.2f))))
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp),
|
||||
modifier = Modifier.fillMaxWidth().padding(horizontal = 14.dp, vertical = 8.dp), content = content,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/** A finished download: its name and store, and Play when it installed - blooming out of a dot when it just did. */
|
||||
@Composable
|
||||
private fun FinishedRow(d: DownloadEntry, s: FrontEndState, a: FrontEndActions, bloom: Boolean = false) {
|
||||
val ctx = LocalContext.current
|
||||
val colors = MaterialTheme.colorScheme
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp),
|
||||
modifier = Modifier.fillMaxWidth().clip(Shape12).background(colors.surface).padding(horizontal = 12.dp, vertical = 6.dp),
|
||||
) {
|
||||
Text(d.name, fontSize = 13.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground, maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f, fill = false))
|
||||
ArtStrip(d.cover, d.name) {
|
||||
Text(d.name, fontSize = 13.sp, fontWeight = FontWeight.Bold, color = Color.White, maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f, fill = false))
|
||||
SourceChip(d.store.id, small = true)
|
||||
Text(stringResource(if (d.state == DownloadState.INSTALLED) R.string.stores_installed_chip else R.string.stores_dl_cancelled), fontSize = 11.sp, color = colors.onSurfaceVariant, maxLines = 1, modifier = Modifier.weight(1f))
|
||||
Text(stringResource(if (d.state == DownloadState.INSTALLED) R.string.stores_installed_chip else R.string.stores_dl_cancelled), fontSize = 12.sp, color = Color.White.copy(alpha = 0.72f), maxLines = 1)
|
||||
Spacer(Modifier.weight(1f))
|
||||
if (d.state == DownloadState.INSTALLED) Box(Modifier.bloomIn(bloom, GATHER_HOLD_MS + 150)) {
|
||||
RoundAction(Icons.Filled.PlayArrow, stringResource(R.string.stores_play), primary = true) { launchStoreGame(ctx, d.store, d.id, s, a) }
|
||||
}
|
||||
|
||||
@@ -125,6 +125,12 @@ internal object StoresMotion {
|
||||
/** Where each store's dot sits on its chip, for a sign-in to come home to. */
|
||||
val dots = HashMap<Store, Rect>()
|
||||
|
||||
/** Where the open game page's hero art sits (root px): what a card's flood lands on, and leaves from. */
|
||||
var heroAt by mutableStateOf<Rect?>(null)
|
||||
|
||||
/** The open game page came out of a card: its hero holds still, for the card's flood to land on. */
|
||||
var heroLands by mutableStateOf(false)
|
||||
|
||||
/** The card a game page is about to open from. */
|
||||
private var card: CardMark? = null
|
||||
private var cardAt = 0L
|
||||
|
||||
@@ -311,6 +311,7 @@ internal fun StoresPage(s: FrontEndState, a: FrontEndActions, modifier: Modifier
|
||||
val mark = StoresMotion.takeCard(g)
|
||||
detailFrom = mark?.let { Origin(it.bounds.translate(-viewportAt), it.corner) }
|
||||
detailArt = mark?.art
|
||||
StoresMotion.heroLands = mark != null
|
||||
leaving = false
|
||||
detail = g
|
||||
} else if (detail != null) {
|
||||
@@ -450,7 +451,9 @@ internal fun StoresPage(s: FrontEndState, a: FrontEndActions, modifier: Modifier
|
||||
},
|
||||
)
|
||||
}
|
||||
PageFlood(from, leaving, art) { body() }
|
||||
// Onto the page's own hero art, not the whole pane: grown to the pane, the art
|
||||
// then cut down to the hero's banner (and back out to the pane to close).
|
||||
PageFlood(from, leaving, art, onto = { StoresMotion.heroAt }, ontoCorner = 16.dp) { body() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user