mirror of
https://gitlab.com/ultrasonic/ultrasonic.git
synced 2025-06-08 03:22:10 +03:00
Small fixes for shuffle
This commit is contained in:
parent
3de3844e75
commit
c04f90a6ac
@ -927,7 +927,8 @@ class PlayerFragment :
|
|||||||
// Swipe to delete from playlist
|
// Swipe to delete from playlist
|
||||||
@SuppressLint("NotifyDataSetChanged")
|
@SuppressLint("NotifyDataSetChanged")
|
||||||
override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {
|
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)
|
val item = mediaPlayerManager.getMediaItemAt(pos)
|
||||||
|
|
||||||
// Remove the item from the list quickly
|
// 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.
|
* 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.
|
* @param searchClosure Determines the condition which the searched for window needs to match.
|
||||||
* @return the index of the window that satisfies the search condition,
|
* @return the index of the window that satisfies the search condition,
|
||||||
* or [C.INDEX_UNSET] if not found.
|
* 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!!
|
val timeline = controller?.currentTimeline!!
|
||||||
var windowIndex = timeline.getFirstWindowIndex(true)
|
var windowIndex = timeline.getFirstWindowIndex(true)
|
||||||
var count = 0
|
var count = 0
|
||||||
|
|
||||||
while (windowIndex != C.INDEX_UNSET) {
|
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++
|
count++
|
||||||
windowIndex = timeline.getNextWindowIndex(
|
windowIndex = timeline.getNextWindowIndex(
|
||||||
windowIndex, REPEAT_MODE_OFF, true
|
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.
|
* @return The index of the item in the shuffled timeline, or [C.INDEX_UNSET] if not found.
|
||||||
*/
|
*/
|
||||||
fun getShuffledIndexOf(searchPosition: Int): Int {
|
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.
|
* @return the index of the item in the unshuffled timeline, or [C.INDEX_UNSET] if not found.
|
||||||
*/
|
*/
|
||||||
fun getUnshuffledIndexOf(shufflePosition: Int): Int {
|
fun getUnshuffledIndexOf(shufflePosition: Int): Int {
|
||||||
return getWindowIndexWhere { count, _ -> count == shufflePosition }
|
return getWindowIndexWhere(true) {
|
||||||
|
count, _ ->
|
||||||
|
count == shufflePosition
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val mediaItemCount: Int
|
val mediaItemCount: Int
|
||||||
|
Loading…
x
Reference in New Issue
Block a user