Skip to content

Commit bdd16e0

Browse files
committed
Add comments describing the purpose of the markAsWatched method
1 parent 4c63281 commit bdd16e0

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

app/src/main/java/org/schabi/newpipe/local/history/HistoryRecordManager.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.schabi.newpipe.R;
2929
import org.schabi.newpipe.database.AppDatabase;
3030
import org.schabi.newpipe.database.LocalItem;
31+
import org.schabi.newpipe.database.feed.dao.FeedDAO;
3132
import org.schabi.newpipe.database.history.dao.SearchHistoryDAO;
3233
import org.schabi.newpipe.database.history.dao.StreamHistoryDAO;
3334
import org.schabi.newpipe.database.history.model.SearchHistoryEntry;
@@ -43,6 +44,7 @@
4344
import org.schabi.newpipe.extractor.InfoItem;
4445
import org.schabi.newpipe.extractor.stream.StreamInfo;
4546
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
47+
import org.schabi.newpipe.local.feed.FeedViewModel;
4648
import org.schabi.newpipe.player.playqueue.PlayQueueItem;
4749
import org.schabi.newpipe.util.ExtractorHelper;
4850

@@ -83,6 +85,15 @@ public HistoryRecordManager(final Context context) {
8385
// Watch History
8486
///////////////////////////////////////////////////////
8587

88+
/**
89+
* Marks a stream item as watched such that it is hidden from the feed if watched videos are
90+
* hidden. Adds a history entry and updates the stream progress to 100%.
91+
*
92+
* @see FeedDAO#getLiveOrNotPlayedStreams
93+
* @see FeedViewModel#togglePlayedItems
94+
* @param info the item to mark as watched
95+
* @return a Maybe containing the ID of the item if successful
96+
*/
8697
public Maybe<Long> markAsWatched(final StreamInfoItem info) {
8798
if (!isStreamHistoryEnabled()) {
8899
return Maybe.empty();
@@ -93,6 +104,7 @@ public Maybe<Long> markAsWatched(final StreamInfoItem info) {
93104
final long streamId = streamTable.upsert(new StreamEntity(info));
94105

95106
long duration = info.getDuration();
107+
// Duration will not exist if the item was loaded with fast mode, so fetch it if empty
96108
if (duration < 0) {
97109
duration = ExtractorHelper.getStreamInfo(
98110
info.getServiceId(),
@@ -103,6 +115,7 @@ public Maybe<Long> markAsWatched(final StreamInfoItem info) {
103115
.getDuration();
104116
}
105117

118+
// Update the stream progress to the full duration of the video
106119
final List<StreamStateEntity> states = streamStateTable.getState(streamId)
107120
.blockingFirst();
108121
if (!states.isEmpty()) {
@@ -117,6 +130,7 @@ public Maybe<Long> markAsWatched(final StreamInfoItem info) {
117130
streamStateTable.insert(entity);
118131
}
119132

133+
// Add a history entry
120134
final StreamHistoryEntity latestEntry = streamHistoryTable.getLatestEntry(streamId);
121135
if (latestEntry != null) {
122136
streamHistoryTable.delete(latestEntry);

0 commit comments

Comments
 (0)