From 0e786cfd1652081331519eaf88cb0e6dd5c0955d Mon Sep 17 00:00:00 2001 From: Konrad Pozniak Date: Sun, 21 Apr 2019 14:29:47 +0200 Subject: [PATCH] fix crash when status has more than 4 images and accessibility service is active (#1204) --- .../tusky/util/ListStatusAccessibilityDelegate.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/util/ListStatusAccessibilityDelegate.kt b/app/src/main/java/com/keylesspalace/tusky/util/ListStatusAccessibilityDelegate.kt index cc86631a..34010b7a 100644 --- a/app/src/main/java/com/keylesspalace/tusky/util/ListStatusAccessibilityDelegate.kt +++ b/app/src/main/java/com/keylesspalace/tusky/util/ListStatusAccessibilityDelegate.kt @@ -16,8 +16,10 @@ import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerViewAccessibilityDelegate import com.keylesspalace.tusky.R import com.keylesspalace.tusky.adapter.StatusBaseViewHolder +import com.keylesspalace.tusky.entity.Status.Companion.MAX_MEDIA_ATTACHMENTS import com.keylesspalace.tusky.interfaces.StatusActionListener import com.keylesspalace.tusky.viewdata.StatusViewData +import kotlin.math.min // Not using lambdas because there's boxing of int then interface StatusProvider { @@ -60,7 +62,8 @@ class ListStatusAccessibilityDelegate( R.id.action_open_media_2, R.id.action_open_media_3, R.id.action_open_media_4) - for (i in 0 until status.attachments.size) { + val attachmentCount = min(status.attachments.size, MAX_MEDIA_ATTACHMENTS) + for (i in 0 until attachmentCount) { info.addAction(AccessibilityActionCompat( mediaActions[i], context.getString(R.string.action_open_media_n, i + 1)))