Prevent crash if WidgetsAdapter is not ready when configuration changes

This commit is contained in:
Ensar Sarajčić 2023-09-21 14:50:13 +02:00
parent 65ace16fbf
commit 28e0f2d59f

View file

@ -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 {