diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/StatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/StatusDisplayItem.java index cdc663c6a..0dd08c548 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/StatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/StatusDisplayItem.java @@ -397,10 +397,11 @@ public abstract class StatusDisplayItem{ } public Optional getDisplayItemOffset(int offset){ - int nextPos=getAbsoluteAdapterPosition() + offset; List displayItems=item.parentFragment.getDisplayItems(); - return displayItems.size() > nextPos - ? Optional.of(displayItems.get(nextPos)) + int thisPos=displayItems.indexOf(item); + int offsetPos=thisPos + offset; + return displayItems.size() > offsetPos && thisPos >= 0 && offsetPos >= 0 + ? Optional.of(displayItems.get(offsetPos)) : Optional.empty(); }