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.
This commit is contained in:
Alexander Capehart 2022-08-27 14:09:20 -06:00
parent 4d8c2abd09
commit 5b2817b2f2
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
3 changed files with 33 additions and 49 deletions

View file

@ -16,6 +16,7 @@
#### What's Fixed
- Fixed "@android:string/<ok/cancel>" 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

View file

@ -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)
}
if (!provider.isBusy) {
// Still probably want to start the notification though regardless of the version,
@ -409,9 +401,8 @@ 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(
@ -438,21 +429,18 @@ class MediaSessionComponent(
state.addCustomAction(extraAction.build())
state.addCustomAction(exitAction)
}
mediaSession.setPlaybackState(state.build())
}
private fun invalidateSecondaryAction() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
invalidateSessionState()
} else {
if (settings.useAltNotifAction) {
notification.updateShuffled(playbackManager.isShuffled)
} else {
notification.updateRepeatMode(playbackManager.repeatMode)
}
}
if (!provider.isBusy) {
callback.onPostNotification(notification, PostingReason.ACTIONS)

View file

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