mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-02-26 00:17:42 +01:00
fetch previous events at scrolling to the top
This commit is contained in:
parent
f00106b671
commit
f943358e8c
@ -46,7 +46,7 @@ ext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.simplemobiletools:commons:3.21.10'
|
implementation 'com.simplemobiletools:commons:3.21.11'
|
||||||
implementation 'joda-time:joda-time:2.9.9'
|
implementation 'joda-time:joda-time:2.9.9'
|
||||||
implementation 'com.facebook.stetho:stetho:1.5.0'
|
implementation 'com.facebook.stetho:stetho:1.5.0'
|
||||||
implementation 'com.android.support:multidex:1.0.3'
|
implementation 'com.android.support:multidex:1.0.3'
|
||||||
|
@ -69,13 +69,18 @@ class EventListFragment : MyFragmentHolder(), RefreshRecyclerViewListener {
|
|||||||
maxFetchedTS = DateTime().plusMonths(6).seconds()
|
maxFetchedTS = DateTime().plusMonths(6).seconds()
|
||||||
context!!.dbHelper.getEvents(minFetchedTS, maxFetchedTS) {
|
context!!.dbHelper.getEvents(minFetchedTS, maxFetchedTS) {
|
||||||
receivedEvents(it, false)
|
receivedEvents(it, false)
|
||||||
if (it.size < 20) {
|
if (it.size < 30) {
|
||||||
fetchNextPeriod(false)
|
minFetchedTS -= FETCH_INTERVAL
|
||||||
|
maxFetchedTS += FETCH_INTERVAL
|
||||||
|
context!!.dbHelper.getEvents(minFetchedTS, maxFetchedTS) {
|
||||||
|
mEvents = it
|
||||||
|
receivedEvents(mEvents, false, true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun receivedEvents(events: ArrayList<Event>, scrollAfterUpdating: Boolean) {
|
private fun receivedEvents(events: ArrayList<Event>, scrollAfterUpdating: Boolean, forceRecreation: Boolean = false) {
|
||||||
if (context == null || activity == null) {
|
if (context == null || activity == null) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -92,7 +97,7 @@ class EventListFragment : MyFragmentHolder(), RefreshRecyclerViewListener {
|
|||||||
|
|
||||||
activity?.runOnUiThread {
|
activity?.runOnUiThread {
|
||||||
val currAdapter = mView.calendar_events_list.adapter
|
val currAdapter = mView.calendar_events_list.adapter
|
||||||
if (currAdapter == null) {
|
if (currAdapter == null || forceRecreation) {
|
||||||
EventListAdapter(activity as SimpleActivity, listItems, true, this, mView.calendar_events_list) {
|
EventListAdapter(activity as SimpleActivity, listItems, true, this, mView.calendar_events_list) {
|
||||||
if (it is ListEvent) {
|
if (it is ListEvent) {
|
||||||
editEvent(it)
|
editEvent(it)
|
||||||
@ -102,6 +107,10 @@ class EventListFragment : MyFragmentHolder(), RefreshRecyclerViewListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mView.calendar_events_list.endlessScrollListener = object : MyRecyclerView.EndlessScrollListener {
|
mView.calendar_events_list.endlessScrollListener = object : MyRecyclerView.EndlessScrollListener {
|
||||||
|
override fun updateTop() {
|
||||||
|
fetchPreviousPeriod()
|
||||||
|
}
|
||||||
|
|
||||||
override fun updateBottom() {
|
override fun updateBottom() {
|
||||||
fetchNextPeriod(true)
|
fetchNextPeriod(true)
|
||||||
}
|
}
|
||||||
@ -131,6 +140,15 @@ class EventListFragment : MyFragmentHolder(), RefreshRecyclerViewListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun fetchPreviousPeriod() {
|
||||||
|
val oldMinFetchedTS = minFetchedTS - 1
|
||||||
|
minFetchedTS -= FETCH_INTERVAL
|
||||||
|
context!!.dbHelper.getEvents(minFetchedTS, oldMinFetchedTS) {
|
||||||
|
mEvents.addAll(0, it)
|
||||||
|
receivedEvents(mEvents, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun fetchNextPeriod(scrollAfterUpdating: Boolean) {
|
private fun fetchNextPeriod(scrollAfterUpdating: Boolean) {
|
||||||
val oldMaxFetchedTS = maxFetchedTS + 1
|
val oldMaxFetchedTS = maxFetchedTS + 1
|
||||||
maxFetchedTS += FETCH_INTERVAL
|
maxFetchedTS += FETCH_INTERVAL
|
||||||
|
Loading…
x
Reference in New Issue
Block a user