From 8c6a2aa060c3b17c1a06329597d8e31878d97b4b Mon Sep 17 00:00:00 2001 From: Kizito Nwose <kizitonwose@gmail.com> Date: Tue, 12 Dec 2023 19:06:41 +0100 Subject: [PATCH] Clean up --- .../java/com/kizitonwose/calendar/view/CalendarView.kt | 2 +- .../java/com/kizitonwose/calendar/view/internal/Utils.kt | 5 ++++- .../com/kizitonwose/calendar/view/internal/WeekHolder.kt | 8 ++++---- .../view/internal/monthcalendar/MonthViewHolder.kt | 2 +- .../calendar/view/internal/weekcalendar/WeekViewHolder.kt | 2 +- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/view/src/main/java/com/kizitonwose/calendar/view/CalendarView.kt b/view/src/main/java/com/kizitonwose/calendar/view/CalendarView.kt index 446fab73..fd6d61ce 100644 --- a/view/src/main/java/com/kizitonwose/calendar/view/CalendarView.kt +++ b/view/src/main/java/com/kizitonwose/calendar/view/CalendarView.kt @@ -268,7 +268,7 @@ open class CalendarView : RecyclerView { } if ( (orientation == HORIZONTAL && pageSnapHelper !== horizontalSnapHelper) || - (orientation != VERTICAL && pageSnapHelper !== verticalSnapHelper) + (orientation == VERTICAL && pageSnapHelper !== verticalSnapHelper) ) { // Remove the currently attached snap helper. pageSnapHelper.attachToRecyclerView(null) diff --git a/view/src/main/java/com/kizitonwose/calendar/view/internal/Utils.kt b/view/src/main/java/com/kizitonwose/calendar/view/internal/Utils.kt index 7cf84b00..6ecd9eb0 100644 --- a/view/src/main/java/com/kizitonwose/calendar/view/internal/Utils.kt +++ b/view/src/main/java/com/kizitonwose/calendar/view/internal/Utils.kt @@ -51,7 +51,10 @@ internal fun <Day, Container : ViewContainer> setupItemRoot( ) val weekHolders = List(weekSize) { - WeekHolder(dayConfig.daySize, List(7) { DayHolder(dayConfig) }) + WeekHolder( + daySize = dayConfig.daySize, + dayHolders = List(size = 7) { DayHolder(dayConfig) }, + ) }.onEach { weekHolder -> rootLayout.addView(weekHolder.inflateWeekView(rootLayout)) } diff --git a/view/src/main/java/com/kizitonwose/calendar/view/internal/WeekHolder.kt b/view/src/main/java/com/kizitonwose/calendar/view/internal/WeekHolder.kt index e5d6e40a..8d111f84 100644 --- a/view/src/main/java/com/kizitonwose/calendar/view/internal/WeekHolder.kt +++ b/view/src/main/java/com/kizitonwose/calendar/view/internal/WeekHolder.kt @@ -16,13 +16,13 @@ private class WidthDivisorLinearLayout : LinearLayout { constructor(context: Context, attrs: AttributeSet?, defStyle: Int) : super(context, attrs, defStyle) - var widthDivisor: Int = 0 + var widthDivisorForHeight: Int = 0 override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { @Suppress("NAME_SHADOWING") - val heightMeasureSpec = if (widthDivisor > 0) { + val heightMeasureSpec = if (widthDivisorForHeight > 0) { val width = MeasureSpec.getSize(widthMeasureSpec) - MeasureSpec.makeMeasureSpec(width / widthDivisor, MeasureSpec.EXACTLY) + MeasureSpec.makeMeasureSpec(width / widthDivisorForHeight, MeasureSpec.EXACTLY) } else { heightMeasureSpec } @@ -53,7 +53,7 @@ internal class WeekHolder<Day>( layoutParams = LinearLayout.LayoutParams(width, height, weight) orientation = LinearLayout.HORIZONTAL weightSum = dayHolders.count().toFloat() - widthDivisor = if (daySize == DaySize.Square) dayHolders.count() else 0 + widthDivisorForHeight = if (daySize == DaySize.Square) dayHolders.count() else 0 for (holder in dayHolders) { addView(holder.inflateDayView(this)) } diff --git a/view/src/main/java/com/kizitonwose/calendar/view/internal/monthcalendar/MonthViewHolder.kt b/view/src/main/java/com/kizitonwose/calendar/view/internal/monthcalendar/MonthViewHolder.kt index 601279b5..5f55e4d4 100644 --- a/view/src/main/java/com/kizitonwose/calendar/view/internal/monthcalendar/MonthViewHolder.kt +++ b/view/src/main/java/com/kizitonwose/calendar/view/internal/monthcalendar/MonthViewHolder.kt @@ -9,7 +9,7 @@ import com.kizitonwose.calendar.view.MonthHeaderFooterBinder import com.kizitonwose.calendar.view.ViewContainer import com.kizitonwose.calendar.view.internal.WeekHolder -internal class MonthViewHolder constructor( +internal class MonthViewHolder( rootLayout: ViewGroup, private val headerView: View?, private val footerView: View?, diff --git a/view/src/main/java/com/kizitonwose/calendar/view/internal/weekcalendar/WeekViewHolder.kt b/view/src/main/java/com/kizitonwose/calendar/view/internal/weekcalendar/WeekViewHolder.kt index 09369714..5ed4a41a 100644 --- a/view/src/main/java/com/kizitonwose/calendar/view/internal/weekcalendar/WeekViewHolder.kt +++ b/view/src/main/java/com/kizitonwose/calendar/view/internal/weekcalendar/WeekViewHolder.kt @@ -9,7 +9,7 @@ import com.kizitonwose.calendar.view.ViewContainer import com.kizitonwose.calendar.view.WeekHeaderFooterBinder import com.kizitonwose.calendar.view.internal.WeekHolder -internal class WeekViewHolder constructor( +internal class WeekViewHolder( rootLayout: ViewGroup, private val headerView: View?, private val footerView: View?,