Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I am using it inside a composable function. how could I can display my events on the calendar? The documentation should be more informative #295

Open
eliomaroun opened this issue Nov 3, 2022 · 0 comments

Comments

@eliomaroun
Copy link

eliomaroun commented Nov 3, 2022

 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)
        }


    }
)

}

@eliomaroun eliomaroun changed the title How do I know the current time/date when clicking onClickEmptyView I am using it inside a composable function. how could I can view myevents on the calendar. The documentation should be more informative Nov 4, 2022
@eliomaroun eliomaroun changed the title I am using it inside a composable function. how could I can view myevents on the calendar. The documentation should be more informative I am using it inside a composable function. how could I can view my events on the calendar. The documentation should be more informative Nov 4, 2022
@eliomaroun eliomaroun changed the title I am using it inside a composable function. how could I can view my events on the calendar. The documentation should be more informative I am using it inside a composable function. how could I can display my events on the calendar? The documentation should be more informative Nov 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant