From bca98d2f4887921dbd607cbe169850730ecfca60 Mon Sep 17 00:00:00 2001 From: Lakoja Date: Wed, 5 Apr 2023 15:48:40 +0200 Subject: [PATCH] Do not crash on/avoid index out of bounds --- .../tusky/components/notifications/NotificationsFragment.kt | 2 +- .../keylesspalace/tusky/components/timeline/TimelineFragment.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/components/notifications/NotificationsFragment.kt b/app/src/main/java/com/keylesspalace/tusky/components/notifications/NotificationsFragment.kt index 1455f83b..49267b5f 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/notifications/NotificationsFragment.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/notifications/NotificationsFragment.kt @@ -161,7 +161,7 @@ class NotificationsFragment : binding.recyclerView, this ) { pos: Int -> - val notification = adapter.snapshot()[pos] + val notification = adapter.snapshot().getOrNull(pos) // We support replies only for now if (notification is NotificationViewData) { notification.statusViewData diff --git a/app/src/main/java/com/keylesspalace/tusky/components/timeline/TimelineFragment.kt b/app/src/main/java/com/keylesspalace/tusky/components/timeline/TimelineFragment.kt index c5998f1d..34608eca 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/timeline/TimelineFragment.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/timeline/TimelineFragment.kt @@ -478,7 +478,7 @@ class TimelineFragment : override fun onLoadMore(position: Int) { val placeholder = adapter.peek(position)?.asPlaceholderOrNull() ?: return loadMorePosition = position - statusIdBelowLoadMore = adapter.peek(position + 1)?.id + statusIdBelowLoadMore = if (position + 1 < adapter.itemCount) adapter.peek(position + 1)?.id else null viewModel.loadMore(placeholder.id) }