Properly handle events spanning midnight

This commit is contained in:
Naveen 2022-05-25 11:23:50 +05:30
parent ac43e14999
commit 2fe3e98695
1 changed files with 15 additions and 10 deletions

View File

@ -741,6 +741,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
val firstDayIndex = startDateTimeInWeek.dayOfMonth // indices must be unique for the visible range (2 weeks) val firstDayIndex = startDateTimeInWeek.dayOfMonth // indices must be unique for the visible range (2 weeks)
val lastDayIndex = firstDayIndex + daysCnt val lastDayIndex = firstDayIndex + daysCnt
val dayIndices = firstDayIndex..lastDayIndex val dayIndices = firstDayIndex..lastDayIndex
val isSameDayEvent = firstDayIndex == lastDayIndex
var doesEventFit: Boolean var doesEventFit: Boolean
var wasEventHandled = false var wasEventHandled = false
@ -753,19 +754,23 @@ class WeekFragment : Fragment(), WeeklyCalendar {
doesEventFit = dayIndices.all { !row.contains(it) } doesEventFit = dayIndices.all { !row.contains(it) }
for (dayIndex in dayIndices) { if (doesEventFit && isSameDayEvent) {
if (doesEventFit) { row.add(firstDayIndex)
row.add(dayIndex) wasEventHandled = true
wasEventHandled = true } else {
} else if (index == allDayRows.lastIndex) { // handle events spanning midnight
allDayRows.add(HashSet()) for (dayIndex in dayIndices) {
addNewLine() if (index == allDayRows.lastIndex) {
drawAtLine++ allDayRows.add(HashSet())
wasEventHandled = true addNewLine()
allDayRows.last().add(dayIndex) drawAtLine++
wasEventHandled = true
allDayRows.last().add(dayIndex)
}
} }
} }
if (wasEventHandled) { if (wasEventHandled) {
break break
} }