Skip to content

Commit 3cc0205

Browse files
committed
Fix inconsistencies when removing playlist
Remove checkDisplayIndexModified because it was causing more problems than it solved. Now when adding new playlists they won't necessarily appear at the top, but will get sorted alphabetically along with the other playlists with index -1. This will be the case until any playlist is sorted, at which point all indices are assigned and newly added playlists will appear at the top again.
1 parent 90979e2 commit 3cc0205

1 file changed

Lines changed: 5 additions & 26 deletions

File tree

app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public final class BookmarkFragment extends BaseLocalListFragment<List<PlaylistL
5656

5757
private static final int MINIMUM_INITIAL_DRAG_VELOCITY = 12;
5858
@State
59-
protected Parcelable itemsListState;
59+
Parcelable itemsListState;
6060

6161
private Subscription databaseSubscription;
6262
private CompositeDisposable disposables = new CompositeDisposable();
@@ -68,6 +68,7 @@ public final class BookmarkFragment extends BaseLocalListFragment<List<PlaylistL
6868
private AtomicBoolean isLoadingComplete;
6969

7070
/* Gives enough time to avoid interrupting user sorting operations */
71+
@Nullable
7172
private DebounceSaver debounceSaver;
7273

7374
private List<Pair<Long, LocalItem.LocalItemType>> deletedItems;
@@ -259,7 +260,6 @@ public void onSubscribe(final Subscription s) {
259260
@Override
260261
public void onNext(final List<PlaylistLocalItem> subscriptions) {
261262
if (debounceSaver == null || !debounceSaver.getIsModified()) {
262-
checkDisplayIndexModified(subscriptions);
263263
handleResult(subscriptions);
264264
isLoadingComplete.set(true);
265265
}
@@ -349,30 +349,9 @@ private void deleteItem(final PlaylistLocalItem item) {
349349
LocalItem.LocalItemType.PLAYLIST_REMOTE_ITEM));
350350
}
351351

352-
debounceSaver.setHasChangesToSave();
353-
}
354-
355-
private void checkDisplayIndexModified(@NonNull final List<PlaylistLocalItem> result) {
356-
if (debounceSaver != null && debounceSaver.getIsModified()) {
357-
return;
358-
}
359-
360-
// Check if the display index does not match the actual index in the list.
361-
// This may happen when a new list is created
362-
// or on the first run after database migration
363-
// or display index is not continuous for some reason
364-
// or the user changes the display index.
365-
boolean isDisplayIndexModified = false;
366-
for (int i = 0; i < result.size(); i++) {
367-
final PlaylistLocalItem item = result.get(i);
368-
if (item.getDisplayIndex() != i) {
369-
isDisplayIndexModified = true;
370-
break;
371-
}
372-
}
373-
374-
if (debounceSaver != null && isDisplayIndexModified) {
352+
if (debounceSaver != null) {
375353
debounceSaver.setHasChangesToSave();
354+
saveImmediate();
376355
}
377356
}
378357

@@ -482,7 +461,7 @@ public boolean onMove(@NonNull final RecyclerView recyclerView,
482461
final int sourceIndex = source.getBindingAdapterPosition();
483462
final int targetIndex = target.getBindingAdapterPosition();
484463
final boolean isSwapped = itemListAdapter.swapItems(sourceIndex, targetIndex);
485-
if (isSwapped) {
464+
if (isSwapped && debounceSaver != null) {
486465
debounceSaver.setHasChangesToSave();
487466
}
488467
return isSwapped;

0 commit comments

Comments
 (0)