From 5b0076302d12451d4100c7864ae2d7af0b1de6f0 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 16 Nov 2018 17:35:46 +0100 Subject: [PATCH] avoid caldav syncing calendars too many times in a row --- .../calendar/pro/activities/MainActivity.kt | 30 +++++++++---------- 1 file changed, 14 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 263d67cc9..0d71db778 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 @@ -46,13 +46,10 @@ import java.util.* import kotlin.collections.ArrayList class MainActivity : SimpleActivity(), RefreshRecyclerViewListener { - private val CALDAV_SYNC_DELAY = 1000L - private var showCalDAVRefreshToast = false private var mShouldFilterBeVisible = false private var mIsSearchOpen = false private var mLatestSearchQuery = "" - private var mCalDAVSyncHandler = Handler() private var mSearchMenuItem: MenuItem? = null private var shouldGoToTodayBeVisible = false private var goToTodayButton: MenuItem? = null @@ -145,7 +142,6 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener { override fun onStop() { super.onStop() - mCalDAVSyncHandler.removeCallbacksAndMessages(null) contentResolver.unregisterContentObserver(calDAVSyncObserver) closeSearch() } @@ -380,18 +376,20 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener { override fun onChange(selfChange: Boolean) { super.onChange(selfChange) if (!selfChange) { - mCalDAVSyncHandler.removeCallbacksAndMessages(null) - mCalDAVSyncHandler.postDelayed({ - recheckCalDAVCalendars { - refreshViewPager() - if (showCalDAVRefreshToast) { - toast(R.string.refreshing_complete) - } - runOnUiThread { - swipe_refresh_layout.isRefreshing = false - } - } - }, CALDAV_SYNC_DELAY) + calDAVChanged() + } + } + } + + private fun calDAVChanged() { + contentResolver.unregisterContentObserver(calDAVSyncObserver) + recheckCalDAVCalendars { + refreshViewPager() + if (showCalDAVRefreshToast) { + toast(R.string.refreshing_complete) + } + runOnUiThread { + swipe_refresh_layout.isRefreshing = false } } }