From baa1c44bcd508139306c14674e5dbbbf9f708a9f Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 26 Mar 2018 18:44:19 +0200 Subject: [PATCH] adding a helper function in MonthView --- .../calendar/activities/SettingsActivity.kt | 4 ++-- .../com/simplemobiletools/calendar/helpers/Config.kt | 4 ++-- .../calendar/helpers/MyWidgetMonthlyProvider.kt | 2 +- .../com/simplemobiletools/calendar/views/MonthView.kt | 9 ++++++++- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt index 5fcd67fd6..f1729d9fb 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt @@ -268,10 +268,10 @@ class SettingsActivity : SimpleActivity() { } private fun setupWeekNumbers() { - settings_week_numbers.isChecked = config.displayWeekNumbers + settings_week_numbers.isChecked = config.showWeekNumbers settings_week_numbers_holder.setOnClickListener { settings_week_numbers.toggle() - config.displayWeekNumbers = settings_week_numbers.isChecked + config.showWeekNumbers = settings_week_numbers.isChecked } } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Config.kt index 919659d9f..ee6457b7a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Config.kt @@ -12,9 +12,9 @@ class Config(context: Context) : BaseConfig(context) { fun newInstance(context: Context) = Config(context) } - var displayWeekNumbers: Boolean + var showWeekNumbers: Boolean get() = prefs.getBoolean(WEEK_NUMBERS, false) - set(displayWeekNumbers) = prefs.edit().putBoolean(WEEK_NUMBERS, displayWeekNumbers).apply() + set(showWeekNumbers) = prefs.edit().putBoolean(WEEK_NUMBERS, showWeekNumbers).apply() var startWeeklyAt: Int get() = prefs.getInt(START_WEEKLY_AT, 7) 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 b2f03e6c9..d2a777666 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/MyWidgetMonthlyProvider.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/MyWidgetMonthlyProvider.kt @@ -82,7 +82,7 @@ class MyWidgetMonthlyProvider : AppWidgetProvider() { } private fun updateDays(context: Context, views: RemoteViews, days: List) { - val displayWeekNumbers = context.config.displayWeekNumbers + val displayWeekNumbers = context.config.showWeekNumbers val textColor = context.config.widgetTextColor val smallerFontSize = context.config.getFontSize() - 3f val res = context.resources 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 b92833558..7c981141b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/views/MonthView.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/views/MonthView.kt @@ -42,6 +42,7 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con private var smallPadding = 0 private var availableHeightForEvents = 0 private var maxEventsPerDay = 0 + private var showWeekNumbers = false private var allEvents = ArrayList() private var bgRectF = RectF() private var dayLetters = ArrayList() @@ -54,6 +55,7 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con init { primaryColor = context.getAdjustedPrimaryColor() textColor = context.config.textColor + showWeekNumbers = context.config.showWeekNumbers weakTextColor = textColor.adjustAlpha(LOW_ALPHA) smallPadding = resources.displayMetrics.density.toInt() @@ -82,6 +84,12 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con days = newDays initWeekDayLetters() setupCurrentDayOfWeekIndex() + showWeekNumbers = context.config.showWeekNumbers + groupAllEvents() + invalidate() + } + + private fun groupAllEvents() { days.forEach { val day = it day.dayEvents.forEach { @@ -99,7 +107,6 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con } allEvents = allEvents.sortedWith(compareBy({ -it.daysCnt }, { !it.isAllDay }, { it.startTS }, { it.startDayIndex }, { it.title })).toMutableList() as ArrayList - invalidate() } override fun onDraw(canvas: Canvas) {