Skip to content

Commit 9e44053

Browse files
authored
Merge pull request #7160 from nschulzke/mark-as-watched-everywhere
Enable Mark as Watched in all the other playlist fragments.
2 parents 344fbff + dee32c3 commit 9e44053

7 files changed

Lines changed: 51 additions & 20 deletions

File tree

app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,13 @@ protected void showStreamDialog(final StreamInfoItem item) {
378378
if (KoreUtils.shouldShowPlayWithKodi(context, item.getServiceId())) {
379379
entries.add(StreamDialogEntry.play_with_kodi);
380380
}
381+
382+
// show "mark as watched" only when watch history is enabled
383+
if (StreamDialogEntry.shouldAddMarkAsWatched(item.getStreamType(), context)) {
384+
entries.add(
385+
StreamDialogEntry.mark_as_watched
386+
);
387+
}
381388
if (!isNullOrEmpty(item.getUploaderUrl())) {
382389
entries.add(StreamDialogEntry.show_channel_details);
383390
}

app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,12 @@ protected void showStreamDialog(final StreamInfoItem item) {
176176
entries.add(StreamDialogEntry.play_with_kodi);
177177
}
178178

179+
// show "mark as watched" only when watch history is enabled
180+
if (StreamDialogEntry.shouldAddMarkAsWatched(item.getStreamType(), context)) {
181+
entries.add(
182+
StreamDialogEntry.mark_as_watched
183+
);
184+
}
179185
if (!isNullOrEmpty(item.getUploaderUrl())) {
180186
entries.add(StreamDialogEntry.show_channel_details);
181187
}

app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -357,13 +357,7 @@ class FeedFragment : BaseStateFragment<FeedState>() {
357357
}
358358

359359
// show "mark as watched" only when watch history is enabled
360-
val isWatchHistoryEnabled = PreferenceManager
361-
.getDefaultSharedPreferences(context)
362-
.getBoolean(getString(R.string.enable_watch_history_key), false)
363-
if (item.streamType != StreamType.AUDIO_LIVE_STREAM &&
364-
item.streamType != StreamType.LIVE_STREAM &&
365-
isWatchHistoryEnabled
366-
) {
360+
if (StreamDialogEntry.shouldAddMarkAsWatched(item.streamType, context)) {
367361
entries.add(
368362
StreamDialogEntry.mark_as_watched
369363
)

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

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -120,19 +120,11 @@ public Maybe<Long> markAsWatched(final StreamInfoItem info) {
120120
}
121121

122122
// Update the stream progress to the full duration of the video
123-
final List<StreamStateEntity> states = streamStateTable.getState(streamId)
124-
.blockingFirst();
125-
if (!states.isEmpty()) {
126-
final StreamStateEntity entity = states.get(0);
127-
entity.setProgressMillis(duration * 1000);
128-
streamStateTable.update(entity);
129-
} else {
130-
final StreamStateEntity entity = new StreamStateEntity(
131-
streamId,
132-
duration * 1000
133-
);
134-
streamStateTable.insert(entity);
135-
}
123+
final StreamStateEntity entity = new StreamStateEntity(
124+
streamId,
125+
duration * 1000
126+
);
127+
streamStateTable.upsert(entity);
136128

137129
// Add a history entry
138130
final StreamHistoryEntity latestEntry = streamHistoryTable.getLatestEntry(streamId);

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,16 @@ private void showStreamDialog(final StreamStatisticsEntry item) {
366366
if (KoreUtils.shouldShowPlayWithKodi(context, infoItem.getServiceId())) {
367367
entries.add(StreamDialogEntry.play_with_kodi);
368368
}
369+
370+
// show "mark as watched" only when watch history is enabled
371+
if (StreamDialogEntry.shouldAddMarkAsWatched(
372+
item.getStreamEntity().getStreamType(),
373+
context
374+
)) {
375+
entries.add(
376+
StreamDialogEntry.mark_as_watched
377+
);
378+
}
369379
entries.add(StreamDialogEntry.show_channel_details);
370380

371381
StreamDialogEntry.setEnabledEntries(entries);

app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,16 @@ protected void showStreamItemDialog(final PlaylistStreamEntry item) {
782782
if (KoreUtils.shouldShowPlayWithKodi(context, infoItem.getServiceId())) {
783783
entries.add(StreamDialogEntry.play_with_kodi);
784784
}
785+
786+
// show "mark as watched" only when watch history is enabled
787+
if (StreamDialogEntry.shouldAddMarkAsWatched(
788+
item.getStreamEntity().getStreamType(),
789+
context
790+
)) {
791+
entries.add(
792+
StreamDialogEntry.mark_as_watched
793+
);
794+
}
785795
entries.add(StreamDialogEntry.show_channel_details);
786796

787797
StreamDialogEntry.setEnabledEntries(entries);

app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
import android.widget.Toast;
66

77
import androidx.fragment.app.Fragment;
8+
import androidx.preference.PreferenceManager;
89

910
import org.schabi.newpipe.NewPipeDatabase;
1011
import org.schabi.newpipe.R;
1112
import org.schabi.newpipe.database.stream.model.StreamEntity;
1213
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
14+
import org.schabi.newpipe.extractor.stream.StreamType;
1315
import org.schabi.newpipe.local.dialog.PlaylistAppendDialog;
1416
import org.schabi.newpipe.local.dialog.PlaylistDialog;
1517
import org.schabi.newpipe.local.history.HistoryRecordManager;
@@ -194,6 +196,16 @@ public interface StreamDialogEntryAction {
194196
void onClick(Fragment fragment, StreamInfoItem infoItem);
195197
}
196198

199+
public static boolean shouldAddMarkAsWatched(final StreamType streamType,
200+
final Context context) {
201+
final boolean isWatchHistoryEnabled = PreferenceManager
202+
.getDefaultSharedPreferences(context)
203+
.getBoolean(context.getString(R.string.enable_watch_history_key), false);
204+
return streamType != StreamType.AUDIO_LIVE_STREAM
205+
&& streamType != StreamType.LIVE_STREAM
206+
&& isWatchHistoryEnabled;
207+
}
208+
197209
/////////////////////////////////////////////
198210
// private method to open channel fragment //
199211
/////////////////////////////////////////////

0 commit comments

Comments
 (0)