From b32f78ea9fad01ef790a50d9286558bde869ddeb Mon Sep 17 00:00:00 2001 From: FooIbar <118464521+FooIbar@users.noreply.github.com> Date: Mon, 29 Apr 2024 23:37:20 +0800 Subject: [PATCH] Archive dialog overhaul --- .../ehviewer/ui/screen/GalleryDetailScreen.kt | 99 +++++++++++++++---- app/src/main/res/values-zh-rCN/strings.xml | 6 +- app/src/main/res/values-zh-rTW/strings.xml | 6 +- app/src/main/res/values/strings.xml | 6 +- 4 files changed, 87 insertions(+), 30 deletions(-) diff --git a/app/src/main/kotlin/com/hippo/ehviewer/ui/screen/GalleryDetailScreen.kt b/app/src/main/kotlin/com/hippo/ehviewer/ui/screen/GalleryDetailScreen.kt index 3443be37c..24bc50c85 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/ui/screen/GalleryDetailScreen.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/ui/screen/GalleryDetailScreen.kt @@ -46,6 +46,7 @@ import androidx.compose.material3.CircularProgressIndicator import androidx.compose.material3.DropdownMenu import androidx.compose.material3.DropdownMenuItem import androidx.compose.material3.FilledTonalButton +import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.LargeTopAppBar @@ -76,10 +77,10 @@ import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.layout.LocalPinnableContainer import androidx.compose.ui.res.dimensionResource import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import androidx.core.text.parseAsHtml -import arrow.core.left import arrow.core.partially1 import coil3.imageLoader import com.hippo.ehviewer.EhApplication.Companion.galleryDetailCache @@ -297,6 +298,7 @@ fun GalleryDetailScreen(args: GalleryDetailScreenArgs, navigator: DestinationsNa var mArchiveList by remember { mutableStateOf?>(null) } var mCurrentFunds by remember { mutableStateOf(null) } + val currentFunds = stringResource(R.string.current_funds) val archiveFree = stringResource(R.string.archive_free) val archiveOriginal = stringResource(R.string.archive_original) val archiveResample = stringResource(R.string.archive_resample) @@ -311,7 +313,7 @@ fun GalleryDetailScreen(args: GalleryDetailScreenArgs, navigator: DestinationsNa if (galleryDetail.apiUid < 0) { showSnackbar(signInFirst) } else { - Unit.runSuspendCatching { + runSuspendCatching { if (mArchiveList == null) { val result = bgWork { withIOContext { @@ -325,28 +327,83 @@ fun GalleryDetailScreen(args: GalleryDetailScreenArgs, navigator: DestinationsNa if (mArchiveList!!.isEmpty()) { showSnackbar(noArchive) } else { - val items = mArchiveList!!.map { - it.run { - if (isHAtH) { - val costStr = if (cost == "Free") archiveFree else cost - "[H@H] $name [$size] [$costStr]" - } else { - val nameStr = if (res == "org") archiveOriginal else archiveResample - val costStr = if (cost == "Free!") archiveFree else cost - "$nameStr [$size] [$costStr]" + val fundsGP = buildString { + append("%,d".format(mCurrentFunds!!.fundsGP)) + // Ex GP numbers are rounded down to the nearest thousand + if (EhUtils.isExHentai) { + append('+') + } + append(" GP") + } + val fundsC = "%,d C".format(mCurrentFunds!!.fundsC) + val (hAtH, nonHAtH) = mArchiveList!!.partition { it.isHAtH } + val selected = showNoButton { + val labelStyle = MaterialTheme.typography.labelMedium + val fundsStyle = MaterialTheme.typography.labelLarge + LazyVerticalGrid( + columns = GridCells.Fixed(2), + contentPadding = PaddingValues(horizontal = 8.dp, vertical = 16.dp), + verticalArrangement = Arrangement.spacedBy(8.dp), + ) { + item(span = { GridItemSpan(maxLineSpan) }, contentType = "funds") { + Text( + text = currentFunds, + textAlign = TextAlign.Center, + ) + } + item(contentType = "funds") { + Text( + text = fundsGP, + textAlign = TextAlign.Center, + style = fundsStyle, + ) + } + item(contentType = "funds") { + Text( + text = fundsC, + textAlign = TextAlign.Center, + style = fundsStyle, + ) + } + items(nonHAtH, contentType = { "archive" }) { + Column(horizontalAlignment = Alignment.CenterHorizontally) { + Text( + text = if (it.cost == "Free!") archiveFree else it.cost, + style = labelStyle, + ) + Button(onClick = { dismissWith(it) }) { + Text(if (it.res == "org") archiveOriginal else archiveResample) + } + Text( + text = it.size, + style = labelStyle, + ) + } + } + item(span = { GridItemSpan(maxLineSpan) }, contentType = "divider") { + Column(horizontalAlignment = Alignment.CenterHorizontally) { + HorizontalDivider(modifier = Modifier.padding(vertical = 8.dp)) + Text(text = "H@H") + } + } + items(hAtH, contentType = { "archive" }) { + Column(horizontalAlignment = Alignment.CenterHorizontally) { + Text( + text = if (it.cost == "Free") archiveFree else it.cost, + style = labelStyle, + ) + Button(onClick = { dismissWith(it) }) { + Text(if (it.res == "org") archiveOriginal else it.name) + } + Text( + text = it.size, + style = labelStyle, + ) + } } } } - var fundsGP = mCurrentFunds!!.fundsGP.toString() - // Ex GP numbers are rounded down to the nearest thousand - if (EhUtils.isExHentai) { - fundsGP += "+" - } - val title = getString(R.string.current_funds, fundsGP, mCurrentFunds!!.fundsC) - val selected = awaitSelectItem(items, title.left()) - val res = mArchiveList!![selected].res - val isHAtH = mArchiveList!![selected].isHAtH - EhEngine.downloadArchive(gid, token, mArchiveFormParamOr!!, res, isHAtH)?.let { + EhEngine.downloadArchive(gid, token, mArchiveFormParamOr!!, selected.res, selected.isHAtH)?.let { val uri = Uri.parse(it) val intent = Intent().apply { action = Intent.ACTION_VIEW diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 2ca7a2417..07c25e4c1 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -411,10 +411,10 @@ 开始下载压缩包 无法下载压缩包 免费 - 原始档案 - 重采样档案 + 原始 + 重采样 下载压缩包需要 H@H 客户端 - 资金:%1$s GP,%2$d Credits + 当前资金: 余额不足 图片配额 已用:%1$d / %2$d diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 4cec3b363..31b38ef73 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -402,10 +402,10 @@ 開始下載壓縮檔 下載失敗 免費 - 原始檔案 - 重新採樣檔案 + 原始 + 重新採樣 下載壓縮檔需要 H@H 客戶端 - 資金:%1$s GP,%2$d Credits + 目前資金: 餘額不足 圖片配額 已用:%1$d / %2$d diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b4d89052f..cec13588a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -468,10 +468,10 @@ Archive download started Failed to download archive Free - Original archive - Resample archive + Original + Resample Need H@H client for archive download - Funds: %1$s GP, %2$d Credits + Current Funds: Insufficient Funds Image Limits Used: %1$d / %2$d