Fix trying to delete object not in list (#6127)

* fix trying to delete object by index -1

* correction in checkstyle-supressions.xml

Co-authored-by: camo0112 <56369484+camo0112@users.noreply.github.com>
This commit is contained in:
Saurav Rao 2021-05-12 18:03:00 +05:30 committed by GitHub
parent 31ea44ccf1
commit 5b4fbe32b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 3 deletions

View File

@ -126,8 +126,19 @@ public class LocalItemListAdapter extends RecyclerView.Adapter<RecyclerView.View
public void removeItem(final LocalItem data) { public void removeItem(final LocalItem data) {
final int index = localItems.indexOf(data); final int index = localItems.indexOf(data);
if (index != -1) {
localItems.remove(index); localItems.remove(index);
notifyItemRemoved(index + (header != null ? 1 : 0)); 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) { public boolean swapItems(final int fromAdapterPosition, final int toAdapterPosition) {

View File

@ -5,7 +5,7 @@
<suppressions> <suppressions>
<suppress checks="FinalParameters" <suppress checks="FinalParameters"
files="LocalItemListAdapter.java" files="LocalItemListAdapter.java"
lines="221,293"/> lines="232,304"/>
<suppress checks="FinalParameters" <suppress checks="FinalParameters"
files="InfoListAdapter.java" files="InfoListAdapter.java"