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) {
config.showFilename = it as Int
settings_show_filename.text = getReplaceTitleText()
withPlayer {
TODO("Force refresh queue.")
}
refreshQueueAndTracks()
}
}
}

View file

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

View file

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

View file

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

View file

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