From 9d869ce50e9848ff63a93cbd6650048b3cb6c54a Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 18 Feb 2020 13:36:04 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/service/DownloadService.kt | 4 ++-- .../io/legado/app/ui/download/DownloadActivity.kt | 11 ++++++----- .../java/io/legado/app/ui/download/DownloadAdapter.kt | 2 ++ 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/service/DownloadService.kt b/app/src/main/java/io/legado/app/service/DownloadService.kt index 081b6d756..320c344ab 100644 --- a/app/src/main/java/io/legado/app/service/DownloadService.kt +++ b/app/src/main/java/io/legado/app/service/DownloadService.kt @@ -68,7 +68,7 @@ class DownloadService : BaseService() { searchPool.close() handler.removeCallbacks(runnable) super.onDestroy() - postEvent(EventBus.UP_DOWNLOAD, false) + postEvent(EventBus.UP_DOWNLOAD, downloadMap) } private fun addDownloadData(bookUrl: String?, start: Int, end: Int) { @@ -144,7 +144,7 @@ class DownloadService : BaseService() { private fun upDownload() { updateNotification(notificationContent) - postEvent(EventBus.UP_DOWNLOAD, true) + postEvent(EventBus.UP_DOWNLOAD, downloadMap) handler.removeCallbacks(runnable) handler.postDelayed(runnable, 1000) } diff --git a/app/src/main/java/io/legado/app/ui/download/DownloadActivity.kt b/app/src/main/java/io/legado/app/ui/download/DownloadActivity.kt index 4daa6272d..5d642bf7d 100644 --- a/app/src/main/java/io/legado/app/ui/download/DownloadActivity.kt +++ b/app/src/main/java/io/legado/app/ui/download/DownloadActivity.kt @@ -105,15 +105,16 @@ class DownloadActivity : VMBaseActivity(R.layout.activity_dow } override fun observeLiveBus() { - observeEvent(EventBus.UP_DOWNLOAD) { - if (it) { - menu?.findItem(R.id.menu_download)?.setIcon(R.drawable.ic_stop_black_24dp) + observeEvent>>(EventBus.UP_DOWNLOAD) { + if (it.isEmpty()) { + menu?.findItem(R.id.menu_download)?.setIcon(R.drawable.ic_play_24dp) menu?.applyTint(this) - adapter.notifyItemRangeChanged(0, adapter.getActualItemCount(), true) } else { - menu?.findItem(R.id.menu_download)?.setIcon(R.drawable.ic_play_24dp) + menu?.findItem(R.id.menu_download)?.setIcon(R.drawable.ic_stop_black_24dp) menu?.applyTint(this) } + adapter.downloadMap = it + adapter.notifyItemRangeChanged(0, adapter.getActualItemCount(), true) } observeEvent(EventBus.SAVE_CONTENT) { adapter.cacheChapters[it.bookUrl]?.add(it.url) diff --git a/app/src/main/java/io/legado/app/ui/download/DownloadAdapter.kt b/app/src/main/java/io/legado/app/ui/download/DownloadAdapter.kt index d0161bd88..bdfecd0e3 100644 --- a/app/src/main/java/io/legado/app/ui/download/DownloadAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/download/DownloadAdapter.kt @@ -5,6 +5,7 @@ import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.data.entities.Book +import io.legado.app.data.entities.BookChapter import kotlinx.android.synthetic.main.item_download.view.* import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.toast @@ -14,6 +15,7 @@ class DownloadAdapter(context: Context, private val callBack: CallBack) : SimpleRecyclerAdapter(context, R.layout.item_download) { val cacheChapters = hashMapOf>() + var downloadMap: HashMap>? = null override fun convert(holder: ItemViewHolder, item: Book, payloads: MutableList) { with(holder.itemView) {