Skip to content

Commit 5b4fbe3

Browse files
authored
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>
1 parent 31ea44c commit 5b4fbe3

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,19 @@ public void addItems(@Nullable final List<? extends LocalItem> data) {
126126

127127
public void removeItem(final LocalItem data) {
128128
final int index = localItems.indexOf(data);
129-
localItems.remove(index);
130-
notifyItemRemoved(index + (header != null ? 1 : 0));
129+
if (index != -1) {
130+
localItems.remove(index);
131+
notifyItemRemoved(index + (header != null ? 1 : 0));
132+
} else {
133+
// this happens when
134+
// 1) removeItem is called on infoItemDuplicate as in showStreamItemDialog of
135+
// LocalPlaylistFragment in this case need to implement delete object by it's duplicate
136+
137+
// OR
138+
139+
// 2)data not in itemList and UI is still not updated so notifyDataSetChanged()
140+
notifyDataSetChanged();
141+
}
131142
}
132143

133144
public boolean swapItems(final int fromAdapterPosition, final int toAdapterPosition) {

checkstyle-suppressions.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<suppressions>
66
<suppress checks="FinalParameters"
77
files="LocalItemListAdapter.java"
8-
lines="221,293"/>
8+
lines="232,304"/>
99

1010
<suppress checks="FinalParameters"
1111
files="InfoListAdapter.java"

0 commit comments

Comments
 (0)