This commit is contained in:
Horis 2024-02-29 20:23:57 +08:00
parent 9755547294
commit a3c3c84ee8
4 changed files with 14 additions and 8 deletions

View File

@ -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

View File

@ -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<CacheBookService> {
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)
}

View File

@ -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

View File

@ -158,12 +158,14 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
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 {