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
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
);

View File

@ -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<PlaylistInfo> {
}
// 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
);

View File

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

View File

@ -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
);

View File

@ -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<List<PlaylistSt
}
// 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
);

View File

@ -5,10 +5,12 @@ import android.net.Uri;
import android.widget.Toast;
import androidx.fragment.app.Fragment;
import androidx.preference.PreferenceManager;
import org.schabi.newpipe.NewPipeDatabase;
import org.schabi.newpipe.R;
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.PlaylistCreationDialog;
import org.schabi.newpipe.local.history.HistoryRecordManager;
@ -191,6 +193,16 @@ public enum StreamDialogEntry {
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 //
/////////////////////////////////////////////