Refresh queue after show filename config is changed

This commit is contained in:
Naveen 2023-08-20 23:50:39 +05:30
parent 05495a58f6
commit 72316119ec
No known key found for this signature in database
GPG key ID: 0E155DAD31671DA3
5 changed files with 21 additions and 24 deletions

View file

@ -113,9 +113,7 @@ class SettingsActivity : SimpleControllerActivity() {
RadioGroupDialog(this@SettingsActivity, items, config.showFilename) { RadioGroupDialog(this@SettingsActivity, items, config.showFilename) {
config.showFilename = it as Int config.showFilename = it as Int
settings_show_filename.text = getReplaceTitleText() settings_show_filename.text = getReplaceTitleText()
withPlayer { refreshQueueAndTracks()
TODO("Force refresh queue.")
}
} }
} }
} }

View file

@ -143,24 +143,23 @@ abstract class SimpleControllerActivity : SimpleActivity(), Player.Listener {
} }
} }
fun refreshAfterEdit(track: Track) { fun refreshQueueAndTracks(trackToUpdate: Track? = null) {
withPlayer { ensureBackgroundThread {
val currentIndex = currentMediaItemIndex val queuedTracks = audioHelper.getAllQueuedTracks()
val currentPosition = currentPosition withPlayer {
val currentMediaItems = currentMediaItems // it's not yet directly possible to update metadata without interrupting the playback: https://github.com/androidx/media/issues/33
ensureBackgroundThread { if (trackToUpdate == null || currentMediaItem.isSameMedia(trackToUpdate)) {
val queuedTracks = audioHelper.getAllQueuedTracks() val wasPlaying = isReallyPlaying
val queuedMediaItems = queuedTracks.toMediaItems() prepareUsingTracks(queuedTracks, currentMediaItemIndex, currentPosition) { success ->
runOnPlayerThread { if (success && wasPlaying) {
if (currentMediaItem.isSameMedia(track)) { play()
// it's not yet directly possible to update metadata without interrupting the playback: https://github.com/androidx/media/issues/33 }
val startIndex = maxOf(queuedMediaItems.indexOfTrack(track), 0) }
prepareAndPlay(queuedTracks, startIndex, currentPosition, startActivity = false) } else {
} else if (currentMediaItems.indexOfTrack(track) != -1) { val trackIndex = currentMediaItems.indexOfTrack(trackToUpdate)
removeMediaItems(0, currentMediaItemIndex - 1) if (trackIndex > 0) {
removeMediaItems(currentMediaItemIndex + 1, currentMediaItems.lastIndex) removeMediaItem(trackIndex)
addMediaItems(queuedMediaItems.subList(0, currentIndex)) addMediaItem(trackIndex, trackToUpdate.toMediaItem())
addMediaItems(queuedMediaItems.subList(currentIndex + 1, queuedMediaItems.lastIndex))
} }
} }
} }

View file

@ -202,7 +202,7 @@ class AlbumsTracksAdapter(
finishActMode() finishActMode()
} }
ctx.refreshAfterEdit(track) ctx.refreshQueueAndTracks(track)
} }
} }
} }

View file

@ -226,7 +226,7 @@ class TracksAdapter(
notifyItemChanged(trackIndex) notifyItemChanged(trackIndex)
finishActMode() finishActMode()
ctx.refreshAfterEdit(track) ctx.refreshQueueAndTracks(track)
} }
} }
} }

View file

@ -196,7 +196,7 @@ class TracksHeaderAdapter(activity: SimpleActivity, items: ArrayList<ListItem>,
finishActMode() finishActMode()
} }
ctx.refreshAfterEdit(track) ctx.refreshQueueAndTracks(track)
} }
} }
} }