feat: 优化代码

pull/105/head
kunfei 5 years ago
parent 187c2c17b7
commit 708b25624f
  1. 7
      app/src/main/java/io/legado/app/service/help/Download.kt
  2. 4
      app/src/main/java/io/legado/app/ui/download/DownloadActivity.kt

@ -17,4 +17,11 @@ object Download {
} }
} }
fun stop(context: Context) {
Intent(context, DownloadService::class.java).let {
it.action = IntentAction.stop
context.startService(it)
}
}
} }

@ -58,6 +58,7 @@ class DownloadActivity : VMBaseActivity<DownloadViewModel>(R.layout.activity_dow
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) { when (item.itemId) {
R.id.menu_download -> launch(IO) { R.id.menu_download -> launch(IO) {
if (adapter.downloadMap.isNullOrEmpty()) {
App.db.bookDao().webBooks.forEach { book -> App.db.bookDao().webBooks.forEach { book ->
Download.start( Download.start(
this@DownloadActivity, this@DownloadActivity,
@ -66,6 +67,9 @@ class DownloadActivity : VMBaseActivity<DownloadViewModel>(R.layout.activity_dow
book.totalChapterNum book.totalChapterNum
) )
} }
} else {
Download.stop(this@DownloadActivity)
}
} }
} }
return super.onCompatOptionsItemSelected(item) return super.onCompatOptionsItemSelected(item)

Loading…
Cancel
Save