From 17c436b3834706b7bde27b772620b1c9762cfb5c Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 13 May 2021 14:55:35 +0200 Subject: [PATCH] adding some widget related null checks --- .../kotlin/com/simplemobiletools/clock/extensions/Context.kt | 4 ++-- .../clock/helpers/MyWidgetDateTimeProvider.kt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/clock/extensions/Context.kt index ce2423cd..16dd29e9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/extensions/Context.kt @@ -160,7 +160,7 @@ fun Context.hideNotification(id: Int) { fun Context.hideTimerNotification() = hideNotification(TIMER_NOTIF_ID) fun Context.updateWidgets() { - val widgetsCnt = AppWidgetManager.getInstance(applicationContext).getAppWidgetIds(ComponentName(applicationContext, MyWidgetDateTimeProvider::class.java)) + val widgetsCnt = AppWidgetManager.getInstance(applicationContext)?.getAppWidgetIds(ComponentName(applicationContext, MyWidgetDateTimeProvider::class.java)) ?: return if (widgetsCnt.isNotEmpty()) { val ids = intArrayOf(R.xml.widget_date_time_info) Intent(applicationContext, MyWidgetDateTimeProvider::class.java).apply { @@ -173,7 +173,7 @@ fun Context.updateWidgets() { @SuppressLint("NewApi") fun Context.scheduleNextWidgetUpdate() { - val widgetsCnt = AppWidgetManager.getInstance(applicationContext).getAppWidgetIds(ComponentName(applicationContext, MyWidgetDateTimeProvider::class.java)) + val widgetsCnt = AppWidgetManager.getInstance(applicationContext)?.getAppWidgetIds(ComponentName(applicationContext, MyWidgetDateTimeProvider::class.java)) ?: return if (widgetsCnt.isEmpty()) { return } diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/helpers/MyWidgetDateTimeProvider.kt b/app/src/main/kotlin/com/simplemobiletools/clock/helpers/MyWidgetDateTimeProvider.kt index b34e60b3..89128df9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/helpers/MyWidgetDateTimeProvider.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/helpers/MyWidgetDateTimeProvider.kt @@ -30,7 +30,7 @@ class MyWidgetDateTimeProvider : AppWidgetProvider() { } private fun performUpdate(context: Context) { - val appWidgetManager = AppWidgetManager.getInstance(context) + val appWidgetManager = AppWidgetManager.getInstance(context) ?: return appWidgetManager.getAppWidgetIds(getComponentName(context)).forEach { RemoteViews(context.packageName, getProperLayout(context)).apply { updateTexts(context, this)