Remove close and add shuffle to notification index 4

This commit is contained in:
Le Zhang
2026-01-18 07:34:17 +09:00
parent 29d333accc
commit 593c55845f
6 changed files with 31 additions and 97 deletions
@@ -37,8 +37,6 @@ import timber.log.Timber as L
interface PlaybackSettings : Settings<PlaybackSettings.Listener> { interface PlaybackSettings : Settings<PlaybackSettings.Listener> {
/** The action to display on the playback bar. */ /** The action to display on the playback bar. */
val barAction: ActionMode val barAction: ActionMode
/** The action to display in the playback notification. */
val notificationAction: ActionMode
/** Whether to start playback when a headset is plugged in. */ /** Whether to start playback when a headset is plugged in. */
val headsetAutoplay: Boolean val headsetAutoplay: Boolean
/** The current ReplayGain configuration. */ /** The current ReplayGain configuration. */
@@ -67,9 +65,6 @@ interface PlaybackSettings : Settings<PlaybackSettings.Listener> {
/** Called when one of the ReplayGain configurations have changed. */ /** Called when one of the ReplayGain configurations have changed. */
fun onReplayGainSettingsChanged() {} fun onReplayGainSettingsChanged() {}
/** Called when [notificationAction] has changed. */
fun onNotificationActionChanged() {}
/** Called when [barAction] has changed. */ /** Called when [barAction] has changed. */
fun onBarActionChanged() {} 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) sharedPreferences.getInt(getString(R.string.set_key_bar_action), Int.MIN_VALUE)
) ?: ActionMode.NEXT ) ?: 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 override val headsetAutoplay: Boolean
get() = sharedPreferences.getBoolean(getString(R.string.set_key_headset_autoplay), false) 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") L.d("Dispatching ReplayGain setting change")
listener.onReplayGainSettingsChanged() listener.onReplayGainSettingsChanged()
} }
getString(R.string.set_key_notif_action) -> {
L.d("Dispatching notification setting change")
listener.onNotificationActionChanged()
}
getString(R.string.set_key_bar_action) -> { getString(R.string.set_key_bar_action) -> {
L.d("Dispatching bar action change") L.d("Dispatching bar action change")
listener.onBarActionChanged() listener.onBarActionChanged()
@@ -42,8 +42,6 @@ import org.oxycblt.auxio.music.resolve
import org.oxycblt.auxio.music.resolveNames import org.oxycblt.auxio.music.resolveNames
import org.oxycblt.auxio.music.service.MediaSessionUID import org.oxycblt.auxio.music.service.MediaSessionUID
import org.oxycblt.auxio.music.service.toMediaDescription 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.PlaybackStateManager
import org.oxycblt.auxio.playback.state.Progression import org.oxycblt.auxio.playback.state.Progression
import org.oxycblt.auxio.playback.state.QueueChange import org.oxycblt.auxio.playback.state.QueueChange
@@ -65,17 +63,15 @@ private constructor(
private val context: Context, private val context: Context,
private val foregroundListener: ForegroundListener, private val foregroundListener: ForegroundListener,
private val playbackManager: PlaybackStateManager, private val playbackManager: PlaybackStateManager,
private val playbackSettings: PlaybackSettings,
private val bitmapProvider: BitmapProvider, private val bitmapProvider: BitmapProvider,
private val imageSettings: ImageSettings, private val imageSettings: ImageSettings,
private val mediaSessionInterface: MediaSessionInterface, private val mediaSessionInterface: MediaSessionInterface,
) : PlaybackStateManager.Listener, ImageSettings.Listener, PlaybackSettings.Listener { ) : PlaybackStateManager.Listener, ImageSettings.Listener {
class Factory class Factory
@Inject @Inject
constructor( constructor(
private val playbackManager: PlaybackStateManager, private val playbackManager: PlaybackStateManager,
private val playbackSettings: PlaybackSettings,
private val bitmapProvider: BitmapProvider, private val bitmapProvider: BitmapProvider,
private val imageSettings: ImageSettings, private val imageSettings: ImageSettings,
private val mediaSessionInterface: MediaSessionInterface, private val mediaSessionInterface: MediaSessionInterface,
@@ -85,7 +81,6 @@ private constructor(
context, context,
foregroundListener, foregroundListener,
playbackManager, playbackManager,
playbackSettings,
bitmapProvider, bitmapProvider,
imageSettings, imageSettings,
mediaSessionInterface, mediaSessionInterface,
@@ -102,7 +97,6 @@ private constructor(
fun attach() { fun attach() {
playbackManager.addListener(this) playbackManager.addListener(this)
playbackSettings.registerListener(this)
imageSettings.registerListener(this) imageSettings.registerListener(this)
mediaSession.apply { mediaSession.apply {
isActive = true isActive = true
@@ -121,7 +115,6 @@ private constructor(
fun release() { fun release() {
bitmapProvider.release() bitmapProvider.release()
playbackManager.removeListener(this) playbackManager.removeListener(this)
playbackSettings.unregisterListener(this)
imageSettings.unregisterListener(this) imageSettings.unregisterListener(this)
mediaSession.apply { mediaSession.apply {
isActive = false isActive = false
@@ -159,7 +152,7 @@ private constructor(
PlaybackStateCompat.SHUFFLE_MODE_NONE PlaybackStateCompat.SHUFFLE_MODE_NONE
} }
) )
invalidateSecondaryAction() invalidateNotificationActions()
} }
override fun onNewPlayback( override fun onNewPlayback(
@@ -190,7 +183,7 @@ private constructor(
} }
) )
invalidateSecondaryAction() invalidateNotificationActions()
} }
// --- SETTINGS OVERRIDES --- // --- SETTINGS OVERRIDES ---
@@ -200,11 +193,6 @@ private constructor(
updateMediaMetadata(playbackManager.currentSong, playbackManager.parent) updateMediaMetadata(playbackManager.currentSong, playbackManager.parent)
} }
override fun onNotificationActionChanged() {
// Need to re-load the action shown in the notification.
invalidateSecondaryAction()
}
// --- MEDIASESSION OVERRIDES --- // --- MEDIASESSION OVERRIDES ---
// --- INTERNAL --- // --- INTERNAL ---
@@ -334,11 +322,18 @@ private constructor(
// Android 13+ relies on custom actions in the notification. // Android 13+ relies on custom actions in the notification.
// Add the secondary action (either repeat/shuffle depending on the configuration) // Add repeat action
val secondaryAction = val repeatAction =
when (playbackSettings.notificationAction) { PlaybackStateCompat.CustomAction.Builder(
ActionMode.SHUFFLE -> { PlaybackActions.ACTION_INC_REPEAT_MODE,
L.d("Using shuffle MediaSession action") context.getString(R.string.desc_change_repeat),
playbackManager.repeatMode.icon,
)
.build()
state.addCustomAction(repeatAction)
// Add shuffle action
val shuffleAction =
PlaybackStateCompat.CustomAction.Builder( PlaybackStateCompat.CustomAction.Builder(
PlaybackActions.ACTION_INVERT_SHUFFLE, PlaybackActions.ACTION_INVERT_SHUFFLE,
context.getString(R.string.desc_shuffle), context.getString(R.string.desc_shuffle),
@@ -348,46 +343,19 @@ private constructor(
R.drawable.ic_shuffle_off_24 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 =
PlaybackStateCompat.CustomAction.Builder(
PlaybackActions.ACTION_EXIT,
context.getString(R.string.desc_exit),
R.drawable.ic_close_24,
)
.build() .build()
state.addCustomAction(exitAction) state.addCustomAction(shuffleAction)
mediaSession.setPlaybackState(state.build()) mediaSession.setPlaybackState(state.build())
} }
/** Invalidate the "secondary" action (i.e shuffle/repeat mode). */ /** Invalidate both repeat and shuffle notification actions. */
private fun invalidateSecondaryAction() { private fun invalidateNotificationActions() {
L.d("Invalidating secondary action") L.d("Invalidating notification actions")
invalidateSessionState() 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) { if (!bitmapProvider.isBusy) {
L.d("Not loading a bitmap, post the notification") L.d("Not loading a bitmap, post the notification")
@@ -427,7 +395,7 @@ private class PlaybackNotification(
addAction( addAction(
buildAction(context, PlaybackActions.ACTION_SKIP_NEXT, R.drawable.ic_skip_next_24) 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( setStyle(
MediaStyle(this).setMediaSession(sessionToken).setShowActionsInCompactView(1, 2, 3) MediaStyle(this).setMediaSession(sessionToken).setShowActionsInCompactView(1, 2, 3)
@@ -486,7 +454,7 @@ private class PlaybackNotification(
*/ */
fun updateShuffled(isShuffled: Boolean) { fun updateShuffled(isShuffled: Boolean) {
L.d("Applying shuffle action: $isShuffled") L.d("Applying shuffle action: $isShuffled")
mActions[0] = buildShuffleAction(context, isShuffled) mActions[4] = buildShuffleAction(context, isShuffled)
} }
// --- NOTIFICATION ACTION BUILDERS --- // --- NOTIFICATION ACTION BUILDERS ---
@@ -102,7 +102,7 @@ private constructor(
private fun handleExitRequest() { private fun handleExitRequest() {
if (isAppForegrounded()) { 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. // be triggered by other ways, e.g. Bluetooth devices.
L.d("Exit Requested: App visible, pausing") L.d("Exit Requested: App visible, pausing")
playbackManager.playing(false) playbackManager.playing(false)
-11
View File
@@ -45,7 +45,6 @@
<string name="set_key_hide_collaborators" translatable="false">auxio_hide_collaborators</string> <string name="set_key_hide_collaborators" translatable="false">auxio_hide_collaborators</string>
<string name="set_key_round_mode" translatable="false">auxio_round_covers</string> <string name="set_key_round_mode" translatable="false">auxio_round_covers</string>
<string name="set_key_bar_action" translatable="false">auxio_bar_action</string> <string name="set_key_bar_action" translatable="false">auxio_bar_action</string>
<string name="set_key_notif_action" translatable="false">auxio_notif_action</string>
<string name="set_key_search_filter_to" translatable="false">KEY_SEARCH_FILTER</string> <string name="set_key_search_filter_to" translatable="false">KEY_SEARCH_FILTER</string>
@@ -111,16 +110,6 @@
<item>@integer/action_mode_shuffle</item> <item>@integer/action_mode_shuffle</item>
</integer-array> </integer-array>
<integer-array name="entries_notif_action">
<item>@string/set_action_mode_repeat</item>
<item>@string/lbl_shuffle</item>
</integer-array>
<integer-array name="values_notif_action">
<item>@integer/action_mode_repeat</item>
<item>@integer/action_mode_shuffle</item>
</integer-array>
<string-array name="entries_play_in_list_with"> <string-array name="entries_play_in_list_with">
<item>@string/set_play_song_from_all</item> <item>@string/set_play_song_from_all</item>
<item>@string/set_play_song_from_album</item> <item>@string/set_play_song_from_album</item>
-1
View File
@@ -246,7 +246,6 @@
<string name="set_lib_tabs_desc">Change visibility and order of library tabs</string> <string name="set_lib_tabs_desc">Change visibility and order of library tabs</string>
<!-- Skip to next (song) --> <!-- Skip to next (song) -->
<string name="set_bar_action">Custom playback bar action</string> <string name="set_bar_action">Custom playback bar action</string>
<string name="set_notif_action">Custom notification action</string>
<string name="set_action_mode_next">Skip to next</string> <string name="set_action_mode_next">Skip to next</string>
<string name="set_action_mode_repeat">Repeat mode</string> <string name="set_action_mode_repeat">Repeat mode</string>
<string name="set_behavior">Behavior</string> <string name="set_behavior">Behavior</string>
@@ -17,13 +17,6 @@
app:key="@string/set_key_bar_action" app:key="@string/set_key_bar_action"
app:title="@string/set_bar_action" /> app:title="@string/set_bar_action" />
<org.oxycblt.auxio.settings.ui.IntListPreference
app:defaultValue="@integer/action_mode_repeat"
app:entries="@array/entries_notif_action"
app:entryValues="@array/values_notif_action"
app:key="@string/set_key_notif_action"
app:title="@string/set_notif_action" />
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory android:title="@string/set_behavior"> <PreferenceCategory android:title="@string/set_behavior">