From 669a93122473ec5bb68a6241a5094f897927855a Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 8 Oct 2017 18:30:40 +0200 Subject: [PATCH] add the events to the monthly widget too --- .../helpers/MyWidgetMonthlyProvider.kt | 40 ++++++++++++++----- .../main/res/layout/day_monthly_item_view.xml | 5 ++- 2 files changed, 32 insertions(+), 13 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 097907876..460150e75 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/MyWidgetMonthlyProvider.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/MyWidgetMonthlyProvider.kt @@ -166,24 +166,42 @@ class MyWidgetMonthlyProvider : AppWidgetProvider(), MonthlyCalendar { textColor = primaryColor.getContrastColor() val id = mRes.getIdentifier("day_$i", "id", packageName) + mRemoteViews!!.removeAllViews(id) + addDayNumber(day, packageName, textColor, id, primaryColor) - mRemoteViews!!.apply { - removeAllViews(id) - val newRemoteView = RemoteViews(packageName, R.layout.day_monthly_item_view).apply { - setTextViewText(R.id.day_monthly_number_id, day.value.toString()) - setTextColor(R.id.day_monthly_number_id, textColor) + day.dayEvents.forEach { + var backgroundColor = it.color + var eventTextColor = backgroundColor.getContrastColor().adjustAlpha(MEDIUM_ALPHA) - if (day.isToday) { - setViewPadding(R.id.day_monthly_number_id, 10, 0, 10, 0) - setBackgroundColor(R.id.day_monthly_number_id, primaryColor) - } + if (!day.isThisMonth) { + eventTextColor = eventTextColor.adjustAlpha(0.25f) + backgroundColor = backgroundColor.adjustAlpha(0.25f) } - addView(id, newRemoteView) - setupDayOpenIntent(id, day.code) + + val newRemoteView = RemoteViews(packageName, R.layout.day_monthly_item_view).apply { + setTextViewText(R.id.day_monthly_id, it.title.replace(" ", "\u00A0")) + setTextColor(R.id.day_monthly_id, eventTextColor) + setBackgroundColor(R.id.day_monthly_id, backgroundColor) + } + mRemoteViews!!.addView(id, newRemoteView) } } } + private fun addDayNumber(day: DayMonthly, packageName: String, textColor: Int, id: Int, primaryColor: Int) { + val newRemoteView = RemoteViews(packageName, R.layout.day_monthly_item_view).apply { + setTextViewText(R.id.day_monthly_id, day.value.toString()) + setTextColor(R.id.day_monthly_id, textColor) + + if (day.isToday) { + setViewPadding(R.id.day_monthly_id, 10, 0, 10, 0) + setBackgroundColor(R.id.day_monthly_id, primaryColor) + } + } + mRemoteViews!!.addView(id, newRemoteView) + setupDayOpenIntent(id, day.code) + } + private fun updateTopViews() { mRemoteViews?.setTextColor(R.id.top_value, mTextColor) mRemoteViews?.setTextSize(R.id.top_value, mLargerFontSize) diff --git a/app/src/main/res/layout/day_monthly_item_view.xml b/app/src/main/res/layout/day_monthly_item_view.xml index 33c9f75d0..074884ed1 100644 --- a/app/src/main/res/layout/day_monthly_item_view.xml +++ b/app/src/main/res/layout/day_monthly_item_view.xml @@ -2,12 +2,13 @@