2828import org .schabi .newpipe .R ;
2929import org .schabi .newpipe .database .AppDatabase ;
3030import org .schabi .newpipe .database .LocalItem ;
31+ import org .schabi .newpipe .database .feed .dao .FeedDAO ;
3132import org .schabi .newpipe .database .history .dao .SearchHistoryDAO ;
3233import org .schabi .newpipe .database .history .dao .StreamHistoryDAO ;
3334import org .schabi .newpipe .database .history .model .SearchHistoryEntry ;
4344import org .schabi .newpipe .extractor .InfoItem ;
4445import org .schabi .newpipe .extractor .stream .StreamInfo ;
4546import org .schabi .newpipe .extractor .stream .StreamInfoItem ;
47+ import org .schabi .newpipe .local .feed .FeedViewModel ;
4648import org .schabi .newpipe .player .playqueue .PlayQueueItem ;
4749import 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