Fix NPE on devices that don't support widgets
Turns out, AppWidgetManager.getInstance(context) can return null. I've tested that this change fixes the issue on the device.
This commit is contained in:
parent
0220e1d800
commit
f647e50a2e
1 changed files with 3 additions and 3 deletions
|
@ -14,7 +14,7 @@ class MessageListWidgetManager(
|
|||
private val messageListRepository: MessageListRepository,
|
||||
private val config: MessageListWidgetConfig,
|
||||
) {
|
||||
private lateinit var appWidgetManager: AppWidgetManager
|
||||
private var appWidgetManager: AppWidgetManager? = null
|
||||
|
||||
private var listenerAdded = false
|
||||
private val listener = MessageListChangedListener {
|
||||
|
@ -83,7 +83,7 @@ class MessageListWidgetManager(
|
|||
private fun triggerMessageListWidgetUpdate() {
|
||||
val appWidgetIds = getAppWidgetIds()
|
||||
if (appWidgetIds.isNotEmpty()) {
|
||||
appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.listView)
|
||||
appWidgetManager?.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.listView)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -101,6 +101,6 @@ class MessageListWidgetManager(
|
|||
|
||||
private fun getAppWidgetIds(): IntArray {
|
||||
val componentName = ComponentName(context, config.providerClass)
|
||||
return appWidgetManager.getAppWidgetIds(componentName)
|
||||
return appWidgetManager?.getAppWidgetIds(componentName) ?: intArrayOf()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue