properly refresh the events at daily view after changing filtering

This commit is contained in:
tibbi 2017-11-13 20:28:10 +01:00
parent c1179639d6
commit c2fe4d6bb0
2 changed files with 5 additions and 6 deletions

View File

@ -293,10 +293,10 @@ private fun addTodaysBackground(textView: TextView, res: Resources, dayLabelHeig
textView.addResizedBackgroundDrawable(res, dayLabelHeight, mPrimaryColor, R.drawable.monthly_today_circle)
fun Context.addDayEvents(day: DayMonthly, linearLayout: LinearLayout, res: Resources, dividerMargin: Int) {
val backgroundDrawable = res.getDrawable(R.drawable.day_monthly_event_background)
val eventLayoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
day.dayEvents.sortedWith(compareBy({ it.startTS }, { it.endTS }, { it.title })).forEach {
val backgroundDrawable = res.getDrawable(R.drawable.day_monthly_event_background)
backgroundDrawable.applyColorFilter(it.color)
eventLayoutParams.setMargins(dividerMargin, 0, dividerMargin, dividerMargin)

View File

@ -117,21 +117,20 @@ class DayFragment : Fragment(), DBHelper.EventUpdateListener, DeleteEventsListen
}
private fun receivedEvents(events: List<Event>) {
val newHash = events.hashCode()
val filtered = context?.getFilteredEvents(events) ?: ArrayList()
val newHash = filtered.hashCode()
if (newHash == lastHash || !isAdded) {
return
}
lastHash = newHash
val replaceDescription = context!!.config.replaceDescription
val sorted = ArrayList<Event>(events.sortedWith(compareBy({ it.startTS }, { it.endTS }, { it.title }, {
val sorted = ArrayList<Event>(filtered.sortedWith(compareBy({ it.startTS }, { it.endTS }, { it.title }, {
if (replaceDescription) it.location else it.description
})))
val filtered = context?.getFilteredEvents(sorted) ?: ArrayList()
activity?.runOnUiThread {
updateEvents(filtered)
updateEvents(sorted)
}
}