properly mark days with events that last multiple days

This commit is contained in:
tibbi 2016-11-03 20:11:33 +01:00
parent bf74b34cb7
commit 9d0c1d35fc
2 changed files with 18 additions and 6 deletions

View File

@ -67,21 +67,33 @@ class MonthlyCalendarImpl(val mCallback: MonthlyCalendar, val mContext: Context)
val newDay = curDay.withDayOfMonth(value)
val dayCode = Formatter.getDayCodeFromDateTime(newDay)
val day = Day(value, isThisMonth, isToday, dayCode, hasEvent(dayCode), newDay.weekOfWeekyear)
val day = Day(value, isThisMonth, isToday, dayCode, false, newDay.weekOfWeekyear)
days.add(day)
value++
}
markEvents(days, firstDayIndex - 1)
mCallback.updateMonthlyCalendar(monthName, days)
}
private fun hasEvent(dayCode: String): Boolean {
private fun markEvents(days: ArrayList<Day>, firstDayIndex: Int) {
for (event in mEvents) {
if (Formatter.getDayCodeFromTS(event.startTS) == dayCode) {
return true
val startDateTime = DateTime().withMillis(event.startTS * 1000L)
val endDateTime = DateTime().withMillis(event.endTS * 1000L)
val endCode = Formatter.getDayCodeFromDateTime(endDateTime)
var currDay = startDateTime
if (currDay.monthOfYear == mTargetDate.monthOfYear)
days[startDateTime.dayOfMonth + firstDayIndex].hasEvent = true
while (Formatter.getDayCodeFromDateTime(currDay) != endCode) {
currDay = currDay.plusDays(1)
if (currDay.monthOfYear == mTargetDate.monthOfYear) {
days[currDay.dayOfMonth + firstDayIndex].hasEvent = true
}
}
}
return false
}
private fun isToday(targetDate: DateTime, curDayInMonth: Int): Boolean {

View File

@ -1,6 +1,6 @@
package com.simplemobiletools.calendar.models
class Day(val value: Int, val isThisMonth: Boolean, val isToday: Boolean, val code: String, val hasEvent: Boolean, val weekOfYear: Int) {
class Day(val value: Int, val isThisMonth: Boolean, val isToday: Boolean, val code: String, var hasEvent: Boolean, val weekOfYear: Int) {
override fun toString(): String {
return "Day {value=$value, isThisMonth=$isThisMonth, itToday=$isToday, code=$code, hasEvent=$hasEvent, weekOfYear=$weekOfYear}"
}