pull/66/head
kunfei 5 years ago
parent 9258598adc
commit d81bb4c403
  1. 1
      app/src/main/java/io/legado/app/service/DownloadService.kt
  2. 12
      app/src/main/java/io/legado/app/ui/download/DownloadActivity.kt
  3. 2
      app/src/main/res/menu/download.xml

@ -62,6 +62,7 @@ class DownloadService : BaseService() {
searchPool.close() searchPool.close()
handler.removeCallbacks(runnable) handler.removeCallbacks(runnable)
super.onDestroy() super.onDestroy()
postEvent(Bus.UP_DOWNLOAD, false)
} }
private fun download(bookUrl: String?, start: Int, end: Int) { private fun download(bookUrl: String?, start: Int, end: Int) {

@ -12,6 +12,7 @@ import io.legado.app.base.BaseActivity
import io.legado.app.constant.Bus import io.legado.app.constant.Bus
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.service.help.Download import io.legado.app.service.help.Download
import io.legado.app.utils.applyTint
import io.legado.app.utils.observeEvent import io.legado.app.utils.observeEvent
import kotlinx.android.synthetic.main.activity_download.* import kotlinx.android.synthetic.main.activity_download.*
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
@ -22,6 +23,7 @@ class DownloadActivity : BaseActivity(R.layout.activity_download) {
lateinit var adapter: DownloadAdapter lateinit var adapter: DownloadAdapter
private var bookshelfLiveData: LiveData<List<Book>>? = null private var bookshelfLiveData: LiveData<List<Book>>? = null
private var menu: Menu? = null
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
initRecyclerView() initRecyclerView()
@ -30,12 +32,13 @@ class DownloadActivity : BaseActivity(R.layout.activity_download) {
override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { override fun onCompatCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.download, menu) menuInflater.inflate(R.menu.download, menu)
this.menu = menu
return super.onCompatCreateOptionsMenu(menu) return super.onCompatCreateOptionsMenu(menu)
} }
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) { when (item.itemId) {
R.id.menu_download_start -> launch(IO) { R.id.menu_download -> launch(IO) {
App.db.bookDao().webBooks.forEach { book -> App.db.bookDao().webBooks.forEach { book ->
Download.start( Download.start(
this@DownloadActivity, this@DownloadActivity,
@ -65,7 +68,14 @@ class DownloadActivity : BaseActivity(R.layout.activity_download) {
override fun observeLiveBus() { override fun observeLiveBus() {
observeEvent<Boolean>(Bus.UP_DOWNLOAD) { observeEvent<Boolean>(Bus.UP_DOWNLOAD) {
if (it) {
menu?.findItem(R.id.menu_download)?.setIcon(R.drawable.ic_stop_black_24dp)
menu?.applyTint(this)
adapter.notifyItemRangeChanged(0, adapter.itemCount, true) adapter.notifyItemRangeChanged(0, adapter.itemCount, true)
} else {
menu?.findItem(R.id.menu_download)?.setIcon(R.drawable.ic_play_24dp)
menu?.applyTint(this)
}
} }
} }
} }

@ -3,7 +3,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<item <item
android:id="@+id/menu_download_start" android:id="@+id/menu_download"
android:title="@string/action_download" android:title="@string/action_download"
android:icon="@drawable/ic_play_24dp" android:icon="@drawable/ic_play_24dp"
app:showAsAction="ifRoom" /> app:showAsAction="ifRoom" />

Loading…
Cancel
Save