implement updating remote caldav calendar name

This commit is contained in:
tibbi 2017-08-22 15:31:43 +02:00
parent a0738b9306
commit 0d5b40583d
2 changed files with 26 additions and 0 deletions

View file

@ -12,6 +12,7 @@ import com.simplemobiletools.calendar.extensions.hasCalendarPermission
import com.simplemobiletools.calendar.extensions.scheduleCalDAVSync import com.simplemobiletools.calendar.extensions.scheduleCalDAVSync
import com.simplemobiletools.calendar.models.CalDAVCalendar import com.simplemobiletools.calendar.models.CalDAVCalendar
import com.simplemobiletools.calendar.models.Event import com.simplemobiletools.calendar.models.Event
import com.simplemobiletools.calendar.models.EventType
import com.simplemobiletools.commons.extensions.getIntValue import com.simplemobiletools.commons.extensions.getIntValue
import com.simplemobiletools.commons.extensions.getLongValue import com.simplemobiletools.commons.extensions.getLongValue
import com.simplemobiletools.commons.extensions.getStringValue import com.simplemobiletools.commons.extensions.getStringValue
@ -64,6 +65,19 @@ class CalDAVHandler(val context: Context) {
return calendars return calendars
} }
fun updateCalDAVCalendar(eventType: EventType): Boolean {
val uri = CalendarContract.Calendars.CONTENT_URI
val values = fillCalendarContentValues(eventType)
val newUri = ContentUris.withAppendedId(uri, eventType.caldavCalendarId.toLong())
return context.contentResolver.update(newUri, values, null, null) == 1
}
private fun fillCalendarContentValues(eventType: EventType): ContentValues {
return ContentValues().apply {
put(CalendarContract.Calendars.CALENDAR_DISPLAY_NAME, eventType.title)
}
}
private fun fetchCalDAVCalendarEvents(calendarId: Int, eventTypeId: Int) { private fun fetchCalDAVCalendarEvents(calendarId: Int, eventTypeId: Int) {
val importIdsMap = HashMap<String, Event>() val importIdsMap = HashMap<String, Event>()
val fetchedEventIds = ArrayList<String>() val fetchedEventIds = ArrayList<String>()

View file

@ -271,6 +271,18 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
} }
fun updateEventType(eventType: EventType): Int { fun updateEventType(eventType: EventType): Int {
return if (eventType.caldavCalendarId != 0) {
if (CalDAVHandler(context).updateCalDAVCalendar(eventType)) {
updateLocalEventType(eventType)
} else {
-1
}
} else {
updateLocalEventType(eventType)
}
}
private fun updateLocalEventType(eventType: EventType): Int {
val selectionArgs = arrayOf(eventType.id.toString()) val selectionArgs = arrayOf(eventType.id.toString())
val values = fillEventTypeValues(eventType) val values = fillEventTypeValues(eventType)
val selection = "$COL_TYPE_ID = ?" val selection = "$COL_TYPE_ID = ?"