diff --git a/core/src/main/java/com/alamkanak/weekview/EventChipsLoader.kt b/core/src/main/java/com/alamkanak/weekview/EventChipsLoader.kt index 4c8a589e9..3c957bc88 100644 --- a/core/src/main/java/com/alamkanak/weekview/EventChipsLoader.kt +++ b/core/src/main/java/com/alamkanak/weekview/EventChipsLoader.kt @@ -8,7 +8,6 @@ internal class EventChipsLoader( private val eventSplitter = WeekViewEventSplitter(config) fun createAndCacheEventChips(events: List>) { - chipCache.clear() chipCache += convertEventsToEventChips(events) } diff --git a/core/src/main/java/com/alamkanak/weekview/EventsLoader.kt b/core/src/main/java/com/alamkanak/weekview/EventsLoader.kt index 7cd058976..cb7fbb169 100644 --- a/core/src/main/java/com/alamkanak/weekview/EventsLoader.kt +++ b/core/src/main/java/com/alamkanak/weekview/EventsLoader.kt @@ -93,7 +93,8 @@ internal class PagedEventsLoader( if (needsRefresh) { val periods = determinePeriodsToFetch(fetchRange) - prepareCache(fetchRange) + val needsToFetchAllPeriods = periods.size == 3 + prepareCache(fetchRange, needsToFetchAllPeriods) fetchPeriods(periods) } @@ -102,12 +103,12 @@ internal class PagedEventsLoader( return pagedCache.allEvents } - private fun prepareCache(fetchRange: FetchRange) { - if (shouldRefreshEvents) { - shouldRefreshEvents = false + private fun prepareCache(fetchRange: FetchRange, needsToFetchAllPeriods: Boolean) { + if (shouldRefreshEvents && needsToFetchAllPeriods) { pagedCache.clear() } + shouldRefreshEvents = false pagedCache.adjustToFetchRange(fetchRange) } diff --git a/core/src/main/java/com/alamkanak/weekview/WeekView.kt b/core/src/main/java/com/alamkanak/weekview/WeekView.kt index 307214e67..15781ef85 100644 --- a/core/src/main/java/com/alamkanak/weekview/WeekView.kt +++ b/core/src/main/java/com/alamkanak/weekview/WeekView.kt @@ -100,6 +100,7 @@ class WeekView @JvmOverloads constructor( if (events.isNullOrEmpty()) { eventChipCache.clear() } else { + eventChipCache.clear() eventChipsLoader.createAndCacheEventChips(events) eventChipsExpander.calculateEventChipPositions() }