mirror of
https://gitlab.com/ultrasonic/ultrasonic.git
synced 2025-04-15 08:50:35 +03:00
Merge branch 'shuffle' into 'develop'
Small fixes for shuffle Closes #1244 and #1248 See merge request ultrasonic/ultrasonic!1044
This commit is contained in:
commit
024b2e8edb
@ -927,7 +927,8 @@ class PlayerFragment :
|
||||
// Swipe to delete from playlist
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {
|
||||
val pos = viewHolder.bindingAdapterPosition
|
||||
val viewPos = viewHolder.bindingAdapterPosition
|
||||
val pos = mediaPlayerManager.getUnshuffledIndexOf(viewPos)
|
||||
val item = mediaPlayerManager.getMediaItemAt(pos)
|
||||
|
||||
// Remove the item from the list quickly
|
||||
|
@ -720,16 +720,25 @@ class MediaPlayerManager(
|
||||
/**
|
||||
* Loops over the timeline windows to find the entry which matches the given closure.
|
||||
*
|
||||
* @param returnWindow Determines which of the two indexes of a match to return:
|
||||
* True for the position in the playlist, False for position in the play order.
|
||||
* @param searchClosure Determines the condition which the searched for window needs to match.
|
||||
* @return the index of the window that satisfies the search condition,
|
||||
* or [C.INDEX_UNSET] if not found.
|
||||
*/
|
||||
private fun getWindowIndexWhere(searchClosure: (Int, Int) -> Boolean): Int {
|
||||
@Suppress("KotlinConstantConditions")
|
||||
private fun getWindowIndexWhere(
|
||||
returnWindow: Boolean,
|
||||
searchClosure: (Int, Int) -> Boolean
|
||||
): Int {
|
||||
val timeline = controller?.currentTimeline!!
|
||||
var windowIndex = timeline.getFirstWindowIndex(true)
|
||||
var count = 0
|
||||
|
||||
while (windowIndex != C.INDEX_UNSET) {
|
||||
if (searchClosure(count, windowIndex)) return count
|
||||
val match = searchClosure(count, windowIndex)
|
||||
if (match && returnWindow) return windowIndex
|
||||
if (match && !returnWindow) return count
|
||||
count++
|
||||
windowIndex = timeline.getNextWindowIndex(
|
||||
windowIndex, REPEAT_MODE_OFF, true
|
||||
@ -748,7 +757,10 @@ class MediaPlayerManager(
|
||||
* @return The index of the item in the shuffled timeline, or [C.INDEX_UNSET] if not found.
|
||||
*/
|
||||
fun getShuffledIndexOf(searchPosition: Int): Int {
|
||||
return getWindowIndexWhere { _, windowIndex -> windowIndex == searchPosition }
|
||||
return getWindowIndexWhere(false) {
|
||||
_, windowIndex ->
|
||||
windowIndex == searchPosition
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -760,7 +772,10 @@ class MediaPlayerManager(
|
||||
* @return the index of the item in the unshuffled timeline, or [C.INDEX_UNSET] if not found.
|
||||
*/
|
||||
fun getUnshuffledIndexOf(shufflePosition: Int): Int {
|
||||
return getWindowIndexWhere { count, _ -> count == shufflePosition }
|
||||
return getWindowIndexWhere(true) {
|
||||
count, _ ->
|
||||
count == shufflePosition
|
||||
}
|
||||
}
|
||||
|
||||
val mediaItemCount: Int
|
||||
|
Loading…
x
Reference in New Issue
Block a user