From e1c6afc56202ec10a4e5fede538f59b63e4238ed Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 11 Jan 2018 16:48:22 +0100 Subject: [PATCH] refresh only the needed caldav accounts --- .../calendar/activities/MainActivity.kt | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt index b84b3a653..65c7f964c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt @@ -1,5 +1,6 @@ package com.simplemobiletools.calendar.activities +import android.accounts.Account import android.content.ContentResolver import android.content.Intent import android.content.pm.ActivityInfo @@ -47,7 +48,7 @@ import java.util.* import kotlin.collections.ArrayList class MainActivity : SimpleActivity(), NavigationListener { - private val CALDAV_SYNC_DELAY = 2000L + private val CALDAV_SYNC_DELAY = 1000L private val PREFILLED_MONTHS = 97 private val PREFILLED_YEARS = 31 private val PREFILLED_WEEKS = 61 @@ -260,10 +261,19 @@ class MainActivity : SimpleActivity(), NavigationListener { toast(R.string.refreshing) val uri = CalendarContract.Calendars.CONTENT_URI contentResolver.registerContentObserver(uri, false, calDAVSyncObserver) + + val accounts = HashSet() + val calendars = CalDAVHandler(applicationContext).getCalDAVCalendars(this, 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) - ContentResolver.requestSync(null, uri.authority, this) + accounts.forEach { + ContentResolver.requestSync(it, uri.authority, this) + } } scheduleCalDAVSync(true) }