Archive dialog overhaul

This commit is contained in:
FooIbar committed 2024-04-29 23:49:40 +08:00
1 parent 78002dac3a
commit b32f78ea9f
4 files changed
+87 -30

No files matched your search

@@ -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<List<ArchiveParser.Archive>?>(null) }
var mCurrentFunds by remember { mutableStateOf<HomeParser.Funds?>(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
+3 -3
View File
@@ -411,10 +411,10 @@
<string name="download_archive_started">开始下载压缩包</string>
<string name="download_archive_failure">无法下载压缩包</string>
<string name="archive_free">免费</string>
<string name="archive_original">原始档案</string>
<string name="archive_resample">重采样档案</string>
<string name="archive_original">原始</string>
<string name="archive_resample">重采样</string>
<string name="download_archive_failure_no_hath">下载压缩包需要 H@H 客户端</string>
<string name="current_funds">资金:%1$s GP,%2$d Credits</string>
<string name="current_funds">当前资金:</string>
<string name="insufficient_funds">余额不足</string>
<string name="image_limits">图片配额</string>
<string name="image_limits_summary">已用:%1$d / %2$d</string>
+3 -3
View File
@@ -402,10 +402,10 @@
<string name="download_archive_started">開始下載壓縮檔</string>
<string name="download_archive_failure">下載失敗</string>
<string name="archive_free">免費</string>
<string name="archive_original">原始檔案</string>
<string name="archive_resample">重新採樣檔案</string>
<string name="archive_original">原始</string>
<string name="archive_resample">重新採樣</string>
<string name="download_archive_failure_no_hath">下載壓縮檔需要 H@H 客戶端</string>
<string name="current_funds">資金:%1$s GP,%2$d Credits</string>
<string name="current_funds">目前資金:</string>
<string name="insufficient_funds">餘額不足</string>
<string name="image_limits">圖片配額</string>
<string name="image_limits_summary">已用:%1$d / %2$d</string>
+3 -3
View File
@@ -468,10 +468,10 @@
<string name="download_archive_started">Archive download started</string>
<string name="download_archive_failure">Failed to download archive</string>
<string name="archive_free">Free</string>
<string name="archive_original">Original archive</string>
<string name="archive_resample">Resample archive</string>
<string name="archive_original">Original</string>
<string name="archive_resample">Resample</string>
<string name="download_archive_failure_no_hath">Need H@H client for archive download</string>
<string name="current_funds">Funds: %1$s GP, %2$d Credits</string>
<string name="current_funds">Current Funds:</string>
<string name="insufficient_funds">Insufficient Funds</string>
<string name="image_limits">Image Limits</string>
<string name="image_limits_summary">Used: %1$d / %2$d</string>