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 798fcdfb8..d8bfae260 100644 --- a/app/src/main/java/io/legado/app/service/DownloadService.kt +++ b/app/src/main/java/io/legado/app/service/DownloadService.kt @@ -62,6 +62,7 @@ class DownloadService : BaseService() { searchPool.close() handler.removeCallbacks(runnable) super.onDestroy() + postEvent(Bus.UP_DOWNLOAD, false) } private fun download(bookUrl: String?, start: Int, end: Int) { 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 9789bc273..a2ff5d99e 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 @@ -12,6 +12,7 @@ import io.legado.app.base.BaseActivity import io.legado.app.constant.Bus import io.legado.app.data.entities.Book import io.legado.app.service.help.Download +import io.legado.app.utils.applyTint import io.legado.app.utils.observeEvent import kotlinx.android.synthetic.main.activity_download.* import kotlinx.coroutines.Dispatchers.IO @@ -22,6 +23,7 @@ class DownloadActivity : BaseActivity(R.layout.activity_download) { lateinit var adapter: DownloadAdapter private var bookshelfLiveData: LiveData>? = null + private var menu: Menu? = null override fun onActivityCreated(savedInstanceState: Bundle?) { initRecyclerView() @@ -30,12 +32,13 @@ class DownloadActivity : BaseActivity(R.layout.activity_download) { override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { menuInflater.inflate(R.menu.download, menu) + this.menu = menu return super.onCompatCreateOptionsMenu(menu) } override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { - R.id.menu_download_start -> launch(IO) { + R.id.menu_download -> launch(IO) { App.db.bookDao().webBooks.forEach { book -> Download.start( this@DownloadActivity, @@ -65,7 +68,14 @@ class DownloadActivity : BaseActivity(R.layout.activity_download) { override fun observeLiveBus() { observeEvent(Bus.UP_DOWNLOAD) { - adapter.notifyItemRangeChanged(0, adapter.itemCount, true) + if (it) { + menu?.findItem(R.id.menu_download)?.setIcon(R.drawable.ic_stop_black_24dp) + menu?.applyTint(this) + adapter.notifyItemRangeChanged(0, adapter.itemCount, true) + } else { + menu?.findItem(R.id.menu_download)?.setIcon(R.drawable.ic_play_24dp) + menu?.applyTint(this) + } } } } \ No newline at end of file diff --git a/app/src/main/res/menu/download.xml b/app/src/main/res/menu/download.xml index cf4375f09..452269d37 100644 --- a/app/src/main/res/menu/download.xml +++ b/app/src/main/res/menu/download.xml @@ -3,7 +3,7 @@ xmlns:app="http://schemas.android.com/apk/res-auto">