Closed hscissors closed 9 months ago
It's a bit tricky but since the header of each month is bound before the days, if you have a month header, you can do this:
class MyHeaderBinder: MonthHeaderFooterBinder<MonthViewContainer> {
private val store = mutableMapOf<YearMonth, CalendarMonth>()
override fun create(view: View): MonthViewContainer {
// ... return header view
}
override fun bind(container: MonthViewContainer, data: CalendarMonth) {
store[data.yearMonth] = data
/// ... bind header
}
fun isLastRow(day: CalendarDay): Boolean {
return store[day.date.yearMonth]?.weekDays?.lastOrNull().orEmpty().contains(day)
}
}
// Set the header binder
calendarView.monthHeaderBinder = MyHeaderBinder()
// Day binder
calendarView.dayBinder = object : MonthDayBinder<DayViewContainer> {
override fun create(view: View) = DayViewContainer(view)
override fun bind(container: DayViewContainer, data: CalendarDay) {
val headerBinder = calendarView.monthHeaderBinder as MyHeaderBinder
if (headerBinder.isLastRow(data)) {
// last row
} else {
// not last row
}
// other biding logic
}
}
Oh I 'm using Compose not the View-based version.
I think the core idea in the logic applies to the compose library as well. The key is that the month will be bound first, you just need to store the month info somewhere and use it when the day is bound.
Closing this issue as resolved, please reopen if you need further assistance.
Library information:
Question:
I need to set border on the bottom of each week, except of the last week of the month. I'm doing this by adding it to every
DayContent
object. Is it possible to figure when that day is in the last week so I can not set it for those days?