pull/1744/head
kunfei 3 years ago
parent ac3d79fcd4
commit 503d03f609
  1. 15
      app/src/main/java/io/legado/app/service/AudioPlayService.kt
  2. 15
      app/src/main/java/io/legado/app/service/BaseReadAloudService.kt

@ -445,6 +445,7 @@ class AudioPlayService : BaseService(),
* 更新通知
*/
private fun upNotification() {
execute {
var nTitle: String = when {
pause -> getString(R.string.audio_pause)
timeMinute in 1..60 -> getString(
@ -458,7 +459,8 @@ class AudioPlayService : BaseService(),
if (subtitle.isEmpty()) {
nSubtitle = getString(R.string.audio_play_s)
}
val builder = NotificationCompat.Builder(this, AppConst.channelIdReadAloud)
val builder = NotificationCompat
.Builder(this@AudioPlayService, AppConst.channelIdReadAloud)
.setSmallIcon(R.drawable.ic_volume_up)
.setOngoing(true)
.setContentTitle(nTitle)
@ -467,7 +469,10 @@ class AudioPlayService : BaseService(),
activityPendingIntent<AudioPlayActivity>("activity")
)
kotlin.runCatching {
ImageLoader.loadBitmap(this, AudioPlay.book?.getDisplayCover()).submit().get()
ImageLoader
.loadBitmap(this@AudioPlayService, AudioPlay.book?.getDisplayCover())
.submit()
.get()
}.getOrElse {
BitmapFactory.decodeResource(resources, R.drawable.icon_read_book)
}.let {
@ -501,8 +506,10 @@ class AudioPlayService : BaseService(),
.setShowActionsInCompactView(0, 1, 2)
)
builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
val notification = builder.build()
startForeground(AppConst.notificationIdAudio, notification)
builder
}.onSuccess {
startForeground(AppConst.notificationIdAudio, it.build())
}
}
/**

@ -301,6 +301,7 @@ abstract class BaseReadAloudService : BaseService(),
* 更新通知
*/
private fun upNotification() {
execute {
var nTitle: String = when {
pause -> getString(R.string.read_aloud_pause)
timeMinute > 0 -> getString(
@ -313,7 +314,8 @@ abstract class BaseReadAloudService : BaseService(),
var nSubtitle = ReadBook.curTextChapter?.title
if (nSubtitle.isNullOrBlank())
nSubtitle = getString(R.string.read_aloud_s)
val builder = NotificationCompat.Builder(this, AppConst.channelIdReadAloud)
val builder = NotificationCompat
.Builder(this@BaseReadAloudService, AppConst.channelIdReadAloud)
.setSmallIcon(R.drawable.ic_volume_up)
.setOngoing(true)
.setContentTitle(nTitle)
@ -322,7 +324,10 @@ abstract class BaseReadAloudService : BaseService(),
activityPendingIntent<ReadBookActivity>("activity")
)
kotlin.runCatching {
ImageLoader.loadBitmap(this, ReadBook.book?.getDisplayCover()).submit().get()
ImageLoader
.loadBitmap(this@BaseReadAloudService, ReadBook.book?.getDisplayCover())
.submit()
.get()
}.getOrElse {
BitmapFactory.decodeResource(resources, R.drawable.icon_read_book)
}.let {
@ -356,8 +361,10 @@ abstract class BaseReadAloudService : BaseService(),
.setShowActionsInCompactView(0, 1, 2)
)
builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
val notification = builder.build()
startForeground(AppConst.notificationIdRead, notification)
builder
}.onSuccess {
startForeground(AppConst.notificationIdRead, it.build())
}
}
abstract fun aloudServicePendingIntent(actionStr: String): PendingIntent?

Loading…
Cancel
Save