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

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

Loading…
Cancel
Save