diff --git a/view/api/view.api b/view/api/view.api index 510d93f2..b03e9067 100644 --- a/view/api/view.api +++ b/view/api/view.api @@ -74,12 +74,9 @@ public final class com/kizitonwose/calendar/view/DaySize : java/lang/Enum { public static fun values ()[Lcom/kizitonwose/calendar/view/DaySize; } -public abstract interface class com/kizitonwose/calendar/view/LayoutHelper { - public abstract fun calculateExtraLayoutSpace (Landroidx/recyclerview/widget/RecyclerView$State;[I)V -} - -public final class com/kizitonwose/calendar/view/LayoutHelper$DefaultImpls { - public static fun calculateExtraLayoutSpace (Lcom/kizitonwose/calendar/view/LayoutHelper;Landroidx/recyclerview/widget/RecyclerView$State;[I)V +public abstract class com/kizitonwose/calendar/view/LayoutHelper { + public fun ()V + public fun getCalculateExtraLayoutSpace ()Lkotlin/jvm/functions/Function2; } public final class com/kizitonwose/calendar/view/MarginValues { 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 d3330402..ff11f681 100644 --- a/view/src/main/java/com/kizitonwose/calendar/view/CalendarView.kt +++ b/view/src/main/java/com/kizitonwose/calendar/view/CalendarView.kt @@ -184,7 +184,7 @@ public open class CalendarView : RecyclerView { } /** - * Interface with methods that can be overridden + * Helper class with methods that can be overridden * in the internal layout manager. */ public var layoutHelper: LayoutHelper? = null diff --git a/view/src/main/java/com/kizitonwose/calendar/view/LayoutHelper.kt b/view/src/main/java/com/kizitonwose/calendar/view/LayoutHelper.kt index b85d926a..5dc1395c 100644 --- a/view/src/main/java/com/kizitonwose/calendar/view/LayoutHelper.kt +++ b/view/src/main/java/com/kizitonwose/calendar/view/LayoutHelper.kt @@ -5,10 +5,13 @@ import androidx.recyclerview.widget.RecyclerView import com.kizitonwose.calendar.view.internal.CalendarLayoutManager /** - * An interface with methods that can be overridden - * in the internal [LinearLayoutManager]. + * Helper class with properties that match the methods that can + * be overridden in the internal [LinearLayoutManager]. This is + * an abstract class instead of an interface so we can have + * default values for properties as we need to call `super` + * for properties that are not provided (null). */ -public interface LayoutHelper { +public abstract class LayoutHelper { /** * Calculates the amount of extra space (in pixels) that should be laid out by * [CalendarLayoutManager] and stores the result in [extraLayoutSpace]. @@ -18,5 +21,5 @@ public interface LayoutHelper { * * @see [LinearLayoutManager.calculateExtraLayoutSpace] */ - public fun calculateExtraLayoutSpace(state: RecyclerView.State, extraLayoutSpace: IntArray) {} + public open val calculateExtraLayoutSpace: ((state: RecyclerView.State, extraLayoutSpace: IntArray) -> Unit)? = null } diff --git a/view/src/main/java/com/kizitonwose/calendar/view/WeekCalendarView.kt b/view/src/main/java/com/kizitonwose/calendar/view/WeekCalendarView.kt index 966d8bd4..f89be4de 100644 --- a/view/src/main/java/com/kizitonwose/calendar/view/WeekCalendarView.kt +++ b/view/src/main/java/com/kizitonwose/calendar/view/WeekCalendarView.kt @@ -151,7 +151,7 @@ public open class WeekCalendarView : RecyclerView { } /** - * Interface with methods that can be overridden + * Helper class with methods that can be overridden * in the internal layout manager. */ public var layoutHelper: LayoutHelper? = null diff --git a/view/src/main/java/com/kizitonwose/calendar/view/YearCalendarView.kt b/view/src/main/java/com/kizitonwose/calendar/view/YearCalendarView.kt index f28f4d5f..dc75ff28 100644 --- a/view/src/main/java/com/kizitonwose/calendar/view/YearCalendarView.kt +++ b/view/src/main/java/com/kizitonwose/calendar/view/YearCalendarView.kt @@ -327,7 +327,7 @@ public open class YearCalendarView : RecyclerView { } /** - * Interface with methods that can be overridden + * Helper class with methods that can be overridden * in the internal layout manager. */ public var layoutHelper: LayoutHelper? = null diff --git a/view/src/main/java/com/kizitonwose/calendar/view/internal/CalendarLayoutManager.kt b/view/src/main/java/com/kizitonwose/calendar/view/internal/CalendarLayoutManager.kt index 2de7b181..84cd077a 100644 --- a/view/src/main/java/com/kizitonwose/calendar/view/internal/CalendarLayoutManager.kt +++ b/view/src/main/java/com/kizitonwose/calendar/view/internal/CalendarLayoutManager.kt @@ -73,13 +73,9 @@ internal abstract class CalendarLayoutManager( } override fun calculateExtraLayoutSpace(state: RecyclerView.State, extraLayoutSpace: IntArray) { - val layoutHelper = getLayoutHelper() - if (layoutHelper != null) { - layoutHelper.calculateExtraLayoutSpace(state, extraLayoutSpace) - // If the interface is provided but the method is not overridden. - if (extraLayoutSpace.isEmpty()) { - super.calculateExtraLayoutSpace(state, extraLayoutSpace) - } + val calculateExtraLayoutSpace = getLayoutHelper()?.calculateExtraLayoutSpace + if (calculateExtraLayoutSpace != null) { + calculateExtraLayoutSpace(state, extraLayoutSpace) } else { super.calculateExtraLayoutSpace(state, extraLayoutSpace) }