From 708b25624f10a6bfcd6f2fe894f3125541e7b088 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 18 Feb 2020 15:21:31 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/service/help/Download.kt | 7 +++++++ .../legado/app/ui/download/DownloadActivity.kt | 18 +++++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/service/help/Download.kt b/app/src/main/java/io/legado/app/service/help/Download.kt index 86accbceb..5692166df 100644 --- a/app/src/main/java/io/legado/app/service/help/Download.kt +++ b/app/src/main/java/io/legado/app/service/help/Download.kt @@ -17,4 +17,11 @@ object Download { } } + fun stop(context: Context) { + Intent(context, DownloadService::class.java).let { + it.action = IntentAction.stop + context.startService(it) + } + } + } \ No newline at end of file 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 5d642bf7d..2b78c4d6a 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 @@ -58,13 +58,17 @@ class DownloadActivity : VMBaseActivity(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) } } }