#66: Fixed behavior on queue shuffling, clearing and end of queue on no-repeat.
This commit is contained in:
parent
50c8dac297
commit
b87766dad2
|
@ -6,6 +6,7 @@ import android.graphics.*
|
|||
import android.graphics.drawable.ColorDrawable
|
||||
import android.view.*
|
||||
import androidx.appcompat.widget.PopupMenu
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.recyclerview.widget.ItemTouchHelper
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.apognu.otter.R
|
||||
|
@ -61,12 +62,12 @@ class TracksAdapter(private val context: Context?, private val favoriteListener:
|
|||
holder.artist.text = track.artist.name
|
||||
|
||||
context?.let {
|
||||
holder.itemView.background = context.getDrawable(R.drawable.ripple)
|
||||
holder.itemView.background = ContextCompat.getDrawable(context, R.drawable.ripple)
|
||||
}
|
||||
|
||||
if (track == currentTrack || track.current) {
|
||||
context?.let {
|
||||
holder.itemView.background = context.getDrawable(R.drawable.current)
|
||||
holder.itemView.background = ContextCompat.getDrawable(context, R.drawable.current)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -104,6 +104,10 @@ class MediaControlsManager(val context: Service, private val scope: CoroutineSco
|
|||
}
|
||||
}
|
||||
|
||||
fun remove() {
|
||||
NotificationManagerCompat.from(context).cancel(AppContext.NOTIFICATION_MEDIA_CONTROL)
|
||||
}
|
||||
|
||||
private fun action(icon: Int, title: String, id: Long): NotificationCompat.Action {
|
||||
return MediaButtonReceiver.buildMediaButtonPendingIntent(context, id).run {
|
||||
NotificationCompat.Action.Builder(icon, title, this).build()
|
||||
|
|
|
@ -185,7 +185,10 @@ class PlayerService : Service() {
|
|||
is Command.PreviousTrack -> skipToPreviousTrack()
|
||||
is Command.Seek -> seek(command.progress)
|
||||
|
||||
is Command.ClearQueue -> queue.clear()
|
||||
is Command.ClearQueue -> {
|
||||
queue.clear()
|
||||
player.stop()
|
||||
}
|
||||
is Command.ShuffleQueue -> queue.shuffle()
|
||||
|
||||
is Command.PlayRadio -> {
|
||||
|
@ -389,7 +392,20 @@ class PlayerService : Service() {
|
|||
when (playbackState) {
|
||||
Player.STATE_READY -> mediaControlsManager.updateNotification(queue.current(), true)
|
||||
Player.STATE_BUFFERING -> EventBus.send(Event.Buffering(true))
|
||||
Player.STATE_ENDED -> EventBus.send(Event.PlaybackStopped)
|
||||
Player.STATE_ENDED -> {
|
||||
setPlaybackState(false)
|
||||
|
||||
queue.current = 0
|
||||
player.seekTo(0, C.TIME_UNSET)
|
||||
|
||||
ProgressBus.send(0, 0, 0)
|
||||
}
|
||||
|
||||
Player.STATE_IDLE -> {
|
||||
setPlaybackState(false)
|
||||
|
||||
return EventBus.send(Event.PlaybackStopped)
|
||||
}
|
||||
}
|
||||
|
||||
if (playbackState != Player.STATE_BUFFERING) EventBus.send(Event.Buffering(false))
|
||||
|
@ -398,13 +414,14 @@ class PlayerService : Service() {
|
|||
false -> {
|
||||
EventBus.send(Event.Buffering(false))
|
||||
|
||||
if (playbackState == Player.STATE_READY) {
|
||||
mediaControlsManager.updateNotification(queue.current(), false)
|
||||
Build.VERSION_CODES.N.onApi(
|
||||
{ stopForeground(STOP_FOREGROUND_DETACH) },
|
||||
{ stopForeground(false) }
|
||||
)
|
||||
|
||||
Build.VERSION_CODES.N.onApi(
|
||||
{ stopForeground(STOP_FOREGROUND_DETACH) },
|
||||
{ stopForeground(false) }
|
||||
)
|
||||
when (playbackState) {
|
||||
Player.STATE_READY -> mediaControlsManager.updateNotification(queue.current(), false)
|
||||
Player.STATE_IDLE -> mediaControlsManager.remove()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -178,26 +178,34 @@ class QueueManager(val context: Context) {
|
|||
metadata = mutableListOf()
|
||||
datasources.clear()
|
||||
current = -1
|
||||
|
||||
persist()
|
||||
}
|
||||
|
||||
fun shuffle() {
|
||||
if (metadata.size == 0) return
|
||||
if (metadata.size < 2) return
|
||||
|
||||
if (current == -1) {
|
||||
replace(metadata.shuffled())
|
||||
} else {
|
||||
val track = metadata[current]
|
||||
val shuffled = metadata.filter { it != track }.shuffled()
|
||||
move(current, 0)
|
||||
current = 0
|
||||
|
||||
shuffled.forEach {
|
||||
metadata.remove(it)
|
||||
val shuffled =
|
||||
metadata
|
||||
.drop(1)
|
||||
.shuffled()
|
||||
|
||||
while (metadata.size > 1) {
|
||||
datasources.removeMediaSource(metadata.size - 1)
|
||||
metadata.removeAt(metadata.size - 1)
|
||||
}
|
||||
|
||||
append(shuffled)
|
||||
|
||||
current = 0
|
||||
}
|
||||
|
||||
persist()
|
||||
|
||||
EventBus.send(Event.QueueChanged)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue