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

Loading…
Cancel
Save