diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d320b805c..e4175c032 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -197,6 +197,7 @@ 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 0e61aec58..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 @@ -206,6 +206,10 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener { main_toolbar.setNavigationOnClickListener { onBackPressed() } + + if (config.caldavSync) { + updateCalDAVEvents() + } } override fun onPause() { @@ -561,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() } } 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 a2a9e4084..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 @@ -328,7 +328,7 @@ class SettingsActivity : SimpleActivity() { } syncCalDAVCalendars { - calDAVHelper.refreshCalendars(true, true) { + calDAVHelper.refreshCalendars(showToasts = true, scheduleNextSync = true) { if (settings_caldav_sync.isChecked) { 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 893e4cfa2..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 @@ -23,6 +23,7 @@ import android.widget.Toast import androidx.constraintlayout.widget.ConstraintLayout import androidx.core.app.AlarmManagerCompat import androidx.core.app.NotificationCompat +import androidx.localbroadcastmanager.content.LocalBroadcastManager import androidx.print.PrintHelper import com.simplemobiletools.calendar.pro.R import com.simplemobiletools.calendar.pro.activities.EventActivity @@ -57,6 +58,8 @@ val Context.completedTasksDB: TasksDao get() = EventsDatabase.getInstance(applic val Context.eventsHelper: EventsHelper get() = EventsHelper(this) val Context.calDAVHelper: CalDAVHelper get() = CalDAVHelper(this) +val Context.localBroadcastManager: LocalBroadcastManager get() = LocalBroadcastManager.getInstance(this) + fun Context.updateWidgets() { val widgetIDs = AppWidgetManager.getInstance(applicationContext)?.getAppWidgetIds(ComponentName(applicationContext, MyWidgetMonthlyProvider::class.java)) ?: return @@ -603,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) } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Constants.kt index a2ddc1b9b..fe9f34b46 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Constants.kt @@ -227,6 +227,7 @@ const val IS_NEW_EVENT = "IS_NEW_EVENT" // actions const val ACTION_MARK_COMPLETED = "ACTION_MARK_COMPLETED" +const val ACTION_REFRESH_EVENTS = "ACTION_REFRESH_EVENTS" fun getNowSeconds() = System.currentTimeMillis() / 1000L