4141import org .schabi .newpipe .error .ErrorInfo ;
4242import org .schabi .newpipe .error .UserAction ;
4343import org .schabi .newpipe .extractor .stream .StreamInfoItem ;
44+ import org .schabi .newpipe .fragments .MainFragment ;
4445import org .schabi .newpipe .fragments .list .playlist .PlaylistControlViewHolder ;
4546import org .schabi .newpipe .info_list .dialog .InfoItemDialog ;
4647import org .schabi .newpipe .info_list .dialog .StreamDialogDefaultEntry ;
7172
7273public class LocalPlaylistFragment extends BaseLocalListFragment <List <PlaylistStreamEntry >, Void >
7374 implements PlaylistControlViewHolder {
74- // Save the list 10 seconds after the last change occurred
75+ /** Save the list 10 seconds after the last change occurred. */
7576 private static final long SAVE_DEBOUNCE_MILLIS = 10000 ;
7677 private static final int MINIMUM_INITIAL_DRAG_VELOCITY = 12 ;
7778 @ State
@@ -92,13 +93,20 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
9293 private PublishSubject <Long > debouncedSaveSignal ;
9394 private CompositeDisposable disposables ;
9495
95- /* Has the playlist been fully loaded from db */
96+ /** Whether the playlist has been fully loaded from db. */
9697 private AtomicBoolean isLoadingComplete ;
97- /* Has the playlist been modified (e.g. items reordered or deleted) */
98+ /** Whether the playlist has been modified (e.g. items reordered or deleted) */
9899 private AtomicBoolean isModified ;
99- /* Flag to prevent simultaneous rewrites of the playlist */
100+ /** Flag to prevent simultaneous rewrites of the playlist. */
100101 private boolean isRewritingPlaylist = false ;
101102
103+ /**
104+ * The pager adapter that the fragment is created from when it is used as frontpage, i.e.
105+ * {@link #useAsFrontPage} is {@link true}.
106+ */
107+ @ Nullable
108+ private MainFragment .SelectedTabsPagerAdapter tabsPagerAdapter = null ;
109+
102110 public static LocalPlaylistFragment getInstance (final long playlistId , final String name ) {
103111 final LocalPlaylistFragment instance = new LocalPlaylistFragment ();
104112 instance .setInitialData (playlistId , name );
@@ -158,9 +166,11 @@ protected ViewBinding getListHeader() {
158166 return headerBinding ;
159167 }
160168
161- // Commit changes immediately when the user turns to the player.
162- // Delete operations will be committed to ensure that the database
163- // is up to date when the user adds the just deleted stream by the player.
169+ /**
170+ * <p>Commit changes immediately if the playlist has been modified.</p>
171+ * Delete operations and other modifications will be committed to ensure that the database
172+ * is up to date, e.g. when the user adds the just deleted stream from another fragment.
173+ */
164174 public void commitChanges () {
165175 if (isModified != null && isModified .get ()) {
166176 saveImmediate ();
@@ -300,6 +310,9 @@ public void onDestroy() {
300310 if (disposables != null ) {
301311 disposables .dispose ();
302312 }
313+ if (tabsPagerAdapter != null ) {
314+ tabsPagerAdapter .getLocalPlaylistFragments ().remove (this );
315+ }
303316
304317 debouncedSaveSignal = null ;
305318 playlistManager = null ;
@@ -886,5 +899,10 @@ private void createShareConfirmationDialog() {
886899 )
887900 .show ();
888901 }
902+
903+ public void setTabsPagerAdapter (
904+ @ Nullable final MainFragment .SelectedTabsPagerAdapter tabsPagerAdapter ) {
905+ this .tabsPagerAdapter = tabsPagerAdapter ;
906+ }
889907}
890908
0 commit comments