diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java index c30b6fc05..6a255b914 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java @@ -378,6 +378,19 @@ public abstract class BaseListFragment extends BaseStateFragment if (KoreUtils.shouldShowPlayWithKodi(context, item.getServiceId())) { entries.add(StreamDialogEntry.play_with_kodi); } + + // show "mark as watched" only when watch history is enabled + final boolean isWatchHistoryEnabled = PreferenceManager + .getDefaultSharedPreferences(context) + .getBoolean(getString(R.string.enable_watch_history_key), false); + if (item.getStreamType() != StreamType.AUDIO_LIVE_STREAM + && item.getStreamType() != StreamType.LIVE_STREAM + && isWatchHistoryEnabled + ) { + entries.add( + StreamDialogEntry.mark_as_watched + ); + } if (!isNullOrEmpty(item.getUploaderUrl())) { entries.add(StreamDialogEntry.show_channel_details); } diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java index f3aa2e306..b03dddc20 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java @@ -15,6 +15,7 @@ import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.content.res.AppCompatResources; +import androidx.preference.PreferenceManager; import androidx.viewbinding.ViewBinding; import org.reactivestreams.Subscriber; @@ -176,6 +177,18 @@ public class PlaylistFragment extends BaseListInfoFragment { entries.add(StreamDialogEntry.play_with_kodi); } + // show "mark as watched" only when watch history is enabled + final boolean isWatchHistoryEnabled = PreferenceManager + .getDefaultSharedPreferences(context) + .getBoolean(getString(R.string.enable_watch_history_key), false); + if (item.getStreamType() != StreamType.AUDIO_LIVE_STREAM + && item.getStreamType() != StreamType.LIVE_STREAM + && isWatchHistoryEnabled + ) { + entries.add( + StreamDialogEntry.mark_as_watched + ); + } if (!isNullOrEmpty(item.getUploaderUrl())) { entries.add(StreamDialogEntry.show_channel_details); } diff --git a/app/src/main/java/org/schabi/newpipe/local/history/HistoryRecordManager.java b/app/src/main/java/org/schabi/newpipe/local/history/HistoryRecordManager.java index 823e56d9e..03f04235a 100644 --- a/app/src/main/java/org/schabi/newpipe/local/history/HistoryRecordManager.java +++ b/app/src/main/java/org/schabi/newpipe/local/history/HistoryRecordManager.java @@ -120,19 +120,11 @@ public class HistoryRecordManager { } // Update the stream progress to the full duration of the video - final List states = streamStateTable.getState(streamId) - .blockingFirst(); - if (!states.isEmpty()) { - final StreamStateEntity entity = states.get(0); - entity.setProgressMillis(duration * 1000); - streamStateTable.update(entity); - } else { - final StreamStateEntity entity = new StreamStateEntity( - streamId, - duration * 1000 - ); - streamStateTable.insert(entity); - } + final StreamStateEntity entity = new StreamStateEntity( + streamId, + duration * 1000 + ); + streamStateTable.upsert(entity); // Add a history entry final StreamHistoryEntity latestEntry = streamHistoryTable.getLatestEntry(streamId); diff --git a/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java index 9632b47f7..4bb907abc 100644 --- a/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java @@ -14,6 +14,7 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.preference.PreferenceManager; import androidx.viewbinding.ViewBinding; import com.google.android.material.snackbar.Snackbar; @@ -366,6 +367,19 @@ public class StatisticsPlaylistFragment if (KoreUtils.shouldShowPlayWithKodi(context, infoItem.getServiceId())) { entries.add(StreamDialogEntry.play_with_kodi); } + + // show "mark as watched" only when watch history is enabled + final boolean isWatchHistoryEnabled = PreferenceManager + .getDefaultSharedPreferences(context) + .getBoolean(getString(R.string.enable_watch_history_key), false); + if (item.getStreamEntity().getStreamType() != StreamType.AUDIO_LIVE_STREAM + && item.getStreamEntity().getStreamType() != StreamType.LIVE_STREAM + && isWatchHistoryEnabled + ) { + entries.add( + StreamDialogEntry.mark_as_watched + ); + } entries.add(StreamDialogEntry.show_channel_details); StreamDialogEntry.setEnabledEntries(entries); diff --git a/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java index 21da9e571..2e33f3db4 100644 --- a/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java @@ -19,6 +19,7 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; +import androidx.preference.PreferenceManager; import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.RecyclerView; import androidx.viewbinding.ViewBinding; @@ -782,6 +783,19 @@ public class LocalPlaylistFragment extends BaseLocalListFragment