forked from github/szkolny
[Agenda] Implement grouping events by type.
This commit is contained in:
parent
3eae8fb58b
commit
777ae945e0
@ -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,11 +138,34 @@ class AgendaFragmentDefault(
|
||||
) {
|
||||
events.removeAll { it is AgendaEvent }
|
||||
|
||||
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
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun addLessonChanges(events: MutableList<CalendarEvent>) {
|
||||
|
@ -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)
|
||||
}
|
@ -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<AgendaEventGroup>() {
|
||||
|
||||
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
|
||||
}
|
||||
|
55
app/src/main/res/layout/agenda_group_item.xml
Normal file
55
app/src/main/res/layout/agenda_group_item.xml
Normal file
@ -0,0 +1,55 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Copyright (c) Kuba Szczodrzyński 2021-4-10.
|
||||
-->
|
||||
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/foreground"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:foreground="@drawable/bg_rounded_8dp_outline"
|
||||
tools:foregroundTint="@color/blue_selected">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/background"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/bg_rounded_8dp"
|
||||
android:orientation="horizontal"
|
||||
tools:backgroundTint="@color/blue_selected"
|
||||
tools:ignore="UselessParent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/name"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:background="@drawable/bg_rounded_8dp"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center"
|
||||
android:maxLines="1"
|
||||
android:padding="10dp"
|
||||
android:textAppearance="@style/NavView.TextView.Medium"
|
||||
tools:backgroundTint="@color/blue_selected"
|
||||
tools:text="informacja"
|
||||
tools:textColor="@color/md_white_1000" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/count"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginVertical="2dp"
|
||||
android:layout_marginRight="-1dp"
|
||||
android:background="@drawable/bg_rounded_8dp"
|
||||
android:gravity="center"
|
||||
android:paddingVertical="10dp"
|
||||
android:paddingStart="16dp"
|
||||
android:paddingLeft="16dp"
|
||||
android:paddingEnd="18dp"
|
||||
android:paddingRight="18dp"
|
||||
android:textSize="20sp"
|
||||
tools:backgroundTint="?android:colorBackground"
|
||||
tools:text="3" />
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
18
app/src/main/res/layout/agenda_wrapped_group.xml
Normal file
18
app/src/main/res/layout/agenda_wrapped_group.xml
Normal file
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Copyright (c) Kuba Szczodrzyński 2021-4-10.
|
||||
-->
|
||||
|
||||
<com.github.tibolte.agendacalendarview.agenda.AgendaEventView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<include
|
||||
android:id="@+id/item"
|
||||
layout="@layout/agenda_group_item"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1" />
|
||||
</com.github.tibolte.agendacalendarview.agenda.AgendaEventView>
|
Loading…
Reference in New Issue
Block a user