making the event ID field nullable
This commit is contained in:
parent
c78b15a629
commit
9356cc3df3
8 changed files with 29 additions and 29 deletions
|
@ -90,7 +90,7 @@ class EventActivity : SimpleActivity() {
|
|||
mEvent.id = 0
|
||||
}
|
||||
|
||||
cancelNotification(mEvent.id)
|
||||
cancelNotification(mEvent.id!!)
|
||||
} else {
|
||||
mEvent = Event()
|
||||
config.apply {
|
||||
|
@ -656,14 +656,14 @@ class EventActivity : SimpleActivity() {
|
|||
}
|
||||
|
||||
private fun shareEvent() {
|
||||
shareEvents(arrayListOf(mEvent.id))
|
||||
shareEvents(arrayListOf(mEvent.id!!))
|
||||
}
|
||||
|
||||
private fun deleteEvent() {
|
||||
DeleteEventDialog(this, arrayListOf(mEvent.id), mEvent.repeatInterval > 0) {
|
||||
DeleteEventDialog(this, arrayListOf(mEvent.id!!), mEvent.repeatInterval > 0) {
|
||||
when (it) {
|
||||
DELETE_SELECTED_OCCURRENCE -> dbHelper.addEventRepeatException(mEvent.id, mEventOccurrenceTS, true)
|
||||
DELETE_FUTURE_OCCURRENCES -> dbHelper.addEventRepeatLimit(mEvent.id, mEventOccurrenceTS)
|
||||
DELETE_SELECTED_OCCURRENCE -> dbHelper.addEventRepeatException(mEvent.id!!, mEventOccurrenceTS, true)
|
||||
DELETE_FUTURE_OCCURRENCES -> dbHelper.addEventRepeatLimit(mEvent.id!!, mEventOccurrenceTS)
|
||||
DELETE_ALL_OCCURRENCES -> dbHelper.deleteEvents(arrayOf(mEvent.id.toString()), true)
|
||||
}
|
||||
finish()
|
||||
|
@ -775,10 +775,10 @@ class EventActivity : SimpleActivity() {
|
|||
finish()
|
||||
}
|
||||
} else {
|
||||
dbHelper.addEventRepeatException(mEvent.id, mEventOccurrenceTS, true)
|
||||
dbHelper.addEventRepeatException(mEvent.id!!, mEventOccurrenceTS, true)
|
||||
mEvent.apply {
|
||||
parentId = id
|
||||
id = 0
|
||||
parentId = id!!
|
||||
id = null
|
||||
repeatRule = 0
|
||||
repeatInterval = 0
|
||||
repeatLimit = 0
|
||||
|
|
|
@ -145,7 +145,7 @@ class DayEventsAdapter(activity: SimpleActivity, val events: ArrayList<Event>, r
|
|||
val nonRepeatingEventIDs = eventsToDelete.asSequence().filter { it.repeatInterval == 0 }.map { it.id.toString() }.toList().toTypedArray()
|
||||
activity.dbHelper.deleteEvents(nonRepeatingEventIDs, true)
|
||||
|
||||
val repeatingEventIDs = eventsToDelete.asSequence().filter { it.repeatInterval != 0 }.map { it.id }.toList()
|
||||
val repeatingEventIDs = eventsToDelete.asSequence().filter { it.repeatInterval != 0 }.map { it.id!! }.toList()
|
||||
activity.handleEventDeleting(repeatingEventIDs, timestamps, it)
|
||||
removeSelectedItems(positions)
|
||||
}
|
||||
|
|
|
@ -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.isPastEvent, it.repeatInterval > 0)
|
||||
listItems.add(listEvent)
|
||||
}
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@ fun Context.scheduleNextEventReminder(event: Event, dbHelper: DBHelper, activity
|
|||
|
||||
val now = getNowSeconds()
|
||||
val reminderSeconds = event.getReminders().reversed().map { it * 60 }
|
||||
dbHelper.getEvents(now, now + YEAR, event.id, false) {
|
||||
dbHelper.getEvents(now, now + YEAR, event.id!!, false) {
|
||||
if (it.isNotEmpty()) {
|
||||
for (curEvent in it) {
|
||||
for (curReminder in reminderSeconds) {
|
||||
|
@ -127,7 +127,7 @@ private fun getNotificationIntent(context: Context, event: Event): PendingIntent
|
|||
val intent = Intent(context, NotificationReceiver::class.java)
|
||||
intent.putExtra(EVENT_ID, event.id)
|
||||
intent.putExtra(EVENT_OCCURRENCE_TS, event.startTS)
|
||||
return PendingIntent.getBroadcast(context, event.id, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
return PendingIntent.getBroadcast(context, event.id!!, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
}
|
||||
|
||||
fun Context.getRepetitionText(seconds: Int) = when (seconds) {
|
||||
|
@ -159,7 +159,7 @@ fun Context.notifyEvent(originalEvent: Event) {
|
|||
var eventStartTS = if (event.getIsAllDay()) Formatter.getDayStartTS(Formatter.getDayCodeFromTS(event.startTS)) else event.startTS
|
||||
// make sure refer to the proper repeatable event instance with "Tomorrow", or the specific date
|
||||
if (event.repeatInterval != 0 && eventStartTS - event.reminder1Minutes * 60 < currentSeconds) {
|
||||
val events = dbHelper.getRepeatableEventsFor(currentSeconds - WEEK_SECONDS, currentSeconds + YEAR_SECONDS, event.id)
|
||||
val events = dbHelper.getRepeatableEventsFor(currentSeconds - WEEK_SECONDS, currentSeconds + YEAR_SECONDS, event.id!!)
|
||||
for (currEvent in events) {
|
||||
eventStartTS = if (currEvent.getIsAllDay()) Formatter.getDayStartTS(Formatter.getDayCodeFromTS(currEvent.startTS)) else currEvent.startTS
|
||||
if (eventStartTS - currEvent.reminder1Minutes * 60 > currentSeconds) {
|
||||
|
@ -186,7 +186,7 @@ fun Context.notifyEvent(originalEvent: Event) {
|
|||
val content = "$displayedStartDate $timeRange $descriptionOrLocation".trim()
|
||||
val notification = getNotification(pendingIntent, event, content)
|
||||
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
notificationManager.notify(event.id, notification)
|
||||
notificationManager.notify(event.id!!, notification)
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
|
@ -262,7 +262,7 @@ private fun getPendingIntent(context: Context, event: Event): PendingIntent {
|
|||
val intent = Intent(context, EventActivity::class.java)
|
||||
intent.putExtra(EVENT_ID, event.id)
|
||||
intent.putExtra(EVENT_OCCURRENCE_TS, event.startTS)
|
||||
return PendingIntent.getActivity(context, event.id, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
return PendingIntent.getActivity(context, event.id!!, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
}
|
||||
|
||||
private fun getSnoozePendingIntent(context: Context, event: Event): PendingIntent {
|
||||
|
@ -270,9 +270,9 @@ private fun getSnoozePendingIntent(context: Context, event: Event): PendingInten
|
|||
val intent = Intent(context, snoozeClass).setAction("Snooze")
|
||||
intent.putExtra(EVENT_ID, event.id)
|
||||
return if (context.config.useSameSnooze) {
|
||||
PendingIntent.getService(context, event.id, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
PendingIntent.getService(context, event.id!!, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
} else {
|
||||
PendingIntent.getActivity(context, event.id, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
PendingIntent.getActivity(context, event.id!!, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -280,7 +280,7 @@ fun Context.rescheduleReminder(event: Event?, minutes: Int) {
|
|||
if (event != null) {
|
||||
applicationContext.scheduleEventIn(System.currentTimeMillis() + minutes * 60000, event)
|
||||
val manager = applicationContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
manager.cancel(event.id)
|
||||
manager.cancel(event.id!!)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -429,7 +429,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.isPastEvent, it.repeatInterval > 0)
|
||||
listItems.add(listEvent)
|
||||
}
|
||||
return listItems
|
||||
|
|
|
@ -201,7 +201,7 @@ class CalDAVHandler(val context: Context) {
|
|||
val importId = getCalDAVEventImportId(calendarId, id)
|
||||
val source = "$CALDAV-$calendarId"
|
||||
val repeatRule = Parser().parseRepeatInterval(rrule, startTS)
|
||||
val event = Event(0, startTS, endTS, title, description, reminders.getOrElse(0) { -1 },
|
||||
val event = Event(null, startTS, endTS, title, description, reminders.getOrElse(0) { -1 },
|
||||
reminders.getOrElse(1) { -1 }, reminders.getOrElse(2) { -1 }, repeatRule.repeatInterval,
|
||||
importId, allDay, repeatRule.repeatLimit, repeatRule.repeatRule, eventTypeId, source = source, location = location)
|
||||
|
||||
|
@ -219,7 +219,7 @@ class CalDAVHandler(val context: Context) {
|
|||
val originalEventId = existingEvent!!.id
|
||||
|
||||
existingEvent.apply {
|
||||
this.id = 0
|
||||
this.id = null
|
||||
color = 0
|
||||
ignoreEventOccurrences = ArrayList()
|
||||
lastUpdated = 0L
|
||||
|
@ -311,7 +311,7 @@ class CalDAVHandler(val context: Context) {
|
|||
}
|
||||
|
||||
private fun setupCalDAVEventImportId(event: Event) {
|
||||
context.dbHelper.updateEventImportIdAndSource(event.id, event.importId, "$CALDAV-${event.getCalDAVCalendarId()}")
|
||||
context.dbHelper.updateEventImportIdAndSource(event.id!!, event.importId, "$CALDAV-${event.getCalDAVCalendarId()}")
|
||||
}
|
||||
|
||||
private fun fillEventContentValues(event: Event): ContentValues {
|
||||
|
|
|
@ -136,7 +136,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
CalDAVHandler(context).insertCalDAVEvent(event)
|
||||
}
|
||||
|
||||
callback(event.id)
|
||||
callback(event.id!!)
|
||||
}
|
||||
|
||||
fun insertEvents(events: ArrayList<Event>, addToCalDAV: Boolean) {
|
||||
|
@ -537,7 +537,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
val cursor = getEventsCursor(selection, selectionArgs)
|
||||
val events = fillEvents(cursor)
|
||||
return if (events.isNotEmpty()) {
|
||||
events.minBy { it.id }?.id ?: 0
|
||||
events.minBy { it.id!! }?.id ?: 0
|
||||
} else {
|
||||
0
|
||||
}
|
||||
|
@ -549,7 +549,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
val cursor = getEventsCursor(selection, selectionArgs)
|
||||
val events = fillEvents(cursor)
|
||||
return if (events.isNotEmpty()) {
|
||||
events.minBy { it.id }?.id ?: 0
|
||||
events.minBy { it.id!! }?.id ?: 0
|
||||
} else {
|
||||
0
|
||||
}
|
||||
|
@ -624,7 +624,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
val events = getEvents(selection)
|
||||
val startTimes = SparseIntArray(events.size)
|
||||
events.forEach {
|
||||
startTimes.put(it.id, it.startTS)
|
||||
startTimes.put(it.id!!, it.startTS)
|
||||
if (it.repeatLimit >= 0) {
|
||||
newEvents.addAll(getEventsRepeatingTillDateOrForever(fromTS, toTS, startTimes, it))
|
||||
} else {
|
||||
|
@ -723,7 +723,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
|
||||
// check if its the proper week, for events repeating every x weeks
|
||||
private fun isOnProperWeek(event: Event, startTimes: SparseIntArray): Boolean {
|
||||
val initialWeekOfYear = Formatter.getDateTimeFromTS(startTimes[event.id]).weekOfWeekyear
|
||||
val initialWeekOfYear = Formatter.getDateTimeFromTS(startTimes[event.id!!]).weekOfWeekyear
|
||||
val currentWeekOfYear = Formatter.getDateTimeFromTS(event.startTS).weekOfWeekyear
|
||||
return (currentWeekOfYear - initialWeekOfYear) % (event.repeatInterval / WEEK) == 0
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import org.joda.time.DateTime
|
|||
import java.io.Serializable
|
||||
import java.util.*
|
||||
|
||||
data class Event(var id: Int = 0, var startTS: Int = 0, var endTS: Int = 0, var title: String = "", var description: String = "",
|
||||
data class Event(var id: Int? = 0, var startTS: Int = 0, var endTS: Int = 0, var title: String = "", var description: String = "",
|
||||
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 ignoreEventOccurrences: ArrayList<Int> = ArrayList(),
|
||||
|
|
|
@ -105,7 +105,7 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
|
|||
val lastEvent = allEvents.lastOrNull { it.id == event.id }
|
||||
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,
|
||||
val monthViewEvent = MonthViewEvent(event.id!!, event.title, event.startTS, event.color, day.indexOnMonthView,
|
||||
daysCnt, day.indexOnMonthView, event.getIsAllDay(), event.isPastEvent)
|
||||
allEvents.add(monthViewEvent)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue