下载界面的复用问题

This commit is contained in:
HapeLee
2025-10-12 21:56:05 +08:00
parent a97e31f103
commit d2d503b2f5
@@ -46,24 +46,24 @@ class CacheAdapter(context: Context, private val callBack: CallBack) :
payloads: MutableList<Any> payloads: MutableList<Any>
) { ) {
binding.run { binding.run {
progressDownload.gone()
progressExport.gone()
tvMsg.gone()
tvDownload.text = ""
ivDownload.icon = null
if (payloads.isEmpty()) { if (payloads.isEmpty()) {
tvName.text = item.name tvName.text = item.name
tvAuthor.text = context.getString(R.string.author_show, item.getRealAuthor()) tvAuthor.text = context.getString(R.string.author_show, item.getRealAuthor())
if (item.isLocal) { if (item.isLocal) {
tvDownload.setText(R.string.local_book) tvDownload.setText(R.string.local_book)
progressDownload.gone()
} else { } else {
val cs = callBack.cacheChapters[item.bookUrl] val cs = callBack.cacheChapters[item.bookUrl]
if (cs == null) { tvDownload.text = if (cs == null) {
tvDownload.setText(R.string.loading) context.getString(R.string.loading)
} else { } else {
tvDownload.text = context.getString(R.string.download_count, cs.size, item.totalChapterNum)
context.getString(
R.string.download_count,
cs.size,
item.totalChapterNum
)
} }
} }
} else { } else {
@@ -71,21 +71,12 @@ class CacheAdapter(context: Context, private val callBack: CallBack) :
tvDownload.setText(R.string.local_book) tvDownload.setText(R.string.local_book)
} else { } else {
val cacheSize = callBack.cacheChapters[item.bookUrl]?.size ?: 0 val cacheSize = callBack.cacheChapters[item.bookUrl]?.size ?: 0
tvDownload.text = context.getString(R.string.download_count, cacheSize, item.totalChapterNum)
val cacheTask = CacheBook.cacheBookMap[item.bookUrl] val cacheTask = CacheBook.cacheBookMap[item.bookUrl]
tvDownload.text =
context.getString(R.string.download_count, cacheSize, item.totalChapterNum)
if (cacheTask != null && !cacheTask.isStop()) { if (cacheTask != null && !cacheTask.isStop()) {
val progress = if (item.totalChapterNum > 0) { val progress = if (item.totalChapterNum > 0) cacheSize * 100 / item.totalChapterNum else 0
(cacheSize * 100 / item.totalChapterNum)
} else {
0
}
tvMsg.gone()
progressDownload.progress = progress progressDownload.progress = progress
progressDownload.visible() progressDownload.visible()
} else {
progressDownload.gone()
} }
} }
} }
@@ -94,6 +85,7 @@ class CacheAdapter(context: Context, private val callBack: CallBack) :
} }
} }
override fun registerListener(holder: ItemViewHolder, binding: ItemDownloadBinding) { override fun registerListener(holder: ItemViewHolder, binding: ItemDownloadBinding) {
binding.run { binding.run {
ivDownload.setOnClickListener { ivDownload.setOnClickListener {
@@ -121,7 +113,7 @@ class CacheAdapter(context: Context, private val callBack: CallBack) :
CacheBook.remove(context, book.bookUrl) CacheBook.remove(context, book.bookUrl)
Handler(Looper.getMainLooper()).postDelayed({ Handler(Looper.getMainLooper()).postDelayed({
callBack.deleteDownload(book) callBack.deleteDownload(book)
}, 500) }, 10)
} else { } else {
callBack.deleteDownload(book) callBack.deleteDownload(book)
} }
@@ -152,22 +144,21 @@ class CacheAdapter(context: Context, private val callBack: CallBack) :
} }
private fun upExportInfo(msgView: TextView, progressView: ProgressBar, book: Book) { private fun upExportInfo(msgView: TextView, progressView: ProgressBar, book: Book) {
msgView.gone()
progressView.gone()
val msg = callBack.exportMsg(book.bookUrl) val msg = callBack.exportMsg(book.bookUrl)
if (msg != null) { if (msg != null) {
msgView.text = msg msgView.text = msg
msgView.visible() msgView.visible()
progressView.gone()
return return
} }
msgView.gone()
val progress = callBack.exportProgress(book.bookUrl) val progress = callBack.exportProgress(book.bookUrl)
if (progress != null) { if (progress != null) {
progressView.max = book.totalChapterNum progressView.max = book.totalChapterNum
progressView.progress = progress progressView.progress = progress
progressView.visible() progressView.visible()
return
} }
progressView.gone()
} }
interface CallBack { interface CallBack {