Search in sources :

Example 1 with AppendEvent

use of org.schabi.newpipe.playlist.events.AppendEvent in project NewPipe by TeamNewPipe.

the class PlayQueue method append.

/**
 * Appends the given {@link PlayQueueItem}s to the current play queue.
 *
 * If the play queue is shuffled, then append the items to the backup queue as is and
 * append the shuffle items to the play queue.
 *
 * Will emit a {@link AppendEvent} on any given context.
 */
public synchronized void append(@NonNull final List<PlayQueueItem> items) {
    List<PlayQueueItem> itemList = new ArrayList<>(items);
    if (isShuffled()) {
        backup.addAll(itemList);
        Collections.shuffle(itemList);
    }
    streams.addAll(itemList);
    broadcast(new AppendEvent(itemList.size()));
}
Also used : ArrayList(java.util.ArrayList) AppendEvent(org.schabi.newpipe.playlist.events.AppendEvent)

Example 2 with AppendEvent

use of org.schabi.newpipe.playlist.events.AppendEvent 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;
    }
}
Also used : ErrorEvent(org.schabi.newpipe.playlist.events.ErrorEvent) RemoveEvent(org.schabi.newpipe.playlist.events.RemoveEvent) SelectEvent(org.schabi.newpipe.playlist.events.SelectEvent) MoveEvent(org.schabi.newpipe.playlist.events.MoveEvent) AppendEvent(org.schabi.newpipe.playlist.events.AppendEvent)

Aggregations

AppendEvent (org.schabi.newpipe.playlist.events.AppendEvent)2 ArrayList (java.util.ArrayList)1 ErrorEvent (org.schabi.newpipe.playlist.events.ErrorEvent)1 MoveEvent (org.schabi.newpipe.playlist.events.MoveEvent)1 RemoveEvent (org.schabi.newpipe.playlist.events.RemoveEvent)1 SelectEvent (org.schabi.newpipe.playlist.events.SelectEvent)1