mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-01-31 19:05:01 +01:00
tweak the way caldav sync is handled
This commit is contained in:
parent
4052d8de7e
commit
95ce2f9858
@ -493,7 +493,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
||||
}
|
||||
|
||||
syncCalDAVCalendars {
|
||||
calDAVHelper.refreshCalendars(true) {
|
||||
calDAVHelper.refreshCalendars(true, true) {
|
||||
calDAVChanged()
|
||||
}
|
||||
}
|
||||
|
@ -318,7 +318,7 @@ class SettingsActivity : SimpleActivity() {
|
||||
}
|
||||
|
||||
syncCalDAVCalendars {
|
||||
calDAVHelper.refreshCalendars(true) {
|
||||
calDAVHelper.refreshCalendars(true, true) {
|
||||
if (settings_caldav_sync.isChecked) {
|
||||
toast(R.string.synchronization_completed)
|
||||
}
|
||||
|
@ -395,10 +395,10 @@ fun Context.getNewEventTimestampFromCode(dayCode: String, allowChangingDay: Bool
|
||||
|
||||
fun Context.getSyncedCalDAVCalendars() = calDAVHelper.getCalDAVCalendars(config.caldavSyncedCalendarIds, false)
|
||||
|
||||
fun Context.recheckCalDAVCalendars(callback: () -> Unit) {
|
||||
fun Context.recheckCalDAVCalendars(scheduleNextCalDAVSync: Boolean, callback: () -> Unit) {
|
||||
if (config.caldavSync) {
|
||||
ensureBackgroundThread {
|
||||
calDAVHelper.refreshCalendars(false, callback)
|
||||
calDAVHelper.refreshCalendars(false, scheduleNextCalDAVSync, callback)
|
||||
updateWidgets()
|
||||
}
|
||||
}
|
||||
@ -406,8 +406,9 @@ fun Context.recheckCalDAVCalendars(callback: () -> Unit) {
|
||||
|
||||
fun Context.scheduleCalDAVSync(activate: Boolean) {
|
||||
val syncIntent = Intent(applicationContext, CalDAVSyncReceiver::class.java)
|
||||
val pendingIntent = PendingIntent.getBroadcast(applicationContext, 0, syncIntent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
val pendingIntent = PendingIntent.getBroadcast(applicationContext, SCHEDULE_CALDAV_REQUEST_CODE, syncIntent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
val alarm = getSystemService(Context.ALARM_SERVICE) as AlarmManager
|
||||
alarm.cancel(pendingIntent)
|
||||
|
||||
if (activate) {
|
||||
val syncCheckInterval = 2 * AlarmManager.INTERVAL_HOUR
|
||||
@ -415,8 +416,6 @@ fun Context.scheduleCalDAVSync(activate: Boolean) {
|
||||
alarm.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + syncCheckInterval, syncCheckInterval, pendingIntent)
|
||||
} catch (ignored: Exception) {
|
||||
}
|
||||
} else {
|
||||
alarm.cancel(pendingIntent)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ import org.joda.time.format.DateTimeFormat
|
||||
class CalDAVHelper(val context: Context) {
|
||||
private val eventsHelper = context.eventsHelper
|
||||
|
||||
fun refreshCalendars(showToasts: Boolean, callback: () -> Unit) {
|
||||
fun refreshCalendars(showToasts: Boolean, scheduleNextSync: Boolean, callback: () -> Unit) {
|
||||
if (isUpdatingCalDAV) {
|
||||
return
|
||||
}
|
||||
@ -44,7 +44,10 @@ class CalDAVHelper(val context: Context) {
|
||||
fetchCalDAVCalendarEvents(calendar.id, localEventType.id!!, showToasts)
|
||||
}
|
||||
|
||||
context.scheduleCalDAVSync(true)
|
||||
if (scheduleNextSync) {
|
||||
context.scheduleCalDAVSync(true)
|
||||
}
|
||||
|
||||
callback()
|
||||
} finally {
|
||||
isUpdatingCalDAV = false
|
||||
|
@ -3,6 +3,7 @@ package com.simplemobiletools.calendar.pro.helpers
|
||||
const val STORED_LOCALLY_ONLY = 0
|
||||
const val ROW_COUNT = 6
|
||||
const val COLUMN_COUNT = 7
|
||||
const val SCHEDULE_CALDAV_REQUEST_CODE = 10000
|
||||
|
||||
const val DAY_CODE = "day_code"
|
||||
const val YEAR_LABEL = "year"
|
||||
|
@ -51,7 +51,7 @@ class CalDAVUpdateListener : JobService() {
|
||||
mRunningParams = params
|
||||
|
||||
if (params.triggeredContentAuthorities != null && params.triggeredContentUris != null) {
|
||||
recheckCalDAVCalendars {}
|
||||
recheckCalDAVCalendars(false) {}
|
||||
}
|
||||
|
||||
mHandler.post(mWorker)
|
||||
|
@ -15,7 +15,7 @@ class BootCompletedReceiver : BroadcastReceiver() {
|
||||
context.apply {
|
||||
scheduleAllEvents()
|
||||
notifyRunningEvents()
|
||||
recheckCalDAVCalendars {}
|
||||
recheckCalDAVCalendars(true) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ class CalDAVSyncReceiver : BroadcastReceiver() {
|
||||
context.refreshCalDAVCalendars(context.config.caldavSyncedCalendarIds, false)
|
||||
}
|
||||
|
||||
context.recheckCalDAVCalendars {
|
||||
context.recheckCalDAVCalendars(true) {
|
||||
context.updateWidgets()
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user