fix IndexOutOfBoundException caused by ListStatusAccessibilityDelegate (#1178)

This commit is contained in:
Konrad Pozniak 2019-04-07 16:32:58 +02:00 committed by GitHub
parent 4ed65ac4a0
commit dd02af9911
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 3 deletions

View File

@ -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();

View File

@ -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);

View File

@ -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);

View File

@ -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);
} }