Search in sources :

Example 1 with MoveEvent

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));
}
Also used : MoveEvent(org.schabi.newpipe.playlist.events.MoveEvent)

Example 2 with MoveEvent

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);
}
Also used : ReorderEvent(org.schabi.newpipe.playlist.events.ReorderEvent) RemoveEvent(org.schabi.newpipe.playlist.events.RemoveEvent) MoveEvent(org.schabi.newpipe.playlist.events.MoveEvent)

Example 3 with MoveEvent

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;
    }
}
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

MoveEvent (org.schabi.newpipe.playlist.events.MoveEvent)3 RemoveEvent (org.schabi.newpipe.playlist.events.RemoveEvent)2 AppendEvent (org.schabi.newpipe.playlist.events.AppendEvent)1 ErrorEvent (org.schabi.newpipe.playlist.events.ErrorEvent)1 ReorderEvent (org.schabi.newpipe.playlist.events.ReorderEvent)1 SelectEvent (org.schabi.newpipe.playlist.events.SelectEvent)1