From e3c08831986d0468eb5c09e91dbaa37766826a34 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 24 Mar 2018 19:26:11 +0100 Subject: [PATCH] mark the current day of the week, if it is at the current month --- .../calendar/views/MonthView.kt | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/views/MonthView.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/views/MonthView.kt index b627722bd..57169879a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/views/MonthView.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/views/MonthView.kt @@ -13,6 +13,7 @@ import com.simplemobiletools.commons.extensions.adjustAlpha import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor import com.simplemobiletools.commons.extensions.getContrastColor import com.simplemobiletools.commons.extensions.moveLastItemToFront +import org.joda.time.DateTime // used in the Monthly view fragment, 1 view per screen class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(context, attrs, defStyle) { @@ -23,6 +24,7 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con private var textColor = 0 private var weakTextColor = 0 private var weekDaysLetterHeight = 0 + private var currDayOfWeek = 0 private var dayLetters = ArrayList() private var days = ArrayList() @@ -42,11 +44,13 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con weekDaysLetterHeight = 2 * normalTextSize.toInt() initWeekDayLetters() + setupCurrentDayOfWeekIndex() } fun updateDays(newDays: ArrayList) { days = newDays initWeekDayLetters() + setupCurrentDayOfWeekIndex() invalidate() } @@ -62,7 +66,11 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con for (i in 0..6) { val xPos = (i + 1) * dayWidth - dayWidth / 2 - canvas.drawText(dayLetters[i], xPos, weekDaysLetterHeight / 2f, paint) + var weekDayLetterPaint = paint + if (i == currDayOfWeek) { + weekDayLetterPaint = getColoredPaint(primaryColor) + } + canvas.drawText(dayLetters[i], xPos, weekDaysLetterHeight / 2f, weekDayLetterPaint) } var curId = 0 @@ -117,4 +125,18 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con dayLetters.moveLastItemToFront() } } + + private fun setupCurrentDayOfWeekIndex() { + if (days.firstOrNull { it.isToday && it.isThisMonth } == null) { + currDayOfWeek = -1 + return + } + + currDayOfWeek = DateTime().dayOfWeek + if (context.config.isSundayFirst) { + currDayOfWeek %= 7 + } else { + currDayOfWeek-- + } + } }