Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Yaya-Dev-Box opened this issue Mar 22, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@Yaya-Dev-Box
Copy link

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

device-2022-03-22-104351.mp4

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

Additional context

  • Android version: [Android 11.0]
  • WeekView version: [5.3.2] & [latest "main" branch commit as of [22/02/2022]
@Yaya-Dev-Box Yaya-Dev-Box added the bug Something isn't working label Mar 22, 2022
@Yaya-Dev-Box
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant