Add ability to mark an item as played

This commit is contained in:
Nathan Schulzke 2021-07-26 20:51:41 -06:00
parent 39722a5563
commit 7fd2ebc252
4 changed files with 53 additions and 3 deletions

View File

@ -331,7 +331,8 @@ class FeedFragment : BaseStateFragment<FeedState>() {
StreamDialogEntry.start_here_on_background,
StreamDialogEntry.append_playlist,
StreamDialogEntry.share,
StreamDialogEntry.open_in_browser
StreamDialogEntry.open_in_browser,
StreamDialogEntry.mark_as_played
)
)
} else {
@ -341,7 +342,8 @@ class FeedFragment : BaseStateFragment<FeedState>() {
StreamDialogEntry.start_here_on_popup,
StreamDialogEntry.append_playlist,
StreamDialogEntry.share,
StreamDialogEntry.open_in_browser
StreamDialogEntry.open_in_browser,
StreamDialogEntry.mark_as_played
)
)
}

View File

@ -42,6 +42,7 @@ import org.schabi.newpipe.database.stream.model.StreamEntity;
import org.schabi.newpipe.database.stream.model.StreamStateEntity;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.stream.StreamInfo;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import org.schabi.newpipe.player.playqueue.PlayQueueItem;
import java.time.OffsetDateTime;
@ -81,6 +82,41 @@ public class HistoryRecordManager {
// Watch History
///////////////////////////////////////////////////////
public Maybe<Long> markAsPlayed(final StreamInfoItem info) {
if (!isStreamHistoryEnabled()) {
return Maybe.empty();
}
final OffsetDateTime currentTime = OffsetDateTime.now(ZoneOffset.UTC);
return Maybe.fromCallable(() -> database.runInTransaction(() -> {
final long streamId = streamTable.upsert(new StreamEntity(info));
final List<StreamStateEntity> states = streamStateTable.getState(streamId)
.blockingFirst();
if (!states.isEmpty()) {
final StreamStateEntity entity = states.get(0);
entity.setProgressMillis(info.getDuration() * 1000);
streamStateTable.update(entity);
} else {
final StreamStateEntity entity = new StreamStateEntity(
streamId,
info.getDuration() * 1000
);
streamStateTable.insert(entity);
}
final StreamHistoryEntity latestEntry = streamHistoryTable.getLatestEntry(streamId);
if (latestEntry != null) {
streamHistoryTable.delete(latestEntry);
latestEntry.setAccessDate(currentTime);
latestEntry.setRepeatCount(latestEntry.getRepeatCount() + 1);
return streamHistoryTable.insert(latestEntry);
} else {
return streamHistoryTable.insert(new StreamHistoryEntity(streamId, currentTime));
}
})).subscribeOn(Schedulers.io());
}
public Maybe<Long> onViewed(final StreamInfo info) {
if (!isStreamHistoryEnabled()) {
return Maybe.empty();

View File

@ -9,6 +9,7 @@ import org.schabi.newpipe.R;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import org.schabi.newpipe.local.dialog.PlaylistAppendDialog;
import org.schabi.newpipe.local.dialog.PlaylistCreationDialog;
import org.schabi.newpipe.local.history.HistoryRecordManager;
import org.schabi.newpipe.player.MainPlayer;
import org.schabi.newpipe.player.helper.PlayerHolder;
import org.schabi.newpipe.player.playqueue.SinglePlayQueue;
@ -18,6 +19,8 @@ import org.schabi.newpipe.util.external_communication.ShareUtils;
import java.util.Collections;
import java.util.List;
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import static org.schabi.newpipe.player.MainPlayer.PlayerType.AUDIO;
import static org.schabi.newpipe.player.MainPlayer.PlayerType.POPUP;
@ -92,9 +95,17 @@ public enum StreamDialogEntry {
item.getThumbnailUrl())),
open_in_browser(R.string.open_in_browser, (fragment, item) ->
ShareUtils.openUrlInBrowser(fragment.getContext(), item.getUrl()));
ShareUtils.openUrlInBrowser(fragment.getContext(), item.getUrl())),
mark_as_played(R.string.mark_as_played, (fragment, item) -> {
new HistoryRecordManager(fragment.getContext())
.markAsPlayed(item)
.onErrorComplete()
.observeOn(AndroidSchedulers.mainThread())
.subscribe();
});
///////////////
// variables //
///////////////

View File

@ -9,6 +9,7 @@
<string name="cancel">Cancel</string>
<string name="fdroid_vlc_url" translatable="false">https://f-droid.org/repository/browse/?fdfilter=vlc&amp;fdid=org.videolan.vlc</string>
<string name="open_in_browser">Open in browser</string>
<string name="mark_as_played">Mark as played</string>
<string name="open_in_popup_mode">Open in popup mode</string>
<string name="open_with">Open with</string>
<string name="share">Share</string>