Skip to content

Commit dee32c3

Browse files
committed
Factor out shouldAddMarkAsWatched as a shared function
1 parent 108af48 commit dee32c3

6 files changed

Lines changed: 23 additions & 38 deletions

File tree

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -380,13 +380,7 @@ protected void showStreamDialog(final StreamInfoItem item) {
380380
}
381381

382382
// 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-
) {
383+
if (StreamDialogEntry.shouldAddMarkAsWatched(item.getStreamType(), context)) {
390384
entries.add(
391385
StreamDialogEntry.mark_as_watched
392386
);

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import androidx.annotation.NonNull;
1616
import androidx.annotation.Nullable;
1717
import androidx.appcompat.content.res.AppCompatResources;
18-
import androidx.preference.PreferenceManager;
1918
import androidx.viewbinding.ViewBinding;
2019

2120
import org.reactivestreams.Subscriber;
@@ -178,13 +177,7 @@ protected void showStreamDialog(final StreamInfoItem item) {
178177
}
179178

180179
// 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-
) {
180+
if (StreamDialogEntry.shouldAddMarkAsWatched(item.getStreamType(), context)) {
188181
entries.add(
189182
StreamDialogEntry.mark_as_watched
190183
);

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
@@ -356,13 +356,7 @@ class FeedFragment : BaseStateFragment<FeedState>() {
356356
}
357357

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

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
import androidx.annotation.NonNull;
1616
import androidx.annotation.Nullable;
17-
import androidx.preference.PreferenceManager;
1817
import androidx.viewbinding.ViewBinding;
1918

2019
import com.google.android.material.snackbar.Snackbar;
@@ -369,13 +368,10 @@ private void showStreamDialog(final StreamStatisticsEntry item) {
369368
}
370369

371370
// 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-
) {
371+
if (StreamDialogEntry.shouldAddMarkAsWatched(
372+
item.getStreamEntity().getStreamType(),
373+
context
374+
)) {
379375
entries.add(
380376
StreamDialogEntry.mark_as_watched
381377
);

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import androidx.annotation.NonNull;
2020
import androidx.annotation.Nullable;
2121
import androidx.appcompat.app.AlertDialog;
22-
import androidx.preference.PreferenceManager;
2322
import androidx.recyclerview.widget.ItemTouchHelper;
2423
import androidx.recyclerview.widget.RecyclerView;
2524
import androidx.viewbinding.ViewBinding;
@@ -785,13 +784,10 @@ protected void showStreamItemDialog(final PlaylistStreamEntry item) {
785784
}
786785

787786
// 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-
) {
787+
if (StreamDialogEntry.shouldAddMarkAsWatched(
788+
item.getStreamEntity().getStreamType(),
789+
context
790+
)) {
795791
entries.add(
796792
StreamDialogEntry.mark_as_watched
797793
);

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,10 +5,12 @@
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.extractor.stream.StreamInfoItem;
13+
import org.schabi.newpipe.extractor.stream.StreamType;
1214
import org.schabi.newpipe.local.dialog.PlaylistAppendDialog;
1315
import org.schabi.newpipe.local.dialog.PlaylistCreationDialog;
1416
import org.schabi.newpipe.local.history.HistoryRecordManager;
@@ -191,6 +193,16 @@ public interface StreamDialogEntryAction {
191193
void onClick(Fragment fragment, StreamInfoItem infoItem);
192194
}
193195

196+
public static boolean shouldAddMarkAsWatched(final StreamType streamType,
197+
final Context context) {
198+
final boolean isWatchHistoryEnabled = PreferenceManager
199+
.getDefaultSharedPreferences(context)
200+
.getBoolean(context.getString(R.string.enable_watch_history_key), false);
201+
return streamType != StreamType.AUDIO_LIVE_STREAM
202+
&& streamType != StreamType.LIVE_STREAM
203+
&& isWatchHistoryEnabled;
204+
}
205+
194206
/////////////////////////////////////////////
195207
// private method to open channel fragment //
196208
/////////////////////////////////////////////

0 commit comments

Comments
 (0)