Browse Source

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>
pull/6274/head
Saurav Rao 7 months ago
committed by GitHub
parent
commit
5b4fbe32b1
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      app/src/main/java/org/schabi/newpipe/local/LocalItemListAdapter.java
  2. 2
      checkstyle-suppressions.xml

15
app/src/main/java/org/schabi/newpipe/local/LocalItemListAdapter.java

@ -126,8 +126,19 @@ public class LocalItemListAdapter extends RecyclerView.Adapter<RecyclerView.View
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) {

2
checkstyle-suppressions.xml

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

Loading…
Cancel
Save