make playlist item deletion more reliable

This commit is contained in:
Christian Schabesberger 2024-09-06 21:59:55 +02:00
parent 33b0360507
commit f5d3c33086
5 changed files with 15 additions and 9 deletions

View File

@ -96,7 +96,7 @@ interface NewPlayer {
fun pause() fun pause()
fun addToPlaylist(item: String) fun addToPlaylist(item: String)
fun movePlaylistItem(fromIndex: Int, toIndex: Int) fun movePlaylistItem(fromIndex: Int, toIndex: Int)
fun removePlaylistItem(index: Int) fun removePlaylistItem(uniqueId: Long)
fun playStream(item: String, playMode: PlayMode) fun playStream(item: String, playMode: PlayMode)
fun selectChapter(index: Int) fun selectChapter(index: Int)
fun playStream(item: String, streamVariant: String, playMode: PlayMode) fun playStream(item: String, streamVariant: String, playMode: PlayMode)
@ -338,8 +338,14 @@ class NewPlayerImpl(
internalPlayer.moveMediaItem(fromIndex, toIndex) internalPlayer.moveMediaItem(fromIndex, toIndex)
} }
override fun removePlaylistItem(index: Int) { override fun removePlaylistItem(uniqueId: Long) {
internalPlayer.removeMediaItem(index) for(i in 0..<internalPlayer.mediaItemCount) {
val id = internalPlayer.getMediaItemAt(i).mediaId.toLong()
if(id == uniqueId) {
internalPlayer.removeMediaItem(i)
break
}
}
} }
override fun playStream(item: String, playMode: PlayMode) { override fun playStream(item: String, playMode: PlayMode) {

View File

@ -62,7 +62,7 @@ interface VideoPlayerViewModel {
fun toggleShuffle() fun toggleShuffle()
fun onStorePlaylist() fun onStorePlaylist()
fun movePlaylistItem(from: Int, to: Int) fun movePlaylistItem(from: Int, to: Int)
fun removePlaylistItem(index: Int) fun removePlaylistItem(uniqueId: Long)
fun onStreamItemDragFinished() fun onStreamItemDragFinished()
fun dialogVisible(visible: Boolean) fun dialogVisible(visible: Boolean)
} }

View File

@ -543,8 +543,8 @@ class VideoPlayerViewModelImpl @Inject constructor(
} }
} }
override fun removePlaylistItem(index: Int) { override fun removePlaylistItem(uniqueId: Long) {
newPlayer?.removePlaylistItem(index) newPlayer?.removePlaylistItem(uniqueId)
} }

View File

@ -108,8 +108,8 @@ open class VideoPlayerViewModelDummy : VideoPlayerViewModel {
println("dummy impl") println("dummy impl")
} }
override fun removePlaylistItem(index: Int) { override fun removePlaylistItem(uniqueId: Long) {
println("dummy impl") println("dummy impl delete uniqueId: $uniqueId")
} }
override fun onStreamItemDragFinished() { override fun onStreamItemDragFinished() {

View File

@ -159,7 +159,7 @@ fun ReorderableStreamItemsList(
isDragging = isDragging, isDragging = isDragging,
isCurrentlyPlaying = playlistItem.uniqueId == uiState.currentlyPlaying.uniqueId, isCurrentlyPlaying = playlistItem.uniqueId == uiState.currentlyPlaying.uniqueId,
onDelete = { onDelete = {
viewModel.removePlaylistItem(index) viewModel.removePlaylistItem(playlistItem.uniqueId)
} }
) )
} }