From b02afc58d86750a683314dc67a04fda3b1fe56fe Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 9 Jul 2023 18:01:07 +0200 Subject: [PATCH] fix displaying the next alarm on the widget --- .../helpers/MyDigitalTimeWidgetProvider.kt | 29 ++++++++----------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/helpers/MyDigitalTimeWidgetProvider.kt b/app/src/main/kotlin/com/simplemobiletools/clock/helpers/MyDigitalTimeWidgetProvider.kt index c2e7125d..53e1b42c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/helpers/MyDigitalTimeWidgetProvider.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/helpers/MyDigitalTimeWidgetProvider.kt @@ -17,11 +17,6 @@ import com.simplemobiletools.commons.extensions.applyColorFilter import com.simplemobiletools.commons.extensions.getLaunchIntent import com.simplemobiletools.commons.extensions.setText import com.simplemobiletools.commons.extensions.setVisibleIf -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.cancel -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext class MyDigitalTimeWidgetProvider : AppWidgetProvider() { override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) { @@ -31,22 +26,22 @@ class MyDigitalTimeWidgetProvider : AppWidgetProvider() { private fun performUpdate(context: Context) { val appWidgetManager = AppWidgetManager.getInstance(context) ?: return - appWidgetManager.getAppWidgetIds(getComponentName(context)).forEach { - RemoteViews(context.packageName, R.layout.widget_digital).apply { - updateTexts(context, this) - updateColors(context, this) - setupAppOpenIntent(context, this) - appWidgetManager.updateAppWidget(it, this) + context.getClosestEnabledAlarmString { nextAlarm -> + appWidgetManager.getAppWidgetIds(getComponentName(context)).forEach { + RemoteViews(context.packageName, R.layout.widget_digital).apply { + updateTexts(context, this, nextAlarm) + updateColors(context, this) + setupAppOpenIntent(context, this) + appWidgetManager.updateAppWidget(it, this) + } } } } - private fun updateTexts(context: Context, views: RemoteViews) { - context.getClosestEnabledAlarmString { nextAlarm -> - views.apply { - setText(R.id.widget_next_alarm, nextAlarm) - setVisibleIf(R.id.widget_alarm_holder, nextAlarm.isNotEmpty()) - } + private fun updateTexts(context: Context, views: RemoteViews, nextAlarm: String) { + views.apply { + setText(R.id.widget_next_alarm, nextAlarm) + setVisibleIf(R.id.widget_alarm_holder, nextAlarm.isNotEmpty()) } }