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.
This commit is contained in:
Stypox 2024-03-30 14:14:31 +01:00
parent 90979e2a81
commit 3cc0205def
No known key found for this signature in database
GPG key ID: 4BDF1B40A49FDD23

View file

@ -56,7 +56,7 @@ public final class BookmarkFragment extends BaseLocalListFragment<List<PlaylistL
private static final int MINIMUM_INITIAL_DRAG_VELOCITY = 12; private static final int MINIMUM_INITIAL_DRAG_VELOCITY = 12;
@State @State
protected Parcelable itemsListState; Parcelable itemsListState;
private Subscription databaseSubscription; private Subscription databaseSubscription;
private CompositeDisposable disposables = new CompositeDisposable(); private CompositeDisposable disposables = new CompositeDisposable();
@ -68,6 +68,7 @@ public final class BookmarkFragment extends BaseLocalListFragment<List<PlaylistL
private AtomicBoolean isLoadingComplete; private AtomicBoolean isLoadingComplete;
/* Gives enough time to avoid interrupting user sorting operations */ /* Gives enough time to avoid interrupting user sorting operations */
@Nullable
private DebounceSaver debounceSaver; private DebounceSaver debounceSaver;
private List<Pair<Long, LocalItem.LocalItemType>> deletedItems; private List<Pair<Long, LocalItem.LocalItemType>> deletedItems;
@ -259,7 +260,6 @@ public final class BookmarkFragment extends BaseLocalListFragment<List<PlaylistL
@Override @Override
public void onNext(final List<PlaylistLocalItem> subscriptions) { public void onNext(final List<PlaylistLocalItem> subscriptions) {
if (debounceSaver == null || !debounceSaver.getIsModified()) { if (debounceSaver == null || !debounceSaver.getIsModified()) {
checkDisplayIndexModified(subscriptions);
handleResult(subscriptions); handleResult(subscriptions);
isLoadingComplete.set(true); isLoadingComplete.set(true);
} }
@ -349,30 +349,9 @@ public final class BookmarkFragment extends BaseLocalListFragment<List<PlaylistL
LocalItem.LocalItemType.PLAYLIST_REMOTE_ITEM)); LocalItem.LocalItemType.PLAYLIST_REMOTE_ITEM));
} }
debounceSaver.setHasChangesToSave(); if (debounceSaver != null) {
}
private void checkDisplayIndexModified(@NonNull final List<PlaylistLocalItem> result) {
if (debounceSaver != null && debounceSaver.getIsModified()) {
return;
}
// Check if the display index does not match the actual index in the list.
// This may happen when a new list is created
// or on the first run after database migration
// or display index is not continuous for some reason
// or the user changes the display index.
boolean isDisplayIndexModified = false;
for (int i = 0; i < result.size(); i++) {
final PlaylistLocalItem item = result.get(i);
if (item.getDisplayIndex() != i) {
isDisplayIndexModified = true;
break;
}
}
if (debounceSaver != null && isDisplayIndexModified) {
debounceSaver.setHasChangesToSave(); debounceSaver.setHasChangesToSave();
saveImmediate();
} }
} }
@ -482,7 +461,7 @@ public final class BookmarkFragment extends BaseLocalListFragment<List<PlaylistL
final int sourceIndex = source.getBindingAdapterPosition(); final int sourceIndex = source.getBindingAdapterPosition();
final int targetIndex = target.getBindingAdapterPosition(); final int targetIndex = target.getBindingAdapterPosition();
final boolean isSwapped = itemListAdapter.swapItems(sourceIndex, targetIndex); final boolean isSwapped = itemListAdapter.swapItems(sourceIndex, targetIndex);
if (isSwapped) { if (isSwapped && debounceSaver != null) {
debounceSaver.setHasChangesToSave(); debounceSaver.setHasChangesToSave();
} }
return isSwapped; return isSwapped;