Skip to content

Commit

Permalink
Fix faulty calculation of date range in DrawingContext
Browse files Browse the repository at this point in the history
  • Loading branch information
thellmund committed Feb 14, 2019
1 parent 716124b commit fa75363
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 25 deletions.
31 changes: 7 additions & 24 deletions library/src/main/java/com/alamkanak/weekview/DrawingContext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,12 @@ package com.alamkanak.weekview

import java.lang.Math.ceil
import java.util.*
import java.util.Calendar.DATE

class DrawingContext(
val dateRange: List<Calendar>,
val startPixel: Float
) {

/**
* Returns the actually visible date range. This can be different from [dateRange] if the user
* is currently scrolling.
*
* @param firstVisibleDate The first visible date
* @param config The [WeekViewConfig]
*
* @return The list of currently visible dates
*/
fun getVisibleDateRange(firstVisibleDate: Calendar, config: WeekViewConfig): List<Calendar> {
val result = dateRange as MutableList
val isScrolling = config.drawingConfig.currentOrigin.x % config.totalDayWidth != 0f
if (isScrolling) {
// If the user is scrolling, a new view becomes partially visible
val lastVisibleDay = firstVisibleDate.clone() as Calendar
lastVisibleDay.add(DATE, config.numberOfVisibleDays)
dateRange.add(lastVisibleDay)
}
return result
}

fun getDateRangeWithStartPixels(config: WeekViewConfig): List<Pair<Calendar, Float>> {
return dateRange.zip(getStartPixels(config))
}
Expand Down Expand Up @@ -67,9 +45,14 @@ class DrawingContext(
+ drawConfig.timeColumnWidth)

val start = leftDaysWithGaps + 1
val end = start + config.numberOfVisibleDays + 1
val dayRange = DateUtils.getDateRange(start, end)
val end = start + config.numberOfVisibleDays

// If the user is scrolling, a new view becomes partially visible, so we must add an
// additional date to the date range
val isNotScrolling = config.drawingConfig.currentOrigin.x % config.totalDayWidth == 0f
val modifiedEnd = if (isNotScrolling) end - 1 else end

val dayRange = DateUtils.getDateRange(start, modifiedEnd)
return DrawingContext(dayRange, startPixel)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private void refreshHeaderHeight(DrawingContext drawingContext) {
return;
}

List<Calendar> dateRange = drawingContext.getVisibleDateRange(firstVisibleDay, config);
List<Calendar> dateRange = drawingContext.getDateRange();
List<WeekViewEvent<T>> visibleEvents = cache.getAllDayEventsInRange(dateRange);

boolean containsAllDayEvent = false;
Expand Down

0 comments on commit fa75363

Please sign in to comment.