Fix more queue bugs
Fix bugs with QueueAdapter where removing the last item from the user queue or the next queue would cause weird behavior or a crash.
This commit is contained in:
@@ -40,7 +40,7 @@ fun NotificationManager.createMediaNotification(
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
val channel = NotificationChannel(
|
||||
NotificationUtils.CHANNEL_ID,
|
||||
context.getString(R.string.label_notification_playback),
|
||||
context.getString(R.string.label_channel),
|
||||
NotificationManager.IMPORTANCE_DEFAULT
|
||||
)
|
||||
|
||||
|
||||
@@ -81,6 +81,19 @@ class QueueAdapter(
|
||||
data.removeAt(adapterIndex)
|
||||
|
||||
notifyItemRemoved(adapterIndex)
|
||||
|
||||
// Check for two things:
|
||||
// If the data from the next queue is now entirely empty [Signified by a header at the end]
|
||||
// Or if the data from the last queue is now entirely empty [Signified by there being 2 headers with no items in between]
|
||||
if (data[data.lastIndex] is Header) {
|
||||
val lastIndex = data.lastIndex
|
||||
|
||||
data.removeAt(lastIndex)
|
||||
notifyItemRemoved(lastIndex)
|
||||
} else if (data.lastIndex >= 1 && data[0] is Header && data[1] is Header) {
|
||||
data.removeAt(0)
|
||||
notifyItemRemoved(0)
|
||||
}
|
||||
}
|
||||
|
||||
// Generic ViewHolder for a queue item
|
||||
|
||||
@@ -302,8 +302,6 @@ class PlaybackStateManager private constructor() {
|
||||
|
||||
mUserQueue.removeAt(index)
|
||||
|
||||
Log.d(this::class.simpleName, mUserQueue.toString())
|
||||
|
||||
forceUserQueueUpdate()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user