fix IndexOutOfBoundException caused by ListStatusAccessibilityDelegate (#1178)
This commit is contained in:
parent
4ed65ac4a0
commit
dd02af9911
|
@ -191,7 +191,7 @@ public class NotificationsFragment extends SFragment implements
|
|||
recyclerView.setLayoutManager(layoutManager);
|
||||
recyclerView.setAccessibilityDelegateCompat(
|
||||
new ListStatusAccessibilityDelegate(recyclerView, this, (pos) -> {
|
||||
NotificationViewData notification = notifications.getPairedItem(pos);
|
||||
NotificationViewData notification = notifications.getPairedItemOrNull(pos);
|
||||
// We support replies only for now
|
||||
if (notification instanceof NotificationViewData.Concrete) {
|
||||
return ((NotificationViewData.Concrete) notification).getStatusViewData();
|
||||
|
|
|
@ -397,7 +397,7 @@ public class TimelineFragment extends SFragment implements
|
|||
|
||||
private void setupRecyclerView() {
|
||||
recyclerView.setAccessibilityDelegateCompat(
|
||||
new ListStatusAccessibilityDelegate(recyclerView, this, statuses::getPairedItem));
|
||||
new ListStatusAccessibilityDelegate(recyclerView, this, statuses::getPairedItemOrNull));
|
||||
Context context = recyclerView.getContext();
|
||||
recyclerView.setHasFixedSize(true);
|
||||
layoutManager = new LinearLayoutManager(context);
|
||||
|
|
|
@ -141,7 +141,7 @@ public final class ViewThreadFragment extends SFragment implements
|
|||
LinearLayoutManager layoutManager = new LinearLayoutManager(context);
|
||||
recyclerView.setLayoutManager(layoutManager);
|
||||
recyclerView.setAccessibilityDelegateCompat(
|
||||
new ListStatusAccessibilityDelegate(recyclerView, this, statuses::getPairedItem));
|
||||
new ListStatusAccessibilityDelegate(recyclerView, this, statuses::getPairedItemOrNull));
|
||||
DividerItemDecoration divider = new DividerItemDecoration(
|
||||
context, layoutManager.getOrientation());
|
||||
recyclerView.addItemDecoration(divider);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.keylesspalace.tusky.util;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.arch.core.util.Function;
|
||||
|
||||
import java.util.AbstractList;
|
||||
|
@ -44,6 +45,15 @@ public final class PairedList<T, V> extends AbstractList<T> {
|
|||
return synced.get(index);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public V getPairedItemOrNull(int index) {
|
||||
if (index >= 0 && index < synced.size()) {
|
||||
return synced.get(index);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setPairedItem(int index, V element) {
|
||||
synced.set(index, element);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue