mirror of
https://github.com/TeamNewPipe/NewPipe.git
synced 2024-11-24 20:15:16 +01:00
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:
parent
90979e2a81
commit
3cc0205def
@ -56,7 +56,7 @@ public final class BookmarkFragment extends BaseLocalListFragment<List<PlaylistL
|
||||
|
||||
private static final int MINIMUM_INITIAL_DRAG_VELOCITY = 12;
|
||||
@State
|
||||
protected Parcelable itemsListState;
|
||||
Parcelable itemsListState;
|
||||
|
||||
private Subscription databaseSubscription;
|
||||
private CompositeDisposable disposables = new CompositeDisposable();
|
||||
@ -68,6 +68,7 @@ public final class BookmarkFragment extends BaseLocalListFragment<List<PlaylistL
|
||||
private AtomicBoolean isLoadingComplete;
|
||||
|
||||
/* Gives enough time to avoid interrupting user sorting operations */
|
||||
@Nullable
|
||||
private DebounceSaver debounceSaver;
|
||||
|
||||
private List<Pair<Long, LocalItem.LocalItemType>> deletedItems;
|
||||
@ -259,7 +260,6 @@ public final class BookmarkFragment extends BaseLocalListFragment<List<PlaylistL
|
||||
@Override
|
||||
public void onNext(final List<PlaylistLocalItem> subscriptions) {
|
||||
if (debounceSaver == null || !debounceSaver.getIsModified()) {
|
||||
checkDisplayIndexModified(subscriptions);
|
||||
handleResult(subscriptions);
|
||||
isLoadingComplete.set(true);
|
||||
}
|
||||
@ -349,30 +349,9 @@ public final class BookmarkFragment extends BaseLocalListFragment<List<PlaylistL
|
||||
LocalItem.LocalItemType.PLAYLIST_REMOTE_ITEM));
|
||||
}
|
||||
|
||||
if (debounceSaver != null) {
|
||||
debounceSaver.setHasChangesToSave();
|
||||
}
|
||||
|
||||
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();
|
||||
saveImmediate();
|
||||
}
|
||||
}
|
||||
|
||||
@ -482,7 +461,7 @@ public final class BookmarkFragment extends BaseLocalListFragment<List<PlaylistL
|
||||
final int sourceIndex = source.getBindingAdapterPosition();
|
||||
final int targetIndex = target.getBindingAdapterPosition();
|
||||
final boolean isSwapped = itemListAdapter.swapItems(sourceIndex, targetIndex);
|
||||
if (isSwapped) {
|
||||
if (isSwapped && debounceSaver != null) {
|
||||
debounceSaver.setHasChangesToSave();
|
||||
}
|
||||
return isSwapped;
|
||||
|
Loading…
Reference in New Issue
Block a user