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,23 +326,27 @@ fun Context.syncCalDAVCalendars(activity: SimpleActivity?, calDAVSyncObserver: C
val uri = CalendarContract.Calendars.CONTENT_URI
contentResolver.unregisterContentObserver(calDAVSyncObserver)
contentResolver.registerContentObserver(uri, false, calDAVSyncObserver)
val accounts = HashSet<Account>()
val calendars = CalDAVHandler(applicationContext).getCalDAVCalendars(activity, config.caldavSyncedCalendarIDs)
calendars.forEach {
accounts.add(Account(it.accountName, it.accountType))
}
Bundle().apply {
putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true)
putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true)
accounts.forEach {
ContentResolver.requestSync(it, uri.authority, this)
}
}
refreshCalDAVCalendars(activity, config.caldavSyncedCalendarIDs)
}.start()
}
fun Context.refreshCalDAVCalendars(activity: SimpleActivity?, ids: String) {
val uri = CalendarContract.Calendars.CONTENT_URI
val accounts = HashSet<Account>()
val calendars = CalDAVHandler(applicationContext).getCalDAVCalendars(activity, ids)
calendars.forEach {
accounts.add(Account(it.accountName, it.accountType))
}
Bundle().apply {
putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true)
putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true)
accounts.forEach {
ContentResolver.requestSync(it, uri.authority, this)
}
}
}
fun Context.addDayNumber(rawTextColor: Int, day: DayMonthly, linearLayout: LinearLayout, dayLabelHeight: Int, callback: (Int) -> Unit) {
var textColor = rawTextColor
if (!day.isThisMonth)

View File

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