From 69683a857a255044782695159e17c8b22bd927de Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 21 Nov 2021 20:09:18 +0100 Subject: [PATCH] fix a rare glitch with events being duplicate after refetching at lists --- .../calendar/pro/fragments/EventListFragment.kt | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/EventListFragment.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/EventListFragment.kt index f2aadce04..e2bb197ca 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/EventListFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/EventListFragment.kt @@ -177,7 +177,12 @@ class EventListFragment : MyFragmentHolder(), RefreshRecyclerViewListener { val oldMinFetchedTS = minFetchedTS - 1 minFetchedTS -= FETCH_INTERVAL requireContext().eventsHelper.getEvents(minFetchedTS, oldMinFetchedTS) { - mEvents.addAll(0, it) + it.forEach { event -> + if (mEvents.firstOrNull { it.id == event.id && it.startTS == event.startTS } == null) { + mEvents.add(0, event) + } + } + receivedEvents(mEvents, UPDATE_TOP) } } @@ -186,7 +191,12 @@ class EventListFragment : MyFragmentHolder(), RefreshRecyclerViewListener { val oldMaxFetchedTS = maxFetchedTS + 1 maxFetchedTS += FETCH_INTERVAL requireContext().eventsHelper.getEvents(oldMaxFetchedTS, maxFetchedTS) { - mEvents.addAll(it) + it.forEach { event -> + if (mEvents.firstOrNull { it.id == event.id && it.startTS == event.startTS } == null) { + mEvents.add(0, event) + } + } + receivedEvents(mEvents, UPDATE_BOTTOM) } }