do some preparations for showing colored dot at monthly view

This commit is contained in:
tibbi 2017-04-22 14:02:28 +02:00
parent 00efe5b33a
commit 67747e329a
2 changed files with 24 additions and 15 deletions

View File

@ -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<Int>())
days.add(day)
value++
}
@ -88,9 +89,15 @@ class MonthlyCalendarImpl(val mCallback: MonthlyCalendar, val mContext: Context)
// it works more often than not, dont touch
private fun markDaysWithEvents(days: ArrayList<Day>) {
val eventCodes = ArrayList<String>()
for ((id, startTS, endTS) in mEvents) {
val startDateTime = Formatter.getDateTimeFromTS(startTS)
val endDateTime = Formatter.getDateTimeFromTS(endTS)
mContext.dbHelper.getEventTypes {
val eventTypes = SparseIntArray()
it.forEach {
eventTypes.put(it.id, it.color)
}
mEvents.forEach {
val startDateTime = Formatter.getDateTimeFromTS(it.startTS)
val endDateTime = Formatter.getDateTimeFromTS(it.endTS)
val endCode = Formatter.getDayCodeFromDateTime(endDateTime)
var currDay = startDateTime
@ -104,6 +111,7 @@ class MonthlyCalendarImpl(val mCallback: MonthlyCalendar, val mContext: Context)
days.filter { eventCodes.contains(it.code) }.forEach { it.hasEvent = true }
}
}
private fun isToday(targetDate: DateTime, curDayInMonth: Int) =
targetDate.withDayOfMonth(curDayInMonth).toString(Formatter.DAYCODE_PATTERN) == mToday

View File

@ -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<Int>)