From 2afe5fe5b2bb313cc124f9f72e4863caefc45f30 Mon Sep 17 00:00:00 2001 From: FooIbar <118464521+FooIbar@users.noreply.github.com> Date: Sun, 15 Jan 2023 20:47:49 +0800 Subject: [PATCH] Show current funds in archive dialog --- .../ehviewer/client/parser/ArchiveParser.kt | 26 +++++++++++----- .../ehviewer/ui/scene/GalleryDetailScene.kt | 31 +++++++++++++++++-- app/src/main/res/values-zh-rCN/strings.xml | 2 ++ app/src/main/res/values/strings.xml | 2 ++ 4 files changed, 50 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/hippo/ehviewer/client/parser/ArchiveParser.kt b/app/src/main/java/com/hippo/ehviewer/client/parser/ArchiveParser.kt index 44cc15b1e..a07d095f1 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/parser/ArchiveParser.kt +++ b/app/src/main/java/com/hippo/ehviewer/client/parser/ArchiveParser.kt @@ -24,6 +24,8 @@ import java.util.regex.Pattern object ArchiveParser { private val PATTERN_ARCHIVE_URL = Pattern.compile("(.*).*Click Here To Start Downloading") + private val PATTERN_CURRENT_FUNDS = + Pattern.compile("

([\\d,]+) GP \\[[^]]*]   ([\\d,]+) Credits \\[[^]]*]

") private val PATTERN_HATH_FORM = Pattern.compile("
") private val PATTERN_HATH_ARCHIVE = @@ -42,18 +44,17 @@ object ArchiveParser { val d = Jsoup.parse(body) val es = d.select("#db>div>div") for (e in es) { - try { - val btn = e.selectFirst("form>div>input") - if (!btn!!.hasAttr("disabled")) { + if (!e.attr("style").contains("color:#CCCCCC")) { + try { val res = e.selectFirst("form>input")!!.attr("value") - val name = btn.attr("value") + val name = e.selectFirst("form>div>input")!!.attr("value") val size = e.selectFirst("p>strong")!!.text() val cost = e.selectFirst("div>strong")!!.text().replace(",", "") val item = Archive(res, name, size, cost, false) archiveList.add(item) + } catch (ex: NullPointerException) { + ex.printStackTrace() } - } catch (ex: NullPointerException) { - ex.printStackTrace() } } m = PATTERN_HATH_ARCHIVE.matcher(body) @@ -65,7 +66,14 @@ object ArchiveParser { val item = Archive(res, name, size, cost, true) archiveList.add(item) } - return Result(paramOr, archiveList) + var funds: Funds? = null + m = PATTERN_CURRENT_FUNDS.matcher(body) + if (m.find()) { + val fundsGP = ParserUtils.parseInt(m.group(1), 0) + val fundsC = ParserUtils.parseInt(m.group(2), 0) + funds = Funds(fundsGP, fundsC) + } + return Result(paramOr, archiveList, funds) } @Throws(NoHAtHClientException::class) @@ -104,5 +112,7 @@ object ArchiveParser { } } - class Result(val paramOr: String?, val archiveList: List) + class Funds(var fundsGP: Int, var fundsC: Int) + + class Result(val paramOr: String?, val archiveList: List, val funds: Funds?) } \ No newline at end of file diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.kt b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.kt index a3d39ad8b..4c0390620 100755 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.kt @@ -78,6 +78,7 @@ import com.hippo.ehviewer.client.data.GalleryTagGroup import com.hippo.ehviewer.client.data.ListUrlBuilder import com.hippo.ehviewer.client.exception.NoHAtHClientException import com.hippo.ehviewer.client.parser.ArchiveParser +import com.hippo.ehviewer.client.parser.ParserUtils import com.hippo.ehviewer.client.parser.RateGalleryParser import com.hippo.ehviewer.client.parser.TorrentParser import com.hippo.ehviewer.client.parser.VoteTagParser @@ -148,6 +149,7 @@ class GalleryDetailScene : CollapsingToolbarScene(), View.OnClickListener, Downl } private var mArchiveFormParamOr: String? = null private var mArchiveList: List? = null + private var mCurrentFunds: ArchiveParser.Funds? = null @State private var mState = STATE_INIT @@ -1438,12 +1440,12 @@ class GalleryDetailScene : CollapsingToolbarScene(), View.OnClickListener, Downl .setCallback(this) mRequest!!.enqueue(this@GalleryDetailScene) } else { - bind(mArchiveList) + bind(mArchiveList, mCurrentFunds) } } } - private fun bind(data: List?) { + private fun bind(data: List?, funds: ArchiveParser.Funds?) { if (null == mDialog || null == mProgressView || null == mErrorText || null == mListView) { return } @@ -1463,6 +1465,15 @@ class GalleryDetailScene : CollapsingToolbarScene(), View.OnClickListener, Downl mListView!!.visibility = View.VISIBLE mListView!!.adapter = ArrayAdapter(mDialog!!.context, R.layout.item_select_dialog, nameArray) + if (funds != null) { + mDialog!!.setTitle( + getString( + R.string.current_funds, + funds.fundsGP, + funds.fundsC + ) + ) + } } } @@ -1470,6 +1481,19 @@ class GalleryDetailScene : CollapsingToolbarScene(), View.OnClickListener, Downl val context = context val activity = mainActivity if (null != context && null != activity && null != mArchiveList && position < mArchiveList!!.size) { + if (mCurrentFunds != null) { + val cost = ParserUtils.parseInt( + mArchiveList!![position].cost.removeSuffix("GP").removeSuffix("Credits"), 0 + ) + if (cost <= mCurrentFunds!!.fundsGP) { + mCurrentFunds!!.fundsGP -= cost + } else if (cost <= mCurrentFunds!!.fundsC) { + mCurrentFunds!!.fundsC -= cost + } else { + showTip(R.string.insufficient_funds, LENGTH_SHORT) + return + } + } val res = mArchiveList!![position].res val isHAtH = mArchiveList!![position].isHAtH val request = EhRequest() @@ -1506,7 +1530,8 @@ class GalleryDetailScene : CollapsingToolbarScene(), View.OnClickListener, Downl mRequest = null mArchiveFormParamOr = result.paramOr mArchiveList = result.archiveList - bind(result.archiveList) + mCurrentFunds = result.funds + bind(result.archiveList, result.funds) } } diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index b7de28a87..af663edfb 100755 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -531,6 +531,8 @@ 原始档案 重采样档案 下载压缩包需要 H@H 客户端 + 资金:%d GP,%d Credits + 余额不足 隐私 不允许屏幕抓取 启用后,将不能截取该应用的屏幕截图,同时,将不会在系统任务切换器中显示该应用的内容预览,重新加载应用以生效此更改 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5d53ddebd..4da48ee79 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -598,6 +598,8 @@ Original archive Resample archive Need H@H client for archive download + Funds: %d GP, %d Credits + Insufficient Funds Privacy Prevent screenshots Prevent the content of the app from being taken screenshots of or shown in the \"Recent Apps\" list.