mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
This commit is contained in:
@@ -46,14 +46,6 @@ object AppConst {
|
||||
const val bookGroupLocalNoneId = -5L
|
||||
const val bookGroupErrorId = -11L
|
||||
|
||||
const val notificationIdRead = -1122391
|
||||
const val notificationIdAudio = -1122392
|
||||
const val notificationIdCache = -1122393
|
||||
const val notificationIdExport = -1122394
|
||||
const val notificationIdWeb = -1122395
|
||||
const val notificationIdDownload = -1122396
|
||||
const val notificationIdCheckSource = -1122397
|
||||
|
||||
const val imagePathKey = "imagePath"
|
||||
|
||||
val menuViewNames = arrayOf(
|
||||
|
||||
18
app/src/main/java/io/legado/app/constant/NotificationId.kt
Normal file
18
app/src/main/java/io/legado/app/constant/NotificationId.kt
Normal file
@@ -0,0 +1,18 @@
|
||||
package io.legado.app.constant
|
||||
|
||||
/**
|
||||
* 通知ID不能重复,统一规划通知ID
|
||||
*/
|
||||
object NotificationId {
|
||||
|
||||
const val ReadAloudService = 101
|
||||
const val AudioPlayService = 102
|
||||
const val CacheBookService = 103
|
||||
const val ExportBookService = 104
|
||||
const val WebService = 105
|
||||
const val DownloadService = 106
|
||||
const val CheckSourceService = 107
|
||||
const val Download = 10000
|
||||
const val ExportBook = 201
|
||||
|
||||
}
|
||||
@@ -614,7 +614,7 @@ class AudioPlayService : BaseService(),
|
||||
builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
||||
builder
|
||||
}.onSuccess {
|
||||
startForeground(AppConst.notificationIdAudio, it.build())
|
||||
startForeground(NotificationId.AudioPlayService, it.build())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -429,7 +429,7 @@ abstract class BaseReadAloudService : BaseService(),
|
||||
builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
||||
builder
|
||||
}.onSuccess {
|
||||
startForeground(AppConst.notificationIdRead, it.build())
|
||||
startForeground(NotificationId.ReadAloudService, it.build())
|
||||
}.onError {
|
||||
AppLog.put("创建朗读通知出错,${it.localizedMessage}", it, true)
|
||||
//创建通知出错不结束服务就会崩溃,服务必须绑定通知
|
||||
|
||||
@@ -8,6 +8,7 @@ import io.legado.app.constant.AppConst
|
||||
import io.legado.app.constant.AppLog
|
||||
import io.legado.app.constant.EventBus
|
||||
import io.legado.app.constant.IntentAction
|
||||
import io.legado.app.constant.NotificationId
|
||||
import io.legado.app.data.appDb
|
||||
import io.legado.app.help.config.AppConfig
|
||||
import io.legado.app.model.CacheBook
|
||||
@@ -167,7 +168,7 @@ class CacheBookService : BaseService() {
|
||||
override fun upNotification() {
|
||||
notificationBuilder.setContentText(notificationContent)
|
||||
val notification = notificationBuilder.build()
|
||||
startForeground(AppConst.notificationIdCache, notification)
|
||||
startForeground(NotificationId.CacheBookService, notification)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import io.legado.app.constant.AppConst
|
||||
import io.legado.app.constant.BookSourceType
|
||||
import io.legado.app.constant.EventBus
|
||||
import io.legado.app.constant.IntentAction
|
||||
import io.legado.app.constant.NotificationId
|
||||
import io.legado.app.data.appDb
|
||||
import io.legado.app.data.entities.Book
|
||||
import io.legado.app.data.entities.BookSource
|
||||
@@ -264,7 +265,7 @@ class CheckSourceService : BaseService() {
|
||||
notificationBuilder.setContentText(notificationMsg)
|
||||
notificationBuilder.setProgress(allIds.size, checkedIds.size, false)
|
||||
postEvent(EventBus.CHECK_SOURCE, notificationMsg)
|
||||
startForeground(AppConst.notificationIdCheckSource, notificationBuilder.build())
|
||||
startForeground(NotificationId.CheckSourceService, notificationBuilder.build())
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import io.legado.app.base.BaseService
|
||||
import io.legado.app.constant.AppConst
|
||||
import io.legado.app.constant.AppLog
|
||||
import io.legado.app.constant.IntentAction
|
||||
import io.legado.app.constant.NotificationId
|
||||
import io.legado.app.utils.IntentType
|
||||
import io.legado.app.utils.openFileUri
|
||||
import io.legado.app.utils.servicePendingIntent
|
||||
@@ -102,7 +103,8 @@ class DownloadService : BaseService() {
|
||||
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName)
|
||||
// 添加一个下载任务
|
||||
val downloadId = downloadManager.enqueue(request)
|
||||
downloads[downloadId] = DownloadInfo(url, fileName, downloads.size + 1)
|
||||
downloads[downloadId] =
|
||||
DownloadInfo(url, fileName, NotificationId.Download + downloads.size)
|
||||
queryState()
|
||||
if (upStateJob == null) {
|
||||
checkDownloadState()
|
||||
@@ -224,7 +226,7 @@ class DownloadService : BaseService() {
|
||||
.setGroupSummary(true)
|
||||
.setOngoing(true)
|
||||
.build()
|
||||
startForeground(AppConst.notificationIdDownload, notification)
|
||||
startForeground(NotificationId.DownloadService, notification)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,6 +19,7 @@ import io.legado.app.constant.AppLog
|
||||
import io.legado.app.constant.AppPattern
|
||||
import io.legado.app.constant.EventBus
|
||||
import io.legado.app.constant.IntentAction
|
||||
import io.legado.app.constant.NotificationId
|
||||
import io.legado.app.data.appDb
|
||||
import io.legado.app.data.entities.Book
|
||||
import io.legado.app.data.entities.BookChapter
|
||||
@@ -132,7 +133,7 @@ class ExportBookService : BaseService() {
|
||||
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
||||
.setGroup(groupKey)
|
||||
.setGroupSummary(true)
|
||||
startForeground(AppConst.notificationIdExport, notification.build())
|
||||
startForeground(NotificationId.ExportBookService, notification.build())
|
||||
}
|
||||
|
||||
private fun upExportNotification() {
|
||||
@@ -152,7 +153,7 @@ class ExportBookService : BaseService() {
|
||||
servicePendingIntent<ExportBookService>(IntentAction.stop)
|
||||
)
|
||||
}
|
||||
notificationManager.notify(AppConst.notificationIdExport + 100, notification.build())
|
||||
notificationManager.notify(NotificationId.ExportBook, notification.build())
|
||||
}
|
||||
|
||||
private fun export() {
|
||||
|
||||
@@ -11,6 +11,7 @@ import io.legado.app.base.BaseService
|
||||
import io.legado.app.constant.AppConst
|
||||
import io.legado.app.constant.EventBus
|
||||
import io.legado.app.constant.IntentAction
|
||||
import io.legado.app.constant.NotificationId
|
||||
import io.legado.app.constant.PreferKey
|
||||
import io.legado.app.receiver.NetworkChangedListener
|
||||
import io.legado.app.utils.*
|
||||
@@ -159,7 +160,7 @@ class WebService : BaseService() {
|
||||
)
|
||||
builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
||||
val notification = builder.build()
|
||||
startForeground(AppConst.notificationIdWeb, notification)
|
||||
startForeground(NotificationId.WebService, notification)
|
||||
}
|
||||
|
||||
@SuppressLint("ObsoleteSdkInt")
|
||||
|
||||
Reference in New Issue
Block a user