diff --git a/app/src/main/java/org/oxycblt/auxio/playback/PlaybackSettings.kt b/app/src/main/java/org/oxycblt/auxio/playback/PlaybackSettings.kt index 45d487ee1..aac61cc74 100644 --- a/app/src/main/java/org/oxycblt/auxio/playback/PlaybackSettings.kt +++ b/app/src/main/java/org/oxycblt/auxio/playback/PlaybackSettings.kt @@ -37,8 +37,6 @@ import timber.log.Timber as L interface PlaybackSettings : Settings { /** The action to display on the playback bar. */ val barAction: ActionMode - /** The action to display in the playback notification. */ - val notificationAction: ActionMode /** Whether to start playback when a headset is plugged in. */ val headsetAutoplay: Boolean /** The current ReplayGain configuration. */ @@ -67,9 +65,6 @@ interface PlaybackSettings : Settings { /** Called when one of the ReplayGain configurations have changed. */ fun onReplayGainSettingsChanged() {} - /** Called when [notificationAction] has changed. */ - fun onNotificationActionChanged() {} - /** Called when [barAction] has changed. */ fun onBarActionChanged() {} @@ -104,12 +99,6 @@ class PlaybackSettingsImpl @Inject constructor(@ApplicationContext context: Cont sharedPreferences.getInt(getString(R.string.set_key_bar_action), Int.MIN_VALUE) ) ?: ActionMode.NEXT - override val notificationAction: ActionMode - get() = - ActionMode.fromIntCode( - sharedPreferences.getInt(getString(R.string.set_key_notif_action), Int.MIN_VALUE) - ) ?: ActionMode.REPEAT - override val headsetAutoplay: Boolean get() = sharedPreferences.getBoolean(getString(R.string.set_key_headset_autoplay), false) @@ -204,10 +193,6 @@ class PlaybackSettingsImpl @Inject constructor(@ApplicationContext context: Cont L.d("Dispatching ReplayGain setting change") listener.onReplayGainSettingsChanged() } - getString(R.string.set_key_notif_action) -> { - L.d("Dispatching notification setting change") - listener.onNotificationActionChanged() - } getString(R.string.set_key_bar_action) -> { L.d("Dispatching bar action change") listener.onBarActionChanged() diff --git a/app/src/main/java/org/oxycblt/auxio/playback/service/MediaSessionHolder.kt b/app/src/main/java/org/oxycblt/auxio/playback/service/MediaSessionHolder.kt index df72b5fb0..09b602aac 100644 --- a/app/src/main/java/org/oxycblt/auxio/playback/service/MediaSessionHolder.kt +++ b/app/src/main/java/org/oxycblt/auxio/playback/service/MediaSessionHolder.kt @@ -42,8 +42,6 @@ import org.oxycblt.auxio.music.resolve import org.oxycblt.auxio.music.resolveNames import org.oxycblt.auxio.music.service.MediaSessionUID import org.oxycblt.auxio.music.service.toMediaDescription -import org.oxycblt.auxio.playback.ActionMode -import org.oxycblt.auxio.playback.PlaybackSettings import org.oxycblt.auxio.playback.state.PlaybackStateManager import org.oxycblt.auxio.playback.state.Progression import org.oxycblt.auxio.playback.state.QueueChange @@ -65,17 +63,15 @@ private constructor( private val context: Context, private val foregroundListener: ForegroundListener, private val playbackManager: PlaybackStateManager, - private val playbackSettings: PlaybackSettings, private val bitmapProvider: BitmapProvider, private val imageSettings: ImageSettings, private val mediaSessionInterface: MediaSessionInterface, -) : PlaybackStateManager.Listener, ImageSettings.Listener, PlaybackSettings.Listener { +) : PlaybackStateManager.Listener, ImageSettings.Listener { class Factory @Inject constructor( private val playbackManager: PlaybackStateManager, - private val playbackSettings: PlaybackSettings, private val bitmapProvider: BitmapProvider, private val imageSettings: ImageSettings, private val mediaSessionInterface: MediaSessionInterface, @@ -85,7 +81,6 @@ private constructor( context, foregroundListener, playbackManager, - playbackSettings, bitmapProvider, imageSettings, mediaSessionInterface, @@ -102,7 +97,6 @@ private constructor( fun attach() { playbackManager.addListener(this) - playbackSettings.registerListener(this) imageSettings.registerListener(this) mediaSession.apply { isActive = true @@ -121,7 +115,6 @@ private constructor( fun release() { bitmapProvider.release() playbackManager.removeListener(this) - playbackSettings.unregisterListener(this) imageSettings.unregisterListener(this) mediaSession.apply { isActive = false @@ -159,7 +152,7 @@ private constructor( PlaybackStateCompat.SHUFFLE_MODE_NONE } ) - invalidateSecondaryAction() + invalidateNotificationActions() } override fun onNewPlayback( @@ -190,7 +183,7 @@ private constructor( } ) - invalidateSecondaryAction() + invalidateNotificationActions() } // --- SETTINGS OVERRIDES --- @@ -200,11 +193,6 @@ private constructor( updateMediaMetadata(playbackManager.currentSong, playbackManager.parent) } - override fun onNotificationActionChanged() { - // Need to re-load the action shown in the notification. - invalidateSecondaryAction() - } - // --- MEDIASESSION OVERRIDES --- // --- INTERNAL --- @@ -334,60 +322,40 @@ private constructor( // Android 13+ relies on custom actions in the notification. - // Add the secondary action (either repeat/shuffle depending on the configuration) - val secondaryAction = - when (playbackSettings.notificationAction) { - ActionMode.SHUFFLE -> { - L.d("Using shuffle MediaSession action") - PlaybackStateCompat.CustomAction.Builder( - PlaybackActions.ACTION_INVERT_SHUFFLE, - context.getString(R.string.desc_shuffle), - if (playbackManager.isShuffled) { - R.drawable.ic_shuffle_on_24 - } else { - R.drawable.ic_shuffle_off_24 - }, - ) - } - else -> { - L.d("Using repeat mode MediaSession action") - PlaybackStateCompat.CustomAction.Builder( - PlaybackActions.ACTION_INC_REPEAT_MODE, - context.getString(R.string.desc_change_repeat), - playbackManager.repeatMode.icon, - ) - } - } - state.addCustomAction(secondaryAction.build()) - - // Add the exit action so the service can be closed - val exitAction = + // Add repeat action + val repeatAction = PlaybackStateCompat.CustomAction.Builder( - PlaybackActions.ACTION_EXIT, - context.getString(R.string.desc_exit), - R.drawable.ic_close_24, + PlaybackActions.ACTION_INC_REPEAT_MODE, + context.getString(R.string.desc_change_repeat), + playbackManager.repeatMode.icon, ) .build() - state.addCustomAction(exitAction) + state.addCustomAction(repeatAction) + + // Add shuffle action + val shuffleAction = + PlaybackStateCompat.CustomAction.Builder( + PlaybackActions.ACTION_INVERT_SHUFFLE, + context.getString(R.string.desc_shuffle), + if (playbackManager.isShuffled) { + R.drawable.ic_shuffle_on_24 + } else { + R.drawable.ic_shuffle_off_24 + }, + ) + .build() + state.addCustomAction(shuffleAction) mediaSession.setPlaybackState(state.build()) } - /** Invalidate the "secondary" action (i.e shuffle/repeat mode). */ - private fun invalidateSecondaryAction() { - L.d("Invalidating secondary action") + /** Invalidate both repeat and shuffle notification actions. */ + private fun invalidateNotificationActions() { + L.d("Invalidating notification actions") invalidateSessionState() - when (playbackSettings.notificationAction) { - ActionMode.SHUFFLE -> { - L.d("Using shuffle notification action") - _notification.updateShuffled(playbackManager.isShuffled) - } - else -> { - L.d("Using repeat mode notification action") - _notification.updateRepeatMode(playbackManager.repeatMode) - } - } + _notification.updateRepeatMode(playbackManager.repeatMode) + _notification.updateShuffled(playbackManager.isShuffled) if (!bitmapProvider.isBusy) { L.d("Not loading a bitmap, post the notification") @@ -427,7 +395,7 @@ private class PlaybackNotification( addAction( buildAction(context, PlaybackActions.ACTION_SKIP_NEXT, R.drawable.ic_skip_next_24) ) - addAction(buildAction(context, PlaybackActions.ACTION_EXIT, R.drawable.ic_close_24)) + addAction(buildShuffleAction(context, false)) setStyle( MediaStyle(this).setMediaSession(sessionToken).setShowActionsInCompactView(1, 2, 3) @@ -486,7 +454,7 @@ private class PlaybackNotification( */ fun updateShuffled(isShuffled: Boolean) { L.d("Applying shuffle action: $isShuffled") - mActions[0] = buildShuffleAction(context, isShuffled) + mActions[4] = buildShuffleAction(context, isShuffled) } // --- NOTIFICATION ACTION BUILDERS --- diff --git a/app/src/main/java/org/oxycblt/auxio/playback/service/PlaybackServiceFragment.kt b/app/src/main/java/org/oxycblt/auxio/playback/service/PlaybackServiceFragment.kt index a639e571d..3abba8a21 100644 --- a/app/src/main/java/org/oxycblt/auxio/playback/service/PlaybackServiceFragment.kt +++ b/app/src/main/java/org/oxycblt/auxio/playback/service/PlaybackServiceFragment.kt @@ -102,7 +102,7 @@ private constructor( private fun handleExitRequest() { if (isAppForegrounded()) { - // (x) in notification will no longer exist, but it might still + // (x) in notification no longer exists, but it might still // be triggered by other ways, e.g. Bluetooth devices. L.d("Exit Requested: App visible, pausing") playbackManager.playing(false) diff --git a/app/src/main/res/values/settings.xml b/app/src/main/res/values/settings.xml index a27a78b6c..406acee81 100644 --- a/app/src/main/res/values/settings.xml +++ b/app/src/main/res/values/settings.xml @@ -45,7 +45,6 @@ auxio_hide_collaborators auxio_round_covers auxio_bar_action - auxio_notif_action KEY_SEARCH_FILTER @@ -111,16 +110,6 @@ @integer/action_mode_shuffle - - @string/set_action_mode_repeat - @string/lbl_shuffle - - - - @integer/action_mode_repeat - @integer/action_mode_shuffle - - @string/set_play_song_from_all @string/set_play_song_from_album diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9b34fb729..861fb6ed5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -246,7 +246,6 @@ Change visibility and order of library tabs Custom playback bar action - Custom notification action Skip to next Repeat mode Behavior diff --git a/app/src/main/res/xml/preferences_personalize.xml b/app/src/main/res/xml/preferences_personalize.xml index 94e17f472..1924ed615 100644 --- a/app/src/main/res/xml/preferences_personalize.xml +++ b/app/src/main/res/xml/preferences_personalize.xml @@ -17,13 +17,6 @@ app:key="@string/set_key_bar_action" app:title="@string/set_bar_action" /> - -