mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-06-05 21:59:17 +02:00
Refresh CalDAV events properly
This commit is contained in:
@ -3,7 +3,9 @@ package com.simplemobiletools.calendar.pro.activities
|
|||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.app.SearchManager
|
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.content.pm.ShortcutInfo
|
||||||
import android.graphics.drawable.ColorDrawable
|
import android.graphics.drawable.ColorDrawable
|
||||||
import android.graphics.drawable.Icon
|
import android.graphics.drawable.Icon
|
||||||
@ -205,14 +207,14 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||||||
onBackPressed()
|
onBackPressed()
|
||||||
}
|
}
|
||||||
|
|
||||||
val intentFilter = IntentFilter(ACTION_REFRESH_EVENTS)
|
if (config.caldavSync) {
|
||||||
localBroadcastManager.registerReceiver(broadcastReceiver, intentFilter)
|
updateCalDAVEvents()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
super.onPause()
|
super.onPause()
|
||||||
storeStateVariables()
|
storeStateVariables()
|
||||||
localBroadcastManager.unregisterReceiver(broadcastReceiver)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
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) {
|
private fun refreshCalDAVCalendars(showRefreshToast: Boolean) {
|
||||||
showCalDAVRefreshToast = showRefreshToast
|
showCalDAVRefreshToast = showRefreshToast
|
||||||
if (showRefreshToast) {
|
if (showRefreshToast) {
|
||||||
toast(R.string.refreshing)
|
toast(R.string.refreshing)
|
||||||
}
|
}
|
||||||
|
updateCalDAVEvents()
|
||||||
syncCalDAVCalendars {
|
syncCalDAVCalendars {
|
||||||
calDAVHelper.refreshCalendars(true, true) {
|
calDAVHelper.refreshCalendars(showToasts = true, scheduleNextSync = true) {
|
||||||
calDAVChanged()
|
calDAVChanged()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1362,12 +1372,4 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||||||
checkWhatsNew(this, BuildConfig.VERSION_CODE)
|
checkWhatsNew(this, BuildConfig.VERSION_CODE)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val broadcastReceiver = object : BroadcastReceiver() {
|
|
||||||
override fun onReceive(context: Context?, intent: Intent?) {
|
|
||||||
if (intent?.action == ACTION_REFRESH_EVENTS) {
|
|
||||||
refreshViewPager()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -330,8 +330,6 @@ class SettingsActivity : SimpleActivity() {
|
|||||||
syncCalDAVCalendars {
|
syncCalDAVCalendars {
|
||||||
calDAVHelper.refreshCalendars(showToasts = true, scheduleNextSync = true) {
|
calDAVHelper.refreshCalendars(showToasts = true, scheduleNextSync = true) {
|
||||||
if (settings_caldav_sync.isChecked) {
|
if (settings_caldav_sync.isChecked) {
|
||||||
val broadcastIntent = Intent(ACTION_REFRESH_EVENTS)
|
|
||||||
localBroadcastManager.sendBroadcast(broadcastIntent)
|
|
||||||
toast(R.string.synchronization_completed)
|
toast(R.string.synchronization_completed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -606,6 +606,7 @@ fun Context.refreshCalDAVCalendars(ids: String, showToasts: Boolean) {
|
|||||||
|
|
||||||
Bundle().apply {
|
Bundle().apply {
|
||||||
putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true)
|
putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true)
|
||||||
|
putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true)
|
||||||
accounts.forEach {
|
accounts.forEach {
|
||||||
ContentResolver.requestSync(it, uri.authority, this)
|
ContentResolver.requestSync(it, uri.authority, this)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user