From 14b94d1eb09bdc248dd8104ddce0334e30a70a8e Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 9 Jan 2018 21:59:17 +0100 Subject: [PATCH] fix #280, fix widget reseting its colors --- .../helpers/MyWidgetMonthlyProvider.kt | 58 +++++++++---------- 1 file changed, 27 insertions(+), 31 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/MyWidgetMonthlyProvider.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/MyWidgetMonthlyProvider.kt index a7d84982e..586ed435e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/MyWidgetMonthlyProvider.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/MyWidgetMonthlyProvider.kt @@ -24,7 +24,7 @@ class MyWidgetMonthlyProvider : AppWidgetProvider() { private val NEW_EVENT = "new_event" companion object { - var targetDate = DateTime.now() + private var targetDate = DateTime.now() } override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) { @@ -32,36 +32,7 @@ class MyWidgetMonthlyProvider : AppWidgetProvider() { } private fun performUpdate(context: Context) { - val largerFontSize = context.config.getFontSize() + 3f - val textColor = context.config.widgetTextColor - val resources = context.resources - - val appWidgetManager = AppWidgetManager.getInstance(context) - appWidgetManager.getAppWidgetIds(getComponentName(context)).forEach { - val views = RemoteViews(context.packageName, R.layout.fragment_month_widget) - views.setBackgroundColor(R.id.calendar_holder, context.config.widgetBgColor) - - views.setTextColor(R.id.top_value, textColor) - views.setTextSize(R.id.top_value, largerFontSize) - - var bmp = resources.getColoredBitmap(R.drawable.ic_pointer_left, textColor) - views.setImageViewBitmap(R.id.top_left_arrow, bmp) - - bmp = resources.getColoredBitmap(R.drawable.ic_pointer_right, textColor) - views.setImageViewBitmap(R.id.top_right_arrow, bmp) - - bmp = resources.getColoredBitmap(R.drawable.ic_plus, textColor) - views.setImageViewBitmap(R.id.top_new_event, bmp) - - setupIntent(context, views, PREV, R.id.top_left_arrow) - setupIntent(context, views, NEXT, R.id.top_right_arrow) - setupIntent(context, views, NEW_EVENT, R.id.top_new_event) - setupAppOpenIntent(context, views, R.id.top_value) - updateDayLabels(context, views, resources, textColor) - - appWidgetManager.updateAppWidget(it, views) - MonthlyCalendarImpl(monthlyCalendar, context).getMonth(targetDate) - } + MonthlyCalendarImpl(monthlyCalendar, context).getMonth(targetDate) } private fun getComponentName(context: Context) = ComponentName(context, MyWidgetMonthlyProvider::class.java) @@ -176,11 +147,36 @@ class MyWidgetMonthlyProvider : AppWidgetProvider() { private val monthlyCalendar = object : MonthlyCalendar { override fun updateMonthlyCalendar(context: Context, month: String, days: List, checkedEvents: Boolean) { + val largerFontSize = context.config.getFontSize() + 3f + val textColor = context.config.widgetTextColor + val resources = context.resources + val appWidgetManager = AppWidgetManager.getInstance(context) appWidgetManager.getAppWidgetIds(getComponentName(context)).forEach { val views = RemoteViews(context.packageName, R.layout.fragment_month_widget) views.setText(R.id.top_value, month) + + views.setBackgroundColor(R.id.calendar_holder, context.config.widgetBgColor) + + views.setTextColor(R.id.top_value, textColor) + views.setTextSize(R.id.top_value, largerFontSize) + + var bmp = resources.getColoredBitmap(R.drawable.ic_pointer_left, textColor) + views.setImageViewBitmap(R.id.top_left_arrow, bmp) + + bmp = resources.getColoredBitmap(R.drawable.ic_pointer_right, textColor) + views.setImageViewBitmap(R.id.top_right_arrow, bmp) + + bmp = resources.getColoredBitmap(R.drawable.ic_plus, textColor) + views.setImageViewBitmap(R.id.top_new_event, bmp) + updateDayLabels(context, views, resources, textColor) updateDays(context, views, days) + + setupIntent(context, views, PREV, R.id.top_left_arrow) + setupIntent(context, views, NEXT, R.id.top_right_arrow) + setupIntent(context, views, NEW_EVENT, R.id.top_new_event) + setupAppOpenIntent(context, views, R.id.top_value) + appWidgetManager.updateAppWidget(it, views) } }