diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/MonthlyCalendarImpl.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/MonthlyCalendarImpl.kt index 9732cf142..1c344b8d2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/MonthlyCalendarImpl.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/MonthlyCalendarImpl.kt @@ -1,6 +1,7 @@ package com.simplemobiletools.calendar.helpers import android.content.Context +import android.util.SparseIntArray import com.simplemobiletools.calendar.extensions.config import com.simplemobiletools.calendar.extensions.dbHelper import com.simplemobiletools.calendar.extensions.getFilteredEvents @@ -75,7 +76,7 @@ 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, false, newDay.weekOfWeekyear) + val day = Day(value, isThisMonth, isToday, dayCode, false, newDay.weekOfWeekyear, ArrayList()) days.add(day) value++ } @@ -88,21 +89,28 @@ class MonthlyCalendarImpl(val mCallback: MonthlyCalendar, val mContext: Context) // it works more often than not, dont touch private fun markDaysWithEvents(days: ArrayList) { val eventCodes = ArrayList() - for ((id, startTS, endTS) in mEvents) { - val startDateTime = Formatter.getDateTimeFromTS(startTS) - val endDateTime = Formatter.getDateTimeFromTS(endTS) - val endCode = Formatter.getDayCodeFromDateTime(endDateTime) - - var currDay = startDateTime - eventCodes.add(Formatter.getDayCodeFromDateTime(currDay)) - - while (Formatter.getDayCodeFromDateTime(currDay) != endCode) { - currDay = currDay.plusDays(1) - eventCodes.add(Formatter.getDayCodeFromDateTime(currDay)) + mContext.dbHelper.getEventTypes { + val eventTypes = SparseIntArray() + it.forEach { + eventTypes.put(it.id, it.color) } - } - days.filter { eventCodes.contains(it.code) }.forEach { it.hasEvent = true } + mEvents.forEach { + val startDateTime = Formatter.getDateTimeFromTS(it.startTS) + val endDateTime = Formatter.getDateTimeFromTS(it.endTS) + val endCode = Formatter.getDayCodeFromDateTime(endDateTime) + + var currDay = startDateTime + eventCodes.add(Formatter.getDayCodeFromDateTime(currDay)) + + while (Formatter.getDayCodeFromDateTime(currDay) != endCode) { + currDay = currDay.plusDays(1) + eventCodes.add(Formatter.getDayCodeFromDateTime(currDay)) + } + } + + days.filter { eventCodes.contains(it.code) }.forEach { it.hasEvent = true } + } } private fun isToday(targetDate: DateTime, curDayInMonth: Int) = diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/models/Day.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/models/Day.kt index f05bf1ff9..2301d9bd8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/models/Day.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/models/Day.kt @@ -1,3 +1,4 @@ package com.simplemobiletools.calendar.models -data class Day(val value: Int, val isThisMonth: Boolean, val isToday: Boolean, val code: String, var hasEvent: Boolean, val weekOfYear: Int) +data class Day(val value: Int, val isThisMonth: Boolean, val isToday: Boolean, val code: String, var hasEvent: Boolean, val weekOfYear: Int, + var eventColors: ArrayList)