From 0adbc34dcc8b80907e7d1f155fc35d1e0c802da1 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 14 Oct 2017 10:50:32 +0200 Subject: [PATCH] adding a couple monthly widget improvements --- .../calendar/extensions/Context.kt | 4 ++-- .../helpers/MyWidgetMonthlyProvider.kt | 21 +++++++++---------- .../res/layout/day_monthly_event_view.xml | 16 ++++++++++++++ ...m_view.xml => day_monthly_number_view.xml} | 4 ++-- 4 files changed, 30 insertions(+), 15 deletions(-) create mode 100644 app/src/main/res/layout/day_monthly_event_view.xml rename app/src/main/res/layout/{day_monthly_item_view.xml => day_monthly_number_view.xml} (86%) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt index 6b86c0d1b..b8d6c78e9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt @@ -268,7 +268,7 @@ fun Context.addDayNumber(rawTextColor: Int, day: DayMonthly, linearLayout: Linea if (!day.isThisMonth) textColor = textColor.adjustAlpha(LOW_ALPHA) - (View.inflate(this, R.layout.day_monthly_item_view, null) as TextView).apply { + (View.inflate(this, R.layout.day_monthly_number_view, null) as TextView).apply { setTextColor(textColor) text = day.value.toString() gravity = Gravity.TOP or Gravity.CENTER_HORIZONTAL @@ -310,7 +310,7 @@ fun Context.addDayEvents(day: DayMonthly, linearLayout: LinearLayout, res: Resou textColor = textColor.adjustAlpha(0.25f) } - (View.inflate(this, R.layout.day_monthly_item_view, null) as TextView).apply { + (View.inflate(this, R.layout.day_monthly_event_view, null) as TextView).apply { setTextColor(textColor) text = it.title.replace(" ", "\u00A0") // allow word break by char background = backgroundDrawable 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 460150e75..d8c29d83b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/MyWidgetMonthlyProvider.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/MyWidgetMonthlyProvider.kt @@ -29,7 +29,6 @@ class MyWidgetMonthlyProvider : AppWidgetProvider(), MonthlyCalendar { private var mTextColor = 0 private var mCalendar: MonthlyCalendarImpl? = null - private var mRemoteViews: RemoteViews? = null private var mSmallerFontSize = 0f private var mMediumFontSize = 0f @@ -42,6 +41,7 @@ class MyWidgetMonthlyProvider : AppWidgetProvider(), MonthlyCalendar { companion object { private var mTargetDate = DateTime() + private var mRemoteViews: RemoteViews? = null } override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) { @@ -112,7 +112,6 @@ class MyWidgetMonthlyProvider : AppWidgetProvider(), MonthlyCalendar { override fun onReceive(context: Context, intent: Intent) { if (mCalendar == null || mRemoteViews == null) { initVariables(context) - return } val action = intent.action @@ -178,10 +177,10 @@ class MyWidgetMonthlyProvider : AppWidgetProvider(), MonthlyCalendar { backgroundColor = backgroundColor.adjustAlpha(0.25f) } - 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) + val newRemoteView = RemoteViews(packageName, R.layout.day_monthly_event_view).apply { + setTextViewText(R.id.day_monthly_event_id, it.title.replace(" ", "\u00A0")) + setTextColor(R.id.day_monthly_event_id, eventTextColor) + setBackgroundColor(R.id.day_monthly_event_id, backgroundColor) } mRemoteViews!!.addView(id, newRemoteView) } @@ -189,13 +188,13 @@ class MyWidgetMonthlyProvider : AppWidgetProvider(), MonthlyCalendar { } 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) + val newRemoteView = RemoteViews(packageName, R.layout.day_monthly_number_view).apply { + setTextViewText(R.id.day_monthly_number_id, day.value.toString()) + setTextColor(R.id.day_monthly_number_id, textColor) if (day.isToday) { - setViewPadding(R.id.day_monthly_id, 10, 0, 10, 0) - setBackgroundColor(R.id.day_monthly_id, primaryColor) + setViewPadding(R.id.day_monthly_number_id, 10, 0, 10, 0) + setBackgroundColor(R.id.day_monthly_number_id, primaryColor) } } mRemoteViews!!.addView(id, newRemoteView) diff --git a/app/src/main/res/layout/day_monthly_event_view.xml b/app/src/main/res/layout/day_monthly_event_view.xml new file mode 100644 index 000000000..9a85d597e --- /dev/null +++ b/app/src/main/res/layout/day_monthly_event_view.xml @@ -0,0 +1,16 @@ + + diff --git a/app/src/main/res/layout/day_monthly_item_view.xml b/app/src/main/res/layout/day_monthly_number_view.xml similarity index 86% rename from app/src/main/res/layout/day_monthly_item_view.xml rename to app/src/main/res/layout/day_monthly_number_view.xml index d27046520..baffa6f6f 100644 --- a/app/src/main/res/layout/day_monthly_item_view.xml +++ b/app/src/main/res/layout/day_monthly_number_view.xml @@ -2,13 +2,13 @@