From 28e0f2d59fba768fd07184d29d29c09a678cb532 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Thu, 21 Sep 2023 14:50:13 +0200 Subject: [PATCH] Prevent crash if WidgetsAdapter is not ready when configuration changes --- .../launcher/fragments/WidgetsFragment.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/fragments/WidgetsFragment.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/fragments/WidgetsFragment.kt index d637565..4b23264 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/fragments/WidgetsFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/fragments/WidgetsFragment.kt @@ -55,8 +55,12 @@ class WidgetsFragment(context: Context, attributeSet: AttributeSet) : MyFragment binding.widgetsList.scrollToPosition(0) setupViews() - val appWidgets = (binding.widgetsList.adapter as WidgetsAdapter).widgetListItems - setupAdapter(appWidgets) + val appWidgets = (binding.widgetsList.adapter as? WidgetsAdapter)?.widgetListItems + if (appWidgets != null) { + setupAdapter(appWidgets) + } else { + getAppWidgets() + } } override fun onInterceptTouchEvent(event: MotionEvent?): Boolean {