fixed wrong shuffle flag

This commit is contained in:
zelva 2022-09-03 13:18:12 +03:00 committed by TobiGr
parent b41f52e5d6
commit deed486159
1 changed files with 19 additions and 12 deletions

View File

@ -77,19 +77,21 @@ public abstract class PlayQueue implements Serializable {
* Also starts a self reporter for logging if debug mode is enabled. * Also starts a self reporter for logging if debug mode is enabled.
* </p> * </p>
*/ */
public synchronized void init() { // todo: cas mechanics public synchronized void init() {
BehaviorSubject<PlayQueueEvent> b = BehaviorSubject.create(); if (broadcastReceiver == null || eventBroadcast == null) {
BehaviorSubject<PlayQueueEvent> b = BehaviorSubject.create();
broadcastReceiver = b.toFlowable(BackpressureStrategy.BUFFER) broadcastReceiver = b.toFlowable(BackpressureStrategy.BUFFER)
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.startWithItem(new InitEvent()); .startWithItem(new InitEvent());
eventBroadcast = b; eventBroadcast = b;
}
} }
/** /**
* Dispose the play queue by stopping all message buses. * Dispose the play queue by stopping all message buses.
*/ */
public synchronized void dispose() { // todo: cas mechanics public synchronized void dispose() {
if (eventBroadcast != null) { if (eventBroadcast != null) {
eventBroadcast.onComplete(); eventBroadcast.onComplete();
} }
@ -447,9 +449,9 @@ public abstract class PlayQueue implements Serializable {
// Create a backup if it doesn't already exist // Create a backup if it doesn't already exist
// Note: The backup-list has to be created at all cost (even when size <= 2). // Note: The backup-list has to be created at all cost (even when size <= 2).
// Otherwise it's not possible to enter shuffle-mode! // Otherwise it's not possible to enter shuffle-mode!
if (backup == null) {
backup = new ArrayList<>(streams); List<PlayQueueItem> copy = backup == null ? new ArrayList<>(streams) : null;
}
// Can't shuffle a list that's empty or only has one element // Can't shuffle a list that's empty or only has one element
if (size() <= 2) { if (size() <= 2) {
return; return;
@ -467,6 +469,9 @@ public abstract class PlayQueue implements Serializable {
history.add(currentItem); history.add(currentItem);
if (copy != null)
backup = copy;
broadcast(new ReorderEvent(originalIndex, 0)); broadcast(new ReorderEvent(originalIndex, 0));
} }
@ -488,6 +493,7 @@ public abstract class PlayQueue implements Serializable {
final PlayQueueItem current = getItem(originIndex); final PlayQueueItem current = getItem(originIndex);
streams = backup; streams = backup;
// storeStoreFence
backup = null; backup = null;
final int newIndex = streams.indexOf(current); final int newIndex = streams.indexOf(current);
@ -535,10 +541,11 @@ public abstract class PlayQueue implements Serializable {
return false; return false;
} }
synchronized (this) { synchronized (this) {
if (size() != other.size()) { final int size = size();
if (size != other.size()) {
return false; return false;
} }
for (int i = 0; i < size(); i++) { for (int i = 0; i < size; i++) {
final PlayQueueItem stream = streams.get(i); final PlayQueueItem stream = streams.get(i);
final PlayQueueItem otherStream = other.streams.get(i); final PlayQueueItem otherStream = other.streams.get(i);
// Check is based on serviceId and URL // Check is based on serviceId and URL