diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/adapters/EventListWidgetAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/adapters/EventListWidgetAdapter.kt index 2b6a89c75..66d4ac3b7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/adapters/EventListWidgetAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/adapters/EventListWidgetAdapter.kt @@ -13,6 +13,7 @@ import com.simplemobiletools.calendar.pro.extensions.eventsHelper import com.simplemobiletools.calendar.pro.extensions.seconds import com.simplemobiletools.calendar.pro.helpers.* import com.simplemobiletools.calendar.pro.helpers.Formatter +import com.simplemobiletools.calendar.pro.models.Event import com.simplemobiletools.calendar.pro.models.ListEvent import com.simplemobiletools.calendar.pro.models.ListItem import com.simplemobiletools.calendar.pro.models.ListSection @@ -159,13 +160,19 @@ class EventListWidgetAdapter(val context: Context) : RemoteViewsService.RemoteVi context.eventsHelper.getEventsSync(fromTS, toTS, applyTypeFilter = true) { val listItems = ArrayList(it.size) val replaceDescription = context.config.replaceDescription - val sorted = it.sortedWith(compareBy({ + val sorted = it.sortedWith(compareBy { if (it.getIsAllDay()) { - Formatter.getDayStartTS(Formatter.getDayCodeFromTS(it.startTS)) + Formatter.getDayStartTS(Formatter.getDayCodeFromTS(it.startTS)) - 1 } else { it.startTS } - }, { it.endTS }, { it.title }, { if (replaceDescription) it.location else it.description })) + }.thenBy { + if (it.getIsAllDay()) { + Formatter.getDayEndTS(Formatter.getDayCodeFromTS(it.endTS)) + } else { + it.endTS + } + }.thenBy { it.title }.thenBy { if (replaceDescription) it.location else it.description }) var prevCode = "" val now = getNowSeconds() diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt index 3813e37bc..a3a75ea17 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt @@ -393,7 +393,19 @@ private fun addTodaysBackground(textView: TextView, res: Resources, dayLabelHeig fun Context.addDayEvents(day: DayMonthly, linearLayout: LinearLayout, res: Resources, dividerMargin: Int) { val eventLayoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) - day.dayEvents.sortedWith(compareBy({ it.startTS }, { it.endTS }, { it.title })).forEach { + day.dayEvents.sortedWith(compareBy { + if (it.getIsAllDay()) { + Formatter.getDayStartTS(Formatter.getDayCodeFromTS(it.startTS)) - 1 + } else { + it.startTS + } + }.thenBy { + if (it.getIsAllDay()) { + Formatter.getDayEndTS(Formatter.getDayCodeFromTS(it.endTS)) + } else { + it.endTS + } + }.thenBy { it.title }).forEach { val backgroundDrawable = res.getDrawable(R.drawable.day_monthly_event_background) backgroundDrawable.applyColorFilter(it.color) eventLayoutParams.setMargins(dividerMargin, 0, dividerMargin, dividerMargin) @@ -420,13 +432,19 @@ fun Context.getEventListItems(events: List): ArrayList { val replaceDescription = config.replaceDescription // move all-day events in front of others - val sorted = events.sortedWith(compareBy({ + val sorted = events.sortedWith(compareBy { if (it.getIsAllDay()) { - Formatter.getDayStartTS(Formatter.getDayCodeFromTS(it.startTS)) + Formatter.getDayStartTS(Formatter.getDayCodeFromTS(it.startTS)) - 1 } else { it.startTS } - }, { it.endTS }, { it.title }, { if (replaceDescription) it.location else it.description })) + }.thenBy { + if (it.getIsAllDay()) { + Formatter.getDayEndTS(Formatter.getDayCodeFromTS(it.endTS)) + } else { + it.endTS + } + }.thenBy { it.title }.thenBy { if (replaceDescription) it.location else it.description }) var prevCode = "" val now = getNowSeconds() diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/WeekFragment.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/WeekFragment.kt index f67f605f2..51f420f24 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/WeekFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/WeekFragment.kt @@ -259,7 +259,7 @@ class WeekFragment : Fragment(), WeeklyCalendar { var hadAllDayEvent = false val replaceDescription = mConfig.replaceDescription - val sorted = events.sortedWith(compareBy({ it.startTS }, { it.endTS }, { it.title }, { if (replaceDescription) it.location else it.description })) + val sorted = events.sortedWith(compareBy { it.startTS }.thenBy { it.endTS }.thenBy { it.title }.thenBy { if (replaceDescription) it.location else it.description }) for (event in sorted) { val startDateTime = Formatter.getDateTimeFromTS(event.startTS) val endDateTime = Formatter.getDateTimeFromTS(event.endTS)