From 1612762808bd9c06be9acfccc080a051939741ef Mon Sep 17 00:00:00 2001 From: Naveen Date: Fri, 26 Aug 2022 21:51:49 +0530 Subject: [PATCH] Refresh CalDAV events properly --- .../calendar/pro/activities/MainActivity.kt | 30 ++++++++++--------- .../pro/activities/SettingsActivity.kt | 2 -- .../calendar/pro/extensions/Context.kt | 1 + 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/MainActivity.kt index 54caf349c..41a85bd88 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/MainActivity.kt @@ -3,7 +3,9 @@ package com.simplemobiletools.calendar.pro.activities import android.annotation.SuppressLint import android.app.Activity import android.app.SearchManager -import android.content.* +import android.content.ActivityNotFoundException +import android.content.Context +import android.content.Intent import android.content.pm.ShortcutInfo import android.graphics.drawable.ColorDrawable import android.graphics.drawable.Icon @@ -205,14 +207,14 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener { onBackPressed() } - val intentFilter = IntentFilter(ACTION_REFRESH_EVENTS) - localBroadcastManager.registerReceiver(broadcastReceiver, intentFilter) + if (config.caldavSync) { + updateCalDAVEvents() + } } override fun onPause() { super.onPause() storeStateVariables() - localBroadcastManager.unregisterReceiver(broadcastReceiver) } override fun onDestroy() { @@ -563,14 +565,22 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener { } } + private fun updateCalDAVEvents() { + ensureBackgroundThread { + calDAVHelper.refreshCalendars(showToasts = false, scheduleNextSync = true) { + refreshViewPager() + } + } + } + private fun refreshCalDAVCalendars(showRefreshToast: Boolean) { showCalDAVRefreshToast = showRefreshToast if (showRefreshToast) { toast(R.string.refreshing) } - + updateCalDAVEvents() syncCalDAVCalendars { - calDAVHelper.refreshCalendars(true, true) { + calDAVHelper.refreshCalendars(showToasts = true, scheduleNextSync = true) { calDAVChanged() } } @@ -1362,12 +1372,4 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener { checkWhatsNew(this, BuildConfig.VERSION_CODE) } } - - private val broadcastReceiver = object : BroadcastReceiver() { - override fun onReceive(context: Context?, intent: Intent?) { - if (intent?.action == ACTION_REFRESH_EVENTS) { - refreshViewPager() - } - } - } } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/SettingsActivity.kt index a882341ed..db9a2bee6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/SettingsActivity.kt @@ -330,8 +330,6 @@ class SettingsActivity : SimpleActivity() { syncCalDAVCalendars { calDAVHelper.refreshCalendars(showToasts = true, scheduleNextSync = true) { if (settings_caldav_sync.isChecked) { - val broadcastIntent = Intent(ACTION_REFRESH_EVENTS) - localBroadcastManager.sendBroadcast(broadcastIntent) toast(R.string.synchronization_completed) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt index 4602e9b2b..e6e62bc39 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt @@ -606,6 +606,7 @@ fun Context.refreshCalDAVCalendars(ids: String, showToasts: Boolean) { Bundle().apply { putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true) + putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true) accounts.forEach { ContentResolver.requestSync(it, uri.authority, this) }