diff --git a/app/src/main/java/io/legado/app/App.kt b/app/src/main/java/io/legado/app/App.kt index 921563c21..23f6798ed 100644 --- a/app/src/main/java/io/legado/app/App.kt +++ b/app/src/main/java/io/legado/app/App.kt @@ -1,6 +1,7 @@ package io.legado.app import android.app.Application +import android.app.Notification import android.app.NotificationChannel import android.app.NotificationManager import android.content.Context @@ -142,7 +143,7 @@ class App : Application() { enableLights(false) enableVibration(false) setSound(null, null) - importance = NotificationManager.IMPORTANCE_LOW + lockscreenVisibility = Notification.VISIBILITY_PUBLIC } val readAloudChannel = NotificationChannel( @@ -153,7 +154,7 @@ class App : Application() { enableLights(false) enableVibration(false) setSound(null, null) - importance = NotificationManager.IMPORTANCE_LOW + lockscreenVisibility = Notification.VISIBILITY_PUBLIC } val webChannel = NotificationChannel( @@ -164,7 +165,7 @@ class App : Application() { enableLights(false) enableVibration(false) setSound(null, null) - importance = NotificationManager.IMPORTANCE_LOW + lockscreenVisibility = Notification.VISIBILITY_PUBLIC } //向notification manager 提交channel diff --git a/app/src/main/java/io/legado/app/model/CacheBook.kt b/app/src/main/java/io/legado/app/model/CacheBook.kt index 41c5847a1..3253bc49f 100644 --- a/app/src/main/java/io/legado/app/model/CacheBook.kt +++ b/app/src/main/java/io/legado/app/model/CacheBook.kt @@ -68,13 +68,14 @@ object CacheBook { } } - fun start(context: Context, book: Book, start: Int, end: Int) { + fun start(context: Context, book: Book, start: Int, end: Int, startDownload: Boolean = true) { if (!book.isLocal) { context.startService { action = IntentAction.start putExtra("bookUrl", book.bookUrl) putExtra("start", start) putExtra("end", end) + putExtra("startDownload", startDownload) } } } @@ -177,6 +178,7 @@ object CacheBook { waitDownloadSet.add(i) } } + cacheBookMap[book.bookUrl] = this postEvent(EventBus.UP_DOWNLOAD, book.bookUrl) } diff --git a/app/src/main/java/io/legado/app/service/CacheBookService.kt b/app/src/main/java/io/legado/app/service/CacheBookService.kt index d9b234fe5..5599ccdec 100644 --- a/app/src/main/java/io/legado/app/service/CacheBookService.kt +++ b/app/src/main/java/io/legado/app/service/CacheBookService.kt @@ -80,7 +80,8 @@ class CacheBookService : BaseService() { IntentAction.start -> addDownloadData( intent.getStringExtra("bookUrl"), intent.getIntExtra("start", 0), - intent.getIntExtra("end", 0) + intent.getIntExtra("end", 0), + intent.getBooleanExtra("startDownload", true) ) IntentAction.remove -> removeDownload(intent.getStringExtra("bookUrl")) @@ -98,7 +99,7 @@ class CacheBookService : BaseService() { postEvent(EventBus.UP_DOWNLOAD, "") } - private fun addDownloadData(bookUrl: String?, start: Int, end: Int) { + private fun addDownloadData(bookUrl: String?, start: Int, end: Int, startDownload: Boolean) { bookUrl ?: return execute { val cacheBook = CacheBook.getOrCreate(bookUrl) ?: return@execute diff --git a/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt b/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt index f58ccca72..f294d94c1 100644 --- a/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt @@ -158,12 +158,14 @@ class CacheActivity : VMBaseActivity() when (item.itemId) { R.id.menu_download -> { if (!CacheBook.isRun) { - adapter.getItems().forEach { book -> + val lastIndex = adapter.itemCount - 1 + adapter.getItems().forEachIndexed { index, book -> CacheBook.start( this@CacheActivity, book, book.durChapterIndex, - book.lastChapterIndex + book.lastChapterIndex, + index == lastIndex ) } } else {