color the dot at day events list as appropriate
This commit is contained in:
parent
d7cae83b5c
commit
166d624eeb
|
@ -1,5 +1,7 @@
|
|||
package com.simplemobiletools.calendar.adapters
|
||||
|
||||
import android.graphics.Color
|
||||
import android.graphics.PorterDuff
|
||||
import android.support.v7.view.ActionMode
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.view.*
|
||||
|
@ -115,12 +117,13 @@ class DayEventsAdapter(val activity: SimpleActivity, val mItems: List<Event>, va
|
|||
|
||||
class ViewHolder(val activity: SimpleActivity, view: View, val itemClick: (Event) -> (Unit)) : SwappingHolder(view, MultiSelector()) {
|
||||
fun bindView(multiSelectorCallback: ModalMultiSelectorCallback, multiSelector: MultiSelector, event: Event, pos: Int): View {
|
||||
|
||||
itemView.apply {
|
||||
event_item_title.text = event.title
|
||||
event_item_description.text = event.description
|
||||
event_item_start.text = if (event.getIsAllDay()) allDayString else Formatter.getTimeFromTS(context, event.startTS)
|
||||
event_item_end.beInvisibleIf(event.startTS == event.endTS)
|
||||
event_item_color.setColorFilter(event.color, PorterDuff.Mode.SRC_IN)
|
||||
|
||||
toggleItemSelection(this, markedItems.contains(pos), pos)
|
||||
|
||||
if (event.startTS != event.endTS) {
|
||||
|
|
|
@ -746,6 +746,11 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
COL_IS_DST_INCLUDED, COL_LAST_UPDATED, COL_EVENT_SOURCE)
|
||||
|
||||
private fun fillEvents(cursor: Cursor?): List<Event> {
|
||||
val eventTypeColors = SparseIntArray()
|
||||
val eventTypes = fetchEventTypes().forEach {
|
||||
eventTypeColors.put(it.id, it.color)
|
||||
}
|
||||
|
||||
val events = ArrayList<Event>()
|
||||
try {
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
|
@ -768,11 +773,12 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
val isDstIncluded = cursor.getIntValue(COL_IS_DST_INCLUDED) == 1
|
||||
val lastUpdated = cursor.getLongValue(COL_LAST_UPDATED)
|
||||
val source = cursor.getStringValue(COL_EVENT_SOURCE)
|
||||
val color = eventTypeColors[eventType]
|
||||
|
||||
val ignoreEventOccurrences = if (repeatInterval != 0) {
|
||||
getIgnoredOccurrences(id)
|
||||
} else {
|
||||
ArrayList<Int>()
|
||||
ArrayList()
|
||||
}
|
||||
|
||||
if (repeatInterval > 0 && repeatInterval % MONTH == 0 && repeatRule == 0) {
|
||||
|
@ -781,7 +787,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
|
||||
val event = Event(id, startTS, endTS, title, description, reminder1Minutes, reminder2Minutes, reminder3Minutes,
|
||||
repeatInterval, importId, flags, repeatLimit, repeatRule, eventType, ignoreEventOccurrences, offset, isDstIncluded,
|
||||
0, lastUpdated, source)
|
||||
0, lastUpdated, source, color)
|
||||
events.add(event)
|
||||
} while (cursor.moveToNext())
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
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
|
||||
|
@ -17,22 +16,18 @@ class MonthlyCalendarImpl(val mCallback: MonthlyCalendar, val mContext: Context)
|
|||
private val YEAR_PATTERN = "YYYY"
|
||||
|
||||
private val mToday: String = DateTime().toString(Formatter.DAYCODE_PATTERN)
|
||||
var mEvents: List<Event>
|
||||
var mEvents = ArrayList<Event>()
|
||||
var mFilterEventTypes = true
|
||||
|
||||
lateinit var mTargetDate: DateTime
|
||||
|
||||
init {
|
||||
mEvents = ArrayList<Event>()
|
||||
}
|
||||
|
||||
fun updateMonthlyCalendar(targetDate: DateTime, filterEventTypes: Boolean = true) {
|
||||
mFilterEventTypes = filterEventTypes
|
||||
mTargetDate = targetDate
|
||||
val startTS = mTargetDate.minusMonths(1).seconds()
|
||||
val endTS = mTargetDate.plusMonths(1).seconds()
|
||||
mContext.dbHelper.getEvents(startTS, endTS) {
|
||||
gotEvents(it)
|
||||
gotEvents(it as ArrayList<Event>)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -72,7 +67,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, ArrayList<Int>())
|
||||
val day = Day(value, isThisMonth, isToday, dayCode, false, newDay.weekOfWeekyear, ArrayList())
|
||||
days.add(day)
|
||||
value++
|
||||
}
|
||||
|
@ -84,11 +79,6 @@ class MonthlyCalendarImpl(val mCallback: MonthlyCalendar, val mContext: Context)
|
|||
private fun markDaysWithEvents(days: ArrayList<Day>) {
|
||||
mContext.dbHelper.getEventTypes {
|
||||
val dayEvents = HashMap<String, ArrayList<Event>>()
|
||||
val eventTypeColors = SparseIntArray()
|
||||
it.forEach {
|
||||
eventTypeColors.put(it.id, it.color)
|
||||
}
|
||||
|
||||
mEvents.forEach {
|
||||
val startDateTime = Formatter.getDateTimeFromTS(it.startTS)
|
||||
val endDateTime = Formatter.getDateTimeFromTS(it.endTS)
|
||||
|
@ -96,13 +86,13 @@ class MonthlyCalendarImpl(val mCallback: MonthlyCalendar, val mContext: Context)
|
|||
|
||||
var currDay = startDateTime
|
||||
var dayCode = Formatter.getDayCodeFromDateTime(currDay)
|
||||
var currDayEvents = (dayEvents[dayCode] ?: ArrayList<Event>()).apply { add(it) }
|
||||
var currDayEvents = (dayEvents[dayCode] ?: ArrayList()).apply { add(it) }
|
||||
dayEvents.put(dayCode, currDayEvents)
|
||||
|
||||
while (Formatter.getDayCodeFromDateTime(currDay) != endCode) {
|
||||
currDay = currDay.plusDays(1)
|
||||
dayCode = Formatter.getDayCodeFromDateTime(currDay)
|
||||
currDayEvents = (dayEvents[dayCode] ?: ArrayList<Event>()).apply { add(it) }
|
||||
currDayEvents = (dayEvents[dayCode] ?: ArrayList()).apply { add(it) }
|
||||
dayEvents.put(dayCode, currDayEvents)
|
||||
}
|
||||
}
|
||||
|
@ -113,7 +103,7 @@ class MonthlyCalendarImpl(val mCallback: MonthlyCalendar, val mContext: Context)
|
|||
|
||||
val events = dayEvents[it.code]
|
||||
events!!.forEach {
|
||||
day.eventColors.add(eventTypeColors[it.eventType])
|
||||
day.eventColors.add(it.color)
|
||||
}
|
||||
}
|
||||
mCallback.updateMonthlyCalendar(monthName, days)
|
||||
|
@ -137,11 +127,11 @@ class MonthlyCalendarImpl(val mCallback: MonthlyCalendar, val mContext: Context)
|
|||
return month
|
||||
}
|
||||
|
||||
fun gotEvents(events: MutableList<Event>) {
|
||||
if (mFilterEventTypes)
|
||||
mEvents = mContext.getFilteredEvents(events)
|
||||
private fun gotEvents(events: ArrayList<Event>) {
|
||||
mEvents = if (mFilterEventTypes)
|
||||
mContext.getFilteredEvents(events) as ArrayList<Event>
|
||||
else
|
||||
mEvents = events
|
||||
events
|
||||
|
||||
getDays()
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ data class Event(var id: Int = 0, var startTS: Int = 0, var endTS: Int = 0, var
|
|||
var importId: String = "", var flags: Int = 0, var repeatLimit: Int = 0, var repeatRule: Int = 0,
|
||||
var eventType: Int = DBHelper.REGULAR_EVENT_TYPE_ID, var ignoreEventOccurrences: ArrayList<Int> = ArrayList(),
|
||||
var offset: String = "", var isDstIncluded: Boolean = false, var parentId: Int = 0, var lastUpdated: Long = 0L,
|
||||
var source: String = SOURCE_SIMPLE_CALENDAR) : Serializable {
|
||||
var source: String = SOURCE_SIMPLE_CALENDAR, var color: Int = 0) : Serializable {
|
||||
|
||||
companion object {
|
||||
private val serialVersionUID = -32456795132345616L
|
||||
|
|
Loading…
Reference in New Issue