kopia lustrzana https://github.com/TeamNewPipe/NewPipe
Add comments describing the purpose of the markAsWatched method
rodzic
4c632810ec
commit
bdd16e06e0
|
@ -28,6 +28,7 @@ import org.schabi.newpipe.NewPipeDatabase;
|
||||||
import org.schabi.newpipe.R;
|
import org.schabi.newpipe.R;
|
||||||
import org.schabi.newpipe.database.AppDatabase;
|
import org.schabi.newpipe.database.AppDatabase;
|
||||||
import org.schabi.newpipe.database.LocalItem;
|
import org.schabi.newpipe.database.LocalItem;
|
||||||
|
import org.schabi.newpipe.database.feed.dao.FeedDAO;
|
||||||
import org.schabi.newpipe.database.history.dao.SearchHistoryDAO;
|
import org.schabi.newpipe.database.history.dao.SearchHistoryDAO;
|
||||||
import org.schabi.newpipe.database.history.dao.StreamHistoryDAO;
|
import org.schabi.newpipe.database.history.dao.StreamHistoryDAO;
|
||||||
import org.schabi.newpipe.database.history.model.SearchHistoryEntry;
|
import org.schabi.newpipe.database.history.model.SearchHistoryEntry;
|
||||||
|
@ -43,6 +44,7 @@ import org.schabi.newpipe.database.stream.model.StreamStateEntity;
|
||||||
import org.schabi.newpipe.extractor.InfoItem;
|
import org.schabi.newpipe.extractor.InfoItem;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
||||||
|
import org.schabi.newpipe.local.feed.FeedViewModel;
|
||||||
import org.schabi.newpipe.player.playqueue.PlayQueueItem;
|
import org.schabi.newpipe.player.playqueue.PlayQueueItem;
|
||||||
import org.schabi.newpipe.util.ExtractorHelper;
|
import org.schabi.newpipe.util.ExtractorHelper;
|
||||||
|
|
||||||
|
@ -83,6 +85,15 @@ public class HistoryRecordManager {
|
||||||
// Watch History
|
// Watch History
|
||||||
///////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marks a stream item as watched such that it is hidden from the feed if watched videos are
|
||||||
|
* hidden. Adds a history entry and updates the stream progress to 100%.
|
||||||
|
*
|
||||||
|
* @see FeedDAO#getLiveOrNotPlayedStreams
|
||||||
|
* @see FeedViewModel#togglePlayedItems
|
||||||
|
* @param info the item to mark as watched
|
||||||
|
* @return a Maybe containing the ID of the item if successful
|
||||||
|
*/
|
||||||
public Maybe<Long> markAsWatched(final StreamInfoItem info) {
|
public Maybe<Long> markAsWatched(final StreamInfoItem info) {
|
||||||
if (!isStreamHistoryEnabled()) {
|
if (!isStreamHistoryEnabled()) {
|
||||||
return Maybe.empty();
|
return Maybe.empty();
|
||||||
|
@ -93,6 +104,7 @@ public class HistoryRecordManager {
|
||||||
final long streamId = streamTable.upsert(new StreamEntity(info));
|
final long streamId = streamTable.upsert(new StreamEntity(info));
|
||||||
|
|
||||||
long duration = info.getDuration();
|
long duration = info.getDuration();
|
||||||
|
// Duration will not exist if the item was loaded with fast mode, so fetch it if empty
|
||||||
if (duration < 0) {
|
if (duration < 0) {
|
||||||
duration = ExtractorHelper.getStreamInfo(
|
duration = ExtractorHelper.getStreamInfo(
|
||||||
info.getServiceId(),
|
info.getServiceId(),
|
||||||
|
@ -103,6 +115,7 @@ public class HistoryRecordManager {
|
||||||
.getDuration();
|
.getDuration();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update the stream progress to the full duration of the video
|
||||||
final List<StreamStateEntity> states = streamStateTable.getState(streamId)
|
final List<StreamStateEntity> states = streamStateTable.getState(streamId)
|
||||||
.blockingFirst();
|
.blockingFirst();
|
||||||
if (!states.isEmpty()) {
|
if (!states.isEmpty()) {
|
||||||
|
@ -117,6 +130,7 @@ public class HistoryRecordManager {
|
||||||
streamStateTable.insert(entity);
|
streamStateTable.insert(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add a history entry
|
||||||
final StreamHistoryEntity latestEntry = streamHistoryTable.getLatestEntry(streamId);
|
final StreamHistoryEntity latestEntry = streamHistoryTable.getLatestEntry(streamId);
|
||||||
if (latestEntry != null) {
|
if (latestEntry != null) {
|
||||||
streamHistoryTable.delete(latestEntry);
|
streamHistoryTable.delete(latestEntry);
|
||||||
|
|
Ładowanie…
Reference in New Issue