From b5665a757545f41fd8463ca74edb609d63cb2b21 Mon Sep 17 00:00:00 2001 From: Kizito Nwose Date: Sun, 8 Nov 2020 16:07:40 +0100 Subject: [PATCH] Don't update start and end months in the setup method. --- .../kizitonwose/calendarview/CalendarView.kt | 60 ++++++++----------- 1 file changed, 25 insertions(+), 35 deletions(-) diff --git a/library/src/main/java/com/kizitonwose/calendarview/CalendarView.kt b/library/src/main/java/com/kizitonwose/calendarview/CalendarView.kt index 32e3ae64..43a93866 100644 --- a/library/src/main/java/com/kizitonwose/calendarview/CalendarView.kt +++ b/library/src/main/java/com/kizitonwose/calendarview/CalendarView.kt @@ -652,9 +652,9 @@ open class CalendarView : RecyclerView { } /** - * Setup the CalendarView. You can call this any time to change the - * the desired [startMonth], [endMonth] or [firstDayOfWeek] on the Calendar. - * See [updateMonthRange] and [updateMonthRangeAsync] for more refined updates. + * Setup the CalendarView. + * See [updateMonthRange] and [updateMonthRangeAsync] to change + * the [startMonth] and [endMonth] values. * * @param startMonth The first month on the calendar. * @param endMonth The last month on the calendar. @@ -662,27 +662,22 @@ open class CalendarView : RecyclerView { */ fun setup(startMonth: YearMonth, endMonth: YearMonth, firstDayOfWeek: DayOfWeek) { configJob?.cancel() - if (this.startMonth != null && this.endMonth != null && this.firstDayOfWeek != null) { - this.firstDayOfWeek = firstDayOfWeek - updateMonthRange(startMonth, endMonth) - } else { - this.startMonth = startMonth - this.endMonth = endMonth - this.firstDayOfWeek = firstDayOfWeek - finishSetup( - MonthConfig( - outDateStyle, inDateStyle, maxRowCount, startMonth, - endMonth, firstDayOfWeek, hasBoundaries, Job() - ) + this.startMonth = startMonth + this.endMonth = endMonth + this.firstDayOfWeek = firstDayOfWeek + finishSetup( + MonthConfig( + outDateStyle, inDateStyle, maxRowCount, startMonth, + endMonth, firstDayOfWeek, hasBoundaries, Job() ) - } + ) } /** - * Setup the CalendarView, asynchronously. You can call this any time to change the - * the desired [startMonth], [endMonth] or [firstDayOfWeek] on the Calendar. + * Setup the CalendarView, asynchronously. * Useful if your [startMonth] and [endMonth] values are many years apart. - * See [updateMonthRange] and [updateMonthRangeAsync] for more refined updates. + * See [updateMonthRange] and [updateMonthRangeAsync] to change the + * [startMonth] and [endMonth] values. * * Note: the setup MUST finish before any other methods can are called. To be * notified when the setup is finished, provide a [completion] parameter. @@ -699,22 +694,17 @@ open class CalendarView : RecyclerView { completion: Completion? = null ) { configJob?.cancel() - if (this.startMonth != null && this.endMonth != null && this.firstDayOfWeek != null) { - this.firstDayOfWeek = firstDayOfWeek - updateMonthRangeAsync(startMonth, endMonth, completion) - } else { - this.startMonth = startMonth - this.endMonth = endMonth - this.firstDayOfWeek = firstDayOfWeek - configJob = GlobalScope.launch { - val monthConfig = MonthConfig( - outDateStyle, inDateStyle, maxRowCount, startMonth, - endMonth, firstDayOfWeek, hasBoundaries, job - ) - withContext(Main) { - finishSetup(monthConfig) - completion?.invoke() - } + this.startMonth = startMonth + this.endMonth = endMonth + this.firstDayOfWeek = firstDayOfWeek + configJob = GlobalScope.launch { + val monthConfig = MonthConfig( + outDateStyle, inDateStyle, maxRowCount, startMonth, + endMonth, firstDayOfWeek, hasBoundaries, job + ) + withContext(Main) { + finishSetup(monthConfig) + completion?.invoke() } } }