fix IndexOutOfBoundException caused by ListStatusAccessibilityDelegate (#1178)

main
Konrad Pozniak 6 years ago committed by GitHub
parent 5ca87062e1
commit 5cf82f402f
  1. 2
      app/src/main/java/com/keylesspalace/tusky/fragment/NotificationsFragment.java
  2. 2
      app/src/main/java/com/keylesspalace/tusky/fragment/TimelineFragment.java
  3. 2
      app/src/main/java/com/keylesspalace/tusky/fragment/ViewThreadFragment.java
  4. 10
      app/src/main/java/com/keylesspalace/tusky/util/PairedList.java

@ -191,7 +191,7 @@ public class NotificationsFragment extends SFragment implements
recyclerView.setLayoutManager(layoutManager); recyclerView.setLayoutManager(layoutManager);
recyclerView.setAccessibilityDelegateCompat( recyclerView.setAccessibilityDelegateCompat(
new ListStatusAccessibilityDelegate(recyclerView, this, (pos) -> { new ListStatusAccessibilityDelegate(recyclerView, this, (pos) -> {
NotificationViewData notification = notifications.getPairedItem(pos); NotificationViewData notification = notifications.getPairedItemOrNull(pos);
// We support replies only for now // We support replies only for now
if (notification instanceof NotificationViewData.Concrete) { if (notification instanceof NotificationViewData.Concrete) {
return ((NotificationViewData.Concrete) notification).getStatusViewData(); return ((NotificationViewData.Concrete) notification).getStatusViewData();

@ -397,7 +397,7 @@ public class TimelineFragment extends SFragment implements
private void setupRecyclerView() { private void setupRecyclerView() {
recyclerView.setAccessibilityDelegateCompat( recyclerView.setAccessibilityDelegateCompat(
new ListStatusAccessibilityDelegate(recyclerView, this, statuses::getPairedItem)); new ListStatusAccessibilityDelegate(recyclerView, this, statuses::getPairedItemOrNull));
Context context = recyclerView.getContext(); Context context = recyclerView.getContext();
recyclerView.setHasFixedSize(true); recyclerView.setHasFixedSize(true);
layoutManager = new LinearLayoutManager(context); layoutManager = new LinearLayoutManager(context);

@ -141,7 +141,7 @@ public final class ViewThreadFragment extends SFragment implements
LinearLayoutManager layoutManager = new LinearLayoutManager(context); LinearLayoutManager layoutManager = new LinearLayoutManager(context);
recyclerView.setLayoutManager(layoutManager); recyclerView.setLayoutManager(layoutManager);
recyclerView.setAccessibilityDelegateCompat( recyclerView.setAccessibilityDelegateCompat(
new ListStatusAccessibilityDelegate(recyclerView, this, statuses::getPairedItem)); new ListStatusAccessibilityDelegate(recyclerView, this, statuses::getPairedItemOrNull));
DividerItemDecoration divider = new DividerItemDecoration( DividerItemDecoration divider = new DividerItemDecoration(
context, layoutManager.getOrientation()); context, layoutManager.getOrientation());
recyclerView.addItemDecoration(divider); recyclerView.addItemDecoration(divider);

@ -1,5 +1,6 @@
package com.keylesspalace.tusky.util; package com.keylesspalace.tusky.util;
import androidx.annotation.Nullable;
import androidx.arch.core.util.Function; import androidx.arch.core.util.Function;
import java.util.AbstractList; import java.util.AbstractList;
@ -44,6 +45,15 @@ public final class PairedList<T, V> extends AbstractList<T> {
return synced.get(index); 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) { public void setPairedItem(int index, V element) {
synced.set(index, element); synced.set(index, element);
} }

Loading…
Cancel
Save