mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-21 05:46:03 +00:00
itch.io: browse the Store tab by sort and price, with paging and a disk cache
The Store tab only had four fixed shelves and a title search. A row of sort (Popular, New, Top rated, Top sellers) and price (Any, Free, On sale) chips now sets a BrowseQuery; anything but the defaults swaps the shelves for that query's games, loaded page by page as the grid scrolls. ItchBrowse builds itch's listing-feed URL (platform and tag segments are in the builder for the next change), tries each spelling of a price filter until one answers, spaces requests 1.2 s apart, backs off once on a 429, and keeps pages in the app cache for three hours. Every request is logged with its status and game count so a wrong URL guess can be fixed from a device. Owned games replace their browse copy so Install and the owned markers are right, and the detail page finds browse results. Strings for all 33 locales; URL-builder tests; docs/development/itch-browse.md.
This commit is contained in:
40 files changed
+708
-8
No files matched your search
@@ -0,0 +1,107 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import androidx.compose.foundation.LocalIndication
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.horizontalScroll
|
||||
import androidx.compose.foundation.hoverable
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.selection.selectable
|
||||
import androidx.compose.foundation.selection.selectableGroup
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.LinearProgressIndicator
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.Role
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.stores.itch.ItchBrowse
|
||||
import com.droiddeck.launcher.stores.itch.ItchBrowseState
|
||||
|
||||
/** Sort and price chips above the itch Store tab; picking anything but the defaults swaps the shelves for results. */
|
||||
@Composable
|
||||
internal fun ItchBrowseBar() {
|
||||
val ctx = LocalContext.current
|
||||
val query = ItchBrowseState.query
|
||||
Column(Modifier.fillMaxWidth().padding(top = 6.dp, bottom = 8.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||
ChipRow {
|
||||
for (sort in ItchBrowse.sorts) BrowseChip(sortLabel(sort), query.sort == sort) { ItchBrowseState.choose(ctx, query.copy(sort = sort)) }
|
||||
}
|
||||
ChipRow {
|
||||
for (price in ItchBrowse.prices) BrowseChip(priceLabel(price), query.price == price) { ItchBrowseState.choose(ctx, query.copy(price = price)) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** The end of the result list: it asks for the next page as it scrolls into view. */
|
||||
@Composable
|
||||
internal fun ItchLoadMore() {
|
||||
val ctx = LocalContext.current
|
||||
val count = ItchBrowseState.items.size
|
||||
LaunchedEffect(count) { ItchBrowseState.more(ctx) }
|
||||
if (ItchBrowseState.loading) LinearProgressIndicator(Modifier.fillMaxWidth().padding(vertical = 12.dp))
|
||||
else if (!ItchBrowseState.ended && count > 0) Box(Modifier.fillMaxWidth().padding(vertical = 8.dp), contentAlignment = Alignment.Center) {
|
||||
BrowseChip(stringResource(R.string.stores_itch_load_more), false) { ItchBrowseState.more(ctx) }
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ChipRow(content: @Composable () -> Unit) {
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.spacedBy(6.dp), verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier.fillMaxWidth().horizontalScroll(rememberScrollState()).selectableGroup(),
|
||||
) { content() }
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun BrowseChip(label: String, selected: Boolean, onClick: () -> Unit) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val pal = LocalPalette.current
|
||||
val shape = RoundedCornerShape(8.dp)
|
||||
val src = remember { MutableInteractionSource() }
|
||||
val hot = rememberHot(src)
|
||||
Text(
|
||||
label, fontSize = 13.sp, fontWeight = FontWeight.SemiBold, maxLines = 1,
|
||||
color = if (selected) pal.onSignal else if (hot) colors.onBackground else colors.onSurfaceVariant,
|
||||
modifier = Modifier.clip(shape).background(if (selected) pal.signal else colors.surfaceVariant)
|
||||
.glideBorder(hot, shape, pal.signal)
|
||||
.hoverable(src).selectable(selected = selected, interactionSource = src, indication = LocalIndication.current, role = Role.Tab, onClick = onClick)
|
||||
.controllerConfirm(onClick = onClick)
|
||||
.padding(horizontal = 12.dp, vertical = 7.dp),
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun sortLabel(sort: String): String = stringResource(
|
||||
when (sort) {
|
||||
ItchBrowse.SORT_NEW -> R.string.stores_itch_sort_new
|
||||
ItchBrowse.SORT_TOP_RATED -> R.string.stores_itch_sort_top_rated
|
||||
ItchBrowse.SORT_TOP_SELLERS -> R.string.stores_itch_sort_top_sellers
|
||||
else -> R.string.stores_itch_sort_popular
|
||||
},
|
||||
)
|
||||
|
||||
@Composable
|
||||
private fun priceLabel(price: String): String = stringResource(
|
||||
when (price) {
|
||||
ItchBrowse.PRICE_FREE -> R.string.stores_itch_price_free
|
||||
ItchBrowse.PRICE_SALE -> R.string.stores_itch_price_sale
|
||||
else -> R.string.stores_itch_price_any
|
||||
},
|
||||
)
|
||||
@@ -145,6 +145,7 @@ import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.frontend.Library
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import com.droiddeck.launcher.stores.CatalogItem
|
||||
import com.droiddeck.launcher.stores.itch.ItchBrowseState
|
||||
import com.droiddeck.launcher.stores.Store
|
||||
import com.droiddeck.launcher.stores.StoreTab
|
||||
import com.droiddeck.launcher.stores.StoresState
|
||||
@@ -954,7 +955,8 @@ private fun Storefront(
|
||||
val everything = remember(library, shelves, found) { (found + library + (shelves?.all ?: emptyList())).distinctBy { it.id } }
|
||||
LaunchedEffect(store, q) { StoresState.search(ctx, store, q) }
|
||||
val loaded = StoresState.library.containsKey(store)
|
||||
val showGrid = tab != "store" || q.isNotEmpty()
|
||||
val browsing = store == Store.ITCH && tab == "store" && q.isEmpty() && ItchBrowseState.active
|
||||
val showGrid = tab != "store" || q.isNotEmpty() || browsing
|
||||
val sort = s.storesSort
|
||||
val lastPlayedFor = remember(s.steamGames) {
|
||||
val byKey = s.steamGames.associate { "${it.source}:${it.storeId}" to it.lastPlayed }
|
||||
@@ -967,8 +969,13 @@ private fun Storefront(
|
||||
lookup
|
||||
}
|
||||
val isSizeSort = tab == "library" && (sort == "sizeAsc" || sort == "sizeDesc")
|
||||
val candidates = remember(library, everything, tab, q, s.storesShowMature) {
|
||||
if (tab == "library") library.filter(::matches) else everything.filter { matches(it) && shown(it) }
|
||||
val browseItems = if (browsing) ItchBrowseState.items else emptyList()
|
||||
val candidates = remember(library, everything, tab, q, s.storesShowMature, browsing, browseItems) {
|
||||
if (tab == "library") library.filter(::matches)
|
||||
else if (browsing) {
|
||||
val owned = library.associateBy { it.id }
|
||||
browseItems.map { owned[it.id] ?: it }.filter(::shown)
|
||||
} else everything.filter { matches(it) && shown(it) }
|
||||
}
|
||||
val candidateKeys = remember(candidates) { candidates.map { it.key } }
|
||||
var resolvedSizeSortKey by remember(store, tab) { mutableStateOf<List<String>?>(null) }
|
||||
@@ -1006,6 +1013,8 @@ private fun Storefront(
|
||||
}
|
||||
val empty = stringResource(when {
|
||||
tab == "library" && library.isEmpty() && StoresState.status[store] != null -> R.string.stores_library_loading
|
||||
browsing && ItchBrowseState.loading -> R.string.stores_shelves_loading
|
||||
browsing && ItchBrowseState.failed -> R.string.stores_itch_browse_failed
|
||||
else -> R.string.stores_nothing_matches
|
||||
})
|
||||
var firstPlaced = false
|
||||
@@ -1016,8 +1025,9 @@ private fun Storefront(
|
||||
// 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 itchBar = store == Store.ITCH && tab == "store" && q.isEmpty()
|
||||
val headerItems = 1 + (if (sizeSortPending) 1 else 0) + (if (barLine != null) 1 else 0) +
|
||||
(if (StoresState.problems[store] != null) 1 else 0)
|
||||
(if (StoresState.problems[store] != null) 1 else 0) + (if (itchBar) 1 else 0)
|
||||
val listMode = s.storesView == "list" && tab == "library"
|
||||
val capsules = s.storesView == "capsules" && tab == "library"
|
||||
val tileWidth = if (capsules) CapsuleWidth else CardWidth
|
||||
@@ -1102,6 +1112,7 @@ private fun Storefront(
|
||||
}
|
||||
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) } } } }
|
||||
if (itchBar) item(key = "itch-browse-bar", span = { GridItemSpan(maxLineSpan) }) { ItchBrowseBar() }
|
||||
when (tab) {
|
||||
"library" -> if (!loaded) Unit
|
||||
else if (split == 0) storeGrid(visible, empty, card)
|
||||
@@ -1112,8 +1123,10 @@ private fun Storefront(
|
||||
storeGrid(visible.drop(split), empty, card)
|
||||
}
|
||||
else -> {
|
||||
if (q.isNotEmpty()) storeGrid(visible, empty, card)
|
||||
else {
|
||||
if (q.isNotEmpty() || browsing) {
|
||||
storeGrid(visible, empty, card)
|
||||
if (browsing) item(key = "itch-more", span = { GridItemSpan(maxLineSpan) }) { ItchLoadMore() }
|
||||
} else {
|
||||
item(key = "shelves", span = { GridItemSpan(maxLineSpan) }) {
|
||||
Column {
|
||||
Shelf(stringResource(R.string.stores_shelf_new), shelf(shelves?.whatsNew), card)
|
||||
|
||||
Reference in new issue
Block a user