mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-23 16:40:32 +00:00
Add ability to mark an item as played
This commit is contained in:
parent
39722a5563
commit
7fd2ebc252
@ -331,7 +331,8 @@ class FeedFragment : BaseStateFragment<FeedState>() {
|
|||||||
StreamDialogEntry.start_here_on_background,
|
StreamDialogEntry.start_here_on_background,
|
||||||
StreamDialogEntry.append_playlist,
|
StreamDialogEntry.append_playlist,
|
||||||
StreamDialogEntry.share,
|
StreamDialogEntry.share,
|
||||||
StreamDialogEntry.open_in_browser
|
StreamDialogEntry.open_in_browser,
|
||||||
|
StreamDialogEntry.mark_as_played
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
@ -341,7 +342,8 @@ class FeedFragment : BaseStateFragment<FeedState>() {
|
|||||||
StreamDialogEntry.start_here_on_popup,
|
StreamDialogEntry.start_here_on_popup,
|
||||||
StreamDialogEntry.append_playlist,
|
StreamDialogEntry.append_playlist,
|
||||||
StreamDialogEntry.share,
|
StreamDialogEntry.share,
|
||||||
StreamDialogEntry.open_in_browser
|
StreamDialogEntry.open_in_browser,
|
||||||
|
StreamDialogEntry.mark_as_played
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,7 @@ import org.schabi.newpipe.database.stream.model.StreamEntity;
|
|||||||
import org.schabi.newpipe.database.stream.model.StreamStateEntity;
|
import org.schabi.newpipe.database.stream.model.StreamStateEntity;
|
||||||
import org.schabi.newpipe.extractor.InfoItem;
|
import org.schabi.newpipe.extractor.InfoItem;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
||||||
|
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
||||||
import org.schabi.newpipe.player.playqueue.PlayQueueItem;
|
import org.schabi.newpipe.player.playqueue.PlayQueueItem;
|
||||||
|
|
||||||
import java.time.OffsetDateTime;
|
import java.time.OffsetDateTime;
|
||||||
@ -81,6 +82,41 @@ public class HistoryRecordManager {
|
|||||||
// Watch History
|
// 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) {
|
public Maybe<Long> onViewed(final StreamInfo info) {
|
||||||
if (!isStreamHistoryEnabled()) {
|
if (!isStreamHistoryEnabled()) {
|
||||||
return Maybe.empty();
|
return Maybe.empty();
|
||||||
|
@ -9,6 +9,7 @@ import org.schabi.newpipe.R;
|
|||||||
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
||||||
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.player.MainPlayer;
|
import org.schabi.newpipe.player.MainPlayer;
|
||||||
import org.schabi.newpipe.player.helper.PlayerHolder;
|
import org.schabi.newpipe.player.helper.PlayerHolder;
|
||||||
import org.schabi.newpipe.player.playqueue.SinglePlayQueue;
|
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.Collections;
|
||||||
import java.util.List;
|
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.AUDIO;
|
||||||
import static org.schabi.newpipe.player.MainPlayer.PlayerType.POPUP;
|
import static org.schabi.newpipe.player.MainPlayer.PlayerType.POPUP;
|
||||||
|
|
||||||
@ -92,9 +95,17 @@ public enum StreamDialogEntry {
|
|||||||
item.getThumbnailUrl())),
|
item.getThumbnailUrl())),
|
||||||
|
|
||||||
open_in_browser(R.string.open_in_browser, (fragment, item) ->
|
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 //
|
// variables //
|
||||||
///////////////
|
///////////////
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
<string name="cancel">Cancel</string>
|
<string name="cancel">Cancel</string>
|
||||||
<string name="fdroid_vlc_url" translatable="false">https://f-droid.org/repository/browse/?fdfilter=vlc&fdid=org.videolan.vlc</string>
|
<string name="fdroid_vlc_url" translatable="false">https://f-droid.org/repository/browse/?fdfilter=vlc&fdid=org.videolan.vlc</string>
|
||||||
<string name="open_in_browser">Open in browser</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_in_popup_mode">Open in popup mode</string>
|
||||||
<string name="open_with">Open with</string>
|
<string name="open_with">Open with</string>
|
||||||
<string name="share">Share</string>
|
<string name="share">Share</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user