From 5b2817b2f2de6f44af9760a7441efdc267d5264a Mon Sep 17 00:00:00 2001 From: Alexander Capehart Date: Sat, 27 Aug 2022 14:09:20 -0600 Subject: [PATCH] playback: do not check for version w/notification Do not check for the version when managing the notification. Some OEMs will update the android system, causing the version number to change, but will THEN not update the system UI, completely breaking my compat hacks. Because you know. Reasons. Fix this by always applying future and obsolete methods of updating the media notification regardless of the context. Resolves #219. --- CHANGELOG.md | 3 +- .../playback/system/MediaSessionComponent.kt | 74 ++++++++----------- .../playback/system/NotificationComponent.kt | 5 -- 3 files changed, 33 insertions(+), 49 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dbbb9fe52..341e7e8cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,8 +14,9 @@ - Added a way to access the system equalizer from the playback menu. #### What's Fixed -- Fixed "@android:string/" strings from appearing in dialog +- Fixed "@android:string/" strings from appearing in dialog buttons +- Fixed issue where LG phones would not show metadata in the notification #### What's Changed - Menus are now opened using a new button to the side of all items diff --git a/app/src/main/java/org/oxycblt/auxio/playback/system/MediaSessionComponent.kt b/app/src/main/java/org/oxycblt/auxio/playback/system/MediaSessionComponent.kt index b9e5b4deb..9141b59c7 100644 --- a/app/src/main/java/org/oxycblt/auxio/playback/system/MediaSessionComponent.kt +++ b/app/src/main/java/org/oxycblt/auxio/playback/system/MediaSessionComponent.kt @@ -21,7 +21,6 @@ import android.content.Context import android.content.Intent import android.graphics.Bitmap import android.net.Uri -import android.os.Build import android.os.Bundle import android.os.SystemClock import android.support.v4.media.MediaDescriptionCompat @@ -62,9 +61,6 @@ import org.oxycblt.auxio.util.logD * @author OxygenCobalt * * TODO: Remove the player callback once smooth seeking is implemented - * - * TODO: Rework what is considered to "start foreground" and what is not from the context of this - * object. This could help reduce the amount of post calls I send on Android 13 onwards, hopefully. */ class MediaSessionComponent( private val context: Context, @@ -229,11 +225,7 @@ class MediaSessionComponent( override fun onPlayingChanged(isPlaying: Boolean) { invalidateSessionState() - - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) { - // Android 13 automatically handles the playing state. - notification.updatePlaying(playbackManager.isPlaying) - } + notification.updatePlaying(playbackManager.isPlaying) if (!provider.isBusy) { // Still probably want to start the notification though regardless of the version, @@ -409,49 +401,45 @@ class MediaSessionComponent( state.setState(playerState, player.currentPosition, 1.0f, SystemClock.elapsedRealtime()) - // Android 13+ leverages custom actions. + // Android 13+ leverages custom actions in the notification. - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { - val extraAction = - if (settings.useAltNotifAction) { - PlaybackStateCompat.CustomAction.Builder( - PlaybackService.ACTION_INVERT_SHUFFLE, - context.getString(R.string.desc_change_repeat), - if (playbackManager.isShuffled) { - R.drawable.ic_shuffle_on_24 - } else { - R.drawable.ic_shuffle_off_24 - }) - } else { - PlaybackStateCompat.CustomAction.Builder( - PlaybackService.ACTION_INC_REPEAT_MODE, - context.getString(R.string.desc_change_repeat), - playbackManager.repeatMode.icon) - } - - val exitAction = + val extraAction = + if (settings.useAltNotifAction) { PlaybackStateCompat.CustomAction.Builder( - PlaybackService.ACTION_EXIT, - context.getString(R.string.desc_exit), - R.drawable.ic_close_24) - .build() + PlaybackService.ACTION_INVERT_SHUFFLE, + context.getString(R.string.desc_change_repeat), + if (playbackManager.isShuffled) { + R.drawable.ic_shuffle_on_24 + } else { + R.drawable.ic_shuffle_off_24 + }) + } else { + PlaybackStateCompat.CustomAction.Builder( + PlaybackService.ACTION_INC_REPEAT_MODE, + context.getString(R.string.desc_change_repeat), + playbackManager.repeatMode.icon) + } - state.addCustomAction(extraAction.build()) - state.addCustomAction(exitAction) - } + val exitAction = + PlaybackStateCompat.CustomAction.Builder( + PlaybackService.ACTION_EXIT, + context.getString(R.string.desc_exit), + R.drawable.ic_close_24) + .build() + + state.addCustomAction(extraAction.build()) + state.addCustomAction(exitAction) mediaSession.setPlaybackState(state.build()) } private fun invalidateSecondaryAction() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { - invalidateSessionState() + invalidateSessionState() + + if (settings.useAltNotifAction) { + notification.updateShuffled(playbackManager.isShuffled) } else { - if (settings.useAltNotifAction) { - notification.updateShuffled(playbackManager.isShuffled) - } else { - notification.updateRepeatMode(playbackManager.repeatMode) - } + notification.updateRepeatMode(playbackManager.repeatMode) } if (!provider.isBusy) { diff --git a/app/src/main/java/org/oxycblt/auxio/playback/system/NotificationComponent.kt b/app/src/main/java/org/oxycblt/auxio/playback/system/NotificationComponent.kt index 50984fc64..8448a5ff1 100644 --- a/app/src/main/java/org/oxycblt/auxio/playback/system/NotificationComponent.kt +++ b/app/src/main/java/org/oxycblt/auxio/playback/system/NotificationComponent.kt @@ -67,11 +67,6 @@ class NotificationComponent(private val context: Context, sessionToken: MediaSes // --- STATE FUNCTIONS --- fun updateMetadata(metadata: MediaMetadataCompat) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { - // Notification is automatically filled in by media session, ignore - return - } - setContentTitle(metadata.getString(MediaMetadataCompat.METADATA_KEY_TITLE)) setContentText(metadata.getText(MediaMetadataCompat.METADATA_KEY_ARTIST))