From a27f25960bf5518e1a707e9e66d8418b7f769cbe Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 13 May 2021 14:54:25 +0200 Subject: [PATCH] adding some widget related null checks --- .../calculator/activities/WidgetConfigureActivity.kt | 2 +- .../simplemobiletools/calculator/helpers/MyWidgetProvider.kt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calculator/activities/WidgetConfigureActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calculator/activities/WidgetConfigureActivity.kt index b2a87987..9baa43ee 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calculator/activities/WidgetConfigureActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calculator/activities/WidgetConfigureActivity.kt @@ -64,7 +64,7 @@ class WidgetConfigureActivity : SimpleActivity() { } private fun saveConfig() { - val appWidgetManager = AppWidgetManager.getInstance(this) + val appWidgetManager = AppWidgetManager.getInstance(this) ?: return val views = RemoteViews(packageName, R.layout.widget).apply { applyColorFilter(R.id.widget_background, mBgColor) } diff --git a/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/MyWidgetProvider.kt b/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/MyWidgetProvider.kt index 80f36c98..81b1819e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/MyWidgetProvider.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/MyWidgetProvider.kt @@ -115,7 +115,7 @@ class MyWidgetProvider : AppWidgetProvider(), Calculator { } override fun showNewResult(value: String, context: Context) { - val appWidgetManager = AppWidgetManager.getInstance(context) + val appWidgetManager = AppWidgetManager.getInstance(context) ?: return appWidgetManager.getAppWidgetIds(getComponentName(context)).forEach { val views = RemoteViews(context.packageName, R.layout.widget) views.setText(R.id.result, value) @@ -124,7 +124,7 @@ class MyWidgetProvider : AppWidgetProvider(), Calculator { } override fun showNewFormula(value: String, context: Context) { - val appWidgetManager = AppWidgetManager.getInstance(context) + val appWidgetManager = AppWidgetManager.getInstance(context) ?: return appWidgetManager.getAppWidgetIds(getComponentName(context)).forEach { val views = RemoteViews(context.packageName, R.layout.widget) views.setText(R.id.formula, value)