refresh events list only if something changed

This commit is contained in:
tibbi 2017-02-05 15:40:52 +01:00
parent 367e30ea61
commit d5dbd6e9f0
1 changed files with 6 additions and 4 deletions

View File

@ -29,6 +29,7 @@ import kotlin.comparisons.compareBy
class EventListFragment : Fragment(), DBHelper.GetEventsListener, DBHelper.EventUpdateListener, EventListAdapter.ItemOperationsListener { class EventListFragment : Fragment(), DBHelper.GetEventsListener, DBHelper.EventUpdateListener, EventListAdapter.ItemOperationsListener {
var mAllEvents: MutableList<Event>? = null var mAllEvents: MutableList<Event>? = null
var prevEventsHash = 0
lateinit var mToBeDeleted: MutableList<Int> lateinit var mToBeDeleted: MutableList<Int>
lateinit var mView: View lateinit var mView: View
@ -45,10 +46,6 @@ class EventListFragment : Fragment(), DBHelper.GetEventsListener, DBHelper.Event
checkEvents() checkEvents()
} }
override fun onPause() {
super.onPause()
}
private fun checkEvents() { private fun checkEvents() {
val fromTS = DateTime().seconds() val fromTS = DateTime().seconds()
val toTS = DateTime().plusYears(1).seconds() val toTS = DateTime().plusYears(1).seconds()
@ -56,6 +53,11 @@ class EventListFragment : Fragment(), DBHelper.GetEventsListener, DBHelper.Event
} }
override fun gotEvents(events: MutableList<Event>) { override fun gotEvents(events: MutableList<Event>) {
val hash = events.hashCode()
if (prevEventsHash == hash)
return
prevEventsHash = hash
val filtered = getEventsToShow(events) val filtered = getEventsToShow(events)
val listItems = ArrayList<ListItem>(filtered.size) val listItems = ArrayList<ListItem>(filtered.size)
val sorted = filtered.sortedWith(compareBy({ it.startTS }, { it.endTS }, { it.title }, { it.description })) val sorted = filtered.sortedWith(compareBy({ it.startTS }, { it.endTS }, { it.title }, { it.description }))