mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 12:28:40 +00:00
itch.io: platform and tag filters (#1497)
This commit is contained in:
1 parent
8d66570d33
commit
7b518d7e6a
38 files changed
+198
-3
No files matched your search
@@ -54,7 +54,7 @@ internal object ItchBrowse {
|
||||
|
||||
fun path(query: BrowseQuery): String {
|
||||
val segments = listOfNotNull(sortSegment(query.sort), priceSegment(query.price)) +
|
||||
query.platforms.sorted().map { "platform-$it" } +
|
||||
platformNames.filter { it in query.platforms }.map { "platform-$it" } +
|
||||
query.tags.map { "tag-" + tagSlug(it) }
|
||||
return if (segments.isEmpty()) BASE else BASE + "/" + segments.joinToString("/")
|
||||
}
|
||||
|
||||
@@ -676,14 +676,15 @@ private fun MoviePreview(url: String, modifier: Modifier = Modifier) {
|
||||
|
||||
/** A dialog with one text box, for a search term or a page number; the Android keyboard comes up with it. */
|
||||
@Composable
|
||||
private fun TextEntryDialog(
|
||||
internal fun TextEntryDialog(
|
||||
title: String, initial: String, number: Boolean, confirm: String, onSubmit: (String) -> Unit, onDismiss: () -> Unit,
|
||||
id: String = "boot-movie-entry",
|
||||
) {
|
||||
val shown = rememberShown(onDismiss)
|
||||
val close = { shown.targetState = false }
|
||||
var text by remember { mutableStateOf(initial) }
|
||||
val submit = { onSubmit(text.trim()); close() }
|
||||
AppDialog(shown, close, "boot-movie-entry", wide = false, maxWidth = 460.dp) {
|
||||
AppDialog(shown, close, id, wide = false, maxWidth = 460.dp) {
|
||||
DialogTitleRow(title, close)
|
||||
AdbTextField(
|
||||
value = text, onValueChange = { text = it }, label = "", keyboardType = if (number) KeyboardType.Number else KeyboardType.Text,
|
||||
|
||||
@@ -20,7 +20,10 @@ import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
@@ -38,6 +41,7 @@ import com.droiddeck.launcher.stores.itch.ItchBrowseState
|
||||
internal fun ItchBrowseBar() {
|
||||
val ctx = LocalContext.current
|
||||
val query = ItchBrowseState.query
|
||||
var picking by remember { mutableStateOf(false) }
|
||||
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)) }
|
||||
@@ -45,7 +49,23 @@ internal fun ItchBrowseBar() {
|
||||
ChipRow {
|
||||
for (price in ItchBrowse.prices) BrowseChip(priceLabel(price), query.price == price) { ItchBrowseState.choose(ctx, query.copy(price = price)) }
|
||||
}
|
||||
ChipRow {
|
||||
BrowseChip(stringResource(R.string.stores_itch_platform_any), query.platforms.isEmpty()) { ItchBrowseState.choose(ctx, query.copy(platforms = emptySet())) }
|
||||
for (platform in ItchBrowse.platformNames) {
|
||||
val on = platform in query.platforms
|
||||
BrowseChip(platformLabel(platform), on) { ItchBrowseState.choose(ctx, query.copy(platforms = if (on) query.platforms - platform else query.platforms + platform)) }
|
||||
}
|
||||
}
|
||||
ChipRow {
|
||||
for (tag in query.tags) BrowseChip("$tag ✕", true) { ItchBrowseState.choose(ctx, query.copy(tags = query.tags - tag)) }
|
||||
BrowseChip(stringResource(R.string.stores_itch_tag_add), false) { picking = true }
|
||||
}
|
||||
}
|
||||
if (picking) TextEntryDialog(
|
||||
stringResource(R.string.stores_itch_tag_title), "", number = false, confirm = stringResource(R.string.common_ok),
|
||||
onSubmit = { value -> ItchBrowse.tagSlug(value).takeIf { it.isNotEmpty() }?.let { ItchBrowseState.choose(ctx, query.copy(tags = (query.tags + it).distinct())) } },
|
||||
onDismiss = { picking = false }, id = "itch-tag",
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
@@ -99,6 +119,19 @@ private fun sortLabel(sort: String): String = stringResource(
|
||||
},
|
||||
)
|
||||
|
||||
@Composable
|
||||
private fun platformLabel(platform: String): String = stringResource(
|
||||
when (platform) {
|
||||
"windows" -> R.string.stores_itch_platform_windows
|
||||
"osx" -> R.string.stores_itch_platform_macos
|
||||
"linux" -> R.string.stores_itch_platform_linux
|
||||
"android" -> R.string.stores_itch_platform_android
|
||||
"ios" -> R.string.stores_itch_platform_ios
|
||||
"web" -> R.string.stores_itch_platform_web
|
||||
else -> R.string.stores_itch_platform_mobile_web
|
||||
},
|
||||
)
|
||||
|
||||
@Composable
|
||||
private fun priceLabel(price: String): String = stringResource(
|
||||
when (price) {
|
||||
|
||||
Reference in new issue
Block a user