diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/AgendaFragmentDefault.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/AgendaFragmentDefault.kt index 680eeb18..9aaf3d5a 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/AgendaFragmentDefault.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/AgendaFragmentDefault.kt @@ -26,6 +26,8 @@ import pl.szczodrzynski.edziennik.ui.dialogs.event.EventDetailsDialog import pl.szczodrzynski.edziennik.ui.dialogs.lessonchange.LessonChangeDialog import pl.szczodrzynski.edziennik.ui.dialogs.teacherabsence.TeacherAbsenceDialog import pl.szczodrzynski.edziennik.ui.modules.agenda.event.AgendaEvent +import pl.szczodrzynski.edziennik.ui.modules.agenda.event.AgendaEventGroup +import pl.szczodrzynski.edziennik.ui.modules.agenda.event.AgendaEventGroupRenderer import pl.szczodrzynski.edziennik.ui.modules.agenda.event.AgendaEventRenderer import pl.szczodrzynski.edziennik.ui.modules.agenda.lessonchanges.LessonChangesEvent import pl.szczodrzynski.edziennik.ui.modules.agenda.lessonchanges.LessonChangesEventRenderer @@ -111,6 +113,7 @@ class AgendaFragmentDefault( } }, AgendaEventRenderer(isCompactMode), + AgendaEventGroupRenderer(), LessonChangesEventRenderer(), TeacherAbsenceEventRenderer() ) @@ -135,10 +138,33 @@ class AgendaFragmentDefault( ) { events.removeAll { it is AgendaEvent } - events += eventList.map { - if (!it.seen) - unreadDates.add(it.date.value) - AgendaEvent(it) + if (!profileConfig.agendaGroupByType) { + events += eventList.map { + if (!it.seen) + unreadDates.add(it.date.value) + AgendaEvent(it) + } + return + } + + eventList.groupBy { + it.date.value to it.type + }.forEach { (_, list) -> + val event = list.first() + if (list.size == 1) { + if (!event.seen) + unreadDates.add(event.date.value) + events += AgendaEvent(event) + } + else { + events.add(0, AgendaEventGroup( + profileId = event.profileId, + date = event.date, + typeName = event.typeName ?: "-", + typeColor = event.typeColor ?: event.eventColor, + eventCount = list.size + )) + } } } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/event/AgendaEventGroup.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/event/AgendaEventGroup.kt new file mode 100644 index 00000000..60e5f769 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/event/AgendaEventGroup.kt @@ -0,0 +1,23 @@ +/* + * Copyright (c) Kuba Szczodrzyński 2021-4-10. + */ + +package pl.szczodrzynski.edziennik.ui.modules.agenda.event + +import pl.szczodrzynski.edziennik.ui.modules.agenda.BaseEvent +import pl.szczodrzynski.edziennik.utils.models.Date + +class AgendaEventGroup( + val profileId: Int, + val date: Date, + val typeName: String, + val typeColor: Int, + val eventCount: Int +) : BaseEvent( + id = date.value.toLong(), + time = date.asCalendar, + color = typeColor, + showBadge = false +) { + override fun copy() = AgendaEventGroup(profileId, date, typeName, typeColor, eventCount) +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/event/AgendaEventGroupRenderer.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/event/AgendaEventGroupRenderer.kt new file mode 100644 index 00000000..191f526c --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/event/AgendaEventGroupRenderer.kt @@ -0,0 +1,31 @@ +/* + * Copyright (c) Kuba Szczodrzyński 2021-4-10. + */ + +package pl.szczodrzynski.edziennik.ui.modules.agenda.event + +import android.view.View +import com.github.tibolte.agendacalendarview.render.EventRenderer +import pl.szczodrzynski.edziennik.R +import pl.szczodrzynski.edziennik.databinding.AgendaWrappedGroupBinding +import pl.szczodrzynski.edziennik.resolveAttr +import pl.szczodrzynski.edziennik.setTintColor +import pl.szczodrzynski.edziennik.utils.Colors + +class AgendaEventGroupRenderer : EventRenderer() { + + override fun render(view: View, event: AgendaEventGroup) { + val b = AgendaWrappedGroupBinding.bind(view).item + + b.foreground.foreground.setTintColor(event.typeColor) + b.background.background.setTintColor(event.typeColor) + b.name.background.setTintColor(event.typeColor) + b.name.text = event.typeName + b.name.setTextColor(Colors.legibleTextColor(event.typeColor)) + b.count.text = event.eventCount.toString() + b.count.background.setTintColor(android.R.attr.colorBackground.resolveAttr(view.context)) + } + + override fun getEventLayout(): Int = R.layout.agenda_wrapped_group +} + diff --git a/app/src/main/res/layout/agenda_group_item.xml b/app/src/main/res/layout/agenda_group_item.xml new file mode 100644 index 00000000..23d3486d --- /dev/null +++ b/app/src/main/res/layout/agenda_group_item.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + diff --git a/app/src/main/res/layout/agenda_wrapped_group.xml b/app/src/main/res/layout/agenda_wrapped_group.xml new file mode 100644 index 00000000..6b081d8e --- /dev/null +++ b/app/src/main/res/layout/agenda_wrapped_group.xml @@ -0,0 +1,18 @@ + + + + + + +