refresh caldav immediately after updating a synced event

This commit is contained in:
tibbi 2018-06-13 13:44:01 +02:00
parent 4787f9b7d8
commit 1c5b669ae3
2 changed files with 25 additions and 14 deletions

View File

@ -326,9 +326,14 @@ fun Context.syncCalDAVCalendars(activity: SimpleActivity?, calDAVSyncObserver: C
val uri = CalendarContract.Calendars.CONTENT_URI val uri = CalendarContract.Calendars.CONTENT_URI
contentResolver.unregisterContentObserver(calDAVSyncObserver) contentResolver.unregisterContentObserver(calDAVSyncObserver)
contentResolver.registerContentObserver(uri, false, calDAVSyncObserver) contentResolver.registerContentObserver(uri, false, calDAVSyncObserver)
refreshCalDAVCalendars(activity, config.caldavSyncedCalendarIDs)
}.start()
}
fun Context.refreshCalDAVCalendars(activity: SimpleActivity?, ids: String) {
val uri = CalendarContract.Calendars.CONTENT_URI
val accounts = HashSet<Account>() val accounts = HashSet<Account>()
val calendars = CalDAVHandler(applicationContext).getCalDAVCalendars(activity, config.caldavSyncedCalendarIDs) val calendars = CalDAVHandler(applicationContext).getCalDAVCalendars(activity, ids)
calendars.forEach { calendars.forEach {
accounts.add(Account(it.accountName, it.accountType)) accounts.add(Account(it.accountName, it.accountType))
} }
@ -340,7 +345,6 @@ fun Context.syncCalDAVCalendars(activity: SimpleActivity?, calDAVSyncObserver: C
ContentResolver.requestSync(it, uri.authority, this) ContentResolver.requestSync(it, uri.authority, this)
} }
} }
}.start()
} }
fun Context.addDayNumber(rawTextColor: Int, day: DayMonthly, linearLayout: LinearLayout, dayLabelHeight: Int, callback: (Int) -> Unit) { fun Context.addDayNumber(rawTextColor: Int, day: DayMonthly, linearLayout: LinearLayout, dayLabelHeight: Int, callback: (Int) -> Unit) {

View File

@ -10,6 +10,7 @@ import android.util.SparseIntArray
import com.simplemobiletools.calendar.activities.SimpleActivity import com.simplemobiletools.calendar.activities.SimpleActivity
import com.simplemobiletools.calendar.extensions.config import com.simplemobiletools.calendar.extensions.config
import com.simplemobiletools.calendar.extensions.dbHelper import com.simplemobiletools.calendar.extensions.dbHelper
import com.simplemobiletools.calendar.extensions.refreshCalDAVCalendars
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
@ -324,6 +325,7 @@ class CalDAVHandler(val context: Context) {
setupCalDAVEventReminders(event) setupCalDAVEventReminders(event)
setupCalDAVEventImportId(event) setupCalDAVEventImportId(event)
refreshCalDAVCalendar(event)
} }
fun updateCalDAVEvent(event: Event) { fun updateCalDAVEvent(event: Event) {
@ -337,6 +339,7 @@ class CalDAVHandler(val context: Context) {
setupCalDAVEventReminders(event) setupCalDAVEventReminders(event)
setupCalDAVEventImportId(event) setupCalDAVEventImportId(event)
refreshCalDAVCalendar(event)
} }
private fun setupCalDAVEventReminders(event: Event) { private fun setupCalDAVEventReminders(event: Event) {
@ -414,12 +417,14 @@ class CalDAVHandler(val context: Context) {
context.contentResolver.delete(contentUri, null, null) context.contentResolver.delete(contentUri, null, null)
} catch (ignored: Exception) { } catch (ignored: Exception) {
} }
refreshCalDAVCalendar(event)
} }
fun insertEventRepeatException(event: Event, occurrenceTS: Int): Long { fun insertEventRepeatException(event: Event, occurrenceTS: Int): Long {
val uri = CalendarContract.Events.CONTENT_URI val uri = CalendarContract.Events.CONTENT_URI
val values = fillEventRepeatExceptionValues(event, occurrenceTS) val values = fillEventRepeatExceptionValues(event, occurrenceTS)
val newUri = context.contentResolver.insert(uri, values) val newUri = context.contentResolver.insert(uri, values)
refreshCalDAVCalendar(event)
return java.lang.Long.parseLong(newUri.lastPathSegment) return java.lang.Long.parseLong(newUri.lastPathSegment)
} }
@ -460,4 +465,6 @@ class CalDAVHandler(val context: Context) {
} }
private fun getCalDAVEventImportId(calendarId: Int, eventId: Long) = "$CALDAV-$calendarId-$eventId" private fun getCalDAVEventImportId(calendarId: Int, eventId: Long) = "$CALDAV-$calendarId-$eventId"
private fun refreshCalDAVCalendar(event: Event) = context.refreshCalDAVCalendars(null, event.getCalDAVCalendarId().toString())
} }