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 addToPlaylist(item: String)
fun movePlaylistItem(fromIndex: Int, toIndex: Int)
fun removePlaylistItem(index: Int)
fun removePlaylistItem(uniqueId: Long)
fun playStream(item: String, playMode: PlayMode)
fun selectChapter(index: Int)
fun playStream(item: String, streamVariant: String, playMode: PlayMode)
@ -338,8 +338,14 @@ class NewPlayerImpl(
internalPlayer.moveMediaItem(fromIndex, toIndex)
}
override fun removePlaylistItem(index: Int) {
internalPlayer.removeMediaItem(index)
override fun removePlaylistItem(uniqueId: Long) {
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) {

View File

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

View File

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

View File

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

View File

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