Horis 2 年之前
父節點
當前提交
41075c7a26

+ 4 - 3
app/src/main/java/io/legado/app/App.kt

@@ -1,6 +1,7 @@
 package io.legado.app
 package io.legado.app
 
 
 import android.app.Application
 import android.app.Application
+import android.app.Notification
 import android.app.NotificationChannel
 import android.app.NotificationChannel
 import android.app.NotificationManager
 import android.app.NotificationManager
 import android.content.Context
 import android.content.Context
@@ -142,7 +143,7 @@ class App : Application() {
             enableLights(false)
             enableLights(false)
             enableVibration(false)
             enableVibration(false)
             setSound(null, null)
             setSound(null, null)
-            importance = NotificationManager.IMPORTANCE_LOW
+            lockscreenVisibility = Notification.VISIBILITY_PUBLIC
         }
         }
 
 
         val readAloudChannel = NotificationChannel(
         val readAloudChannel = NotificationChannel(
@@ -153,7 +154,7 @@ class App : Application() {
             enableLights(false)
             enableLights(false)
             enableVibration(false)
             enableVibration(false)
             setSound(null, null)
             setSound(null, null)
-            importance = NotificationManager.IMPORTANCE_LOW
+            lockscreenVisibility = Notification.VISIBILITY_PUBLIC
         }
         }
 
 
         val webChannel = NotificationChannel(
         val webChannel = NotificationChannel(
@@ -164,7 +165,7 @@ class App : Application() {
             enableLights(false)
             enableLights(false)
             enableVibration(false)
             enableVibration(false)
             setSound(null, null)
             setSound(null, null)
-            importance = NotificationManager.IMPORTANCE_LOW
+            lockscreenVisibility = Notification.VISIBILITY_PUBLIC
         }
         }
 
 
         //向notification manager 提交channel
         //向notification manager 提交channel

+ 3 - 1
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) {
         if (!book.isLocal) {
             context.startService<CacheBookService> {
             context.startService<CacheBookService> {
                 action = IntentAction.start
                 action = IntentAction.start
                 putExtra("bookUrl", book.bookUrl)
                 putExtra("bookUrl", book.bookUrl)
                 putExtra("start", start)
                 putExtra("start", start)
                 putExtra("end", end)
                 putExtra("end", end)
+                putExtra("startDownload", startDownload)
             }
             }
         }
         }
     }
     }
@@ -177,6 +178,7 @@ object CacheBook {
                     waitDownloadSet.add(i)
                     waitDownloadSet.add(i)
                 }
                 }
             }
             }
+            cacheBookMap[book.bookUrl] = this
             postEvent(EventBus.UP_DOWNLOAD, book.bookUrl)
             postEvent(EventBus.UP_DOWNLOAD, book.bookUrl)
         }
         }
 
 

+ 3 - 2
app/src/main/java/io/legado/app/service/CacheBookService.kt

@@ -80,7 +80,8 @@ class CacheBookService : BaseService() {
                 IntentAction.start -> addDownloadData(
                 IntentAction.start -> addDownloadData(
                     intent.getStringExtra("bookUrl"),
                     intent.getStringExtra("bookUrl"),
                     intent.getIntExtra("start", 0),
                     intent.getIntExtra("start", 0),
-                    intent.getIntExtra("end", 0)
+                    intent.getIntExtra("end", 0),
+                    intent.getBooleanExtra("startDownload", true)
                 )
                 )
 
 
                 IntentAction.remove -> removeDownload(intent.getStringExtra("bookUrl"))
                 IntentAction.remove -> removeDownload(intent.getStringExtra("bookUrl"))
@@ -98,7 +99,7 @@ class CacheBookService : BaseService() {
         postEvent(EventBus.UP_DOWNLOAD, "")
         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
         bookUrl ?: return
         execute {
         execute {
             val cacheBook = CacheBook.getOrCreate(bookUrl) ?: return@execute
             val cacheBook = CacheBook.getOrCreate(bookUrl) ?: return@execute

+ 4 - 2
app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt

@@ -158,12 +158,14 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
         when (item.itemId) {
         when (item.itemId) {
             R.id.menu_download -> {
             R.id.menu_download -> {
                 if (!CacheBook.isRun) {
                 if (!CacheBook.isRun) {
-                    adapter.getItems().forEach { book ->
+                    val lastIndex = adapter.itemCount - 1
+                    adapter.getItems().forEachIndexed { index, book ->
                         CacheBook.start(
                         CacheBook.start(
                             this@CacheActivity,
                             this@CacheActivity,
                             book,
                             book,
                             book.durChapterIndex,
                             book.durChapterIndex,
-                            book.lastChapterIndex
+                            book.lastChapterIndex,
+                            index == lastIndex
                         )
                         )
                     }
                     }
                 } else {
                 } else {