some corrections to really mark all days with events

This commit is contained in:
tibbi 2016-11-03 20:34:29 +01:00
parent 9d0c1d35fc
commit c826ef12ac
1 changed files with 12 additions and 7 deletions

View File

@ -72,27 +72,32 @@ class MonthlyCalendarImpl(val mCallback: MonthlyCalendar, val mContext: Context)
value++ value++
} }
markEvents(days, firstDayIndex - 1) markDaysWithEvents(days)
mCallback.updateMonthlyCalendar(monthName, days) mCallback.updateMonthlyCalendar(monthName, days)
} }
private fun markEvents(days: ArrayList<Day>, firstDayIndex: Int) { // it works more often than not, dont touch
private fun markDaysWithEvents(days: ArrayList<Day>) {
val eventCodes = ArrayList<String>()
for (event in mEvents) { for (event in mEvents) {
val startDateTime = DateTime().withMillis(event.startTS * 1000L) val startDateTime = DateTime().withMillis(event.startTS * 1000L)
val endDateTime = DateTime().withMillis(event.endTS * 1000L) val endDateTime = DateTime().withMillis(event.endTS * 1000L)
val endCode = Formatter.getDayCodeFromDateTime(endDateTime) val endCode = Formatter.getDayCodeFromDateTime(endDateTime)
var currDay = startDateTime var currDay = startDateTime
if (currDay.monthOfYear == mTargetDate.monthOfYear) eventCodes.add(Formatter.getDayCodeFromDateTime(currDay))
days[startDateTime.dayOfMonth + firstDayIndex].hasEvent = true
while (Formatter.getDayCodeFromDateTime(currDay) != endCode) { while (Formatter.getDayCodeFromDateTime(currDay) != endCode) {
currDay = currDay.plusDays(1) currDay = currDay.plusDays(1)
if (currDay.monthOfYear == mTargetDate.monthOfYear) { eventCodes.add(Formatter.getDayCodeFromDateTime(currDay))
days[currDay.dayOfMonth + firstDayIndex].hasEvent = true
} }
} }
for (day in days) {
if (eventCodes.contains(day.code)) {
day.hasEvent = true
}
} }
} }