From c2d120b99d662679b1120dbf706f6f39530dc1e1 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 9 May 2018 23:56:09 +0200 Subject: [PATCH] fix some glitches related to fetching events to the list on every resume --- .../calendar/fragments/EventListFragment.kt | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/EventListFragment.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/EventListFragment.kt index 764205552..7df1f88a5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/EventListFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/EventListFragment.kt @@ -30,6 +30,7 @@ import java.util.* class EventListFragment : MyFragmentHolder(), RefreshRecyclerViewListener { private var FETCH_INTERVAL = 6 * MONTH_SECONDS + private var MIN_EVENTS_TRESHOLD = 30 private var mEvents = ArrayList() private var minFetchedTS = 0 @@ -65,7 +66,6 @@ class EventListFragment : MyFragmentHolder(), RefreshRecyclerViewListener { use24HourFormat = use24Hour (mView.calendar_events_list.adapter as? EventListAdapter)?.toggle24HourFormat(use24HourFormat) } - wereInitialEventsAdded = true } override fun onPause() { @@ -74,18 +74,25 @@ class EventListFragment : MyFragmentHolder(), RefreshRecyclerViewListener { } private fun checkEvents() { - minFetchedTS = DateTime().minusMonths(3).seconds() - maxFetchedTS = DateTime().plusMonths(6).seconds() + if (!wereInitialEventsAdded) { + minFetchedTS = DateTime().minusMonths(3).seconds() + maxFetchedTS = DateTime().plusMonths(6).seconds() + } + context!!.dbHelper.getEvents(minFetchedTS, maxFetchedTS) { - receivedEvents(it, false) - if (it.size < 30) { - minFetchedTS -= FETCH_INTERVAL - maxFetchedTS += FETCH_INTERVAL + if (it.size >= MIN_EVENTS_TRESHOLD) { + receivedEvents(it, false) + } else { + if (!wereInitialEventsAdded) { + minFetchedTS -= FETCH_INTERVAL + maxFetchedTS += FETCH_INTERVAL + } context!!.dbHelper.getEvents(minFetchedTS, maxFetchedTS) { mEvents = it receivedEvents(mEvents, false, !wereInitialEventsAdded) } } + wereInitialEventsAdded = true } }