From 4a0bf0445825a76446a8ff7f75993450ec4d4905 Mon Sep 17 00:00:00 2001 From: Haggai Eran Date: Tue, 22 Aug 2023 18:32:59 +0300 Subject: [PATCH] Update media browsers when the list of local playlist changes --- .../mediabrowser/MediaBrowserConnector.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/src/main/java/org/schabi/newpipe/player/mediabrowser/MediaBrowserConnector.java b/app/src/main/java/org/schabi/newpipe/player/mediabrowser/MediaBrowserConnector.java index 7a383e09616..3593155efbd 100644 --- a/app/src/main/java/org/schabi/newpipe/player/mediabrowser/MediaBrowserConnector.java +++ b/app/src/main/java/org/schabi/newpipe/player/mediabrowser/MediaBrowserConnector.java @@ -70,6 +70,8 @@ public MediaBrowserConnector(@NonNull final PlayerService playerService) { sessionConnector.setMetadataDeduplicationEnabled(true); sessionConnector.setPlaybackPreparer(this); playerService.setSessionToken(mediaSession.getSessionToken()); + + setupBookmarksNotifications(); } @NonNull @@ -79,6 +81,7 @@ public MediaSessionConnector getSessionConnector() { public void release() { disposePrepareOrPlayCommands(); + disposeBookmarksNotifications(); mediaSession.release(); } @@ -228,6 +231,20 @@ private LocalPlaylistManager getPlaylistManager() { return localPlaylistManager; } + @Nullable Disposable bookmarksNotificationsDisposable; + + private void setupBookmarksNotifications() { + bookmarksNotificationsDisposable = getPlaylistManager().getPlaylists().subscribe( + playlistMetadataEntries -> playerService.notifyChildrenChanged(ID_BOOKMARKS)); + } + + private void disposeBookmarksNotifications() { + if (bookmarksNotificationsDisposable != null) { + bookmarksNotificationsDisposable.dispose(); + bookmarksNotificationsDisposable = null; + } + } + // Suppress Sonar warning replace list collection by Stream.toList call, as this method is only // available in Android API 34 and not currently available with desugaring @SuppressWarnings("squid:S6204")