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. 18
      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,13 +58,17 @@ class DownloadActivity : VMBaseActivity<DownloadViewModel>(R.layout.activity_dow
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.menu_download -> launch(IO) {
App.db.bookDao().webBooks.forEach { book ->
Download.start(
this@DownloadActivity,
book.bookUrl,
book.durChapterIndex,
book.totalChapterNum
)
if (adapter.downloadMap.isNullOrEmpty()) {
App.db.bookDao().webBooks.forEach { book ->
Download.start(
this@DownloadActivity,
book.bookUrl,
book.durChapterIndex,
book.totalChapterNum
)
}
} else {
Download.stop(this@DownloadActivity)
}
}
}

Loading…
Cancel
Save