Closed thecodeside closed 2 years ago
Hi there 👋 Where are you calling refresh()
in the sample app?
I just added listener on click in the BasicActivity
to test it.
I can push changes if you want, but this is a very simple code.
private lateinit var adapter: BasicActivityWeekViewAdapter
override fun onCreate(savedInstanceState: Bundle?) {
(...)
adapter = BasicActivityWeekViewAdapter(
dragHandler = viewModel::handleDrag,
loadMoreHandler = viewModel::fetchEvents,
onEmptyViewClick = {
adapter.refresh()
}
)
private class BasicActivityWeekViewAdapter(
private val dragHandler: (Long, LocalDateTime, LocalDateTime) -> Unit,
private val loadMoreHandler: (List<YearMonth>) -> Unit,
private val onEmptyViewClick: () -> Unit,
) : WeekViewPagingAdapterJsr310<CalendarEntity>() {
override fun onEmptyViewLongClick(time: LocalDateTime) {
onEmptyViewClick()
context.showToast("Empty view long-clicked at ${defaultDateTimeFormatter.format(time)}")
}
I see… the issue here is that viewModel.fetchEvents()
never clears the already loaded events in the view state, therefore calling refresh()
(which then calls loadMore()
) will result in duplicate events. Can you try to update the view model’s viewState
before calling adapter.refresh()
?
You have 100% right! That fixes the bug! Thank you!
Describe the bug When you refresh the adapter and load events it is rendered as old events would exist. Screenshot before refresh and after refresh and resubmitted events attached.
To Reproduce Steps to reproduce the behavior:
loadMore()
is calledExpected behavior Events rendered as it would be clear calendar instance.
Screenshots Before refresh: After refresh and added events resubmited:
Additional context Latest sample app on the
master
branch.