From 2fe3e9869587f037a135e51822a0f10e26790a3d Mon Sep 17 00:00:00 2001 From: Naveen Date: Wed, 25 May 2022 11:23:50 +0530 Subject: [PATCH] Properly handle events spanning midnight --- .../calendar/pro/fragments/WeekFragment.kt | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/WeekFragment.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/WeekFragment.kt index 50e9559cc..40dbf679b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/WeekFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/WeekFragment.kt @@ -741,6 +741,7 @@ class WeekFragment : Fragment(), WeeklyCalendar { val firstDayIndex = startDateTimeInWeek.dayOfMonth // indices must be unique for the visible range (2 weeks) val lastDayIndex = firstDayIndex + daysCnt val dayIndices = firstDayIndex..lastDayIndex + val isSameDayEvent = firstDayIndex == lastDayIndex var doesEventFit: Boolean var wasEventHandled = false @@ -753,19 +754,23 @@ class WeekFragment : Fragment(), WeeklyCalendar { doesEventFit = dayIndices.all { !row.contains(it) } - for (dayIndex in dayIndices) { - if (doesEventFit) { - row.add(dayIndex) - wasEventHandled = true - } else if (index == allDayRows.lastIndex) { - allDayRows.add(HashSet()) - addNewLine() - drawAtLine++ - wasEventHandled = true - allDayRows.last().add(dayIndex) + if (doesEventFit && isSameDayEvent) { + row.add(firstDayIndex) + wasEventHandled = true + } else { + // handle events spanning midnight + for (dayIndex in dayIndices) { + if (index == allDayRows.lastIndex) { + allDayRows.add(HashSet()) + addNewLine() + drawAtLine++ + wasEventHandled = true + allDayRows.last().add(dayIndex) + } } } + if (wasEventHandled) { break }