Search in sources :

Example 1 with StreamEntity

use of org.schabi.newpipe.database.stream.model.StreamEntity in project NewPipe by TeamNewPipe.

the class StreamDAO method upsertAll.

@Transaction
public List<Long> upsertAll(List<StreamEntity> streams) {
    silentInsertAllInternal(streams);
    final List<Long> streamIds = new ArrayList<>(streams.size());
    for (StreamEntity stream : streams) {
        final Long streamId = getStreamIdInternal(stream.getServiceId(), stream.getUrl());
        if (streamId == null) {
            throw new IllegalStateException("StreamID cannot be null just after insertion.");
        }
        streamIds.add(streamId);
        stream.setUid(streamId);
    }
    update(streams);
    return streamIds;
}
Also used : ArrayList(java.util.ArrayList) StreamEntity(org.schabi.newpipe.database.stream.model.StreamEntity) PlaylistStreamEntity(org.schabi.newpipe.database.playlist.model.PlaylistStreamEntity) Transaction(android.arch.persistence.room.Transaction)

Example 2 with StreamEntity

use of org.schabi.newpipe.database.stream.model.StreamEntity in project NewPipe by TeamNewPipe.

the class PlaylistAppendDialog method fromStreamInfoItems.

public static PlaylistAppendDialog fromStreamInfoItems(final List<StreamInfoItem> items) {
    PlaylistAppendDialog dialog = new PlaylistAppendDialog();
    List<StreamEntity> entities = new ArrayList<>(items.size());
    for (final StreamInfoItem item : items) {
        entities.add(new StreamEntity(item));
    }
    dialog.setInfo(entities);
    return dialog;
}
Also used : StreamInfoItem(org.schabi.newpipe.extractor.stream.StreamInfoItem) ArrayList(java.util.ArrayList) StreamEntity(org.schabi.newpipe.database.stream.model.StreamEntity)

Example 3 with StreamEntity

use of org.schabi.newpipe.database.stream.model.StreamEntity in project NewPipe by TeamNewPipe.

the class PlaylistAppendDialog method fromPlayQueueItems.

public static PlaylistAppendDialog fromPlayQueueItems(final List<PlayQueueItem> items) {
    PlaylistAppendDialog dialog = new PlaylistAppendDialog();
    List<StreamEntity> entities = new ArrayList<>(items.size());
    for (final PlayQueueItem item : items) {
        entities.add(new StreamEntity(item));
    }
    dialog.setInfo(entities);
    return dialog;
}
Also used : PlayQueueItem(org.schabi.newpipe.playlist.PlayQueueItem) ArrayList(java.util.ArrayList) StreamEntity(org.schabi.newpipe.database.stream.model.StreamEntity)

Example 4 with StreamEntity

use of org.schabi.newpipe.database.stream.model.StreamEntity in project NewPipe by TeamNewPipe.

the class HistoryRecordManager method onViewed.

// /////////////////////////////////////////////////////
// Watch History
// /////////////////////////////////////////////////////
public Maybe<Long> onViewed(final StreamInfo info) {
    if (!isStreamHistoryEnabled())
        return Maybe.empty();
    final Date currentTime = new Date();
    return Maybe.fromCallable(() -> database.runInTransaction(() -> {
        final long streamId = streamTable.upsert(new StreamEntity(info));
        StreamHistoryEntity latestEntry = streamHistoryTable.getLatestEntry();
        if (latestEntry != null && latestEntry.getStreamUid() == streamId) {
            streamHistoryTable.delete(latestEntry);
            latestEntry.setAccessDate(currentTime);
            latestEntry.setRepeatCount(latestEntry.getRepeatCount() + 1);
            return streamHistoryTable.insert(latestEntry);
        } else {
            return streamHistoryTable.insert(new StreamHistoryEntity(streamId, currentTime));
        }
    })).subscribeOn(Schedulers.io());
}
Also used : StreamEntity(org.schabi.newpipe.database.stream.model.StreamEntity) StreamHistoryEntity(org.schabi.newpipe.database.history.model.StreamHistoryEntity) Date(java.util.Date)

Example 5 with StreamEntity

use of org.schabi.newpipe.database.stream.model.StreamEntity in project NewPipe by TeamNewPipe.

the class LocalPlaylistManager method createPlaylist.

public Maybe<List<Long>> createPlaylist(final String name, final List<StreamEntity> streams) {
    // Disallow creation of empty playlists
    if (streams.isEmpty())
        return Maybe.empty();
    final StreamEntity defaultStream = streams.get(0);
    final PlaylistEntity newPlaylist = new PlaylistEntity(name, defaultStream.getThumbnailUrl());
    return Maybe.fromCallable(() -> database.runInTransaction(() -> upsertStreams(playlistTable.insert(newPlaylist), streams, 0))).subscribeOn(Schedulers.io());
}
Also used : PlaylistEntity(org.schabi.newpipe.database.playlist.model.PlaylistEntity) StreamEntity(org.schabi.newpipe.database.stream.model.StreamEntity) PlaylistStreamEntity(org.schabi.newpipe.database.playlist.model.PlaylistStreamEntity)

Aggregations

StreamEntity (org.schabi.newpipe.database.stream.model.StreamEntity)5 ArrayList (java.util.ArrayList)3 PlaylistStreamEntity (org.schabi.newpipe.database.playlist.model.PlaylistStreamEntity)2 Transaction (android.arch.persistence.room.Transaction)1 Date (java.util.Date)1 StreamHistoryEntity (org.schabi.newpipe.database.history.model.StreamHistoryEntity)1 PlaylistEntity (org.schabi.newpipe.database.playlist.model.PlaylistEntity)1 StreamInfoItem (org.schabi.newpipe.extractor.stream.StreamInfoItem)1 PlayQueueItem (org.schabi.newpipe.playlist.PlayQueueItem)1