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
1 changed files with 6 additions and 2 deletions

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
val appWidgets = (binding.widgetsList.adapter as? WidgetsAdapter)?.widgetListItems
if (appWidgets != null) {
setupAdapter(appWidgets)
} else {
getAppWidgets()
}
}
override fun onInterceptTouchEvent(event: MotionEvent?): Boolean {