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 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
}