From 3e58b3d1dec46a01a164558f3caf726ceed8cd2d Mon Sep 17 00:00:00 2001 From: m-i-n-a-r Date: Sat, 11 Mar 2023 00:50:20 +0100 Subject: [PATCH] Persistent sunday highlight through appearances --- tasticalendar/build.gradle | 2 +- .../tasticalendar/core/TastiCalendarMonth.kt | 81 ++++++++++--------- 2 files changed, 42 insertions(+), 41 deletions(-) diff --git a/tasticalendar/build.gradle b/tasticalendar/build.gradle index 03a7ea1..c6bc43d 100644 --- a/tasticalendar/build.gradle +++ b/tasticalendar/build.gradle @@ -56,7 +56,7 @@ publishing { release(MavenPublication) { groupId = 'com.github.m-i-n-a-r' artifactId = 'tasticalendar' - version = '1.3.4' + version = '1.3.5' afterEvaluate { from components.release diff --git a/tasticalendar/src/main/java/com/minar/tasticalendar/core/TastiCalendarMonth.kt b/tasticalendar/src/main/java/com/minar/tasticalendar/core/TastiCalendarMonth.kt index 7db30d8..b8ea8a7 100644 --- a/tasticalendar/src/main/java/com/minar/tasticalendar/core/TastiCalendarMonth.kt +++ b/tasticalendar/src/main/java/com/minar/tasticalendar/core/TastiCalendarMonth.kt @@ -58,6 +58,7 @@ class TastiCalendarMonth(context: Context, attrs: AttributeSet) : LinearLayout(c private var snackBarsPrefix: Int? = null private var snackBarsBaseView: View? = null private var snackBarsDuration: Int = 3000 + private var sundayIndex = 6 init { context.theme.obtainStyledAttributes( @@ -367,7 +368,6 @@ class TastiCalendarMonth(context: Context, attrs: AttributeSet) : LinearLayout(c val sunday = DayOfWeek.SUNDAY val locale = Locale.getDefault() if (!hideWeekDays) { - var sundayIndex = 6 if (!sundayFirst) { weekDaysList[0].text = monday.getDisplayName(TextStyle.NARROW, locale) weekDaysList[1].text = tuesday.getDisplayName(TextStyle.NARROW, locale) @@ -386,45 +386,6 @@ class TastiCalendarMonth(context: Context, attrs: AttributeSet) : LinearLayout(c weekDaysList[5].text = friday.getDisplayName(TextStyle.NARROW, locale) weekDaysList[6].text = saturday.getDisplayName(TextStyle.NARROW, locale) } - // Set the highlighting style for sunday - when (sundayAppearance) { - 0 -> { - weekDaysList[sundayIndex].setTypeface(null, Typeface.NORMAL) - weekDaysList[sundayIndex].setTextColor( - getThemeColor( - com.google.android.material.R.attr.colorOnSurfaceVariant, - context - ) - ) - } - 1 -> { - weekDaysList[sundayIndex].setTypeface(null, Typeface.BOLD) - weekDaysList[sundayIndex].setTextColor( - getThemeColor( - com.google.android.material.R.attr.colorOnSurfaceVariant, - context - ) - ) - } - 2 -> { - weekDaysList[sundayIndex].setTypeface(null, Typeface.NORMAL) - weekDaysList[sundayIndex].setTextColor( - getThemeColor( - com.google.android.material.R.attr.colorTertiary, - context - ) - ) - } - 3 -> { - weekDaysList[sundayIndex].setTypeface(null, Typeface.BOLD) - weekDaysList[sundayIndex].setTextColor( - getThemeColor( - com.google.android.material.R.attr.colorTertiary, - context - ) - ) - } - } } else { weekDaysList[0].visibility = View.GONE weekDaysList[1].visibility = View.GONE @@ -781,5 +742,45 @@ class TastiCalendarMonth(context: Context, attrs: AttributeSet) : LinearLayout(c ) ) for (weekDay in weekDaysList) weekDay.alpha = .85f + + // Set the highlighting style for sunday + when (sundayAppearance) { + 0 -> { + weekDaysList[sundayIndex].setTypeface(null, Typeface.NORMAL) + weekDaysList[sundayIndex].setTextColor( + getThemeColor( + com.google.android.material.R.attr.colorOnSurfaceVariant, + context + ) + ) + } + 1 -> { + weekDaysList[sundayIndex].setTypeface(null, Typeface.BOLD) + weekDaysList[sundayIndex].setTextColor( + getThemeColor( + com.google.android.material.R.attr.colorOnSurfaceVariant, + context + ) + ) + } + 2 -> { + weekDaysList[sundayIndex].setTypeface(null, Typeface.NORMAL) + weekDaysList[sundayIndex].setTextColor( + getThemeColor( + com.google.android.material.R.attr.colorTertiary, + context + ) + ) + } + 3 -> { + weekDaysList[sundayIndex].setTypeface(null, Typeface.BOLD) + weekDaysList[sundayIndex].setTextColor( + getThemeColor( + com.google.android.material.R.attr.colorTertiary, + context + ) + ) + } + } } } \ No newline at end of file