Search in sources :

Example 1 with StreamHistoryEntity

use of org.schabi.newpipe.database.history.model.StreamHistoryEntity 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)

Aggregations

Date (java.util.Date)1 StreamHistoryEntity (org.schabi.newpipe.database.history.model.StreamHistoryEntity)1 StreamEntity (org.schabi.newpipe.database.stream.model.StreamEntity)1