|
|
@ -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? |
|
|
|