thellmund / Android-Week-View

Display highly customizable calendar views in your Android app
Apache License 2.0
188 stars 98 forks source link

Limited date and time sample: event chips that are partially out of range don't show correctly #276

Open Yaya-Dev-Box opened 2 years ago

Yaya-Dev-Box commented 2 years ago

Describe the bug Setting "minHour" or "maxHour" to other values than 0 and 24 will cause the partially out of range events to disappear (depends on the duration of the event)

To Reproduce See the attached video

https://user-images.githubusercontent.com/58863987/159453904-ec57c85e-95fb-461f-89b2-65a1b93c061f.mp4

Expected behavior The events should still be shown, even partially (same as the multi day events in the basic sample)

Additional context

Yaya-Dev-Box commented 2 years ago

I'm trying to fix this myself by modifying the library's codes, could you tell me what is the code responsible for drawing the event chips so I can investigate there?

Yaya-Dev-Box commented 2 years ago

Found the issue: In the ResolvedWeekViewEvent.kt class, replace:

internal fun isWithin( minHour: Int, maxHour: Int ): Boolean = startTime.hour >= minHour && endTime.hour <= maxHour by internal fun isWithin( minHour: Int, maxHour: Int ): Boolean = startTime.hour >= minHour || endTime.hour <= maxHour

Awesome library and code structure by the way :) thank you.

Yaya-Dev-Box commented 2 years ago

Update, I improved the code to cover more edge cases:

internal fun isWithin(
        minHour: Int,
        maxHour: Int
    ): Boolean {

        val startTimeIsInRange = startTime.hour in minHour..maxHour
        val endTimeIsInRange = endTime.hour in minHour..maxHour
        val eventHoursStartBeforeAndEndAfterLimits = (startTime.hour..endTime.hour intersect minHour..maxHour).isNotEmpty()
        val eventIsMultiDay = endTime.toEpochDays() - startTime.toEpochDays() > 0

        return startTimeIsInRange || endTimeIsInRange || eventHoursStartBeforeAndEndAfterLimits || eventIsMultiDay
    }

Please be careful with eventIsMultiDay, as it accepts all events that span across multiple days, even if they don't intersect with minHour and maxHour.