implement updating remote caldav calendar name
This commit is contained in:
parent
a0738b9306
commit
0d5b40583d
2 changed files with 26 additions and 0 deletions
|
@ -12,6 +12,7 @@ import com.simplemobiletools.calendar.extensions.hasCalendarPermission
|
|||
import com.simplemobiletools.calendar.extensions.scheduleCalDAVSync
|
||||
import com.simplemobiletools.calendar.models.CalDAVCalendar
|
||||
import com.simplemobiletools.calendar.models.Event
|
||||
import com.simplemobiletools.calendar.models.EventType
|
||||
import com.simplemobiletools.commons.extensions.getIntValue
|
||||
import com.simplemobiletools.commons.extensions.getLongValue
|
||||
import com.simplemobiletools.commons.extensions.getStringValue
|
||||
|
@ -64,6 +65,19 @@ class CalDAVHandler(val context: Context) {
|
|||
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) {
|
||||
val importIdsMap = HashMap<String, Event>()
|
||||
val fetchedEventIds = ArrayList<String>()
|
||||
|
|
|
@ -271,6 +271,18 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
}
|
||||
|
||||
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 values = fillEventTypeValues(eventType)
|
||||
val selection = "$COL_TYPE_ID = ?"
|
||||
|
|
Loading…
Reference in a new issue