Factor out shouldAddMarkAsWatched as a shared function

This commit is contained in:
Nathan Schulzke 2021-11-13 10:14:54 -07:00
parent 108af48b76
commit dee32c3dc5
6 changed files with 23 additions and 38 deletions

View file

@ -380,13 +380,7 @@ public abstract class BaseListFragment<I, N> extends BaseStateFragment<I>
} }
// show "mark as watched" only when watch history is enabled // show "mark as watched" only when watch history is enabled
final boolean isWatchHistoryEnabled = PreferenceManager if (StreamDialogEntry.shouldAddMarkAsWatched(item.getStreamType(), context)) {
.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( entries.add(
StreamDialogEntry.mark_as_watched StreamDialogEntry.mark_as_watched
); );

View file

@ -15,7 +15,6 @@ import android.view.ViewGroup;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.content.res.AppCompatResources; import androidx.appcompat.content.res.AppCompatResources;
import androidx.preference.PreferenceManager;
import androidx.viewbinding.ViewBinding; import androidx.viewbinding.ViewBinding;
import org.reactivestreams.Subscriber; import org.reactivestreams.Subscriber;
@ -178,13 +177,7 @@ public class PlaylistFragment extends BaseListInfoFragment<PlaylistInfo> {
} }
// show "mark as watched" only when watch history is enabled // show "mark as watched" only when watch history is enabled
final boolean isWatchHistoryEnabled = PreferenceManager if (StreamDialogEntry.shouldAddMarkAsWatched(item.getStreamType(), context)) {
.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( entries.add(
StreamDialogEntry.mark_as_watched StreamDialogEntry.mark_as_watched
); );

View file

@ -356,13 +356,7 @@ class FeedFragment : BaseStateFragment<FeedState>() {
} }
// show "mark as watched" only when watch history is enabled // show "mark as watched" only when watch history is enabled
val isWatchHistoryEnabled = PreferenceManager if (StreamDialogEntry.shouldAddMarkAsWatched(item.streamType, context)) {
.getDefaultSharedPreferences(context)
.getBoolean(getString(R.string.enable_watch_history_key), false)
if (item.streamType != StreamType.AUDIO_LIVE_STREAM &&
item.streamType != StreamType.LIVE_STREAM &&
isWatchHistoryEnabled
) {
entries.add( entries.add(
StreamDialogEntry.mark_as_watched StreamDialogEntry.mark_as_watched
) )

View file

@ -14,7 +14,6 @@ import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.preference.PreferenceManager;
import androidx.viewbinding.ViewBinding; import androidx.viewbinding.ViewBinding;
import com.google.android.material.snackbar.Snackbar; import com.google.android.material.snackbar.Snackbar;
@ -369,13 +368,10 @@ public class StatisticsPlaylistFragment
} }
// show "mark as watched" only when watch history is enabled // show "mark as watched" only when watch history is enabled
final boolean isWatchHistoryEnabled = PreferenceManager if (StreamDialogEntry.shouldAddMarkAsWatched(
.getDefaultSharedPreferences(context) item.getStreamEntity().getStreamType(),
.getBoolean(getString(R.string.enable_watch_history_key), false); context
if (item.getStreamEntity().getStreamType() != StreamType.AUDIO_LIVE_STREAM )) {
&& item.getStreamEntity().getStreamType() != StreamType.LIVE_STREAM
&& isWatchHistoryEnabled
) {
entries.add( entries.add(
StreamDialogEntry.mark_as_watched StreamDialogEntry.mark_as_watched
); );

View file

@ -19,7 +19,6 @@ import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.preference.PreferenceManager;
import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import androidx.viewbinding.ViewBinding; import androidx.viewbinding.ViewBinding;
@ -785,13 +784,10 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
} }
// show "mark as watched" only when watch history is enabled // show "mark as watched" only when watch history is enabled
final boolean isWatchHistoryEnabled = PreferenceManager if (StreamDialogEntry.shouldAddMarkAsWatched(
.getDefaultSharedPreferences(context) item.getStreamEntity().getStreamType(),
.getBoolean(getString(R.string.enable_watch_history_key), false); context
if (item.getStreamEntity().getStreamType() != StreamType.AUDIO_LIVE_STREAM )) {
&& item.getStreamEntity().getStreamType() != StreamType.LIVE_STREAM
&& isWatchHistoryEnabled
) {
entries.add( entries.add(
StreamDialogEntry.mark_as_watched StreamDialogEntry.mark_as_watched
); );

View file

@ -5,10 +5,12 @@ import android.net.Uri;
import android.widget.Toast; import android.widget.Toast;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.preference.PreferenceManager;
import org.schabi.newpipe.NewPipeDatabase; import org.schabi.newpipe.NewPipeDatabase;
import org.schabi.newpipe.R; import org.schabi.newpipe.R;
import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import org.schabi.newpipe.extractor.stream.StreamType;
import org.schabi.newpipe.local.dialog.PlaylistAppendDialog; import org.schabi.newpipe.local.dialog.PlaylistAppendDialog;
import org.schabi.newpipe.local.dialog.PlaylistCreationDialog; import org.schabi.newpipe.local.dialog.PlaylistCreationDialog;
import org.schabi.newpipe.local.history.HistoryRecordManager; import org.schabi.newpipe.local.history.HistoryRecordManager;
@ -191,6 +193,16 @@ public enum StreamDialogEntry {
void onClick(Fragment fragment, StreamInfoItem infoItem); void onClick(Fragment fragment, StreamInfoItem infoItem);
} }
public static boolean shouldAddMarkAsWatched(final StreamType streamType,
final Context context) {
final boolean isWatchHistoryEnabled = PreferenceManager
.getDefaultSharedPreferences(context)
.getBoolean(context.getString(R.string.enable_watch_history_key), false);
return streamType != StreamType.AUDIO_LIVE_STREAM
&& streamType != StreamType.LIVE_STREAM
&& isWatchHistoryEnabled;
}
///////////////////////////////////////////// /////////////////////////////////////////////
// private method to open channel fragment // // private method to open channel fragment //
///////////////////////////////////////////// /////////////////////////////////////////////