add a helper function for fetching event type with a particular caldav calendar id

This commit is contained in:
tibbi 2017-08-18 16:08:48 +02:00
parent bd9372b8c4
commit 26bd74f17d
2 changed files with 22 additions and 2 deletions

View File

@ -489,6 +489,9 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
val wasRepeatable = mEvent.repeatInterval > 0
val newImportId = if (mEvent.id != 0) mEvent.importId else UUID.randomUUID().toString().replace("-", "") + System.currentTimeMillis().toString()
val newEventType = if (!config.caldavSync || config.lastUsedCaldavCalendar == 0) mEventTypeId else dbHelper.getEventTypeIdWithCalDAVCalendarId(config.lastUsedCaldavCalendar)
val newSource = if (!config.caldavSync || config.lastUsedCaldavCalendar == 0) SOURCE_SIMPLE_CALENDAR else "$CALDAV-${config.lastUsedCaldavCalendar}"
val reminders = sortedSetOf(mReminder1Minutes, mReminder2Minutes, mReminder3Minutes).filter { it != REMINDER_OFF }
val newDescription = event_description.value
mEvent.apply {
@ -504,11 +507,11 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
flags = if (event_all_day.isChecked) (mEvent.flags or FLAG_ALL_DAY) else (mEvent.flags.removeFlag(FLAG_ALL_DAY))
repeatLimit = if (repeatInterval == 0) 0 else mRepeatLimit
repeatRule = mRepeatRule
eventType = mEventTypeId
eventType = newEventType
offset = getCurrentOffset()
isDstIncluded = TimeZone.getDefault().inDaylightTime(Date())
lastUpdated = System.currentTimeMillis()
source = if (!config.caldavSync || config.lastUsedCaldavCalendar == 0) SOURCE_SIMPLE_CALENDAR else "$CALDAV-${config.lastUsedCaldavCalendar}"
source = newSource
}
storeEvent(wasRepeatable)

View File

@ -277,6 +277,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
return ContentValues().apply {
put(COL_TYPE_TITLE, eventType.title)
put(COL_TYPE_COLOR, eventType.color)
put(COL_TYPE_CALDAV_CALENDAR_ID, eventType.caldavCalendarId)
}
}
@ -319,6 +320,22 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
return -1
}
fun getEventTypeIdWithCalDAVCalendarId(calendarId: Int): Int {
val cols = arrayOf(COL_TYPE_ID)
val selection = "$COL_TYPE_CALDAV_CALENDAR_ID = ?"
val selectionArgs = arrayOf(calendarId.toString())
var cursor: Cursor? = null
try {
cursor = mDb.query(TYPES_TABLE_NAME, cols, selection, selectionArgs, null, null, null)
if (cursor?.moveToFirst() == true) {
return cursor.getIntValue(COL_TYPE_ID)
}
} finally {
cursor?.close()
}
return -1
}
fun getEventType(id: Int): EventType? {
val cols = arrayOf(COL_TYPE_TITLE, COL_TYPE_COLOR)
val selection = "$COL_TYPE_ID = ?"