From 9d9a98d47bf3a8285899b3eb7bfa43bda3cd41b2 Mon Sep 17 00:00:00 2001 From: Tlaster Date: Mon, 1 Mar 2021 16:55:25 +0800 Subject: [PATCH] fix crash at status details adapter --- .../twidere/adapter/StatusDetailsAdapter.kt | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/adapter/StatusDetailsAdapter.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/adapter/StatusDetailsAdapter.kt index 9973b4fd5..4250604f5 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/adapter/StatusDetailsAdapter.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/adapter/StatusDetailsAdapter.kt @@ -124,21 +124,26 @@ class StatusDetailsAdapter( } override fun getStatus(position: Int, raw: Boolean): ParcelableStatus { - when (getItemCountIndex(position, raw)) { - ITEM_IDX_CONVERSATION -> { - var idx = position - getIndexStart(ITEM_IDX_CONVERSATION) - if (data!![idx].is_filtered) idx++ - return data!![idx] - } - ITEM_IDX_REPLY -> { - var idx = position - getIndexStart(ITEM_IDX_CONVERSATION) - - getTypeCount(ITEM_IDX_CONVERSATION) - getTypeCount(ITEM_IDX_STATUS) + - replyStart - if (data!![idx].is_filtered) idx++ - return data!![idx] - } - ITEM_IDX_STATUS -> { - return status!! + data?.let { data -> + when (getItemCountIndex(position, raw)) { + ITEM_IDX_CONVERSATION -> { + var idx = position - getIndexStart(ITEM_IDX_CONVERSATION) + if (data.getOrNull(idx)?.is_filtered == true) idx++ + return data[idx] + } + ITEM_IDX_REPLY -> { + var idx = position - getIndexStart(ITEM_IDX_CONVERSATION) - + getTypeCount(ITEM_IDX_CONVERSATION) - getTypeCount(ITEM_IDX_STATUS) + + replyStart + if (data.getOrNull(idx)?.is_filtered == true) idx++ + return data[idx] + } + ITEM_IDX_STATUS -> { + return status!! + } + else -> { + + } } } throw IndexOutOfBoundsException("index: $position")