mirror of
https://github.com/gedoor/legado.git
synced 2024-07-06 23:47:49 +08:00
优化
This commit is contained in:
parent
34f7cb9025
commit
d44d2a3b08
@ -584,7 +584,7 @@ class AudioPlayService : BaseService(),
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createNotification(): NotificationCompat.Builder {
|
private fun createNotification(): NotificationCompat.Builder {
|
||||||
var nTitle: String = when {
|
var nTitle: String = when {
|
||||||
pause -> getString(R.string.audio_pause)
|
pause -> getString(R.string.audio_pause)
|
||||||
timeMinute in 1..60 -> getString(
|
timeMinute in 1..60 -> getString(
|
||||||
@ -642,11 +642,14 @@ class AudioPlayService : BaseService(),
|
|||||||
return builder
|
return builder
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun upAudioPlayNotification() {
|
private fun upAudioPlayNotification() {
|
||||||
execute {
|
execute {
|
||||||
createNotification()
|
try {
|
||||||
}.onSuccess {
|
val notification = createNotification()
|
||||||
notificationManager.notify(NotificationId.AudioPlayService, it.build())
|
notificationManager.notify(NotificationId.AudioPlayService, notification.build())
|
||||||
|
} catch (e: Exception) {
|
||||||
|
AppLog.put("创建音频播放通知出错,${e.localizedMessage}", e, true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -655,9 +658,14 @@ class AudioPlayService : BaseService(),
|
|||||||
*/
|
*/
|
||||||
override fun startForegroundNotification() {
|
override fun startForegroundNotification() {
|
||||||
execute {
|
execute {
|
||||||
createNotification()
|
try {
|
||||||
}.onSuccess {
|
val notification = createNotification()
|
||||||
startForeground(NotificationId.AudioPlayService, it.build())
|
startForeground(NotificationId.AudioPlayService, notification.build())
|
||||||
|
} catch (e: Exception) {
|
||||||
|
AppLog.put("创建音频播放通知出错,${e.localizedMessage}", e, true)
|
||||||
|
//创建通知出错不结束服务就会崩溃,服务必须绑定通知
|
||||||
|
stopSelf()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -471,11 +471,12 @@ abstract class BaseReadAloudService : BaseService(),
|
|||||||
|
|
||||||
private fun upReadAloudNotification() {
|
private fun upReadAloudNotification() {
|
||||||
execute {
|
execute {
|
||||||
createNotification()
|
try {
|
||||||
}.onSuccess {
|
val notification = createNotification()
|
||||||
notificationManager.notify(NotificationId.ReadAloudService, it.build())
|
notificationManager.notify(NotificationId.ReadAloudService, notification.build())
|
||||||
}.onError {
|
} catch (e: Exception) {
|
||||||
AppLog.put("创建朗读通知出错,${it.localizedMessage}", it, true)
|
AppLog.put("创建朗读通知出错,${e.localizedMessage}", e, true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -542,13 +543,14 @@ abstract class BaseReadAloudService : BaseService(),
|
|||||||
*/
|
*/
|
||||||
override fun startForegroundNotification() {
|
override fun startForegroundNotification() {
|
||||||
execute {
|
execute {
|
||||||
createNotification()
|
try {
|
||||||
}.onSuccess {
|
val notification = createNotification()
|
||||||
startForeground(NotificationId.ReadAloudService, it.build())
|
startForeground(NotificationId.ReadAloudService, notification.build())
|
||||||
}.onError {
|
} catch (e: Exception) {
|
||||||
AppLog.put("创建朗读通知出错,${it.localizedMessage}", it, true)
|
AppLog.put("创建朗读通知出错,${e.localizedMessage}", e, true)
|
||||||
//创建通知出错不结束服务就会崩溃,服务必须绑定通知
|
//创建通知出错不结束服务就会崩溃,服务必须绑定通知
|
||||||
stopSelf()
|
stopSelf()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user