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 package com.simplemobiletools.calendar.helpers
import android.content.Context import android.content.Context
import android.util.SparseIntArray
import com.simplemobiletools.calendar.extensions.config import com.simplemobiletools.calendar.extensions.config
import com.simplemobiletools.calendar.extensions.dbHelper import com.simplemobiletools.calendar.extensions.dbHelper
import com.simplemobiletools.calendar.extensions.getFilteredEvents import com.simplemobiletools.calendar.extensions.getFilteredEvents
@ -75,7 +76,7 @@ class MonthlyCalendarImpl(val mCallback: MonthlyCalendar, val mContext: Context)
val newDay = curDay.withDayOfMonth(value) val newDay = curDay.withDayOfMonth(value)
val dayCode = Formatter.getDayCodeFromDateTime(newDay) 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) days.add(day)
value++ value++
} }
@ -88,21 +89,28 @@ class MonthlyCalendarImpl(val mCallback: MonthlyCalendar, val mContext: Context)
// it works more often than not, dont touch // it works more often than not, dont touch
private fun markDaysWithEvents(days: ArrayList<Day>) { private fun markDaysWithEvents(days: ArrayList<Day>) {
val eventCodes = ArrayList<String>() val eventCodes = ArrayList<String>()
for ((id, startTS, endTS) in mEvents) { mContext.dbHelper.getEventTypes {
val startDateTime = Formatter.getDateTimeFromTS(startTS) val eventTypes = SparseIntArray()
val endDateTime = Formatter.getDateTimeFromTS(endTS) it.forEach {
val endCode = Formatter.getDayCodeFromDateTime(endDateTime) eventTypes.put(it.id, it.color)
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 } 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) = private fun isToday(targetDate: DateTime, curDayInMonth: Int) =

View File

@ -1,3 +1,4 @@
package com.simplemobiletools.calendar.models 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>)