limit events displayed in lists to 50

This commit is contained in:
tibbi 2016-11-30 19:24:15 +01:00
parent 11bebdce62
commit 1d47de4b29
2 changed files with 8 additions and 7 deletions

View File

@ -88,8 +88,9 @@ class EventListWidgetAdapter(val context: Context, val intent: Intent) : RemoteV
override fun gotEvents(events: MutableList<Event>) {
val listItems = ArrayList<ListItem>(events.size)
val sorted = events.sortedWith(compareBy({ it.startTS }, { it.endTS }, { it.title }, { it.description }))
val sublist = sorted.subList(0, Math.min(sorted.size, 50))
var prevCode = ""
sorted.forEach {
sublist.forEach {
val code = Formatter.getDayCodeFromTS(it.startTS)
if (code != prevCode) {
val day = Formatter.getDayTitle(context, code)

View File

@ -30,7 +30,6 @@ import kotlin.comparisons.compareBy
class EventListFragment : Fragment(), DBHelper.GetEventsListener, DBHelper.EventUpdateListener, EventListAdapter.ItemOperationsListener {
private val EDIT_EVENT = 1
var mListItems: ArrayList<ListItem> = ArrayList()
var mAllEvents: MutableList<Event>? = null
lateinit var mToBeDeleted: MutableList<Int>
lateinit var mView: View
@ -58,21 +57,22 @@ class EventListFragment : Fragment(), DBHelper.GetEventsListener, DBHelper.Event
override fun gotEvents(events: MutableList<Event>) {
val filtered = getEventsToShow(events)
mListItems = ArrayList<ListItem>(filtered.size)
val listItems = ArrayList<ListItem>(filtered.size)
val sorted = filtered.sortedWith(compareBy({ it.startTS }, { it.endTS }, { it.title }, { it.description }))
val sublist = sorted.subList(0, Math.min(sorted.size, 50))
var prevCode = ""
sorted.forEach {
sublist.forEach {
val code = Formatter.getDayCodeFromTS(it.startTS)
if (code != prevCode) {
val day = Formatter.getDayTitle(context, code)
mListItems.add(ListSection(day))
listItems.add(ListSection(day))
prevCode = code
}
mListItems.add(ListEvent(it.id, it.startTS, it.endTS, it.title, it.description))
listItems.add(ListEvent(it.id, it.startTS, it.endTS, it.title, it.description))
}
mAllEvents = events
val eventsAdapter = EventListAdapter(activity as SimpleActivity, mListItems, this) {
val eventsAdapter = EventListAdapter(activity as SimpleActivity, listItems, this) {
(activity as MainActivity).checkDeleteEvents()
editEvent(it)
}