fix some glitches related to fetching events to the list on every resume

This commit is contained in:
tibbi 2018-05-09 23:56:09 +02:00
parent 729ff88de5
commit c2d120b99d
1 changed files with 14 additions and 7 deletions

View File

@ -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<Event>()
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() {
if (!wereInitialEventsAdded) {
minFetchedTS = DateTime().minusMonths(3).seconds()
maxFetchedTS = DateTime().plusMonths(6).seconds()
}
context!!.dbHelper.getEvents(minFetchedTS, maxFetchedTS) {
if (it.size >= MIN_EVENTS_TRESHOLD) {
receivedEvents(it, false)
if (it.size < 30) {
} else {
if (!wereInitialEventsAdded) {
minFetchedTS -= FETCH_INTERVAL
maxFetchedTS += FETCH_INTERVAL
}
context!!.dbHelper.getEvents(minFetchedTS, maxFetchedTS) {
mEvents = it
receivedEvents(mEvents, false, !wereInitialEventsAdded)
}
}
wereInitialEventsAdded = true
}
}