fix some glitches related to fetching events to the list on every resume
This commit is contained in:
parent
729ff88de5
commit
c2d120b99d
|
@ -30,6 +30,7 @@ import java.util.*
|
||||||
|
|
||||||
class EventListFragment : MyFragmentHolder(), RefreshRecyclerViewListener {
|
class EventListFragment : MyFragmentHolder(), RefreshRecyclerViewListener {
|
||||||
private var FETCH_INTERVAL = 6 * MONTH_SECONDS
|
private var FETCH_INTERVAL = 6 * MONTH_SECONDS
|
||||||
|
private var MIN_EVENTS_TRESHOLD = 30
|
||||||
|
|
||||||
private var mEvents = ArrayList<Event>()
|
private var mEvents = ArrayList<Event>()
|
||||||
private var minFetchedTS = 0
|
private var minFetchedTS = 0
|
||||||
|
@ -65,7 +66,6 @@ class EventListFragment : MyFragmentHolder(), RefreshRecyclerViewListener {
|
||||||
use24HourFormat = use24Hour
|
use24HourFormat = use24Hour
|
||||||
(mView.calendar_events_list.adapter as? EventListAdapter)?.toggle24HourFormat(use24HourFormat)
|
(mView.calendar_events_list.adapter as? EventListAdapter)?.toggle24HourFormat(use24HourFormat)
|
||||||
}
|
}
|
||||||
wereInitialEventsAdded = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
|
@ -74,18 +74,25 @@ class EventListFragment : MyFragmentHolder(), RefreshRecyclerViewListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkEvents() {
|
private fun checkEvents() {
|
||||||
minFetchedTS = DateTime().minusMonths(3).seconds()
|
if (!wereInitialEventsAdded) {
|
||||||
maxFetchedTS = DateTime().plusMonths(6).seconds()
|
minFetchedTS = DateTime().minusMonths(3).seconds()
|
||||||
|
maxFetchedTS = DateTime().plusMonths(6).seconds()
|
||||||
|
}
|
||||||
|
|
||||||
context!!.dbHelper.getEvents(minFetchedTS, maxFetchedTS) {
|
context!!.dbHelper.getEvents(minFetchedTS, maxFetchedTS) {
|
||||||
receivedEvents(it, false)
|
if (it.size >= MIN_EVENTS_TRESHOLD) {
|
||||||
if (it.size < 30) {
|
receivedEvents(it, false)
|
||||||
minFetchedTS -= FETCH_INTERVAL
|
} else {
|
||||||
maxFetchedTS += FETCH_INTERVAL
|
if (!wereInitialEventsAdded) {
|
||||||
|
minFetchedTS -= FETCH_INTERVAL
|
||||||
|
maxFetchedTS += FETCH_INTERVAL
|
||||||
|
}
|
||||||
context!!.dbHelper.getEvents(minFetchedTS, maxFetchedTS) {
|
context!!.dbHelper.getEvents(minFetchedTS, maxFetchedTS) {
|
||||||
mEvents = it
|
mEvents = it
|
||||||
receivedEvents(mEvents, false, !wereInitialEventsAdded)
|
receivedEvents(mEvents, false, !wereInitialEventsAdded)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
wereInitialEventsAdded = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue