making the event ID field nullable

This commit is contained in:
tibbi
2018-11-10 14:53:24 +01:00
parent c78b15a629
commit 9356cc3df3
8 changed files with 29 additions and 29 deletions

View File

@@ -90,7 +90,7 @@ class EventActivity : SimpleActivity() {
mEvent.id = 0 mEvent.id = 0
} }
cancelNotification(mEvent.id) cancelNotification(mEvent.id!!)
} else { } else {
mEvent = Event() mEvent = Event()
config.apply { config.apply {
@@ -656,14 +656,14 @@ class EventActivity : SimpleActivity() {
} }
private fun shareEvent() { private fun shareEvent() {
shareEvents(arrayListOf(mEvent.id)) shareEvents(arrayListOf(mEvent.id!!))
} }
private fun deleteEvent() { private fun deleteEvent() {
DeleteEventDialog(this, arrayListOf(mEvent.id), mEvent.repeatInterval > 0) { DeleteEventDialog(this, arrayListOf(mEvent.id!!), mEvent.repeatInterval > 0) {
when (it) { when (it) {
DELETE_SELECTED_OCCURRENCE -> dbHelper.addEventRepeatException(mEvent.id, mEventOccurrenceTS, true) DELETE_SELECTED_OCCURRENCE -> dbHelper.addEventRepeatException(mEvent.id!!, mEventOccurrenceTS, true)
DELETE_FUTURE_OCCURRENCES -> dbHelper.addEventRepeatLimit(mEvent.id, mEventOccurrenceTS) DELETE_FUTURE_OCCURRENCES -> dbHelper.addEventRepeatLimit(mEvent.id!!, mEventOccurrenceTS)
DELETE_ALL_OCCURRENCES -> dbHelper.deleteEvents(arrayOf(mEvent.id.toString()), true) DELETE_ALL_OCCURRENCES -> dbHelper.deleteEvents(arrayOf(mEvent.id.toString()), true)
} }
finish() finish()
@@ -775,10 +775,10 @@ class EventActivity : SimpleActivity() {
finish() finish()
} }
} else { } else {
dbHelper.addEventRepeatException(mEvent.id, mEventOccurrenceTS, true) dbHelper.addEventRepeatException(mEvent.id!!, mEventOccurrenceTS, true)
mEvent.apply { mEvent.apply {
parentId = id parentId = id!!
id = 0 id = null
repeatRule = 0 repeatRule = 0
repeatInterval = 0 repeatInterval = 0
repeatLimit = 0 repeatLimit = 0

View File

@@ -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() val nonRepeatingEventIDs = eventsToDelete.asSequence().filter { it.repeatInterval == 0 }.map { it.id.toString() }.toList().toTypedArray()
activity.dbHelper.deleteEvents(nonRepeatingEventIDs, true) 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) activity.handleEventDeleting(repeatingEventIDs, timestamps, it)
removeSelectedItems(positions) removeSelectedItems(positions)
} }

View File

@@ -174,7 +174,7 @@ class EventListWidgetAdapter(val context: Context) : RemoteViewsService.RemoteVi
prevCode = code 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) listItems.add(listEvent)
} }

View File

@@ -85,7 +85,7 @@ fun Context.scheduleNextEventReminder(event: Event, dbHelper: DBHelper, activity
val now = getNowSeconds() val now = getNowSeconds()
val reminderSeconds = event.getReminders().reversed().map { it * 60 } 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()) { if (it.isNotEmpty()) {
for (curEvent in it) { for (curEvent in it) {
for (curReminder in reminderSeconds) { for (curReminder in reminderSeconds) {
@@ -127,7 +127,7 @@ private fun getNotificationIntent(context: Context, event: Event): PendingIntent
val intent = Intent(context, NotificationReceiver::class.java) val intent = Intent(context, NotificationReceiver::class.java)
intent.putExtra(EVENT_ID, event.id) intent.putExtra(EVENT_ID, event.id)
intent.putExtra(EVENT_OCCURRENCE_TS, event.startTS) 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) { 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 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 // make sure refer to the proper repeatable event instance with "Tomorrow", or the specific date
if (event.repeatInterval != 0 && eventStartTS - event.reminder1Minutes * 60 < currentSeconds) { 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) { for (currEvent in events) {
eventStartTS = if (currEvent.getIsAllDay()) Formatter.getDayStartTS(Formatter.getDayCodeFromTS(currEvent.startTS)) else currEvent.startTS eventStartTS = if (currEvent.getIsAllDay()) Formatter.getDayStartTS(Formatter.getDayCodeFromTS(currEvent.startTS)) else currEvent.startTS
if (eventStartTS - currEvent.reminder1Minutes * 60 > currentSeconds) { if (eventStartTS - currEvent.reminder1Minutes * 60 > currentSeconds) {
@@ -186,7 +186,7 @@ fun Context.notifyEvent(originalEvent: Event) {
val content = "$displayedStartDate $timeRange $descriptionOrLocation".trim() val content = "$displayedStartDate $timeRange $descriptionOrLocation".trim()
val notification = getNotification(pendingIntent, event, content) val notification = getNotification(pendingIntent, event, content)
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.notify(event.id, notification) notificationManager.notify(event.id!!, notification)
} }
@SuppressLint("NewApi") @SuppressLint("NewApi")
@@ -262,7 +262,7 @@ private fun getPendingIntent(context: Context, event: Event): PendingIntent {
val intent = Intent(context, EventActivity::class.java) val intent = Intent(context, EventActivity::class.java)
intent.putExtra(EVENT_ID, event.id) intent.putExtra(EVENT_ID, event.id)
intent.putExtra(EVENT_OCCURRENCE_TS, event.startTS) 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 { 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") val intent = Intent(context, snoozeClass).setAction("Snooze")
intent.putExtra(EVENT_ID, event.id) intent.putExtra(EVENT_ID, event.id)
return if (context.config.useSameSnooze) { 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 { } 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) { if (event != null) {
applicationContext.scheduleEventIn(System.currentTimeMillis() + minutes * 60000, event) applicationContext.scheduleEventIn(System.currentTimeMillis() + minutes * 60000, event)
val manager = applicationContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager 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) listItems.add(listSection)
prevCode = code 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) listItems.add(listEvent)
} }
return listItems return listItems

View File

@@ -201,7 +201,7 @@ class CalDAVHandler(val context: Context) {
val importId = getCalDAVEventImportId(calendarId, id) val importId = getCalDAVEventImportId(calendarId, id)
val source = "$CALDAV-$calendarId" val source = "$CALDAV-$calendarId"
val repeatRule = Parser().parseRepeatInterval(rrule, startTS) 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, reminders.getOrElse(1) { -1 }, reminders.getOrElse(2) { -1 }, repeatRule.repeatInterval,
importId, allDay, repeatRule.repeatLimit, repeatRule.repeatRule, eventTypeId, source = source, location = location) importId, allDay, repeatRule.repeatLimit, repeatRule.repeatRule, eventTypeId, source = source, location = location)
@@ -219,7 +219,7 @@ class CalDAVHandler(val context: Context) {
val originalEventId = existingEvent!!.id val originalEventId = existingEvent!!.id
existingEvent.apply { existingEvent.apply {
this.id = 0 this.id = null
color = 0 color = 0
ignoreEventOccurrences = ArrayList() ignoreEventOccurrences = ArrayList()
lastUpdated = 0L lastUpdated = 0L
@@ -311,7 +311,7 @@ class CalDAVHandler(val context: Context) {
} }
private fun setupCalDAVEventImportId(event: Event) { 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 { private fun fillEventContentValues(event: Event): ContentValues {

View File

@@ -136,7 +136,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
CalDAVHandler(context).insertCalDAVEvent(event) CalDAVHandler(context).insertCalDAVEvent(event)
} }
callback(event.id) callback(event.id!!)
} }
fun insertEvents(events: ArrayList<Event>, addToCalDAV: Boolean) { 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 cursor = getEventsCursor(selection, selectionArgs)
val events = fillEvents(cursor) val events = fillEvents(cursor)
return if (events.isNotEmpty()) { return if (events.isNotEmpty()) {
events.minBy { it.id }?.id ?: 0 events.minBy { it.id!! }?.id ?: 0
} else { } else {
0 0
} }
@@ -549,7 +549,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
val cursor = getEventsCursor(selection, selectionArgs) val cursor = getEventsCursor(selection, selectionArgs)
val events = fillEvents(cursor) val events = fillEvents(cursor)
return if (events.isNotEmpty()) { return if (events.isNotEmpty()) {
events.minBy { it.id }?.id ?: 0 events.minBy { it.id!! }?.id ?: 0
} else { } else {
0 0
} }
@@ -624,7 +624,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
val events = getEvents(selection) val events = getEvents(selection)
val startTimes = SparseIntArray(events.size) val startTimes = SparseIntArray(events.size)
events.forEach { events.forEach {
startTimes.put(it.id, it.startTS) startTimes.put(it.id!!, it.startTS)
if (it.repeatLimit >= 0) { if (it.repeatLimit >= 0) {
newEvents.addAll(getEventsRepeatingTillDateOrForever(fromTS, toTS, startTimes, it)) newEvents.addAll(getEventsRepeatingTillDateOrForever(fromTS, toTS, startTimes, it))
} else { } 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 // check if its the proper week, for events repeating every x weeks
private fun isOnProperWeek(event: Event, startTimes: SparseIntArray): Boolean { 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 val currentWeekOfYear = Formatter.getDateTimeFromTS(event.startTS).weekOfWeekyear
return (currentWeekOfYear - initialWeekOfYear) % (event.repeatInterval / WEEK) == 0 return (currentWeekOfYear - initialWeekOfYear) % (event.repeatInterval / WEEK) == 0
} }

View File

@@ -7,7 +7,7 @@ import org.joda.time.DateTime
import java.io.Serializable import java.io.Serializable
import java.util.* 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 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 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(), var eventType: Long = DBHelper.REGULAR_EVENT_TYPE_ID, var ignoreEventOccurrences: ArrayList<Int> = ArrayList(),

View File

@@ -105,7 +105,7 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
val lastEvent = allEvents.lastOrNull { it.id == event.id } val lastEvent = allEvents.lastOrNull { it.id == event.id }
val daysCnt = getEventLastingDaysCount(event) val daysCnt = getEventLastingDaysCount(event)
if (lastEvent == null || lastEvent.startDayIndex + daysCnt <= day.indexOnMonthView) { 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) daysCnt, day.indexOnMonthView, event.getIsAllDay(), event.isPastEvent)
allEvents.add(monthViewEvent) allEvents.add(monthViewEvent)
} }