Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Mark as Watched in all the other playlist fragments. #7160

Merged
merged 2 commits into from
Nov 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,13 @@ protected void showStreamDialog(final StreamInfoItem item) {
if (KoreUtils.shouldShowPlayWithKodi(context, item.getServiceId())) {
entries.add(StreamDialogEntry.play_with_kodi);
}

// show "mark as watched" only when watch history is enabled
if (StreamDialogEntry.shouldAddMarkAsWatched(item.getStreamType(), context)) {
entries.add(
StreamDialogEntry.mark_as_watched
);
}
if (!isNullOrEmpty(item.getUploaderUrl())) {
entries.add(StreamDialogEntry.show_channel_details);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@ protected void showStreamDialog(final StreamInfoItem item) {
entries.add(StreamDialogEntry.play_with_kodi);
}

// show "mark as watched" only when watch history is enabled
if (StreamDialogEntry.shouldAddMarkAsWatched(item.getStreamType(), context)) {
entries.add(
StreamDialogEntry.mark_as_watched
);
}
if (!isNullOrEmpty(item.getUploaderUrl())) {
entries.add(StreamDialogEntry.show_channel_details);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,11 @@ public Maybe<Long> markAsWatched(final StreamInfoItem info) {
}

// Update the stream progress to the full duration of the video
final List<StreamStateEntity> 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);
nschulzke marked this conversation as resolved.
Show resolved Hide resolved

// Add a history entry
final StreamHistoryEntity latestEntry = streamHistoryTable.getLatestEntry(streamId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,16 @@ private void showStreamDialog(final StreamStatisticsEntry item) {
if (KoreUtils.shouldShowPlayWithKodi(context, infoItem.getServiceId())) {
entries.add(StreamDialogEntry.play_with_kodi);
}

// show "mark as watched" only when watch history is enabled
if (StreamDialogEntry.shouldAddMarkAsWatched(
item.getStreamEntity().getStreamType(),
context
)) {
entries.add(
StreamDialogEntry.mark_as_watched
);
}
entries.add(StreamDialogEntry.show_channel_details);

StreamDialogEntry.setEnabledEntries(entries);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,16 @@ protected void showStreamItemDialog(final PlaylistStreamEntry item) {
if (KoreUtils.shouldShowPlayWithKodi(context, infoItem.getServiceId())) {
entries.add(StreamDialogEntry.play_with_kodi);
}

// show "mark as watched" only when watch history is enabled
if (StreamDialogEntry.shouldAddMarkAsWatched(
item.getStreamEntity().getStreamType(),
context
)) {
entries.add(
StreamDialogEntry.mark_as_watched
);
}
entries.add(StreamDialogEntry.show_channel_details);

StreamDialogEntry.setEnabledEntries(entries);
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
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;
Expand Down Expand Up @@ -191,6 +193,16 @@ public interface StreamDialogEntryAction {
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 //
/////////////////////////////////////////////
Expand Down