adding some widget related null checks

This commit is contained in:
tibbi 2021-05-13 14:55:35 +02:00
parent 56a5ebabbe
commit 17c436b383
2 changed files with 3 additions and 3 deletions

View File

@ -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
}

View File

@ -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)