adding some widget related null checks

This commit is contained in:
tibbi 2021-05-13 14:54:25 +02:00
parent d09aa44f91
commit a27f25960b
2 changed files with 3 additions and 3 deletions

View File

@ -64,7 +64,7 @@ class WidgetConfigureActivity : SimpleActivity() {
} }
private fun saveConfig() { private fun saveConfig() {
val appWidgetManager = AppWidgetManager.getInstance(this) val appWidgetManager = AppWidgetManager.getInstance(this) ?: return
val views = RemoteViews(packageName, R.layout.widget).apply { val views = RemoteViews(packageName, R.layout.widget).apply {
applyColorFilter(R.id.widget_background, mBgColor) applyColorFilter(R.id.widget_background, mBgColor)
} }

View File

@ -115,7 +115,7 @@ class MyWidgetProvider : AppWidgetProvider(), Calculator {
} }
override fun showNewResult(value: String, context: Context) { override fun showNewResult(value: String, context: Context) {
val appWidgetManager = AppWidgetManager.getInstance(context) val appWidgetManager = AppWidgetManager.getInstance(context) ?: return
appWidgetManager.getAppWidgetIds(getComponentName(context)).forEach { appWidgetManager.getAppWidgetIds(getComponentName(context)).forEach {
val views = RemoteViews(context.packageName, R.layout.widget) val views = RemoteViews(context.packageName, R.layout.widget)
views.setText(R.id.result, value) views.setText(R.id.result, value)
@ -124,7 +124,7 @@ class MyWidgetProvider : AppWidgetProvider(), Calculator {
} }
override fun showNewFormula(value: String, context: Context) { override fun showNewFormula(value: String, context: Context) {
val appWidgetManager = AppWidgetManager.getInstance(context) val appWidgetManager = AppWidgetManager.getInstance(context) ?: return
appWidgetManager.getAppWidgetIds(getComponentName(context)).forEach { appWidgetManager.getAppWidgetIds(getComponentName(context)).forEach {
val views = RemoteViews(context.packageName, R.layout.widget) val views = RemoteViews(context.packageName, R.layout.widget)
views.setText(R.id.formula, value) views.setText(R.id.formula, value)