Skip to content

Commit

Permalink
Fix issue where calendar would stay empty when going to a specific date
Browse files Browse the repository at this point in the history
  • Loading branch information
thellmund committed Oct 30, 2019
1 parent 62123ef commit 3b4c6f9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ internal class EventChipsLoader<T>(
private val eventSplitter = WeekViewEventSplitter<T>(config)

fun createAndCacheEventChips(events: List<WeekViewEvent<T>>) {
chipCache.clear()
chipCache += convertEventsToEventChips(events)
}

Expand Down
9 changes: 5 additions & 4 deletions core/src/main/java/com/alamkanak/weekview/EventsLoader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ internal class PagedEventsLoader<T>(

if (needsRefresh) {
val periods = determinePeriodsToFetch(fetchRange)
prepareCache(fetchRange)
val needsToFetchAllPeriods = periods.size == 3
prepareCache(fetchRange, needsToFetchAllPeriods)
fetchPeriods(periods)
}

Expand All @@ -102,12 +103,12 @@ internal class PagedEventsLoader<T>(
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)
}

Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/com/alamkanak/weekview/WeekView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class WeekView<T> @JvmOverloads constructor(
if (events.isNullOrEmpty()) {
eventChipCache.clear()
} else {
eventChipCache.clear()
eventChipsLoader.createAndCacheEventChips(events)
eventChipsExpander.calculateEventChipPositions()
}
Expand Down

0 comments on commit 3b4c6f9

Please sign in to comment.