From 108af48b76486d682f8c0c39548e8251358359f2 Mon Sep 17 00:00:00 2001 From: Nathan Schulzke Date: Thu, 23 Sep 2021 21:39:47 -0600 Subject: [PATCH 1/2] Enable Mark as Watched in all the other playlist fragments. --- .../fragments/list/BaseListFragment.java | 13 +++++++++++++ .../list/playlist/PlaylistFragment.java | 13 +++++++++++++ .../local/history/HistoryRecordManager.java | 18 +++++------------- .../history/StatisticsPlaylistFragment.java | 14 ++++++++++++++ .../local/playlist/LocalPlaylistFragment.java | 14 ++++++++++++++ 5 files changed, 59 insertions(+), 13 deletions(-) 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 Date: Sat, 13 Nov 2021 10:14:54 -0700 Subject: [PATCH 2/2] Factor out shouldAddMarkAsWatched as a shared function --- .../newpipe/fragments/list/BaseListFragment.java | 8 +------- .../fragments/list/playlist/PlaylistFragment.java | 9 +-------- .../org/schabi/newpipe/local/feed/FeedFragment.kt | 8 +------- .../local/history/StatisticsPlaylistFragment.java | 12 ++++-------- .../local/playlist/LocalPlaylistFragment.java | 12 ++++-------- .../org/schabi/newpipe/util/StreamDialogEntry.java | 12 ++++++++++++ 6 files changed, 23 insertions(+), 38 deletions(-) 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 6a255b914..4899af353 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 @@ -380,13 +380,7 @@ public abstract class BaseListFragment extends BaseStateFragment } // 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 - ) { + if (StreamDialogEntry.shouldAddMarkAsWatched(item.getStreamType(), context)) { entries.add( StreamDialogEntry.mark_as_watched ); 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 b03dddc20..a8763af73 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,7 +15,6 @@ 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; @@ -178,13 +177,7 @@ public class PlaylistFragment extends BaseListInfoFragment { } // 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 - ) { + if (StreamDialogEntry.shouldAddMarkAsWatched(item.getStreamType(), context)) { entries.add( StreamDialogEntry.mark_as_watched ); diff --git a/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt b/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt index b3619276d..4959244d8 100644 --- a/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt +++ b/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt @@ -356,13 +356,7 @@ class FeedFragment : BaseStateFragment() { } // show "mark as watched" only when watch history is enabled - val isWatchHistoryEnabled = PreferenceManager - .getDefaultSharedPreferences(context) - .getBoolean(getString(R.string.enable_watch_history_key), false) - if (item.streamType != StreamType.AUDIO_LIVE_STREAM && - item.streamType != StreamType.LIVE_STREAM && - isWatchHistoryEnabled - ) { + if (StreamDialogEntry.shouldAddMarkAsWatched(item.streamType, context)) { entries.add( StreamDialogEntry.mark_as_watched ) 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 4bb907abc..4f03debca 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,7 +14,6 @@ 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; @@ -369,13 +368,10 @@ public class StatisticsPlaylistFragment } // 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 - ) { + if (StreamDialogEntry.shouldAddMarkAsWatched( + item.getStreamEntity().getStreamType(), + context + )) { entries.add( StreamDialogEntry.mark_as_watched ); 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 2e33f3db4..11174e735 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,7 +19,6 @@ 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; @@ -785,13 +784,10 @@ public class LocalPlaylistFragment extends BaseLocalListFragment