Fixed Classic Notification crash
This commit is contained in:
parent
802cab7818
commit
fe1a5c8ab0
4 changed files with 48 additions and 56 deletions
|
@ -68,8 +68,8 @@ import code.name.monkey.retromusic.providers.MusicPlaybackQueueStore
|
||||||
import code.name.monkey.retromusic.providers.SongPlayCountStore
|
import code.name.monkey.retromusic.providers.SongPlayCountStore
|
||||||
import code.name.monkey.retromusic.service.AudioFader.Companion.startFadeAnimator
|
import code.name.monkey.retromusic.service.AudioFader.Companion.startFadeAnimator
|
||||||
import code.name.monkey.retromusic.service.notification.PlayingNotification
|
import code.name.monkey.retromusic.service.notification.PlayingNotification
|
||||||
import code.name.monkey.retromusic.service.notification.PlayingNotificationClassic.Companion.from
|
import code.name.monkey.retromusic.service.notification.PlayingNotificationClassic
|
||||||
import code.name.monkey.retromusic.service.notification.PlayingNotificationImpl24.Companion.from
|
import code.name.monkey.retromusic.service.notification.PlayingNotificationImpl24
|
||||||
import code.name.monkey.retromusic.service.playback.Playback
|
import code.name.monkey.retromusic.service.playback.Playback
|
||||||
import code.name.monkey.retromusic.service.playback.Playback.PlaybackCallbacks
|
import code.name.monkey.retromusic.service.playback.Playback.PlaybackCallbacks
|
||||||
import code.name.monkey.retromusic.util.MusicUtil.getMediaStoreAlbumCoverUri
|
import code.name.monkey.retromusic.util.MusicUtil.getMediaStoreAlbumCoverUri
|
||||||
|
@ -194,10 +194,10 @@ class MusicService : MediaBrowserServiceCompat(),
|
||||||
playerHandler?.obtainMessage(FOCUS_CHANGE, focusChange, 0)?.sendToTarget()
|
playerHandler?.obtainMessage(FOCUS_CHANGE, focusChange, 0)?.sendToTarget()
|
||||||
}
|
}
|
||||||
private var playingNotification: PlayingNotification? = null
|
private var playingNotification: PlayingNotification? = null
|
||||||
|
|
||||||
private val updateFavoriteReceiver: BroadcastReceiver = object : BroadcastReceiver() {
|
private val updateFavoriteReceiver: BroadcastReceiver = object : BroadcastReceiver() {
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
playingNotification?.updateFavorite(currentSong) { startForegroundOrNotify() }
|
playingNotification?.updateFavorite(currentSong) { startForegroundOrNotify() }
|
||||||
startForegroundOrNotify()
|
|
||||||
appWidgetCircle.notifyChange(this@MusicService, FAVORITE_STATE_CHANGED)
|
appWidgetCircle.notifyChange(this@MusicService, FAVORITE_STATE_CHANGED)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -594,9 +594,9 @@ class MusicService : MediaBrowserServiceCompat(),
|
||||||
playingNotification = if (VERSION.SDK_INT >= VERSION_CODES.N
|
playingNotification = if (VERSION.SDK_INT >= VERSION_CODES.N
|
||||||
&& !isClassicNotification
|
&& !isClassicNotification
|
||||||
) {
|
) {
|
||||||
from(this, notificationManager!!, mediaSession!!)
|
PlayingNotificationImpl24.from(this, notificationManager!!, mediaSession!!)
|
||||||
} else {
|
} else {
|
||||||
from(this, notificationManager!!)
|
PlayingNotificationClassic.from(this, notificationManager!!)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -732,11 +732,18 @@ class MusicService : MediaBrowserServiceCompat(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ALBUM_ART_ON_LOCK_SCREEN, BLURRED_ALBUM_ART -> updateMediaSessionMetaData()
|
ALBUM_ART_ON_LOCK_SCREEN, BLURRED_ALBUM_ART -> updateMediaSessionMetaData()
|
||||||
COLORED_NOTIFICATION -> updateNotification()
|
COLORED_NOTIFICATION -> {
|
||||||
|
playingNotification?.updateMetadata(currentSong) {
|
||||||
|
playingNotification?.setPlaying(isPlaying)
|
||||||
|
startForegroundOrNotify()
|
||||||
|
}
|
||||||
|
}
|
||||||
CLASSIC_NOTIFICATION -> {
|
CLASSIC_NOTIFICATION -> {
|
||||||
updateNotification()
|
updateNotification()
|
||||||
playingNotification?.setPlaying(isPlaying) { startForegroundOrNotify() }
|
playingNotification?.updateMetadata(currentSong) {
|
||||||
playingNotification?.updateMetadata(currentSong) { startForegroundOrNotify() }
|
playingNotification?.setPlaying(isPlaying)
|
||||||
|
startForegroundOrNotify()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
PLAYBACK_SPEED -> updateMediaSessionPlaybackState()
|
PLAYBACK_SPEED -> updateMediaSessionPlaybackState()
|
||||||
TOGGLE_HEADSET -> registerHeadsetEvents()
|
TOGGLE_HEADSET -> registerHeadsetEvents()
|
||||||
|
@ -1195,12 +1202,14 @@ class MusicService : MediaBrowserServiceCompat(),
|
||||||
savePositionInTrack()
|
savePositionInTrack()
|
||||||
}
|
}
|
||||||
songPlayCountHelper.notifyPlayStateChanged(isPlaying)
|
songPlayCountHelper.notifyPlayStateChanged(isPlaying)
|
||||||
playingNotification?.setPlaying(isPlaying) { startForegroundOrNotify() }
|
playingNotification?.setPlaying(isPlaying)
|
||||||
startForegroundOrNotify()
|
startForegroundOrNotify()
|
||||||
}
|
}
|
||||||
FAVORITE_STATE_CHANGED -> {
|
FAVORITE_STATE_CHANGED -> {
|
||||||
playingNotification?.updateFavorite(currentSong) { startForegroundOrNotify() }
|
playingNotification?.updateFavorite(currentSong) {
|
||||||
playingNotification?.updateMetadata(currentSong) { startForegroundOrNotify() }
|
startForegroundOrNotify()
|
||||||
|
}
|
||||||
|
|
||||||
updateMediaSessionMetaData()
|
updateMediaSessionMetaData()
|
||||||
updateMediaSessionPlaybackState()
|
updateMediaSessionPlaybackState()
|
||||||
savePosition()
|
savePosition()
|
||||||
|
|
|
@ -29,7 +29,7 @@ abstract class PlayingNotification(context: Context) :
|
||||||
|
|
||||||
abstract fun updateMetadata(song: Song, onUpdate: () -> Unit)
|
abstract fun updateMetadata(song: Song, onUpdate: () -> Unit)
|
||||||
|
|
||||||
abstract fun setPlaying(isPlaying: Boolean, onUpdate: () -> Unit)
|
abstract fun setPlaying(isPlaying: Boolean)
|
||||||
|
|
||||||
abstract fun updateFavorite(song: Song, onUpdate: () -> Unit)
|
abstract fun updateFavorite(song: Song, onUpdate: () -> Unit)
|
||||||
|
|
||||||
|
|
|
@ -56,13 +56,28 @@ import com.bumptech.glide.request.transition.Transition
|
||||||
class PlayingNotificationClassic(
|
class PlayingNotificationClassic(
|
||||||
val context: Context
|
val context: Context
|
||||||
) : PlayingNotification(context) {
|
) : PlayingNotification(context) {
|
||||||
|
|
||||||
private var primaryColor: Int = 0
|
private var primaryColor: Int = 0
|
||||||
private var isInitialized = false
|
private var isInitialized = false
|
||||||
|
|
||||||
init {
|
private fun getCombinedRemoteViews(collapsed: Boolean, song: Song): RemoteViews {
|
||||||
val notificationLayout = getCombinedRemoteViews(true)
|
val remoteViews = RemoteViews(
|
||||||
val notificationLayoutBig = getCombinedRemoteViews(false)
|
context.packageName,
|
||||||
|
if (collapsed) R.layout.layout_notification_collapsed else R.layout.layout_notification_expanded
|
||||||
|
)
|
||||||
|
remoteViews.setTextViewText(
|
||||||
|
R.id.appName,
|
||||||
|
context.getString(R.string.app_name) + " • " + song.albumName
|
||||||
|
)
|
||||||
|
remoteViews.setTextViewText(R.id.title, song.title)
|
||||||
|
remoteViews.setTextViewText(R.id.subtitle, song.artistName)
|
||||||
|
linkButtons(remoteViews)
|
||||||
|
return remoteViews
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun updateMetadata(song: Song, onUpdate: () -> Unit) {
|
||||||
|
isInitialized = true
|
||||||
|
val notificationLayout = getCombinedRemoteViews(true, song)
|
||||||
|
val notificationLayoutBig = getCombinedRemoteViews(false, song)
|
||||||
|
|
||||||
val action = Intent(context, MainActivity::class.java)
|
val action = Intent(context, MainActivity::class.java)
|
||||||
action.putExtra(MainActivity.EXPAND_PANEL, PreferenceUtil.isExpandPanel)
|
action.putExtra(MainActivity.EXPAND_PANEL, PreferenceUtil.isExpandPanel)
|
||||||
|
@ -83,25 +98,12 @@ class PlayingNotificationClassic(
|
||||||
setContentIntent(clickIntent)
|
setContentIntent(clickIntent)
|
||||||
setDeleteIntent(deleteIntent)
|
setDeleteIntent(deleteIntent)
|
||||||
setCategory(NotificationCompat.CATEGORY_SERVICE)
|
setCategory(NotificationCompat.CATEGORY_SERVICE)
|
||||||
setColorized(true)
|
setColorized(PreferenceUtil.isColoredNotification)
|
||||||
priority = NotificationCompat.PRIORITY_MAX
|
priority = NotificationCompat.PRIORITY_MAX
|
||||||
setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
||||||
setCustomContentView(notificationLayout)
|
setCustomContentView(notificationLayout)
|
||||||
setCustomBigContentView(notificationLayoutBig)
|
setCustomBigContentView(notificationLayoutBig)
|
||||||
setOngoing(true)
|
setOngoing(true)
|
||||||
}
|
|
||||||
|
|
||||||
private fun getCombinedRemoteViews(collapsed: Boolean): RemoteViews {
|
|
||||||
val remoteViews = RemoteViews(
|
|
||||||
context.packageName,
|
|
||||||
if (collapsed) R.layout.layout_notification_collapsed else R.layout.layout_notification_expanded
|
|
||||||
)
|
|
||||||
linkButtons(remoteViews)
|
|
||||||
return remoteViews
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun updateMetadata(song: Song, onUpdate: () -> Unit) {
|
|
||||||
isInitialized = true
|
|
||||||
val bigNotificationImageSize = context.resources
|
val bigNotificationImageSize = context.resources
|
||||||
.getDimensionPixelSize(R.dimen.notification_big_image_size)
|
.getDimensionPixelSize(R.dimen.notification_big_image_size)
|
||||||
GlideApp.with(context).asBitmapPalette().songCoverOptions(song)
|
GlideApp.with(context).asBitmapPalette().songCoverOptions(song)
|
||||||
|
@ -128,6 +130,10 @@ class PlayingNotificationClassic(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onLoadCleared(placeholder: Drawable?) {
|
override fun onLoadCleared(placeholder: Drawable?) {
|
||||||
|
update(
|
||||||
|
null,
|
||||||
|
resolveColor(context, R.attr.colorSurface, Color.WHITE)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun update(bitmap: Bitmap?, bgColor: Int) {
|
private fun update(bitmap: Bitmap?, bgColor: Int) {
|
||||||
|
@ -208,14 +214,6 @@ class PlayingNotificationClassic(
|
||||||
contentView.setImageViewBitmap(R.id.action_next, next)
|
contentView.setImageViewBitmap(R.id.action_next, next)
|
||||||
contentView.setImageViewBitmap(R.id.action_play_pause, playPause)
|
contentView.setImageViewBitmap(R.id.action_play_pause, playPause)
|
||||||
|
|
||||||
contentView.setTextViewText(
|
|
||||||
R.id.appName,
|
|
||||||
context.getString(R.string.app_name) + " • " + song.albumName
|
|
||||||
)
|
|
||||||
contentView.setTextViewText(R.id.title, song.title)
|
|
||||||
contentView.setTextViewText(R.id.subtitle, song.artistName)
|
|
||||||
|
|
||||||
|
|
||||||
bigContentView.setTextColor(R.id.title, primary)
|
bigContentView.setTextColor(R.id.title, primary)
|
||||||
bigContentView.setTextColor(R.id.subtitle, secondary)
|
bigContentView.setTextColor(R.id.subtitle, secondary)
|
||||||
bigContentView.setTextColor(R.id.appName, secondary)
|
bigContentView.setTextColor(R.id.appName, secondary)
|
||||||
|
@ -225,14 +223,6 @@ class PlayingNotificationClassic(
|
||||||
bigContentView.setImageViewBitmap(R.id.action_next, next)
|
bigContentView.setImageViewBitmap(R.id.action_next, next)
|
||||||
bigContentView.setImageViewBitmap(R.id.action_play_pause, playPause)
|
bigContentView.setImageViewBitmap(R.id.action_play_pause, playPause)
|
||||||
|
|
||||||
bigContentView.setTextViewText(
|
|
||||||
R.id.appName,
|
|
||||||
context.getString(R.string.app_name) + " • " + song.albumName
|
|
||||||
)
|
|
||||||
bigContentView.setTextViewText(R.id.title, song.title)
|
|
||||||
bigContentView.setTextViewText(R.id.subtitle, song.artistName)
|
|
||||||
|
|
||||||
|
|
||||||
contentView.setImageViewBitmap(
|
contentView.setImageViewBitmap(
|
||||||
R.id.smallIcon,
|
R.id.smallIcon,
|
||||||
createBitmap(
|
createBitmap(
|
||||||
|
@ -269,7 +259,7 @@ class PlayingNotificationClassic(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setPlaying(isPlaying: Boolean, onUpdate: () -> Unit) {
|
override fun setPlaying(isPlaying: Boolean) {
|
||||||
getPlayPauseBitmap(isPlaying).also {
|
getPlayPauseBitmap(isPlaying).also {
|
||||||
contentView.setImageViewBitmap(R.id.action_play_pause, it)
|
contentView.setImageViewBitmap(R.id.action_play_pause, it)
|
||||||
bigContentView.setImageViewBitmap(R.id.action_play_pause, it)
|
bigContentView.setImageViewBitmap(R.id.action_play_pause, it)
|
||||||
|
@ -277,9 +267,6 @@ class PlayingNotificationClassic(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun updateFavorite(song: Song, onUpdate: () -> Unit) {
|
override fun updateFavorite(song: Song, onUpdate: () -> Unit) {
|
||||||
if (!isInitialized) {
|
|
||||||
updateMetadata(song, onUpdate)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun buildPendingIntent(
|
private fun buildPendingIntent(
|
||||||
|
|
|
@ -46,10 +46,7 @@ import code.name.monkey.retromusic.util.PreferenceUtil
|
||||||
import code.name.monkey.retromusic.util.RetroColorUtil
|
import code.name.monkey.retromusic.util.RetroColorUtil
|
||||||
import com.bumptech.glide.request.target.CustomTarget
|
import com.bumptech.glide.request.target.CustomTarget
|
||||||
import com.bumptech.glide.request.transition.Transition
|
import com.bumptech.glide.request.transition.Transition
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.*
|
||||||
import kotlinx.coroutines.GlobalScope
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import kotlinx.coroutines.withContext
|
|
||||||
|
|
||||||
@SuppressLint("RestrictedApi")
|
@SuppressLint("RestrictedApi")
|
||||||
class PlayingNotificationImpl24(
|
class PlayingNotificationImpl24(
|
||||||
|
@ -207,9 +204,8 @@ class PlayingNotificationImpl24(
|
||||||
).build()
|
).build()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setPlaying(isPlaying: Boolean, onUpdate: () -> Unit) {
|
override fun setPlaying(isPlaying: Boolean) {
|
||||||
mActions[2] = buildPlayAction(isPlaying)
|
mActions[2] = buildPlayAction(isPlaying)
|
||||||
onUpdate()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun updateFavorite(song: Song, onUpdate: () -> Unit) {
|
override fun updateFavorite(song: Song, onUpdate: () -> Unit) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue