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,6 +166,17 @@ protected ViewBinding getListHeader() {
158166 return headerBinding ;
159167 }
160168
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+ */
174+ public void commitChanges () {
175+ if (isModified != null && isModified .get ()) {
176+ saveImmediate ();
177+ }
178+ }
179+
161180 @ Override
162181 protected void initListeners () {
163182 super .initListeners ();
@@ -291,6 +310,9 @@ public void onDestroy() {
291310 if (disposables != null ) {
292311 disposables .dispose ();
293312 }
313+ if (tabsPagerAdapter != null ) {
314+ tabsPagerAdapter .getLocalPlaylistFragments ().remove (this );
315+ }
294316
295317 debouncedSaveSignal = null ;
296318 playlistManager = null ;
@@ -877,5 +899,10 @@ private void createShareConfirmationDialog() {
877899 )
878900 .show ();
879901 }
902+
903+ public void setTabsPagerAdapter (
904+ @ Nullable final MainFragment .SelectedTabsPagerAdapter tabsPagerAdapter ) {
905+ this .tabsPagerAdapter = tabsPagerAdapter ;
906+ }
880907}
881908
0 commit comments