Skip to content

Commit 108af48

Browse files
committed
Enable Mark as Watched in all the other playlist fragments.
1 parent f36fd2f commit 108af48

5 files changed

Lines changed: 59 additions & 13 deletions

File tree

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,19 @@ 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+
final boolean isWatchHistoryEnabled = PreferenceManager
384+
.getDefaultSharedPreferences(context)
385+
.getBoolean(getString(R.string.enable_watch_history_key), false);
386+
if (item.getStreamType() != StreamType.AUDIO_LIVE_STREAM
387+
&& item.getStreamType() != StreamType.LIVE_STREAM
388+
&& isWatchHistoryEnabled
389+
) {
390+
entries.add(
391+
StreamDialogEntry.mark_as_watched
392+
);
393+
}
381394
if (!isNullOrEmpty(item.getUploaderUrl())) {
382395
entries.add(StreamDialogEntry.show_channel_details);
383396
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import androidx.annotation.NonNull;
1616
import androidx.annotation.Nullable;
1717
import androidx.appcompat.content.res.AppCompatResources;
18+
import androidx.preference.PreferenceManager;
1819
import androidx.viewbinding.ViewBinding;
1920

2021
import org.reactivestreams.Subscriber;
@@ -176,6 +177,18 @@ protected void showStreamDialog(final StreamInfoItem item) {
176177
entries.add(StreamDialogEntry.play_with_kodi);
177178
}
178179

180+
// show "mark as watched" only when watch history is enabled
181+
final boolean isWatchHistoryEnabled = PreferenceManager
182+
.getDefaultSharedPreferences(context)
183+
.getBoolean(getString(R.string.enable_watch_history_key), false);
184+
if (item.getStreamType() != StreamType.AUDIO_LIVE_STREAM
185+
&& item.getStreamType() != StreamType.LIVE_STREAM
186+
&& isWatchHistoryEnabled
187+
) {
188+
entries.add(
189+
StreamDialogEntry.mark_as_watched
190+
);
191+
}
179192
if (!isNullOrEmpty(item.getUploaderUrl())) {
180193
entries.add(StreamDialogEntry.show_channel_details);
181194
}

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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import androidx.annotation.NonNull;
1616
import androidx.annotation.Nullable;
17+
import androidx.preference.PreferenceManager;
1718
import androidx.viewbinding.ViewBinding;
1819

1920
import com.google.android.material.snackbar.Snackbar;
@@ -366,6 +367,19 @@ private void showStreamDialog(final StreamStatisticsEntry item) {
366367
if (KoreUtils.shouldShowPlayWithKodi(context, infoItem.getServiceId())) {
367368
entries.add(StreamDialogEntry.play_with_kodi);
368369
}
370+
371+
// show "mark as watched" only when watch history is enabled
372+
final boolean isWatchHistoryEnabled = PreferenceManager
373+
.getDefaultSharedPreferences(context)
374+
.getBoolean(getString(R.string.enable_watch_history_key), false);
375+
if (item.getStreamEntity().getStreamType() != StreamType.AUDIO_LIVE_STREAM
376+
&& item.getStreamEntity().getStreamType() != StreamType.LIVE_STREAM
377+
&& isWatchHistoryEnabled
378+
) {
379+
entries.add(
380+
StreamDialogEntry.mark_as_watched
381+
);
382+
}
369383
entries.add(StreamDialogEntry.show_channel_details);
370384

371385
StreamDialogEntry.setEnabledEntries(entries);

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import androidx.annotation.NonNull;
2020
import androidx.annotation.Nullable;
2121
import androidx.appcompat.app.AlertDialog;
22+
import androidx.preference.PreferenceManager;
2223
import androidx.recyclerview.widget.ItemTouchHelper;
2324
import androidx.recyclerview.widget.RecyclerView;
2425
import androidx.viewbinding.ViewBinding;
@@ -782,6 +783,19 @@ protected void showStreamItemDialog(final PlaylistStreamEntry item) {
782783
if (KoreUtils.shouldShowPlayWithKodi(context, infoItem.getServiceId())) {
783784
entries.add(StreamDialogEntry.play_with_kodi);
784785
}
786+
787+
// show "mark as watched" only when watch history is enabled
788+
final boolean isWatchHistoryEnabled = PreferenceManager
789+
.getDefaultSharedPreferences(context)
790+
.getBoolean(getString(R.string.enable_watch_history_key), false);
791+
if (item.getStreamEntity().getStreamType() != StreamType.AUDIO_LIVE_STREAM
792+
&& item.getStreamEntity().getStreamType() != StreamType.LIVE_STREAM
793+
&& isWatchHistoryEnabled
794+
) {
795+
entries.add(
796+
StreamDialogEntry.mark_as_watched
797+
);
798+
}
785799
entries.add(StreamDialogEntry.show_channel_details);
786800

787801
StreamDialogEntry.setEnabledEntries(entries);

0 commit comments

Comments
 (0)