From bc2f0f9f3ee9c2adcbf75cf576bdf47e833de41f Mon Sep 17 00:00:00 2001 From: Douile <25043847+Douile@users.noreply.github.com> Date: Thu, 28 Oct 2021 01:11:53 +0100 Subject: [PATCH] Update stream state in database after loading --- .../schabi/newpipe/local/feed/FeedFragment.kt | 5 +++++ .../newpipe/util/StreamDialogEntry.java | 19 +++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt b/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt index b3619276d..1b00d20ea 100644 --- a/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt +++ b/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt @@ -159,6 +159,11 @@ class FeedFragment : BaseStateFragment() { } } + // TODO: Move + fun redrawContent() { + groupAdapter.notifyItemRangeChanged(0, Int.MAX_VALUE) + } + fun setupListViewMode() { // does everything needed to setup the layouts for grid or list modes groupAdapter.spanCount = if (shouldUseGridLayout(context)) getGridSpanCountStreams(context) else 1 diff --git a/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java b/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java index dc5852416..321c744b7 100644 --- a/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java +++ b/app/src/main/java/org/schabi/newpipe/util/StreamDialogEntry.java @@ -62,13 +62,13 @@ public enum StreamDialogEntry { * Info: Add this entry within showStreamDialog. */ enqueue(R.string.enqueue_stream, (fragment, item) -> { - fetchItemInfoIfSparse(item, + fetchItemInfoIfSparse(fragment, item, fullItem -> NavigationHelper.enqueueOnPlayer(fragment.getContext(), fullItem) ); }), enqueue_next(R.string.enqueue_next_stream, (fragment, item) -> { - fetchItemInfoIfSparse(item, + fetchItemInfoIfSparse(fragment, item, fullItem -> NavigationHelper.enqueueNextOnPlayer(fragment.getContext(), fullItem) ); }), @@ -218,8 +218,9 @@ public enum StreamDialogEntry { void onInfo(SinglePlayQueue item); } - private static void fetchItemInfoIfSparse(final StreamInfoItem item, - final InfoCallback callback) { + private static void fetchItemInfoIfSparse(final Fragment fragment, + final StreamInfoItem item, + final InfoCallback callback) { if (item.getDuration() < 0) { // Sparse item: fetched by fast fetch final Disposable currentWorker = ExtractorHelper.getStreamInfo( @@ -227,9 +228,19 @@ public enum StreamDialogEntry { item.getUrl(), false ) + .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(result -> { + final HistoryRecordManager recordManager = + new HistoryRecordManager(fragment.getContext()); + recordManager.saveStreamState(result, 0) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .doOnError(throwable -> Log.e("StreamDialogEntry", + throwable.toString())) + .subscribe(); + callback.onInfo(new SinglePlayQueue(result)); }, throwable -> Log.e("StreamDialogEntry", throwable.toString())); } else {