Skip to content

Commit

Permalink
Fix inconsistencies when removing playlist
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Stypox committed Mar 30, 2024
1 parent 90979e2 commit 3cc0205
Showing 1 changed file with 5 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand Down Expand Up @@ -259,7 +260,6 @@ public void onSubscribe(final Subscription s) {
@Override
public void onNext(final List<PlaylistLocalItem> subscriptions) {
if (debounceSaver == null || !debounceSaver.getIsModified()) {
checkDisplayIndexModified(subscriptions);
handleResult(subscriptions);
isLoadingComplete.set(true);
}
Expand Down Expand Up @@ -349,30 +349,9 @@ private void deleteItem(final PlaylistLocalItem item) {
LocalItem.LocalItemType.PLAYLIST_REMOTE_ITEM));
}

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) {
if (debounceSaver != null) {
debounceSaver.setHasChangesToSave();
saveImmediate();
}
}

Expand Down Expand Up @@ -482,7 +461,7 @@ public boolean onMove(@NonNull final RecyclerView recyclerView,
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;
Expand Down

0 comments on commit 3cc0205

Please sign in to comment.