优化
This commit is contained in:
@@ -445,64 +445,71 @@ class AudioPlayService : BaseService(),
|
|||||||
* 更新通知
|
* 更新通知
|
||||||
*/
|
*/
|
||||||
private fun upNotification() {
|
private fun upNotification() {
|
||||||
var nTitle: String = when {
|
execute {
|
||||||
pause -> getString(R.string.audio_pause)
|
var nTitle: String = when {
|
||||||
timeMinute in 1..60 -> getString(
|
pause -> getString(R.string.audio_pause)
|
||||||
R.string.playing_timer,
|
timeMinute in 1..60 -> getString(
|
||||||
timeMinute
|
R.string.playing_timer,
|
||||||
)
|
timeMinute
|
||||||
else -> getString(R.string.audio_play_t)
|
)
|
||||||
}
|
else -> getString(R.string.audio_play_t)
|
||||||
nTitle += ": $title"
|
}
|
||||||
var nSubtitle = subtitle
|
nTitle += ": $title"
|
||||||
if (subtitle.isEmpty()) {
|
var nSubtitle = subtitle
|
||||||
nSubtitle = getString(R.string.audio_play_s)
|
if (subtitle.isEmpty()) {
|
||||||
}
|
nSubtitle = getString(R.string.audio_play_s)
|
||||||
val builder = NotificationCompat.Builder(this, AppConst.channelIdReadAloud)
|
}
|
||||||
.setSmallIcon(R.drawable.ic_volume_up)
|
val builder = NotificationCompat
|
||||||
.setOngoing(true)
|
.Builder(this@AudioPlayService, AppConst.channelIdReadAloud)
|
||||||
.setContentTitle(nTitle)
|
.setSmallIcon(R.drawable.ic_volume_up)
|
||||||
.setContentText(nSubtitle)
|
.setOngoing(true)
|
||||||
.setContentIntent(
|
.setContentTitle(nTitle)
|
||||||
activityPendingIntent<AudioPlayActivity>("activity")
|
.setContentText(nSubtitle)
|
||||||
)
|
.setContentIntent(
|
||||||
kotlin.runCatching {
|
activityPendingIntent<AudioPlayActivity>("activity")
|
||||||
ImageLoader.loadBitmap(this, AudioPlay.book?.getDisplayCover()).submit().get()
|
)
|
||||||
}.getOrElse {
|
kotlin.runCatching {
|
||||||
BitmapFactory.decodeResource(resources, R.drawable.icon_read_book)
|
ImageLoader
|
||||||
}.let {
|
.loadBitmap(this@AudioPlayService, AudioPlay.book?.getDisplayCover())
|
||||||
builder.setLargeIcon(it)
|
.submit()
|
||||||
}
|
.get()
|
||||||
if (pause) {
|
}.getOrElse {
|
||||||
|
BitmapFactory.decodeResource(resources, R.drawable.icon_read_book)
|
||||||
|
}.let {
|
||||||
|
builder.setLargeIcon(it)
|
||||||
|
}
|
||||||
|
if (pause) {
|
||||||
|
builder.addAction(
|
||||||
|
R.drawable.ic_play_24dp,
|
||||||
|
getString(R.string.resume),
|
||||||
|
servicePendingIntent<AudioPlayService>(IntentAction.resume)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
builder.addAction(
|
||||||
|
R.drawable.ic_pause_24dp,
|
||||||
|
getString(R.string.pause),
|
||||||
|
servicePendingIntent<AudioPlayService>(IntentAction.pause)
|
||||||
|
)
|
||||||
|
}
|
||||||
builder.addAction(
|
builder.addAction(
|
||||||
R.drawable.ic_play_24dp,
|
R.drawable.ic_stop_black_24dp,
|
||||||
getString(R.string.resume),
|
getString(R.string.stop),
|
||||||
servicePendingIntent<AudioPlayService>(IntentAction.resume)
|
servicePendingIntent<AudioPlayService>(IntentAction.stop)
|
||||||
)
|
)
|
||||||
} else {
|
|
||||||
builder.addAction(
|
builder.addAction(
|
||||||
R.drawable.ic_pause_24dp,
|
R.drawable.ic_time_add_24dp,
|
||||||
getString(R.string.pause),
|
getString(R.string.set_timer),
|
||||||
servicePendingIntent<AudioPlayService>(IntentAction.pause)
|
servicePendingIntent<AudioPlayService>(IntentAction.addTimer)
|
||||||
)
|
)
|
||||||
|
builder.setStyle(
|
||||||
|
androidx.media.app.NotificationCompat.MediaStyle()
|
||||||
|
.setShowActionsInCompactView(0, 1, 2)
|
||||||
|
)
|
||||||
|
builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
||||||
|
builder
|
||||||
|
}.onSuccess {
|
||||||
|
startForeground(AppConst.notificationIdAudio, it.build())
|
||||||
}
|
}
|
||||||
builder.addAction(
|
|
||||||
R.drawable.ic_stop_black_24dp,
|
|
||||||
getString(R.string.stop),
|
|
||||||
servicePendingIntent<AudioPlayService>(IntentAction.stop)
|
|
||||||
)
|
|
||||||
builder.addAction(
|
|
||||||
R.drawable.ic_time_add_24dp,
|
|
||||||
getString(R.string.set_timer),
|
|
||||||
servicePendingIntent<AudioPlayService>(IntentAction.addTimer)
|
|
||||||
)
|
|
||||||
builder.setStyle(
|
|
||||||
androidx.media.app.NotificationCompat.MediaStyle()
|
|
||||||
.setShowActionsInCompactView(0, 1, 2)
|
|
||||||
)
|
|
||||||
builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
|
||||||
val notification = builder.build()
|
|
||||||
startForeground(AppConst.notificationIdAudio, notification)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -301,63 +301,70 @@ abstract class BaseReadAloudService : BaseService(),
|
|||||||
* 更新通知
|
* 更新通知
|
||||||
*/
|
*/
|
||||||
private fun upNotification() {
|
private fun upNotification() {
|
||||||
var nTitle: String = when {
|
execute {
|
||||||
pause -> getString(R.string.read_aloud_pause)
|
var nTitle: String = when {
|
||||||
timeMinute > 0 -> getString(
|
pause -> getString(R.string.read_aloud_pause)
|
||||||
R.string.read_aloud_timer,
|
timeMinute > 0 -> getString(
|
||||||
timeMinute
|
R.string.read_aloud_timer,
|
||||||
)
|
timeMinute
|
||||||
else -> getString(R.string.read_aloud_t)
|
)
|
||||||
}
|
else -> getString(R.string.read_aloud_t)
|
||||||
nTitle += ": ${ReadBook.book?.name}"
|
}
|
||||||
var nSubtitle = ReadBook.curTextChapter?.title
|
nTitle += ": ${ReadBook.book?.name}"
|
||||||
if (nSubtitle.isNullOrBlank())
|
var nSubtitle = ReadBook.curTextChapter?.title
|
||||||
nSubtitle = getString(R.string.read_aloud_s)
|
if (nSubtitle.isNullOrBlank())
|
||||||
val builder = NotificationCompat.Builder(this, AppConst.channelIdReadAloud)
|
nSubtitle = getString(R.string.read_aloud_s)
|
||||||
.setSmallIcon(R.drawable.ic_volume_up)
|
val builder = NotificationCompat
|
||||||
.setOngoing(true)
|
.Builder(this@BaseReadAloudService, AppConst.channelIdReadAloud)
|
||||||
.setContentTitle(nTitle)
|
.setSmallIcon(R.drawable.ic_volume_up)
|
||||||
.setContentText(nSubtitle)
|
.setOngoing(true)
|
||||||
.setContentIntent(
|
.setContentTitle(nTitle)
|
||||||
activityPendingIntent<ReadBookActivity>("activity")
|
.setContentText(nSubtitle)
|
||||||
)
|
.setContentIntent(
|
||||||
kotlin.runCatching {
|
activityPendingIntent<ReadBookActivity>("activity")
|
||||||
ImageLoader.loadBitmap(this, ReadBook.book?.getDisplayCover()).submit().get()
|
)
|
||||||
}.getOrElse {
|
kotlin.runCatching {
|
||||||
BitmapFactory.decodeResource(resources, R.drawable.icon_read_book)
|
ImageLoader
|
||||||
}.let {
|
.loadBitmap(this@BaseReadAloudService, ReadBook.book?.getDisplayCover())
|
||||||
builder.setLargeIcon(it)
|
.submit()
|
||||||
}
|
.get()
|
||||||
if (pause) {
|
}.getOrElse {
|
||||||
|
BitmapFactory.decodeResource(resources, R.drawable.icon_read_book)
|
||||||
|
}.let {
|
||||||
|
builder.setLargeIcon(it)
|
||||||
|
}
|
||||||
|
if (pause) {
|
||||||
|
builder.addAction(
|
||||||
|
R.drawable.ic_play_24dp,
|
||||||
|
getString(R.string.resume),
|
||||||
|
aloudServicePendingIntent(IntentAction.resume)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
builder.addAction(
|
||||||
|
R.drawable.ic_pause_24dp,
|
||||||
|
getString(R.string.pause),
|
||||||
|
aloudServicePendingIntent(IntentAction.pause)
|
||||||
|
)
|
||||||
|
}
|
||||||
builder.addAction(
|
builder.addAction(
|
||||||
R.drawable.ic_play_24dp,
|
R.drawable.ic_stop_black_24dp,
|
||||||
getString(R.string.resume),
|
getString(R.string.stop),
|
||||||
aloudServicePendingIntent(IntentAction.resume)
|
aloudServicePendingIntent(IntentAction.stop)
|
||||||
)
|
)
|
||||||
} else {
|
|
||||||
builder.addAction(
|
builder.addAction(
|
||||||
R.drawable.ic_pause_24dp,
|
R.drawable.ic_time_add_24dp,
|
||||||
getString(R.string.pause),
|
getString(R.string.set_timer),
|
||||||
aloudServicePendingIntent(IntentAction.pause)
|
aloudServicePendingIntent(IntentAction.addTimer)
|
||||||
)
|
)
|
||||||
|
builder.setStyle(
|
||||||
|
androidx.media.app.NotificationCompat.MediaStyle()
|
||||||
|
.setShowActionsInCompactView(0, 1, 2)
|
||||||
|
)
|
||||||
|
builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
||||||
|
builder
|
||||||
|
}.onSuccess {
|
||||||
|
startForeground(AppConst.notificationIdRead, it.build())
|
||||||
}
|
}
|
||||||
builder.addAction(
|
|
||||||
R.drawable.ic_stop_black_24dp,
|
|
||||||
getString(R.string.stop),
|
|
||||||
aloudServicePendingIntent(IntentAction.stop)
|
|
||||||
)
|
|
||||||
builder.addAction(
|
|
||||||
R.drawable.ic_time_add_24dp,
|
|
||||||
getString(R.string.set_timer),
|
|
||||||
aloudServicePendingIntent(IntentAction.addTimer)
|
|
||||||
)
|
|
||||||
builder.setStyle(
|
|
||||||
androidx.media.app.NotificationCompat.MediaStyle()
|
|
||||||
.setShowActionsInCompactView(0, 1, 2)
|
|
||||||
)
|
|
||||||
builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
|
||||||
val notification = builder.build()
|
|
||||||
startForeground(AppConst.notificationIdRead, notification)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract fun aloudServicePendingIntent(actionStr: String): PendingIntent?
|
abstract fun aloudServicePendingIntent(actionStr: String): PendingIntent?
|
||||||
|
|||||||
Reference in New Issue
Block a user