use of org.schabi.newpipe.playlist.events.MoveEvent in project NewPipe by TeamNewPipe.
the class PlayQueue method move.
/**
* Moves a queue item at the source index to the target index.
*
* If the item being moved is the currently playing, then the current playing index is set
* to that of the target.
* If the moved item is not the currently playing and moves to an index <b>AFTER</b> the
* current playing index, then the current playing index is decremented.
* Vice versa if the an item after the currently playing is moved <b>BEFORE</b>.
*/
public synchronized void move(final int source, final int target) {
if (source < 0 || target < 0)
return;
if (source >= streams.size() || target >= streams.size())
return;
final int current = getIndex();
if (source == current) {
queueIndex.set(target);
} else if (source < current && target >= current) {
queueIndex.decrementAndGet();
} else if (source > current && target <= current) {
queueIndex.incrementAndGet();
}
streams.add(target, streams.remove(source));
broadcast(new MoveEvent(source, target));
}
use of org.schabi.newpipe.playlist.events.MoveEvent in project NewPipe by TeamNewPipe.
the class MediaSourceManager method onPlayQueueChanged.
private void onPlayQueueChanged(final PlayQueueEvent event) {
if (playQueue.isEmpty() && playQueue.isComplete()) {
playbackListener.onPlaybackShutdown();
return;
}
// Event specific action
switch(event.type()) {
case INIT:
case ERROR:
maybeBlock();
case APPEND:
populateSources();
break;
case SELECT:
maybeRenewCurrentIndex();
break;
case REMOVE:
final RemoveEvent removeEvent = (RemoveEvent) event;
remove(removeEvent.getRemoveIndex());
break;
case MOVE:
final MoveEvent moveEvent = (MoveEvent) event;
move(moveEvent.getFromIndex(), moveEvent.getToIndex());
break;
case REORDER:
// Need to move to ensure the playing index from play queue matches that of
// the source timeline, and then window correction can take care of the rest
final ReorderEvent reorderEvent = (ReorderEvent) event;
move(reorderEvent.getFromSelectedIndex(), reorderEvent.getToSelectedIndex());
break;
case RECOVERY:
default:
break;
}
// Loading and Syncing
switch(event.type()) {
case INIT:
case REORDER:
case ERROR:
case SELECT:
// low frequency, critical events
loadImmediate();
break;
case APPEND:
case REMOVE:
case MOVE:
case RECOVERY:
default:
// high frequency or noncritical events
loadDebounced();
break;
}
if (!isPlayQueueReady()) {
maybeBlock();
playQueue.fetch();
}
playQueueReactor.request(1);
}
use of org.schabi.newpipe.playlist.events.MoveEvent in project NewPipe by TeamNewPipe.
the class PlayQueueAdapter method onPlayQueueChanged.
private void onPlayQueueChanged(final PlayQueueEvent message) {
switch(message.type()) {
case RECOVERY:
// Do nothing.
break;
case SELECT:
final SelectEvent selectEvent = (SelectEvent) message;
notifyItemChanged(selectEvent.getOldIndex());
notifyItemChanged(selectEvent.getNewIndex());
break;
case APPEND:
final AppendEvent appendEvent = (AppendEvent) message;
notifyItemRangeInserted(playQueue.size(), appendEvent.getAmount());
break;
case ERROR:
final ErrorEvent errorEvent = (ErrorEvent) message;
if (!errorEvent.isSkippable()) {
notifyItemRemoved(errorEvent.getErrorIndex());
}
notifyItemChanged(errorEvent.getErrorIndex());
notifyItemChanged(errorEvent.getQueueIndex());
break;
case REMOVE:
final RemoveEvent removeEvent = (RemoveEvent) message;
notifyItemRemoved(removeEvent.getRemoveIndex());
notifyItemChanged(removeEvent.getQueueIndex());
break;
case MOVE:
final MoveEvent moveEvent = (MoveEvent) message;
notifyItemMoved(moveEvent.getFromIndex(), moveEvent.getToIndex());
break;
case INIT:
case REORDER:
default:
notifyDataSetChanged();
break;
}
}
Aggregations