playback: make bar action respond to settings
Now that the navigation graphs are unified, the playback bar now has to respond to when it's custom action setting changes.
This commit is contained in:
parent
9e5b737d1a
commit
e490ff64c1
4 changed files with 70 additions and 49 deletions
|
|
@ -70,7 +70,6 @@ class PlaybackBarFragment : ViewBindingFragment<FragmentPlaybackBarBinding>() {
|
||||||
|
|
||||||
// Set up actions
|
// Set up actions
|
||||||
binding.playbackPlayPause.setOnClickListener { playbackModel.togglePlaying() }
|
binding.playbackPlayPause.setOnClickListener { playbackModel.togglePlaying() }
|
||||||
setupSecondaryActions(binding, playbackModel.currentBarAction)
|
|
||||||
|
|
||||||
// Load the track color in manually as it's unclear whether the track actually supports
|
// Load the track color in manually as it's unclear whether the track actually supports
|
||||||
// using a ColorStateList in the resources.
|
// using a ColorStateList in the resources.
|
||||||
|
|
@ -81,6 +80,11 @@ class PlaybackBarFragment : ViewBindingFragment<FragmentPlaybackBarBinding>() {
|
||||||
collectImmediately(playbackModel.song, ::updateSong)
|
collectImmediately(playbackModel.song, ::updateSong)
|
||||||
collectImmediately(playbackModel.isPlaying, ::updatePlaying)
|
collectImmediately(playbackModel.isPlaying, ::updatePlaying)
|
||||||
collectImmediately(playbackModel.positionDs, ::updatePosition)
|
collectImmediately(playbackModel.positionDs, ::updatePosition)
|
||||||
|
collectImmediately(
|
||||||
|
playbackModel.currentBarAction,
|
||||||
|
playbackModel.repeatMode,
|
||||||
|
playbackModel.isShuffled,
|
||||||
|
::updateBarAction)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroyBinding(binding: FragmentPlaybackBarBinding) {
|
override fun onDestroyBinding(binding: FragmentPlaybackBarBinding) {
|
||||||
|
|
@ -90,39 +94,6 @@ class PlaybackBarFragment : ViewBindingFragment<FragmentPlaybackBarBinding>() {
|
||||||
binding.playbackInfo.isSelected = false
|
binding.playbackInfo.isSelected = false
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupSecondaryActions(binding: FragmentPlaybackBarBinding, actionMode: ActionMode) {
|
|
||||||
when (actionMode) {
|
|
||||||
ActionMode.NEXT -> {
|
|
||||||
logD("Setting up skip next action")
|
|
||||||
binding.playbackSecondaryAction.apply {
|
|
||||||
setIconResource(R.drawable.ic_skip_next_24)
|
|
||||||
contentDescription = getString(R.string.desc_skip_next)
|
|
||||||
iconTint = context.getAttrColorCompat(MR.attr.colorOnSurfaceVariant)
|
|
||||||
setOnClickListener { playbackModel.next() }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ActionMode.REPEAT -> {
|
|
||||||
logD("Setting up repeat mode action")
|
|
||||||
binding.playbackSecondaryAction.apply {
|
|
||||||
contentDescription = getString(R.string.desc_change_repeat)
|
|
||||||
iconTint = context.getColorCompat(R.color.sel_activatable_icon)
|
|
||||||
setOnClickListener { playbackModel.toggleRepeatMode() }
|
|
||||||
collectImmediately(playbackModel.repeatMode, ::updateRepeat)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ActionMode.SHUFFLE -> {
|
|
||||||
logD("Setting up shuffle action")
|
|
||||||
binding.playbackSecondaryAction.apply {
|
|
||||||
setIconResource(R.drawable.sel_shuffle_state_24)
|
|
||||||
contentDescription = getString(R.string.desc_shuffle)
|
|
||||||
iconTint = context.getColorCompat(R.color.sel_activatable_icon)
|
|
||||||
setOnClickListener { playbackModel.toggleShuffled() }
|
|
||||||
collectImmediately(playbackModel.isShuffled, ::updateShuffled)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun updateSong(song: Song?) {
|
private fun updateSong(song: Song?) {
|
||||||
if (song == null) {
|
if (song == null) {
|
||||||
// Nothing to do.
|
// Nothing to do.
|
||||||
|
|
@ -141,19 +112,55 @@ class PlaybackBarFragment : ViewBindingFragment<FragmentPlaybackBarBinding>() {
|
||||||
requireBinding().playbackPlayPause.isActivated = isPlaying
|
requireBinding().playbackPlayPause.isActivated = isPlaying
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateRepeat(repeatMode: RepeatMode) {
|
|
||||||
requireBinding().playbackSecondaryAction.apply {
|
|
||||||
setIconResource(repeatMode.icon)
|
|
||||||
// Icon tinting is controlled through isActivated, so update that flag as well.
|
|
||||||
isActivated = repeatMode != RepeatMode.NONE
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun updateShuffled(isShuffled: Boolean) {
|
|
||||||
requireBinding().playbackSecondaryAction.isActivated = isShuffled
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun updatePosition(positionDs: Long) {
|
private fun updatePosition(positionDs: Long) {
|
||||||
requireBinding().playbackProgressBar.progress = positionDs.toInt()
|
requireBinding().playbackProgressBar.progress = positionDs.toInt()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun updateBarAction(
|
||||||
|
actionMode: ActionMode,
|
||||||
|
repeatMode: RepeatMode,
|
||||||
|
isShuffled: Boolean
|
||||||
|
) {
|
||||||
|
val binding = requireBinding()
|
||||||
|
when (actionMode) {
|
||||||
|
ActionMode.NEXT -> {
|
||||||
|
logD("Using skip next action")
|
||||||
|
binding.playbackSecondaryAction.apply {
|
||||||
|
if (tag != actionMode) {
|
||||||
|
setIconResource(R.drawable.ic_skip_next_24)
|
||||||
|
contentDescription = getString(R.string.desc_skip_next)
|
||||||
|
iconTint = context.getAttrColorCompat(MR.attr.colorOnSurfaceVariant)
|
||||||
|
setOnClickListener { playbackModel.next() }
|
||||||
|
tag = actionMode
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ActionMode.REPEAT -> {
|
||||||
|
logD("Using repeat mode action")
|
||||||
|
binding.playbackSecondaryAction.apply {
|
||||||
|
if (tag != actionMode) {
|
||||||
|
contentDescription = getString(R.string.desc_change_repeat)
|
||||||
|
iconTint = context.getColorCompat(R.color.sel_activatable_icon)
|
||||||
|
setOnClickListener { playbackModel.toggleRepeatMode() }
|
||||||
|
tag = actionMode
|
||||||
|
}
|
||||||
|
setIconResource(repeatMode.icon)
|
||||||
|
isActivated = repeatMode != RepeatMode.NONE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ActionMode.SHUFFLE -> {
|
||||||
|
logD("Using shuffle action")
|
||||||
|
binding.playbackSecondaryAction.apply {
|
||||||
|
if (tag != actionMode) {
|
||||||
|
setIconResource(R.drawable.sel_shuffle_state_24)
|
||||||
|
contentDescription = getString(R.string.desc_shuffle)
|
||||||
|
iconTint = context.getColorCompat(R.color.sel_activatable_icon)
|
||||||
|
setOnClickListener { playbackModel.toggleShuffled() }
|
||||||
|
tag = actionMode
|
||||||
|
}
|
||||||
|
isActivated = isShuffled
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -238,10 +238,10 @@ class PlaybackPanelFragment :
|
||||||
|
|
||||||
private fun handleShow(show: Show?) {
|
private fun handleShow(show: Show?) {
|
||||||
when (show) {
|
when (show) {
|
||||||
|
is Show.SongAlbumDetails,
|
||||||
is Show.ArtistDetails,
|
is Show.ArtistDetails,
|
||||||
is Show.AlbumDetails -> playbackModel.openMain()
|
is Show.AlbumDetails -> playbackModel.openMain()
|
||||||
is Show.SongDetails,
|
is Show.SongDetails,
|
||||||
is Show.SongAlbumDetails,
|
|
||||||
is Show.SongArtistDetails,
|
is Show.SongArtistDetails,
|
||||||
is Show.AlbumArtistDetails,
|
is Show.AlbumArtistDetails,
|
||||||
is Show.GenreDetails,
|
is Show.GenreDetails,
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,8 @@ interface PlaybackSettings : Settings<PlaybackSettings.Listener> {
|
||||||
fun onReplayGainSettingsChanged() {}
|
fun onReplayGainSettingsChanged() {}
|
||||||
/** Called when [notificationAction] has changed. */
|
/** Called when [notificationAction] has changed. */
|
||||||
fun onNotificationActionChanged() {}
|
fun onNotificationActionChanged() {}
|
||||||
|
/** Called when [barAction] has changed. */
|
||||||
|
fun onBarActionChanged() {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -206,6 +208,10 @@ class PlaybackSettingsImpl @Inject constructor(@ApplicationContext context: Cont
|
||||||
logD("Dispatching notification setting change")
|
logD("Dispatching notification setting change")
|
||||||
listener.onNotificationActionChanged()
|
listener.onNotificationActionChanged()
|
||||||
}
|
}
|
||||||
|
getString(R.string.set_key_bar_action) -> {
|
||||||
|
logD("Dispatching bar action change")
|
||||||
|
listener.onBarActionChanged()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ constructor(
|
||||||
private val persistenceRepository: PersistenceRepository,
|
private val persistenceRepository: PersistenceRepository,
|
||||||
private val musicRepository: MusicRepository,
|
private val musicRepository: MusicRepository,
|
||||||
private val musicSettings: MusicSettings
|
private val musicSettings: MusicSettings
|
||||||
) : ViewModel(), PlaybackStateManager.Listener {
|
) : ViewModel(), PlaybackStateManager.Listener, PlaybackSettings.Listener {
|
||||||
private var lastPositionJob: Job? = null
|
private var lastPositionJob: Job? = null
|
||||||
|
|
||||||
private val _song = MutableStateFlow<Song?>(null)
|
private val _song = MutableStateFlow<Song?>(null)
|
||||||
|
|
@ -89,7 +89,9 @@ constructor(
|
||||||
val isShuffled: StateFlow<Boolean>
|
val isShuffled: StateFlow<Boolean>
|
||||||
get() = _isShuffled
|
get() = _isShuffled
|
||||||
|
|
||||||
val currentBarAction: ActionMode = playbackSettings.barAction
|
private val _currentBarAction = MutableStateFlow(playbackSettings.barAction)
|
||||||
|
val currentBarAction: StateFlow<ActionMode>
|
||||||
|
get() = _currentBarAction
|
||||||
|
|
||||||
private val _openPanel = MutableEvent<OpenPanel>()
|
private val _openPanel = MutableEvent<OpenPanel>()
|
||||||
val openPanel: Event<OpenPanel>
|
val openPanel: Event<OpenPanel>
|
||||||
|
|
@ -108,10 +110,12 @@ constructor(
|
||||||
|
|
||||||
init {
|
init {
|
||||||
playbackManager.addListener(this)
|
playbackManager.addListener(this)
|
||||||
|
playbackSettings.registerListener(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCleared() {
|
override fun onCleared() {
|
||||||
playbackManager.removeListener(this)
|
playbackManager.removeListener(this)
|
||||||
|
playbackSettings.unregisterListener(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onIndexMoved(queue: Queue) {
|
override fun onIndexMoved(queue: Queue) {
|
||||||
|
|
@ -161,6 +165,10 @@ constructor(
|
||||||
_repeatMode.value = repeatMode
|
_repeatMode.value = repeatMode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onBarActionChanged() {
|
||||||
|
_currentBarAction.value = playbackSettings.barAction
|
||||||
|
}
|
||||||
|
|
||||||
// --- PLAYING FUNCTIONS ---
|
// --- PLAYING FUNCTIONS ---
|
||||||
|
|
||||||
/** Shuffle all songs in the music library. */
|
/** Shuffle all songs in the music library. */
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue