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 814938448..def91dd6e 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 @@ -454,7 +454,7 @@ class WeekFragment : Fragment(), WeeklyCalendar { val endDayCode = Formatter.getDayCodeFromDateTime(endDateTime) val isAllDay = event.getIsAllDay() - if ((isAllDay || (startDayCode != endDayCode)) && config.showMidnightSpanningEventsAtTop) { + if (shouldAddEventOnTopBar(isAllDay, startDayCode, endDayCode)) { continue } @@ -543,7 +543,8 @@ class WeekFragment : Fragment(), WeeklyCalendar { val startDayCode = Formatter.getDayCodeFromDateTime(startDateTime) val endDateTime = Formatter.getDateTimeFromTS(event.endTS) val endDayCode = Formatter.getDayCodeFromDateTime(endDateTime) - if ((event.getIsAllDay() || (startDayCode != endDayCode)) && config.showMidnightSpanningEventsAtTop) { + + if (shouldAddEventOnTopBar(event.getIsAllDay(), startDayCode, endDayCode)) { addAllDayEvent(event) } else { var currentDateTime = startDateTime @@ -696,6 +697,12 @@ class WeekFragment : Fragment(), WeeklyCalendar { } } + private fun shouldAddEventOnTopBar(isAllDay: Boolean, startDayCode: String, endDayCode: String): Boolean { + val spansMultipleDays = startDayCode != endDayCode + val isSingleDayAllDayEvent = isAllDay && !spansMultipleDays + return isSingleDayAllDayEvent || spansMultipleDays && config.showMidnightSpanningEventsAtTop + } + @SuppressLint("NewApi") private fun addAllDayEvent(event: Event) { (inflater.inflate(R.layout.week_all_day_event_marker, null, false) as ConstraintLayout).apply {