From 3180a9c5162469c4c1e6ec0428f5c8838f707594 Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Thu, 6 Apr 2017 19:23:41 +0800 Subject: [PATCH] fixed crashes when no network available --- .../mariotaku/twidere/adapter/ParcelableStatusesAdapter.kt | 2 +- .../twidere/fragment/ParcelableStatusesFragment.kt | 2 +- .../kotlin/org/mariotaku/twidere/fragment/StatusFragment.kt | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/adapter/ParcelableStatusesAdapter.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/adapter/ParcelableStatusesAdapter.kt index e1e43b7e4..3a48f9b08 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/adapter/ParcelableStatusesAdapter.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/adapter/ParcelableStatusesAdapter.kt @@ -415,7 +415,7 @@ abstract class ParcelableStatusesAdapter( var sum = 0 for (i in 0 until itemCounts.size) { sum += when (i) { - ITEM_INDEX_STATUS -> data!!.size + ITEM_INDEX_STATUS -> data?.size ?: 0 else -> itemCounts[i] } if (position < sum) { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ParcelableStatusesFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ParcelableStatusesFragment.kt index 19902c850..23e9a7385 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ParcelableStatusesFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ParcelableStatusesFragment.kt @@ -167,7 +167,7 @@ abstract class ParcelableStatusesFragment : AbsStatusesFragment() { super.triggerRefresh() val accountKeys = accountKeys val statusStartIndex = adapter.statusStartIndex - if (statusStartIndex >= 0) { + if (statusStartIndex >= 0 && adapter.getStatusCount(true) > 0) { val firstStatus = adapter.getStatus(statusStartIndex, true) val sinceIds = Array(accountKeys.size) { return@Array if (firstStatus.account_key == accountKeys[it]) firstStatus.id else null diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/StatusFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/StatusFragment.kt index 2bddd2e78..7e46a8a1a 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/StatusFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/StatusFragment.kt @@ -2018,14 +2018,14 @@ class StatusFragment : BaseFragment(), LoaderCallbacks 0) { if (isSmoothScrollbarEnabled) { var extent = childCount * 100 - var view = findViewByPosition(firstPosition) + var view = findViewByPosition(firstPosition) ?: return 0 val top = view.top var height = view.height if (height > 0) { extent += top * 100 / height } - view = findViewByPosition(lastPosition) + view = findViewByPosition(lastPosition) ?: return 0 val bottom = view.bottom height = view.height if (height > 0) { @@ -2047,7 +2047,7 @@ class StatusFragment : BaseFragment(), LoaderCallbacks= skippedCount && childCount > 0) { if (isSmoothScrollbarEnabled) { - val view = findViewByPosition(firstPosition) + val view = findViewByPosition(firstPosition) ?: return 0 val top = view.top val height = view.height if (height > 0) {