I am using it inside a composable function. how could I can display my events on the calendar? The documentation should be more informative
eliomaroun opened this issue · 0 comments
eliomaroun commented
class CalendarAdapter(private val viewModel: CalenderViewModel) :
WeekViewSimpleAdapterJsr310<Appointment>() {
val defaultDateTimeFormatter: DateTimeFormatter =
DateTimeFormatter.ofLocalizedDateTime(MEDIUM, SHORT)
fun Appointment.toWeekViewEntity(): WeekViewEntity = toWeekViewEntity()
override fun onCreateEntity(item: Appointment): WeekViewEntity = item.toWeekViewEntity()
override fun onEmptyViewClick(time: LocalDateTime) {
super.onEmptyViewClick(time)
viewModel.onEvent(CalendarEvents.OnEmptyViewClicked(time))
}
override fun onEventClick(data: Appointment) {
super.onEventClick(data)
viewModel.onEvent(CalendarEvents.OnAppointmentClicked(data))
}
override fun onRangeChanged(firstVisibleDate: LocalDate, lastVisibleDate: LocalDate) {
super.onRangeChanged(firstVisibleDate, lastVisibleDate)
viewModel.onEvent(CalendarEvents.OnRangeChanged(firstVisibleDate, lastVisibleDate))
}
}
@Composable
fun CalXML(viewModel: CalenderViewModel = CalenderViewModel()) {
val weekdayFormatter = DateTimeFormatter.ofPattern("EEE", Locale.getDefault())
val dateFormatter = DateTimeFormatter.ofPattern("MM/dd", Locale.getDefault())
AndroidView(
factory = { context ->
val view = WeekView(context)
val adapter = CalendarAdapter(viewModel)
view.adapter = adapter
if (viewModel.state.value.appointmentList.isNotEmpty()) {
viewModel.state.value.appointmentList.map { adapter.onCreateEntity(it) }
}
adapter.submitList(viewModel.state.value.appointmentList)
view
},
update = { view ->
println("${viewModel.state.value.appointmentList}")
//view.setBackgroundColor(if (viewModel.state.value.appointmentList.isEmpty()) 0 else 88)
view.setDateFormatter { date: LocalDate ->
weekdayFormatter.format(date)
dateFormatter.format(date)
}
}
)
}