music: clean up playlist experience
Add a variety of mild fixes and qol improvements regarding playlists.
This commit is contained in:
@@ -348,7 +348,6 @@ constructor(
|
||||
* @param at The position of the item to remove, in the list adapter data.
|
||||
*/
|
||||
fun removePlaylistSong(at: Int) {
|
||||
// TODO: Remove header when empty
|
||||
val playlist = _currentPlaylist.value ?: return
|
||||
val editedPlaylist = (_editedPlaylist.value ?: return).toMutableList()
|
||||
val realAt = at - 2
|
||||
@@ -357,7 +356,13 @@ constructor(
|
||||
}
|
||||
editedPlaylist.removeAt(realAt)
|
||||
_editedPlaylist.value = editedPlaylist
|
||||
refreshPlaylistList(playlist, UpdateInstructions.Remove(at))
|
||||
refreshPlaylistList(
|
||||
playlist,
|
||||
if (editedPlaylist.isNotEmpty()) {
|
||||
UpdateInstructions.Remove(at, 1)
|
||||
} else {
|
||||
UpdateInstructions.Remove(at - 2, 3)
|
||||
})
|
||||
}
|
||||
|
||||
private fun refreshAudioInfo(song: Song) {
|
||||
@@ -490,18 +495,15 @@ constructor(
|
||||
logD("Refreshing playlist list")
|
||||
val list = mutableListOf<Item>()
|
||||
|
||||
val newInstructions =
|
||||
if (playlist.songs.isNotEmpty()) {
|
||||
val header = EditHeader(R.string.lbl_songs)
|
||||
list.add(Divider(header))
|
||||
list.add(header)
|
||||
list.addAll(_editedPlaylist.value ?: playlist.songs)
|
||||
instructions
|
||||
} else {
|
||||
UpdateInstructions.Diff
|
||||
}
|
||||
val songs = editedPlaylist.value ?: playlist.songs
|
||||
if (songs.isNotEmpty()) {
|
||||
val header = EditHeader(R.string.lbl_songs)
|
||||
list.add(Divider(header))
|
||||
list.add(header)
|
||||
list.addAll(songs)
|
||||
}
|
||||
|
||||
_playlistInstructions.put(newInstructions)
|
||||
_playlistInstructions.put(instructions)
|
||||
_playlistList.value = list
|
||||
}
|
||||
|
||||
|
||||
@@ -211,8 +211,7 @@ class PlaylistDetailFragment :
|
||||
}
|
||||
|
||||
override fun onOpenMenu(item: Song, anchor: View) {
|
||||
// TODO: Remove "Add to playlist" option, makes no sense
|
||||
openMusicMenu(anchor, R.menu.menu_song_actions, item)
|
||||
openMusicMenu(anchor, R.menu.menu_playlist_song_actions, item)
|
||||
}
|
||||
|
||||
override fun onPlay() {
|
||||
@@ -284,9 +283,11 @@ class PlaylistDetailFragment :
|
||||
playlistHeaderAdapter.setEditedPlaylist(editedPlaylist)
|
||||
selectionModel.drop()
|
||||
|
||||
logD(editedPlaylist == detailModel.currentPlaylist.value?.songs)
|
||||
requireBinding().detailEditToolbar.menu.findItem(R.id.action_save).isEnabled =
|
||||
editedPlaylist != detailModel.currentPlaylist.value?.songs
|
||||
if (editedPlaylist != null) {
|
||||
requireBinding().detailEditToolbar.menu.findItem(R.id.action_save).apply {
|
||||
isEnabled = editedPlaylist != detailModel.currentPlaylist.value?.songs
|
||||
}
|
||||
}
|
||||
|
||||
updateMultiToolbar()
|
||||
}
|
||||
|
||||
@@ -83,6 +83,7 @@ private constructor(private val binding: ItemDetailHeaderBinding) :
|
||||
editedPlaylist: List<Song>?,
|
||||
listener: DetailHeaderAdapter.Listener
|
||||
) {
|
||||
// TODO: Debug perpetually re-binding images
|
||||
binding.detailCover.bind(playlist, editedPlaylist)
|
||||
binding.detailType.text = binding.context.getString(R.string.lbl_playlist)
|
||||
binding.detailName.text = playlist.name.resolve(binding.context)
|
||||
|
||||
@@ -99,7 +99,7 @@ class PlaylistDetailListAdapter(private val listener: Listener) :
|
||||
return
|
||||
}
|
||||
this.isEditing = editing
|
||||
notifyItemRangeChanged(1, currentList.size - 2, PAYLOAD_EDITING_CHANGED)
|
||||
notifyItemRangeChanged(1, currentList.size - 1, PAYLOAD_EDITING_CHANGED)
|
||||
}
|
||||
|
||||
/** An extended [DetailListAdapter.Listener] for [PlaylistDetailListAdapter]. */
|
||||
@@ -256,6 +256,7 @@ private constructor(private val binding: ItemEditableSongBinding) :
|
||||
}
|
||||
|
||||
override fun updateSelectionIndicator(isSelected: Boolean) {
|
||||
binding.interactBody.isActivated = isSelected
|
||||
binding.songAlbumCover.isActivated = isSelected
|
||||
}
|
||||
|
||||
|
||||
@@ -44,6 +44,13 @@ import org.oxycblt.auxio.playback.formatDurationMs
|
||||
import org.oxycblt.auxio.util.collectImmediately
|
||||
import org.oxycblt.auxio.util.logD
|
||||
|
||||
/**
|
||||
* A [ListFragment] that shows a list of [Playlist]s.
|
||||
*
|
||||
* @author Alexander Capehart (OxygenCobalt)
|
||||
*
|
||||
* TODO: Show a placeholder when there are no playlists.
|
||||
*/
|
||||
class PlaylistListFragment :
|
||||
ListFragment<Playlist, FragmentHomeListBinding>(),
|
||||
FastScrollRecyclerView.PopupProvider,
|
||||
|
||||
@@ -93,8 +93,9 @@ sealed interface UpdateInstructions {
|
||||
* Remove an item.
|
||||
*
|
||||
* @param at The location that the item should be removed from.
|
||||
* @param size The amount of items to add.
|
||||
*/
|
||||
data class Remove(val at: Int) : UpdateInstructions
|
||||
data class Remove(val at: Int, val size: Int) : UpdateInstructions
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -147,7 +148,7 @@ private class FlexibleListDiffer<T>(
|
||||
}
|
||||
is UpdateInstructions.Remove -> {
|
||||
currentList = newList
|
||||
updateCallback.onRemoved(instructions.at, 1)
|
||||
updateCallback.onRemoved(instructions.at, instructions.size)
|
||||
callback?.invoke()
|
||||
}
|
||||
is UpdateInstructions.Diff,
|
||||
|
||||
@@ -131,7 +131,6 @@ class IndexerService :
|
||||
override val scope = indexScope
|
||||
|
||||
override fun onMusicChanges(changes: MusicRepository.Changes) {
|
||||
// TODO: Do not pause when playlist changes
|
||||
val deviceLibrary = musicRepository.deviceLibrary ?: return
|
||||
// Wipe possibly-invalidated outdated covers
|
||||
imageLoader.memoryCache?.clear()
|
||||
|
||||
@@ -34,6 +34,7 @@ import org.oxycblt.auxio.MainFragmentDirections
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.databinding.FragmentPlaybackPanelBinding
|
||||
import org.oxycblt.auxio.music.MusicParent
|
||||
import org.oxycblt.auxio.music.MusicViewModel
|
||||
import org.oxycblt.auxio.music.Song
|
||||
import org.oxycblt.auxio.music.resolveNames
|
||||
import org.oxycblt.auxio.navigation.MainNavigationAction
|
||||
@@ -50,6 +51,8 @@ import org.oxycblt.auxio.util.systemBarInsetsCompat
|
||||
* available controls.
|
||||
*
|
||||
* @author Alexander Capehart (OxygenCobalt)
|
||||
*
|
||||
* TODO: Improve flickering situation on play button
|
||||
*/
|
||||
@AndroidEntryPoint
|
||||
class PlaybackPanelFragment :
|
||||
@@ -57,6 +60,7 @@ class PlaybackPanelFragment :
|
||||
Toolbar.OnMenuItemClickListener,
|
||||
StyledSeekBar.Listener {
|
||||
private val playbackModel: PlaybackViewModel by activityViewModels()
|
||||
private val musicModel: MusicViewModel by activityViewModels()
|
||||
private val navModel: NavigationViewModel by activityViewModels()
|
||||
private var equalizerLauncher: ActivityResultLauncher<Intent>? = null
|
||||
|
||||
@@ -164,6 +168,10 @@ class PlaybackPanelFragment :
|
||||
navigateToCurrentAlbum()
|
||||
true
|
||||
}
|
||||
R.id.action_playlist_add -> {
|
||||
playbackModel.song.value?.let(musicModel::addToPlaylist)
|
||||
true
|
||||
}
|
||||
R.id.action_song_detail -> {
|
||||
playbackModel.song.value?.let { song ->
|
||||
navModel.mainNavigateTo(
|
||||
|
||||
@@ -306,7 +306,7 @@ class EditableQueue : Queue {
|
||||
else -> Queue.Change.Type.MAPPING
|
||||
}
|
||||
check()
|
||||
return Queue.Change(type, UpdateInstructions.Remove(at))
|
||||
return Queue.Change(type, UpdateInstructions.Remove(at, 1))
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -534,17 +534,24 @@ class PlaybackStateManagerImpl @Inject constructor() : PlaybackStateManager {
|
||||
val internalPlayer = internalPlayer ?: return
|
||||
logD("Restoring state $savedState")
|
||||
|
||||
val lastSong = queue.currentSong
|
||||
parent = savedState.parent
|
||||
queue.applySavedState(savedState.queueState)
|
||||
repeatMode = savedState.repeatMode
|
||||
notifyNewPlayback()
|
||||
|
||||
// Continuing playback while also possibly doing drastic state updates is
|
||||
// a bad idea, so pause.
|
||||
internalPlayer.loadSong(queue.currentSong, false)
|
||||
if (queue.currentSong != null) {
|
||||
// Internal player may have reloaded the media item, re-seek to the previous position
|
||||
seekTo(savedState.positionMs)
|
||||
// Check if we need to reload the player with a new music file, or if we can just leave
|
||||
// it be. Specifically done so we don't pause on music updates that don't really change
|
||||
// what's playing (ex. playlist editing)
|
||||
if (lastSong != queue.currentSong) {
|
||||
// Continuing playback while also possibly doing drastic state updates is
|
||||
// a bad idea, so pause.
|
||||
internalPlayer.loadSong(queue.currentSong, false)
|
||||
if (queue.currentSong != null) {
|
||||
// Internal player may have reloaded the media item, re-seek to the previous
|
||||
// position
|
||||
seekTo(savedState.positionMs)
|
||||
}
|
||||
}
|
||||
isInitialized = true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user