Refresh CalDAV events properly
This commit is contained in:
parent
7a3ea5f8a8
commit
1612762808
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue