Skip to content

Commit

Permalink
fix trying to delete object by index -1
Browse files Browse the repository at this point in the history
  • Loading branch information
sauravrao637 committed Apr 21, 2021
1 parent c12ac64 commit 4af4055
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,19 @@ public void addItems(@Nullable final List<? extends LocalItem> data) {

public void removeItem(final LocalItem data) {
final int index = localItems.indexOf(data);
localItems.remove(index);
notifyItemRemoved(index + (header != null ? 1 : 0));
if (index != -1) {
localItems.remove(index);
notifyItemRemoved(index + (header != null ? 1 : 0));
} else {
// this happens when
// 1) removeItem is called on infoItemDuplicate as in showStreamItemDialog of
// LocalPlaylistFragment in this case need to implement delete object by it's duplicate

// OR

// 2)data not in itemList and UI is still not updated so notifyDataSetChanged()
notifyDataSetChanged();
}
}

public boolean swapItems(final int fromAdapterPosition, final int toAdapterPosition) {
Expand Down

0 comments on commit 4af4055

Please sign in to comment.