diff --git a/app/src/main/kotlin/org/akanework/gramophone/logic/ui/MeiZuLyricsMediaNotificationProvider.kt b/app/src/main/kotlin/org/akanework/gramophone/logic/ui/MeiZuLyricsMediaNotificationProvider.kt index 14addefa6..41a585b8e 100644 --- a/app/src/main/kotlin/org/akanework/gramophone/logic/ui/MeiZuLyricsMediaNotificationProvider.kt +++ b/app/src/main/kotlin/org/akanework/gramophone/logic/ui/MeiZuLyricsMediaNotificationProvider.kt @@ -55,33 +55,12 @@ class MeiZuLyricsMediaNotificationProvider(private val context: MediaSessionServ mediaSession, customLayout, actionFactory ) { onNotificationChangedCallback.onNotificationChanged(it.also { - if (ticker != null) { - it.notification.apply { - extras.putInt("ticker_icon", R.drawable.ic_gramophone_monochrome) - extras.putBoolean("ticker_icon_switch", false) - } - } - if (tickerProvider() != null) { - updateTickerLater(mediaSession) - } + if (ticker != null) + it.applyNotificationFlags(false) }) }.also { - if (ticker != null) { - it.notification.apply { - extras.putInt("ticker_icon", R.drawable.ic_gramophone_monochrome) - extras.putBoolean("ticker_icon_switch", false) - } - } - if (ticker != null && isManualNotificationUpdate) { - it.notification.apply { - // Keep the status bar lyrics scrolling - flags = flags.or(FLAG_ALWAYS_SHOW_TICKER) - // Only update the ticker (lyrics), and do not update other properties - flags = flags.or(FLAG_ONLY_UPDATE_TICKER) - } - } else if (ticker != null) { - updateTickerLater(mediaSession) - } + if (ticker != null) + it.applyNotificationFlags(isManualNotificationUpdate) } } @@ -91,18 +70,15 @@ class MeiZuLyricsMediaNotificationProvider(private val context: MediaSessionServ extras: Bundle ) = inner.handleCustomCommand(session, action, extras) - private fun updateTickerLater(mediaSession: MediaSession) { - // If we set FLAG_ONLY_UPDATE_TICKER on native impl, other notification content - // won't be updated. - // If we don't set FLAG_ONLY_UPDATE_TICKER, Xposed impl won't consider this as - // lyrics. Hence first update for new content and then again to re-apply ticker. - // Yes, these post() calls are needed. (Otherwise we go into a race with media3). - Handler(mediaSession.player.applicationLooper).post { - Handler(Looper.getMainLooper()).post { - Handler(mediaSession.player.applicationLooper).post { - context.doUpdateNotification(mediaSession) - } - } + private fun MediaNotification.applyNotificationFlags(onlyUpdateTicker: Boolean) { + notification.apply { + extras.putInt("ticker_icon", R.drawable.ic_gramophone_monochrome) + extras.putBoolean("ticker_icon_switch", false) + // Keep the status bar lyrics scrolling + flags = flags.or(FLAG_ALWAYS_SHOW_TICKER) + // Only update the ticker (lyrics), and do not update other properties + if (onlyUpdateTicker) + flags = flags.or(FLAG_ONLY_UPDATE_TICKER) } }