diff --git a/app/src/main/java/com/droiddeck/launcher/stores/download/DownloadModels.kt b/app/src/main/java/com/droiddeck/launcher/stores/download/DownloadModels.kt index 57f07742cf..115e0b1132 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/download/DownloadModels.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/download/DownloadModels.kt @@ -46,6 +46,26 @@ data class DownloadEntry( stageItemsTotal > 0 -> (stageItems.toFloat() / stageItemsTotal).coerceIn(0f, 1f) else -> -1f } + val downloadFraction: Float get() = if (bytesTotal > 0L) (bytesDone.toDouble() / bytesTotal).toFloat().coerceIn(0f, 1f) else -1f + val installFraction: Float get() = when { + stage != DownloadStage.DOWNLOAD && stage != DownloadStage.INSTALL -> -1f + stageTotal > 0L -> (stageDone.toDouble() / stageTotal).toFloat().coerceIn(0f, 1f) + stageItemsTotal > 0 -> (stageItems.toFloat() / stageItemsTotal).coerceIn(0f, 1f) + else -> -1f + } + val streaming: Boolean get() = state == DownloadState.RUNNING && bytesTotal > 0L && bytesDone < bytesTotal && installFraction >= 0f && + (stage == DownloadStage.INSTALL || (stage == DownloadStage.DOWNLOAD && passed(DownloadStage.INSTALL))) + /** Whole job as one bar: downloading fills the first 90%, installing the rest, also when they run together. */ + val overallFraction: Float get() { + if (state == DownloadState.INSTALLED || stage == DownloadStage.DONE) return 1f + val downloaded = when { + bytesTotal > 0L -> downloadFraction + passed(DownloadStage.DOWNLOAD) -> 1f + else -> 0f + } + val installed = if (stage == DownloadStage.INSTALL || (stage == DownloadStage.DOWNLOAD && passed(DownloadStage.INSTALL))) installFraction.coerceAtLeast(0f) else 0f + return (0.9f * downloaded + 0.1f * installed).coerceIn(0f, 1f) + } val fraction: Float get() = stageFraction.coerceAtLeast(0f) val percent: Int get() = (fraction * 100).toInt() } diff --git a/app/src/main/java/com/droiddeck/launcher/stores/download/DownloadQueue.kt b/app/src/main/java/com/droiddeck/launcher/stores/download/DownloadQueue.kt index 917b2c0ba1..4ceb4278bf 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/download/DownloadQueue.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/download/DownloadQueue.kt @@ -45,13 +45,18 @@ object DownloadQueue { val e = item.entry if (e.stage == stage) return item.speedAt = 0L; item.speedBytes = 0L; item.speedEwma = 0.0 - item.entry = e.copy( - stage = stage, stagesPassed = e.stagesPassed or (1 shl e.stage.ordinal), speedBps = 0, etaSeconds = -1, + val passed = e.stagesPassed or (1 shl e.stage.ordinal) + // Streaming installers (GOG) alternate between DOWNLOAD and INSTALL; the install count lives on across the swaps. + val streaming = e.stage in STREAMED && stage in STREAMED && (passed and (1 shl DownloadStage.INSTALL.ordinal)) != 0 + item.entry = if (streaming) e.copy(stage = stage, stagesPassed = passed, speedBps = 0, etaSeconds = -1) + else e.copy( + stage = stage, stagesPassed = passed, speedBps = 0, etaSeconds = -1, stageDone = 0, stageTotal = 0, stageItems = 0, stageItemsTotal = 0, ) } private const val SPEED_WINDOW_MS = 3000.0 + private val STREAMED = setOf(DownloadStage.DOWNLOAD, DownloadStage.INSTALL) private fun stageCount(key: String, done: Long, total: Long, files: Int, filesTotal: Int, bytes: Boolean) { synchronized(lock) { diff --git a/app/src/main/java/com/droiddeck/launcher/ui/BottomDownloadsPage.kt b/app/src/main/java/com/droiddeck/launcher/ui/BottomDownloadsPage.kt index 7ad576f956..7c33334a26 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/BottomDownloadsPage.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/BottomDownloadsPage.kt @@ -100,7 +100,7 @@ fun BottomDownloadsPage() { formatSpeed(e.speedBps), ).filter { it.isNotEmpty() }.joinToString(" · ") } - BottomDownloadRow(e.name, e.store.label, detail, e.stageFraction.takeIf { it >= 0f }) + BottomDownloadRow(e.name, e.store.label, detail, steadyProgress(e)) } } } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndRail.kt b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndRail.kt index c35f3d10df..a60c4ee5ae 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndRail.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndRail.kt @@ -60,7 +60,6 @@ import androidx.compose.material.icons.outlined.SportsEsports import androidx.compose.material.icons.outlined.Storefront import androidx.compose.material.icons.outlined.SystemUpdate import androidx.compose.material.icons.outlined.Tune -import androidx.compose.material.icons.outlined.VideoLibrary import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.material3.Icon import androidx.compose.material3.MaterialTheme @@ -196,7 +195,7 @@ internal fun SideRail( internal fun railLabelIcon(key: String): Pair = when (key) { "steam" -> R.string.rail_steam to Icons.Outlined.SportsEsports - "games" -> R.string.rail_games to Icons.Outlined.VideoLibrary + "games" -> R.string.rail_games to GameShelfIcon "soundtracks" -> R.string.rail_music to SoundtrackIcon "stores" -> R.string.rail_stores to Icons.Outlined.LocalMall "downloads" -> R.string.stores_tab_downloads to Icons.Outlined.Download diff --git a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndWidgets.kt b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndWidgets.kt index 6d360d7357..6bc4fd2149 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndWidgets.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndWidgets.kt @@ -27,6 +27,7 @@ import androidx.compose.foundation.layout.ExperimentalLayoutApi import androidx.compose.foundation.layout.FlowRow import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.widthIn import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.heightIn import androidx.compose.foundation.layout.padding @@ -113,8 +114,8 @@ internal fun Actions(content: @Composable () -> Unit) = FlowRow( ) { content() } @Composable -internal fun ActionChip(t: String, ok: Boolean, fraction: Float? = null, key: Any? = null) = - Box(contentAlignment = Alignment.Center, modifier = Modifier.heightIn(min = 44.dp)) { Chip(t, ok, fraction, key) } +internal fun ActionChip(t: String, ok: Boolean, fraction: Float? = null, key: Any? = null, minWidth: androidx.compose.ui.unit.Dp = 0.dp) = + Box(contentAlignment = Alignment.Center, modifier = Modifier.heightIn(min = 44.dp)) { Chip(t, ok, fraction, key, minWidth) } internal val Shape16 = RoundedCornerShape(16.dp) @@ -141,15 +142,16 @@ internal fun BackLink(label: String, compact: Boolean = false, onClick: () -> Un } @Composable -internal fun Chip(t: String, ok: Boolean, fraction: Float? = null, key: Any? = null) { +internal fun Chip(t: String, ok: Boolean, fraction: Float? = null, key: Any? = null, minWidth: androidx.compose.ui.unit.Dp = 0.dp) { val colors = MaterialTheme.colorScheme val pal = LocalPalette.current val shape = RoundedCornerShape(99.dp) val ink = if (ok) pal.good else colors.onSurfaceVariant - Box(Modifier.clip(shape).background(colors.surfaceVariant).border(1.dp, if (ok) pal.good.copy(alpha = 0.3f) else pal.line, shape)) { + Box(Modifier.widthIn(min = minWidth).clip(shape).background(colors.surfaceVariant).border(1.dp, if (ok) pal.good.copy(alpha = 0.3f) else pal.line, shape), contentAlignment = Alignment.CenterStart) { if (fraction != null) ChipFill(fraction, key, pal.signal.copy(alpha = 0.3f)) Text( t, fontSize = 12.sp, color = ink, maxLines = 1, overflow = TextOverflow.Ellipsis, + style = androidx.compose.ui.text.TextStyle(fontFeatureSettings = "tnum"), modifier = Modifier.padding(horizontal = 9.dp, vertical = 4.dp), ) } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/GameDetail.kt b/app/src/main/java/com/droiddeck/launcher/ui/GameDetail.kt index 9697fc289d..3b93f06527 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/GameDetail.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/GameDetail.kt @@ -1,5 +1,7 @@ package com.droiddeck.launcher.ui +import androidx.compose.foundation.interaction.collectIsPressedAsState +import androidx.compose.material.icons.automirrored.filled.KeyboardArrowRight import android.widget.Toast import androidx.compose.foundation.horizontalScroll import androidx.compose.foundation.LocalIndication @@ -482,7 +484,7 @@ internal fun GameActions( if (installed != null && id != null) { LaunchedEffect(id) { BattleNetInstall.checkUpdate(ctx, installed) } if (download != null) { - ActionChip(downloadLabel(download), ok = false, fraction = download.stageFraction.takeIf { it >= 0f }, key = download.stage) + SteadyDownloadChip(download) if (download.state != DownloadState.PAUSED) SecondaryButton(stringResource(R.string.stores_dl_pause)) { DownloadQueue.pause(download.key) } else SecondaryButton(stringResource(R.string.stores_dl_resume)) { DownloadQueue.resume(ctx, download.key) } } else if (BattleNetInstall.updates[id] == true) { @@ -497,7 +499,7 @@ internal fun GameActions( } } download != null -> { - ActionChip(downloadLabel(download), ok = false, fraction = download.stageFraction.takeIf { it >= 0f }, key = download.stage) + SteadyDownloadChip(download) if (download.state != DownloadState.PAUSED) SecondaryButton(stringResource(R.string.stores_dl_pause), modifier = leadOn) { DownloadQueue.pause(download.key) } else PrimaryButton(stringResource(R.string.stores_dl_resume), main = true, modifier = leadOn) { DownloadQueue.resume(ctx, download.key) } ConfirmButton(stringResource(R.string.stores_dl_cancel), stringResource(R.string.stores_dl_cancel_confirm)) { DownloadQueue.cancel(ctx, download.key) } @@ -1146,3 +1148,47 @@ internal object FolderSizes { }, "folder-size").start() } } + +@Composable +private fun SteadyDownloadChip(download: com.droiddeck.launcher.stores.download.DownloadEntry) { + val progress = steadyProgress(download) + val label = steadyLabel(download, progress) + val show = LocalShowSection.current + val colors = MaterialTheme.colorScheme + val pal = LocalPalette.current + val shape = if (LocalPillButtons.current) androidx.compose.foundation.shape.CircleShape else Shape12 + val src = remember { androidx.compose.foundation.interaction.MutableInteractionSource() } + val hot = rememberHot(src) + val pressed by src.collectIsPressedAsState() + val scale by androidx.compose.animation.core.animateFloatAsState(if (pressed) 0.955f else if (hot) 1.02f else 1f, Motion.sp(0.5f, androidx.compose.animation.core.Spring.StiffnessMedium), label = "dlScale") + val placed = remember { arrayOfNulls(1) } + val description = stringResource(R.string.stores_tab_downloads) + val open = { + placed[0]?.takeIf { it.isAttached }?.boundsInRoot()?.let { StoresMotion.fly(it) } + show("downloads") + } + Box( + contentAlignment = Alignment.CenterStart, + modifier = Modifier.paneItem("detail-download").testTag("detail-download") + .onGloballyPositioned { placed[0] = it } + .widthIn(min = 200.dp).heightIn(min = 48.dp) + .graphicsLayer { scaleX = scale; scaleY = scale }.clip(shape) + .background(Color.White.copy(alpha = 0.04f)) + .glideBorder(hot, shape, pal.signal, pal.line2) + .hoverable(src) + .clickable(interactionSource = src, indication = androidx.compose.foundation.LocalIndication.current, role = androidx.compose.ui.semantics.Role.Button, onClickLabel = description, onClick = open) + .controllerConfirm(onClick = open), + ) { + ChipFill(progress, download.key, pal.signal.copy(alpha = 0.42f)) + Row( + verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.SpaceBetween, + modifier = Modifier.widthIn(min = 200.dp).padding(start = 16.dp, end = 10.dp), + ) { + Text( + label, fontSize = 15.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 0.5.sp, color = colors.onBackground, maxLines = 1, + style = androidx.compose.ui.text.TextStyle(fontFeatureSettings = "tnum"), modifier = Modifier.padding(end = 8.dp), + ) + Icon(androidx.compose.material.icons.Icons.AutoMirrored.Filled.KeyboardArrowRight, description, tint = if (hot) colors.onBackground else colors.onSurfaceVariant, modifier = Modifier.size(20.dp)) + } + } +} diff --git a/app/src/main/java/com/droiddeck/launcher/ui/GameShelfIcon.kt b/app/src/main/java/com/droiddeck/launcher/ui/GameShelfIcon.kt new file mode 100644 index 0000000000..74b92c9be8 --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/ui/GameShelfIcon.kt @@ -0,0 +1,17 @@ +package com.droiddeck.launcher.ui + +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.PathFillType +import androidx.compose.ui.graphics.SolidColor +import androidx.compose.ui.graphics.vector.ImageVector +import androidx.compose.ui.graphics.vector.addPathNodes +import androidx.compose.ui.unit.dp + +internal val GameShelfIcon: ImageVector = ImageVector.Builder("GameShelf", 24.dp, 24.dp, 24f, 24f).apply { + for (d in listOf( + "M3,4H7V20H3ZM4.4,5.4V18.6H5.6V5.4Z", + "M8.5,4H12.5V20H8.5ZM9.9,5.4V18.6H11.1V5.4Z", + "M14.2,5.1L18.1,4.2L21.4,19.8L17.5,20.7ZM15.9,6.2L18.6,18.9L19.8,18.6L17.1,5.9Z", + "M2,21H22V22.5H2Z", + )) addPath(addPathNodes(d), fill = SolidColor(Color.Black), pathFillType = PathFillType.EvenOdd) +}.build() diff --git a/app/src/main/java/com/droiddeck/launcher/ui/LibraryAccounts.kt b/app/src/main/java/com/droiddeck/launcher/ui/LibraryAccounts.kt index 2b10c7902e..c79337e850 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/LibraryAccounts.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/LibraryAccounts.kt @@ -19,7 +19,7 @@ import androidx.compose.foundation.verticalScroll import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.filled.Add +import androidx.compose.material.icons.filled.ManageAccounts import androidx.compose.material3.Icon import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text @@ -66,7 +66,7 @@ internal fun StoreAccountsButton() { placed[0]?.takeIf { it.isAttached }?.boundsInRoot()?.let { at -> Steps.ask(StepAsk( anchor = at, side = StepSide.Left, accent = pal.signal, items = storesWithSignIn().size + 1, pillCorner = 20.dp, maxWidth = 380.dp, - handle = { Icon(Icons.Filled.Add, null, tint = pal.signal, modifier = Modifier.size(20.dp)) }, + handle = { Icon(Icons.Filled.ManageAccounts, null, tint = pal.signal, modifier = Modifier.size(20.dp)) }, ) { StoreAccountsStep(onSignIn = { store, row -> Steps.fold() @@ -92,7 +92,7 @@ internal fun StoreAccountsButton() { .hoverable(src) .clickable(interactionSource = src, indication = LocalIndication.current, role = Role.Button, onClickLabel = label, onClick = open) .controllerConfirm(onClick = open), - ) { Icon(Icons.Filled.Add, label, tint = if (hot) colors.onBackground else colors.onSurfaceVariant, modifier = Modifier.size(20.dp)) } + ) { Icon(Icons.Filled.ManageAccounts, label, tint = if (hot) colors.onBackground else colors.onSurfaceVariant, modifier = Modifier.size(20.dp)) } } } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/LibraryPage.kt b/app/src/main/java/com/droiddeck/launcher/ui/LibraryPage.kt index 272f42840c..b1fd672a68 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/LibraryPage.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/LibraryPage.kt @@ -41,6 +41,8 @@ import androidx.compose.foundation.selection.selectable import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.ExpandLess +import androidx.compose.material.icons.filled.ExpandMore import androidx.compose.material.icons.filled.Add import androidx.compose.material.icons.filled.BookmarkBorder import androidx.compose.material.icons.filled.FilterAlt @@ -177,8 +179,9 @@ internal fun librarySources( } internal object LibraryDisplay { + const val DEFAULT_LEVEL = 2 val scales = listOf(0.75f, 0.875f, 1f, 1.2f, 1.45f) - var level by mutableIntStateOf(2) + var level by mutableIntStateOf(DEFAULT_LEVEL) private set var title by mutableStateOf(true) private set @@ -215,6 +218,68 @@ internal object LibraryDisplay { } } +private enum class ToggleAt { NONE, TOP, SPLIT, BOTTOM } + +private const val NOT_INSTALLED_ROW = "library-not-installed" + +@Composable +private fun NotInstalledRow(count: Int, expanded: Boolean, keys: Modifier, onFocus: (Boolean) -> Unit, onToggle: () -> Unit) { + val colors = MaterialTheme.colorScheme + val pal = LocalPalette.current + val src = remember { MutableInteractionSource() } + val hot = rememberHot(src) + val shape = RoundedCornerShape(12.dp) + Row( + verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp), + modifier = Modifier.fillMaxWidth().padding(top = 6.dp, bottom = 2.dp).then(keys).paneItem(NOT_INSTALLED_ROW).onFocusChanged { onFocus(it.isFocused) }.testTag(NOT_INSTALLED_ROW) + .heightIn(min = 44.dp).clip(shape) + .background(if (hot) pal.signal.copy(alpha = 0.12f) else Color.Transparent) + .glideBorder(hot, shape, pal.signal, Color.Transparent) + .hoverable(src).clickable(interactionSource = src, indication = LocalIndication.current, role = Role.Button, onClick = onToggle) + .controllerConfirm(onClick = onToggle) + .padding(horizontal = 4.dp, vertical = 8.dp), + ) { + Text( + stringResource(R.string.stores_section_not_installed).uppercase() + " · " + count, + fontSize = 12.sp, fontWeight = FontWeight.Bold, letterSpacing = 1.2.sp, color = if (hot) colors.onBackground else colors.onSurfaceVariant, maxLines = 1, + ) + Box(Modifier.weight(1f).height(1.dp).background(pal.line)) + val hop = remember { androidx.compose.animation.core.Animatable(0f) } + LaunchedEffect(expanded, hot, Motion.scale) { + hop.snapTo(0f) + if (Motion.scale == 0f) return@LaunchedEffect + val toward = if (expanded) -3.5f else 3.5f + kotlinx.coroutines.delay(if (hot) 0L else 1_200L) + while (true) { + repeat(2) { + hop.animateTo(toward, androidx.compose.animation.core.tween(150, easing = androidx.compose.animation.core.FastOutSlowInEasing)) + hop.animateTo(0f, androidx.compose.animation.core.spring(dampingRatio = 0.45f, stiffness = androidx.compose.animation.core.Spring.StiffnessMedium)) + } + kotlinx.coroutines.delay(3_500L) + } + } + Icon( + if (expanded) Icons.Filled.ExpandLess else Icons.Filled.ExpandMore, stringResource(if (expanded) R.string.library_filter_installed else R.string.library_browse_owned), + tint = if (hot) colors.onBackground else colors.onSurfaceVariant, + modifier = Modifier.size(22.dp).graphicsLayer { translationY = hop.value.dp.toPx() }, + ) + } +} + +internal fun libraryColumns(width: Int, base: Int, gap: Int, level: Int): Int = + (((width + gap) / (base + gap)).coerceAtLeast(1) + LibraryDisplay.DEFAULT_LEVEL - level).coerceAtLeast(1) + +private class LevelCells(private val base: androidx.compose.ui.unit.Dp, private val level: Int) : GridCells { + override fun androidx.compose.ui.unit.Density.calculateCrossAxisCellSizes(availableSize: Int, spacing: Int): List { + val count = libraryColumns(availableSize, base.roundToPx(), spacing, level) + val usable = (availableSize - spacing * (count - 1)).coerceAtLeast(0) + return List(count) { usable / count + if (it < usable % count) 1 else 0 } + } + + override fun equals(other: Any?): Boolean = other is LevelCells && other.base == base && other.level == level + override fun hashCode(): Int = 31 * base.hashCode() + level +} + internal object LibraryView { var source by mutableStateOf(LIBRARY_ALL) var query by mutableStateOf("") @@ -305,6 +370,7 @@ internal fun LibraryPage(s: FrontEndState, a: FrontEndActions, selected: String, } val collectionItems = collectionId?.let { if (source == Store.GAMEJOLT.id) GameJoltCollections.gamesOf(it) else ItchCollections.gamesOf(it) } val pool = if (collectionId == null) all else collectionEntries(all, collectionItems.orEmpty(), Store.byId(source) ?: Store.ITCH) + val libraryTotal = if (soundMode) 0 else all.count { inLibrarySource(LIBRARY_ALL, it, favorites, concealed) } val matching = pool.filter { inLibrarySource(source, it, favorites, concealed) && (q.isEmpty() || it.title.lowercase().contains(q)) && keepsXbox(xboxFilter, it) } @@ -433,7 +499,7 @@ internal fun LibraryPage(s: FrontEndState, a: FrontEndActions, selected: String, val detailScroll = rememberScrollState() var cycled by remember { mutableIntStateOf(0) } var gridFocused by remember { mutableStateOf(false) } - LaunchedEffect(source, sort, listUninstalled) { grid.scrollToItem(0) } + LaunchedEffect(source, sort) { grid.scrollToItem(0) } LaunchedEffect(cycled) { if (cycled == 0 || ff == null || inputMode.inputMode != androidx.compose.ui.input.InputMode.Keyboard) return@LaunchedEffect focusWithinFrames({ gridFocused }) { @@ -449,7 +515,7 @@ internal fun LibraryPage(s: FrontEndState, a: FrontEndActions, selected: String, wrap = { key, content -> StoreTheme(GameRef.parse(key).let { r -> r.store ?: r.game(s.steamGames)?.source?.let { Store.byId(it) } }) { content() } }, grid = { LibraryGrid( - s, a, grid, visible, split, visible.size, sources, source, sizesPending, syncing, + s, a, grid, visible, split, if (soundMode) visible.size else libraryTotal, sources, source, sizesPending, syncing, showUninstalled = listUninstalled.takeIf { !s.shortcutPicker },onShowUninstalled = setShowUninstalled, hiddenUninstalled = hiddenUninstalled, onSource = { LibraryView.source = it }, @@ -517,12 +583,43 @@ private fun LibraryGrid( ) { val listMode = s.storesView == "list" val capsules = s.storesView == "capsules" - val tileWidth = (if (capsules) CapsuleWidth else if (listMode) CardWidth else LibraryCardWidth) * LibraryDisplay.scales[LibraryDisplay.level] + val baseWidth = if (capsules) CapsuleWidth else LibraryCardWidth + val level = LibraryDisplay.level val focus = LocalFrontFocus.current val scope = rememberCoroutineScope() val density = androidx.compose.ui.platform.LocalDensity.current var columns by remember { mutableIntStateOf(1) } val headerItems = 2 + (if (sizesPending) 1 else 0) + syncing.size + val expanded = showUninstalled == true + val notInstalled = if (expanded) visible.count { !it.installed } else hiddenUninstalled + val toggleAt = when { + showUninstalled == null || soundMode || notInstalled == 0 || (expanded && visible.isEmpty()) -> ToggleAt.NONE + !expanded -> ToggleAt.BOTTOM + split > 0 -> ToggleAt.SPLIT + else -> ToggleAt.TOP + } + val itemIndex: (Int) -> Int = { i -> + headerItems + i + when { + split > 0 -> if (i < split) 1 else 2 + toggleAt == ToggleAt.TOP -> 1 + else -> 0 + } + } + val toggleIndex = when (toggleAt) { + ToggleAt.TOP -> headerItems + ToggleAt.SPLIT -> headerItems + split + 1 + else -> headerItems + visible.size + } + val gapPx = with(density) { 10.dp.toPx() } + val moveFocus: (String, Int, Int, Int) -> Unit = { target, targetIndex, currentIndex, direction -> + val shown = grid.layoutInfo.visibleItemsInfo.any { it.index == targetIndex } + if (focus != null && (!shown || (focus.attached[target] ?: 0) == 0 || + runCatching { focus.items.getValue(target).requestFocus() }.isFailure)) scope.launch { + launch { grid.revealRow(currentIndex, targetIndex, direction, gapPx) } + focusWithinFrames({ focus.last == target }) { focus.items[target] ?: FocusRequester.Default } + } + } + val rowStart: (Int) -> Int? = { i -> if (i < 0) null else if (listMode) i else i - i % columns.coerceAtLeast(1) } val tile: @Composable (LibraryEntry) -> Unit = { e -> val first = e.key == visible.firstOrNull()?.key val navigation = if (focus == null) Modifier else Modifier.onPreviewKeyEvent { event -> @@ -534,21 +631,21 @@ private fun LibraryGrid( } val index = visible.indexOfFirst { it.key == e.key } val next = storeGridNeighbor(index, visible.size, if (listMode) 1 else columns, direction, split) + val toToggle = index >= 0 && when (toggleAt) { + ToggleAt.BOTTOM -> next == null && direction > 0 + ToggleAt.TOP -> next == null && direction < 0 + ToggleAt.SPLIT -> next != null && (index < split) != (next < split) + ToggleAt.NONE -> false + } when { direction == 0 || index < 0 -> false + toToggle -> { + if (key.action == KeyEvent.ACTION_DOWN) moveFocus(NOT_INSTALLED_ROW, toggleIndex, itemIndex(index), direction) + true + } next == null -> direction > 0 && trackHits.isEmpty() else -> { - if (key.action == KeyEvent.ACTION_DOWN) { - val target = "card:${visible[next].key}" - val targetIndex = headerItems + next + if (split == 0) 0 else if (next < split) 1 else 2 - val currentIndex = headerItems + index + if (split == 0) 0 else if (index < split) 1 else 2 - val shown = grid.layoutInfo.visibleItemsInfo.any { it.index == targetIndex } - if (!shown || (focus.attached[target] ?: 0) == 0 || - runCatching { focus.items.getValue(target).requestFocus() }.isFailure) scope.launch { - launch { grid.revealRow(currentIndex, targetIndex, direction, with(density) { 10.dp.toPx() }) } - focusWithinFrames({ focus.last == target }) { focus.items[target] ?: FocusRequester.Default } - } - } + if (key.action == KeyEvent.ACTION_DOWN) moveFocus("card:${visible[next].key}", itemIndex(next), itemIndex(index), direction) true } } @@ -557,12 +654,51 @@ private fun LibraryGrid( val choose = if (picker) ({ a.onSteamGame(e.game!!) }) else null if (listMode) LibraryRow(e, first, navigation, choose, onOpen) else LibraryTile(e, capsules, first, navigation, choose, onOpen, showSource = source == LIBRARY_ALL || source == LIBRARY_FAVORITES || source == LIBRARY_HIDDEN) } + var rowFocused by remember { mutableStateOf(false) } + val toggleRow: @Composable () -> Unit = { + val keys = if (focus == null) Modifier else Modifier.onPreviewKeyEvent { event -> + val key = event.nativeKeyEvent + val direction = when (key.keyCode) { + KeyEvent.KEYCODE_DPAD_DOWN -> 1 + KeyEvent.KEYCODE_DPAD_UP -> -1 + else -> 0 + } + val target = when { + direction > 0 && toggleAt == ToggleAt.TOP -> 0 + direction > 0 && toggleAt == ToggleAt.SPLIT -> split + direction < 0 && toggleAt == ToggleAt.SPLIT -> rowStart(split - 1) + direction < 0 && toggleAt == ToggleAt.BOTTOM -> rowStart(visible.lastIndex) + else -> null + } + when { + direction == 0 -> false + target == null -> direction > 0 && toggleAt == ToggleAt.BOTTOM && trackHits.isEmpty() + else -> { + if (key.action == KeyEvent.ACTION_DOWN) moveFocus("card:${visible[target].key}", itemIndex(target), toggleIndex, direction) + true + } + } + } + NotInstalledRow(notInstalled, expanded, keys, onFocus = { rowFocused = it }) { + rowFocused = false + val landing = if (expanded) headerItems + split else headerItems + visible.size + 1 + onShowUninstalled(!expanded) + if (focus != null && focus.last == NOT_INSTALLED_ROW) scope.launch { + androidx.compose.runtime.withFrameNanos { } + if (grid.layoutInfo.visibleItemsInfo.none { it.key == NOT_INSTALLED_ROW }) grid.scrollToItem((landing - 1).coerceAtLeast(0)) + repeat(30) { + androidx.compose.runtime.withFrameNanos { } + if (rowFocused) return@launch + runCatching { focus.items[NOT_INSTALLED_ROW]?.requestFocus() } + } + } + } + } LazyVerticalGrid( - columns = if (listMode) GridCells.Fixed(1) else GridCells.Adaptive(tileWidth), state = grid, + columns = if (listMode) GridCells.Fixed(1) else remember(baseWidth, level) { LevelCells(baseWidth, level) }, state = grid, modifier = Modifier.fillMaxSize().onFocusChanged { onFocus(it.hasFocus) }.focusGroup().bumpers(onPrevious = { onCycle(-1) }, onNext = { onCycle(1) }).onSizeChanged { val gap = with(density) { 10.dp.roundToPx() } - val minimum = with(density) { (if (listMode) CardWidth * 2 else tileWidth).roundToPx() } - columns = ((it.width + gap) / (minimum + gap)).coerceAtLeast(1) + columns = if (listMode) 1 else libraryColumns(it.width, with(density) { baseWidth.roundToPx() }, gap, level) }, horizontalArrangement = Arrangement.spacedBy(10.dp), verticalArrangement = Arrangement.spacedBy(10.dp), contentPadding = PaddingValues(top = 4.dp, bottom = 16.dp), @@ -587,17 +723,17 @@ private fun LibraryGrid( } } val empty = emptyText - if (visible.isEmpty() && hiddenUninstalled > 0) item(key = "browse-owned", span = { GridItemSpan(maxLineSpan) }) { - Column(horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(12.dp), modifier = Modifier.fillMaxWidth().padding(vertical = 32.dp)) { - Text(stringResource(R.string.library_no_installed_matches), fontSize = 13.sp, color = MaterialTheme.colorScheme.onSurfaceVariant) - SecondaryButton(stringResource(R.string.library_browse_owned), modifier = Modifier.testTag("library-browse-owned")) { onShowUninstalled(true) } - } + if (split == 0) { + if (toggleAt == ToggleAt.TOP) item(key = NOT_INSTALLED_ROW, span = { GridItemSpan(maxLineSpan) }) { toggleRow() } + if (visible.isNotEmpty() || toggleAt == ToggleAt.NONE) libraryGrid(visible, empty, tile) + if (toggleAt == ToggleAt.BOTTOM) item(key = NOT_INSTALLED_ROW, span = { GridItemSpan(maxLineSpan) }) { toggleRow() } } - else if (split == 0) libraryGrid(visible, empty, tile) else { item(key = "installed-label", span = { GridItemSpan(maxLineSpan) }) { SectionLabel(stringResource(R.string.stores_section_installed)) } libraryGrid(visible.take(split), empty, tile) - item(key = "not-installed-label", span = { GridItemSpan(maxLineSpan) }) { SectionLabel(stringResource(R.string.stores_section_not_installed)) } + item(key = NOT_INSTALLED_ROW, span = { GridItemSpan(maxLineSpan) }) { + if (toggleAt == ToggleAt.SPLIT) toggleRow() else SectionLabel(stringResource(R.string.stores_section_not_installed)) + } libraryGrid(visible.drop(split), empty, tile) } if (trackHits.isNotEmpty()) { @@ -683,7 +819,7 @@ private fun LibraryHeader( ) { if (soundMode) HeaderIconButton(stringResource(R.string.soundtracks_saved), Icons.Filled.BookmarkBorder, "collections", onClick = onCollections) DisplayButton() - if (!soundMode && (showUninstalled != null || xbox)) LibraryFilterButton(showUninstalled, onShowUninstalled, xbox) + if (!soundMode && xbox) LibraryFilterButton(null, onShowUninstalled, xbox) if (collections != null) CollectionsButton(collections) SortButton(s, a) ViewButton(s, a) @@ -792,7 +928,7 @@ internal fun libraryTileWidth() = LibraryCardWidth * LibraryDisplay.scales[Libra @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}%" + download != null -> "${(steadyProgress(download) * 100).toInt()}%" e.item != null && StoresState.isUnfinished(e.item) -> stringResource(R.string.stores_resume) e.installed && libraryUpdateAvailable(e) -> stringResource(R.string.common_update) else -> null @@ -835,7 +971,7 @@ internal fun ArtCard( ) badge?.invoke(this) if (chip != null) Box(Modifier.align(Alignment.TopEnd).padding(6.dp)) { - StateChip(chip, ChipTone.BUSY, small = true, fraction = download?.stageFraction?.takeIf { it >= 0f }, key = download?.stage) + StateChip(chip, ChipTone.BUSY, small = true, fraction = download?.let { steadyProgress(it) }, key = download?.key) } val showName = LibraryDisplay.title || hot val showDetail = LibraryDisplay.size || hot diff --git a/app/src/main/java/com/droiddeck/launcher/ui/StoresPage.kt b/app/src/main/java/com/droiddeck/launcher/ui/StoresPage.kt index 440541dda4..2a8e8e67a8 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/StoresPage.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/StoresPage.kt @@ -92,6 +92,7 @@ import androidx.compose.material.icons.filled.Check import androidx.compose.material.icons.filled.Close import androidx.compose.material.icons.filled.Search import androidx.compose.material.icons.automirrored.filled.Login +import androidx.compose.material.icons.automirrored.filled.KeyboardArrowRight import androidx.compose.foundation.basicMarquee import androidx.compose.material.icons.filled.Settings import androidx.compose.material.icons.outlined.Download @@ -927,16 +928,13 @@ private fun ProfileStrip(store: Store, owned: Int, loaded: Boolean, s: FrontEndS } Column(Modifier.weight(1f)) { Text(name.ifEmpty { store.label }, fontSize = 15.sp, fontWeight = FontWeight.Bold, color = colors.onBackground, maxLines = 1, overflow = TextOverflow.Ellipsis) - Text( - if (loaded) store.shortLabel + " · " + androidx.compose.ui.res.pluralStringResource(R.plurals.mode_added_count, owned, owned) else store.label, - fontSize = 12.sp, color = colors.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis, - ) - } - Actions { - SmallTextButton(stringResource(R.string.stores_owned_in_library), key = "owned-in-library") { + if (loaded) OwnedLink(store.shortLabel + " · " + androidx.compose.ui.res.pluralStringResource(R.plurals.mode_added_count, owned, owned)) { LibraryView.showOwned(ctx, store) show("games") } + else Text(store.label, fontSize = 12.sp, color = colors.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis) + } + Actions { SmallTextButton(stringResource(R.string.stores_refresh)) { StoresState.open(ctx, store, force = true) } if (store == Store.XBOX) SmallTextButton(stringResource(R.string.stores_xbox_cloud_settings), key = "xbox-cloud-settings") { ctx.startActivity(android.content.Intent(ctx, com.droiddeck.launcher.stores.xbox.XboxCloudSettingsActivity::class.java)) @@ -949,6 +947,28 @@ private fun ProfileStrip(store: Store, owned: Int, loaded: Boolean, s: FrontEndS } } +@Composable +private fun OwnedLink(label: String, onClick: () -> Unit) { + val colors = MaterialTheme.colorScheme + val pal = LocalPalette.current + val src = remember { MutableInteractionSource() } + val hot = rememberHot(src) + val shape = RoundedCornerShape(8.dp) + val description = stringResource(R.string.stores_owned_in_library) + Row( + verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(2.dp), + modifier = Modifier.paneItem("owned-in-library").testTag("owned-in-library").clip(shape) + .background(if (hot) pal.signal.copy(alpha = 0.14f) else Color.Transparent) + .glideBorder(hot, shape, pal.signal, Color.Transparent) + .hoverable(src).clickable(interactionSource = src, indication = LocalIndication.current, role = Role.Button, onClickLabel = description, onClick = onClick) + .controllerConfirm(onClick = onClick) + .padding(start = 2.dp, end = 4.dp, top = 2.dp, bottom = 2.dp), + ) { + Text(label, fontSize = 12.sp, color = if (hot) colors.onBackground else colors.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis) + Icon(Icons.AutoMirrored.Filled.KeyboardArrowRight, description, tint = if (hot) pal.signal else colors.onSurfaceVariant, modifier = Modifier.size(16.dp)) + } +} + @Composable private fun BattleNetLauncherRow(s: FrontEndState, a: FrontEndActions) { val ctx = LocalContext.current @@ -1385,7 +1405,25 @@ internal fun ProgressBarThin(fraction: Float, paused: Boolean = false, verify: B internal fun downloadLabel(d: com.droiddeck.launcher.stores.download.DownloadEntry): String = when (d.state) { DownloadState.PAUSED -> stringResource(R.string.stores_dl_paused) DownloadState.QUEUED -> stringResource(R.string.stores_dl_queued) - else -> if (d.stageFraction >= 0f) stringResource(R.string.stores_dl_active_percent, activeStageLabel(d), d.percent) else activeStageLabel(d) + else -> when { + d.streaming -> stringResource(R.string.stores_dl_active_percent, stringResource(R.string.stores_stage_installing), (d.installFraction * 100).toInt()) + d.stageFraction >= 0f -> stringResource(R.string.stores_dl_active_percent, activeStageLabel(d), d.percent) + else -> activeStageLabel(d) + } +} + +@Composable +internal fun steadyProgress(d: com.droiddeck.launcher.stores.download.DownloadEntry): Float { + val best = androidx.compose.runtime.remember(d.key) { floatArrayOf(0f) } + best[0] = maxOf(best[0], d.overallFraction) + return best[0] +} + +@Composable +internal fun steadyLabel(d: com.droiddeck.launcher.stores.download.DownloadEntry, progress: Float): String = when (d.state) { + DownloadState.QUEUED -> stringResource(R.string.stores_dl_queued) + DownloadState.PAUSED -> stringResource(R.string.stores_dl_active_percent, stringResource(R.string.stores_dl_paused), (progress * 100).toInt()) + else -> stringResource(R.string.stores_dl_active_percent, stringResource(R.string.stores_stage_installing), (progress * 100).toInt()) } @Composable diff --git a/app/src/test/java/com/droiddeck/launcher/stores/download/DownloadEntryTest.kt b/app/src/test/java/com/droiddeck/launcher/stores/download/DownloadEntryTest.kt index 46b38647c9..914089a2ca 100644 --- a/app/src/test/java/com/droiddeck/launcher/stores/download/DownloadEntryTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/stores/download/DownloadEntryTest.kt @@ -24,4 +24,45 @@ class DownloadEntryTest { assertFalse(e.passed(DownloadStage.INSTALL)) assertTrue(e.copy(state = DownloadState.INSTALLED).passed(DownloadStage.INSTALL)) } + + @Test fun streamingInstallKeepsDownloadAndInstallProgressApart() { + val installBit = 1 shl DownloadStage.INSTALL.ordinal + val installing = base.copy(stage = DownloadStage.INSTALL, bytesDone = 10, bytesTotal = 100, stageDone = 25, stageTotal = 100) + assertTrue(installing.streaming) + assertEquals(0.10f, installing.downloadFraction, 0.001f) + assertEquals(0.25f, installing.installFraction, 0.001f) + val backToDownload = installing.copy(stage = DownloadStage.DOWNLOAD, stagesPassed = installBit) + assertTrue(backToDownload.streaming) + assertEquals(0.25f, backToDownload.installFraction, 0.001f) + assertFalse(base.copy(stage = DownloadStage.DOWNLOAD, bytesDone = 10, bytesTotal = 100).streaming) + assertTrue(installing.copy(bytesDone = 99_950, bytesTotal = 100_000).streaming) + assertTrue(installing.copy(bytesDone = 99_999_999, bytesTotal = 100_000_000).streaming) + assertFalse(installing.copy(bytesDone = 100).streaming) + assertFalse(installing.copy(state = DownloadState.PAUSED).streaming) + } + + @Test fun overallProgressOnlyGrowsAcrossSequentialAndStreamingStages() { + val installBit = 1 shl DownloadStage.INSTALL.ordinal + val downloadBit = 1 shl DownloadStage.DOWNLOAD.ordinal + val sequential = listOf( + base.copy(stage = DownloadStage.MANIFEST), + base.copy(stage = DownloadStage.DOWNLOAD, bytesDone = 50, bytesTotal = 100), + base.copy(stage = DownloadStage.DOWNLOAD, bytesDone = 100, bytesTotal = 100), + base.copy(stage = DownloadStage.INSTALL, bytesDone = 100, bytesTotal = 100, stagesPassed = downloadBit, stageDone = 0, stageTotal = 10), + base.copy(stage = DownloadStage.INSTALL, bytesDone = 100, bytesTotal = 100, stagesPassed = downloadBit, stageDone = 10, stageTotal = 10), + base.copy(state = DownloadState.INSTALLED), + ).map { it.overallFraction } + assertEquals(sequential, sequential.sorted()) + assertEquals(1f, sequential.last(), 0f) + val streaming = listOf( + base.copy(stage = DownloadStage.DOWNLOAD, bytesDone = 10, bytesTotal = 100), + base.copy(stage = DownloadStage.INSTALL, bytesDone = 20, bytesTotal = 100, stageDone = 15, stageTotal = 100), + base.copy(stage = DownloadStage.DOWNLOAD, bytesDone = 40, bytesTotal = 100, stageDone = 15, stageTotal = 100, stagesPassed = installBit), + base.copy(stage = DownloadStage.INSTALL, bytesDone = 60, bytesTotal = 100, stageDone = 55, stageTotal = 100, stagesPassed = installBit), + base.copy(stage = DownloadStage.DOWNLOAD, bytesDone = 100, bytesTotal = 100, stageDone = 60, stageTotal = 100, stagesPassed = installBit), + base.copy(stage = DownloadStage.INSTALL, bytesDone = 100, bytesTotal = 100, stageDone = 80, stageTotal = 100, stagesPassed = installBit or downloadBit), + ).map { it.overallFraction } + assertEquals(streaming, streaming.sorted()) + } } + diff --git a/app/src/test/java/com/droiddeck/launcher/ui/LibraryColumnsTest.kt b/app/src/test/java/com/droiddeck/launcher/ui/LibraryColumnsTest.kt new file mode 100644 index 0000000000..3d0340e064 --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/ui/LibraryColumnsTest.kt @@ -0,0 +1,13 @@ +package com.droiddeck.launcher.ui + +import org.junit.Assert.assertEquals +import org.junit.Test + +class LibraryColumnsTest { + @Test fun everySizeStepChangesTheColumnCountUntilOne() { + val phone = (0..4).map { libraryColumns(width = 1080, base = 450, gap = 30, level = it) } + assertEquals(listOf(4, 3, 2, 1, 1), phone) + val tablet = (0..4).map { libraryColumns(width = 2400, base = 450, gap = 30, level = it) } + assertEquals(listOf(7, 6, 5, 4, 3), tablet) + } +} diff --git a/app/src/test/java/com/droiddeck/launcher/ui/LibraryVisibilityTest.kt b/app/src/test/java/com/droiddeck/launcher/ui/LibraryVisibilityTest.kt index f6085e5126..ecefb57d46 100644 --- a/app/src/test/java/com/droiddeck/launcher/ui/LibraryVisibilityTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/ui/LibraryVisibilityTest.kt @@ -76,52 +76,43 @@ class LibraryVisibilityTest { LibraryView.focusFirst = false } - @Test fun uninstalledGamesAreHiddenUntilSelectedInTheFilterAndTheChoiceSurvivesReopeningLibrary() { + @Test fun uninstalledGamesStayFoldedUnderTheirRowAndTheChoiceSurvivesReopeningLibrary() { show() compose.onNodeWithText("Installed Steam game").assertExists() compose.onNodeWithText("Uninstalled GOG").assertDoesNotExist() - chooseVisibility(true) + compose.onNodeWithText("NOT INSTALLED · 2").assertExists() + compose.onNodeWithText("3 games").assertExists() + toggleNotInstalled(true) + compose.onNodeWithText("3 games").assertExists() compose.onNodeWithText("Uninstalled GOG").assertExists() - assertTrue(SessionPrefs.libraryShowUninstalled(ctx)) compose.runOnIdle { generation++; Snapshot.sendApplyNotifications() } compose.mainClock.advanceTimeBy(2_000) compose.onNodeWithText("Uninstalled GOG").assertExists() - chooseVisibility(false) + toggleNotInstalled(false) compose.onNodeWithText("Uninstalled GOG").assertDoesNotExist() - assertFalse(SessionPrefs.libraryShowUninstalled(ctx)) } - @Test fun theFilterExpandsBesideSortWithoutChangingTheSelectionOnOpen() { + @Test fun theNotInstalledRowReplacesTheFilterButtonAndSortStillOpens() { show() - val filter = compose.onNodeWithContentDescription("Filter · Installed only") - val sort = compose.onNodeWithContentDescription("Sort") - assertTrue(filter.fetchSemanticsNode().boundsInRoot.right <= sort.fetchSemanticsNode().boundsInRoot.left) - filter.performClick() - compose.mainClock.advanceTimeBy(2_000) - compose.onNodeWithText("Installed only").assertIsDisplayed() - compose.onNodeWithText("All owned games").assertIsDisplayed() - compose.onAllNodesWithText("Filter").assertCountEquals(1) - compose.onNodeWithText("Uninstalled GOG").assertDoesNotExist() + compose.onNodeWithContentDescription("Filter · Installed only").assertDoesNotExist() + compose.onNodeWithTag("library-not-installed").assertExists() assertFalse(SessionPrefs.libraryShowUninstalled(ctx)) - compose.runOnIdle { Steps.fold(); Snapshot.sendApplyNotifications() } - compose.mainClock.advanceTimeBy(1_000) - sort.performClick() + compose.onNodeWithContentDescription("Sort").performClick() compose.mainClock.advanceTimeBy(2_000) compose.onAllNodesWithText("Sort").assertCountEquals(1) compose.onNodeWithText("Recently played").assertIsDisplayed() } - @Test fun theXboxAccessChoicesShareTheLibraryFilter() { + @Test fun theXboxFilterOnlyOffersTheXboxAccessChoices() { StoreAccounts.write(ctx, Store.XBOX, JSONObject().put("username", "Library test")) StoresState.accounts[Store.XBOX] = "Library test" StoresState.library[Store.XBOX] = listOf(CatalogItem(Store.XBOX, "owned", "Uninstalled Xbox", null, owned = true)) LibraryView.source = Store.XBOX.id try { show() - compose.onNodeWithContentDescription("Filter · Installed only").performClick() + compose.onNodeWithContentDescription("Filter · All").performClick() compose.mainClock.advanceTimeBy(2_000) - compose.onNodeWithText("Installed only").assertIsDisplayed() - compose.onNodeWithText("All owned games").assertIsDisplayed() + compose.onNodeWithText("Installed only").assertDoesNotExist() compose.onNodeWithText("Game Pass").assertIsDisplayed().performClick() compose.mainClock.advanceTimeBy(1_000) assertEquals(XboxLibraryFilter.GAME_PASS, XboxLibraryFilter.current) @@ -131,14 +122,19 @@ class LibraryVisibilityTest { } } - @Test fun aSearchWithOnlyUninstalledMatchesOffersToRevealThem() { + @Test fun aSearchWithOnlyUninstalledMatchesShowsTheFoldedRowToRevealThem() { LibraryView.query = "Uninstalled GOG" show() compose.onNodeWithText("Uninstalled GOG").assertDoesNotExist() - compose.onNodeWithTag("library-browse-owned").performClick() + compose.onNodeWithText("No installed games match these filters", substring = true).assertDoesNotExist() + compose.onNodeWithTag("library-not-installed").performClick() compose.mainClock.advanceTimeBy(1_000) compose.onNodeWithText("Uninstalled GOG").assertExists() assertEquals("Uninstalled GOG", LibraryView.query) + compose.onNodeWithTag("library-not-installed").performClick() + compose.mainClock.advanceTimeBy(1_000) + compose.onNodeWithText("Uninstalled GOG").assertDoesNotExist() + compose.onNodeWithTag("library-not-installed").assertExists() } @Test fun aHiddenStoreRemainsReachableInLibraryInItsConfiguredOrder() { @@ -151,11 +147,19 @@ class LibraryVisibilityTest { assertTrue(steam < epic && epic < gog) compose.onNodeWithTag("library-source-gog").performClick() compose.mainClock.advanceTimeBy(1_000) - compose.onNodeWithTag("library-browse-owned").assertIsDisplayed().performClick() + compose.onNodeWithTag("library-not-installed").assertIsDisplayed().performClick() compose.mainClock.advanceTimeBy(1_000) compose.onNodeWithText("Uninstalled GOG").assertExists() } + @Test fun theHeaderCountsTheWholeLibraryWhicheverStoreIsPicked() { + show() + compose.onNodeWithText("3 games").assertExists() + compose.onNodeWithTag("library-source-gog").performClick() + compose.mainClock.advanceTimeBy(1_000) + compose.onNodeWithText("3 games").assertExists() + } + @Test fun theStoresOwnedGamesLinkRevealsOwnedGamesDespiteTheSavedInstalledOnlyView() { assertFalse(SessionPrefs.libraryShowUninstalled(ctx)) LibraryView.showOwned(ctx, Store.GOG) @@ -188,13 +192,8 @@ class LibraryVisibilityTest { compose.mainClock.advanceTimeBy(2_000) } - private fun chooseVisibility(show: Boolean) { - compose.onNodeWithContentDescription("Filter · " + if (SessionPrefs.libraryShowUninstalled(ctx)) "All owned games" else "Installed only") - .performClick() - compose.mainClock.advanceTimeBy(2_000) - assertTrue(Steps.open) - compose.onNodeWithText(if (show) "All owned games" else "Installed only") - .performClick() + private fun toggleNotInstalled(show: Boolean) { + compose.onNodeWithTag("library-not-installed").performClick() compose.mainClock.advanceTimeBy(1_000) assertEquals(show, SessionPrefs.libraryShowUninstalled(ctx)) }