removing the event isPastEvent field

This commit is contained in:
tibbi 2018-11-12 23:38:26 +01:00
parent 57235ab44a
commit 4ac956d315
9 changed files with 51 additions and 18 deletions

View File

@ -119,7 +119,7 @@ class DayEventsAdapter(activity: SimpleActivity, val events: ArrayList<Event>, r
}
var newTextColor = textColor
if (dimPastEvents && event.isPastEvent) {
if (dimPastEvents && event.getIsPastEvent()) {
newTextColor = newTextColor.adjustAlpha(LOW_ALPHA)
}

View File

@ -174,7 +174,7 @@ class EventListWidgetAdapter(val context: Context) : RemoteViewsService.RemoteVi
prevCode = code
}
val listEvent = ListEvent(it.id!!, it.startTS, it.endTS, it.title, it.description, it.getIsAllDay(), it.color, it.location, it.isPastEvent, it.repeatInterval > 0)
val listEvent = ListEvent(it.id!!, it.startTS, it.endTS, it.title, it.description, it.getIsAllDay(), it.color, it.location, it.getIsPastEvent(), it.repeatInterval > 0)
listItems.add(listEvent)
}

View File

@ -425,7 +425,7 @@ fun Context.getEventListItems(events: List<Event>): ArrayList<ListItem> {
listItems.add(listSection)
prevCode = code
}
val listEvent = ListEvent(it.id!!, it.startTS, it.endTS, it.title, it.description, it.getIsAllDay(), it.color, it.location, it.isPastEvent, it.repeatInterval > 0)
val listEvent = ListEvent(it.id!!, it.startTS, it.endTS, it.title, it.description, it.getIsAllDay(), it.color, it.location, it.getIsPastEvent(), it.repeatInterval > 0)
listItems.add(listEvent)
}
return listItems

View File

@ -270,7 +270,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
(inflater.inflate(R.layout.week_event_marker, null, false) as TextView).apply {
var backgroundColor = eventTypeColors.get(event.eventType, primaryColor)
var textColor = backgroundColor.getContrastColor()
if (dimPastEvents && event.isPastEvent) {
if (dimPastEvents && event.getIsPastEvent()) {
backgroundColor = backgroundColor.adjustAlpha(LOW_ALPHA)
textColor = textColor.adjustAlpha(LOW_ALPHA)
}
@ -339,7 +339,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
(inflater.inflate(R.layout.week_all_day_event_marker, null, false) as TextView).apply {
var backgroundColor = eventTypeColors.get(event.eventType, primaryColor)
var textColor = backgroundColor.getContrastColor()
if (dimPastEvents && event.isPastEvent) {
if (dimPastEvents && event.getIsPastEvent()) {
backgroundColor = backgroundColor.adjustAlpha(LOW_ALPHA)
textColor = textColor.adjustAlpha(LOW_ALPHA)
}

View File

@ -74,6 +74,7 @@ const val REPEAT_ORDER_WEEKDAY = 4 // i.e. every 4th sunday
// special event flags
const val FLAG_ALL_DAY = 1
const val FLAG_IS_PAST_EVENT = 2
// constants related to ICS file exporting / importing
const val BEGIN_CALENDAR = "BEGIN:VCALENDAR"

View File

@ -649,11 +649,17 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
if (event.repeatInterval.isXWeeklyRepetition()) {
if (event.startTS.isTsOnProperDay(event)) {
if (isOnProperWeek(event, startTimes)) {
events.add(event.copy(isPastEvent = getIsPastEvent(event)))
event.copy().apply {
setIsPastEvent(getIsPastEvent(this))
events.add(this)
}
}
}
} else {
events.add(event.copy(isPastEvent = getIsPastEvent(event)))
event.copy().apply {
setIsPastEvent(getIsPastEvent(this))
events.add(this)
}
}
}
@ -661,14 +667,20 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
if (event.repeatInterval.isXWeeklyRepetition()) {
if (event.endTS >= toTS && event.startTS.isTsOnProperDay(event)) {
if (isOnProperWeek(event, startTimes)) {
events.add(event.copy(isPastEvent = getIsPastEvent(event)))
event.copy().apply {
setIsPastEvent(getIsPastEvent(this))
events.add(this)
}
}
}
} else {
val dayCode = Formatter.getDayCodeFromTS(fromTS)
val endDayCode = Formatter.getDayCodeFromTS(event.endTS)
if (dayCode == endDayCode) {
events.add(event.copy(isPastEvent = getIsPastEvent(event)))
event.copy().apply {
setIsPastEvent(getIsPastEvent(this))
events.add(this)
}
}
}
}
@ -685,19 +697,28 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
if (event.startTS.isTsOnProperDay(event)) {
if (isOnProperWeek(event, startTimes)) {
if (event.endTS >= fromTS) {
events.add(event.copy(isPastEvent = getIsPastEvent(event)))
event.copy().apply {
setIsPastEvent(getIsPastEvent(this))
events.add(this)
}
}
event.repeatLimit++
}
}
} else {
if (event.endTS >= fromTS) {
events.add(event.copy(isPastEvent = getIsPastEvent(event)))
event.copy().apply {
setIsPastEvent(getIsPastEvent(this))
events.add(this)
}
} else if (event.getIsAllDay()) {
val dayCode = Formatter.getDayCodeFromTS(fromTS)
val endDayCode = Formatter.getDayCodeFromTS(event.endTS)
if (dayCode == endDayCode) {
events.add(event.copy(isPastEvent = getIsPastEvent(event)))
event.copy().apply {
setIsPastEvent(getIsPastEvent(this))
events.add(this)
}
}
}
event.repeatLimit++
@ -851,15 +872,14 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
val source = cursor.getStringValue(COL_EVENT_SOURCE)
val location = cursor.getStringValue(COL_LOCATION)
val color = eventTypeColors.get(eventType)!!
val isPastEvent = false
if (repeatInterval > 0 && repeatRule == 0 && (repeatInterval % MONTH == 0 || repeatInterval % YEAR == 0)) {
repeatRule = REPEAT_SAME_DAY
}
val event = Event(id, startTS, endTS, title, description, reminder1Minutes, reminder2Minutes, reminder3Minutes,
repeatInterval, importId, flags, repeatLimit, repeatRule, eventType, 0, lastUpdated, source, color, location, isPastEvent)
event.isPastEvent = getIsPastEvent(event)
repeatInterval, importId, flags, repeatLimit, repeatRule, eventType, 0, lastUpdated, source, color, location)
event.setIsPastEvent(getIsPastEvent(event))
events.add(event)
} while (cursor.moveToNext())

View File

@ -125,7 +125,7 @@ class MyWidgetMonthlyProvider : AppWidgetProvider() {
var backgroundColor = it.color
var eventTextColor = backgroundColor.getContrastColor()
if (!day.isThisMonth || (dimPastEvents && it.isPastEvent)) {
if (!day.isThisMonth || (dimPastEvents && it.getIsPastEvent())) {
eventTextColor = eventTextColor.adjustAlpha(0.25f)
backgroundColor = backgroundColor.adjustAlpha(0.25f)
}

View File

@ -2,6 +2,8 @@ package com.simplemobiletools.calendar.pro.models
import com.simplemobiletools.calendar.pro.extensions.seconds
import com.simplemobiletools.calendar.pro.helpers.*
import com.simplemobiletools.commons.extensions.addBit
import com.simplemobiletools.commons.extensions.removeBit
import org.joda.time.DateTime
import java.io.Serializable
@ -9,7 +11,7 @@ data class Event(var id: Long?, var startTS: Int = 0, var endTS: Int = 0, var ti
var reminder1Minutes: Int = -1, var reminder2Minutes: Int = -1, var reminder3Minutes: Int = -1, var repeatInterval: Int = 0,
var importId: String = "", var flags: Int = 0, var repeatLimit: Int = 0, var repeatRule: Int = 0,
var eventType: Long = DBHelper.REGULAR_EVENT_TYPE_ID, var parentId: Long = 0, var lastUpdated: Long = 0L,
var source: String = SOURCE_SIMPLE_CALENDAR, var color: Int = 0, var location: String = "", var isPastEvent: Boolean = false)
var source: String = SOURCE_SIMPLE_CALENDAR, var color: Int = 0, var location: String = "")
: Serializable {
companion object {
@ -93,6 +95,16 @@ data class Event(var id: Long?, var startTS: Int = 0, var endTS: Int = 0, var ti
fun getIsAllDay() = flags and FLAG_ALL_DAY != 0
fun getIsPastEvent() = flags and FLAG_IS_PAST_EVENT != 0
fun setIsPastEvent(isPastEvent: Boolean) {
flags = if (isPastEvent) {
flags.addBit(FLAG_IS_PAST_EVENT)
} else {
flags.removeBit(FLAG_IS_PAST_EVENT)
}
}
fun getReminders() = setOf(reminder1Minutes, reminder2Minutes, reminder3Minutes).filter { it != REMINDER_OFF }
// properly return the start time of all-day events as midnight

View File

@ -106,7 +106,7 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
val daysCnt = getEventLastingDaysCount(event)
if (lastEvent == null || lastEvent.startDayIndex + daysCnt <= day.indexOnMonthView) {
val monthViewEvent = MonthViewEvent(event.id!!, event.title, event.startTS, event.color, day.indexOnMonthView,
daysCnt, day.indexOnMonthView, event.getIsAllDay(), event.isPastEvent)
daysCnt, day.indexOnMonthView, event.getIsAllDay(), event.getIsPastEvent())
allEvents.add(monthViewEvent)
}
}