Skip to content

Commit 078b791

Browse files
reduced Calendar instance creation a bit
1 parent e58f6f5 commit 078b791

File tree

1 file changed

+21
-23
lines changed
  • library/src/main/java/com/alamkanak/weekview

1 file changed

+21
-23
lines changed

library/src/main/java/com/alamkanak/weekview/WeekView.kt

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,10 +1436,6 @@ class WeekView @JvmOverloads constructor(context: Context, attrs: AttributeSet?
14361436
val startFromPixel = xStartPixel
14371437
var startPixel = startFromPixel
14381438

1439-
// Prepare to iterate for each day.
1440-
var day = today.clone() as Calendar
1441-
day.add(Calendar.HOUR_OF_DAY, 6)
1442-
14431439
// Prepare to iterate for each hour to draw the hour lines.
14441440
var lineCount = ((height.toFloat() - mHeaderHeight - (mHeaderRowPadding * 2).toFloat() -
14451441
mHeaderMarginBottom) / mHourHeight).toInt() + 1
@@ -1469,7 +1465,7 @@ class WeekView @JvmOverloads constructor(context: Context, attrs: AttributeSet?
14691465
if (autoLimitTime) {
14701466
val days = ArrayList<Calendar>()
14711467
for (dayNumber in leftDaysWithGaps + 1..leftDaysWithGaps + realNumberOfVisibleDays) {
1472-
day = mHomeDate!!.clone() as Calendar
1468+
val day = mHomeDate!!.clone() as Calendar
14731469
day.add(Calendar.DATE, dayNumber - 1)
14741470
days.add(day)
14751471
}
@@ -1478,7 +1474,7 @@ class WeekView @JvmOverloads constructor(context: Context, attrs: AttributeSet?
14781474

14791475
for (dayNumber in leftDaysWithGaps + 1..leftDaysWithGaps + realNumberOfVisibleDays + 1) {
14801476
// Check if the day is today.
1481-
day = mHomeDate!!.clone() as Calendar
1477+
val day = mHomeDate!!.clone() as Calendar
14821478
lastVisibleDay = day.clone() as Calendar
14831479
day.add(Calendar.DATE, dayNumber - 1)
14841480
lastVisibleDay!!.add(Calendar.DATE, dayNumber - 2)
@@ -1581,24 +1577,26 @@ class WeekView @JvmOverloads constructor(context: Context, attrs: AttributeSet?
15811577
canvas.drawRect(0f, 0f, width.toFloat(), mHeaderHeight + mHeaderRowPadding * 2, mHeaderBackgroundPaint)
15821578

15831579
// Draw the header row texts.
1584-
startPixel = startFromPixel
1585-
for (dayNumber in leftDaysWithGaps + 1..leftDaysWithGaps + realNumberOfVisibleDays + 1) {
1586-
// Check if the day is today.
1587-
day = mHomeDate!!.clone() as Calendar
1588-
day.add(Calendar.DATE, dayNumber - 1)
1589-
val isToday = isSameDay(day, today)
1590-
1591-
// Don't draw days which are outside requested range
1592-
if (!dateIsValid(day))
1593-
continue
1594-
1595-
// Draw the day labels.
1596-
val dayLabel = dateTimeInterpreter.interpretDate(day)
1597-
canvas.drawText(dayLabel, startPixel + mWidthPerDay / 2, mHeaderTextHeight + mHeaderRowPadding, if (isToday) mTodayHeaderTextPaint else mHeaderTextPaint)
1598-
drawAllDayEvents(day, startPixel, canvas)
1599-
startPixel += mWidthPerDay + mColumnGap
1580+
run {
1581+
val day = mHomeDate!!.clone() as Calendar
1582+
startPixel = startFromPixel
1583+
day.add(Calendar.DATE, leftDaysWithGaps)
1584+
for (dayNumber in leftDaysWithGaps + 1..leftDaysWithGaps + realNumberOfVisibleDays + 1) {
1585+
// Check if the day is today.
1586+
val isToday = isSameDay(day, today)
1587+
// Don't draw days which are outside requested range
1588+
if (!dateIsValid(day)) {
1589+
day.add(Calendar.DAY_OF_YEAR, 1)
1590+
continue
1591+
}
1592+
// Draw the day labels.
1593+
val dayLabel = dateTimeInterpreter.interpretDate(day)
1594+
canvas.drawText(dayLabel, startPixel + mWidthPerDay / 2, mHeaderTextHeight + mHeaderRowPadding, if (isToday) mTodayHeaderTextPaint else mHeaderTextPaint)
1595+
drawAllDayEvents(day, startPixel, canvas)
1596+
startPixel += mWidthPerDay + mColumnGap
1597+
day.add(Calendar.DAY_OF_YEAR, 1)
1598+
}
16001599
}
1601-
16021600
}
16031601

16041602
/**

0 commit comments

Comments
 (0)