[UI/Agenda] Update DayDialog for showing event group.

This commit is contained in:
Kuba Szczodrzyński 2021-04-14 16:59:12 +02:00
parent 755b846b50
commit 776806caef
No known key found for this signature in database
GPG Key ID: 70CB8A85BA1633CB
8 changed files with 170 additions and 189 deletions

View File

@ -7,7 +7,7 @@ package pl.szczodrzynski.edziennik.ui.dialogs.day
import android.view.View
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.Observer
import androidx.core.view.isVisible
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import kotlinx.coroutines.*
@ -19,6 +19,10 @@ import pl.szczodrzynski.edziennik.ui.dialogs.event.EventListAdapter
import pl.szczodrzynski.edziennik.ui.dialogs.event.EventManualDialog
import pl.szczodrzynski.edziennik.ui.dialogs.lessonchange.LessonChangeDialog
import pl.szczodrzynski.edziennik.ui.dialogs.teacherabsence.TeacherAbsenceDialog
import pl.szczodrzynski.edziennik.ui.modules.agenda.lessonchanges.LessonChangesEvent
import pl.szczodrzynski.edziennik.ui.modules.agenda.lessonchanges.LessonChangesEventRenderer
import pl.szczodrzynski.edziennik.ui.modules.agenda.teacherabsence.TeacherAbsenceEvent
import pl.szczodrzynski.edziennik.ui.modules.agenda.teacherabsence.TeacherAbsenceEventRenderer
import pl.szczodrzynski.edziennik.utils.SimpleDividerItemDecoration
import pl.szczodrzynski.edziennik.utils.models.Date
import pl.szczodrzynski.edziennik.utils.models.Time
@ -29,6 +33,7 @@ class DayDialog(
val activity: AppCompatActivity,
val profileId: Int,
val date: Date,
val eventTypeId: Long? = null,
val onShowListener: ((tag: String) -> Unit)? = null,
val onDismissListener: ((tag: String) -> Unit)? = null
) : CoroutineScope {
@ -109,10 +114,16 @@ class DayDialog(
}
lessonChanges.ifNotEmpty {
b.lessonChangeContainer.root.visibility = View.VISIBLE
b.lessonChangeContainer.lessonChangeCount.text = it.size.toString()
LessonChangesEventRenderer().render(
b.lessonChanges, LessonChangesEvent(
profileId = profileId,
date = date,
count = it.size,
showBadge = false
)
)
b.lessonChangeLayout.onClick {
b.lessonChangesFrame.onClick {
LessonChangeDialog(
activity,
profileId,
@ -122,16 +133,22 @@ class DayDialog(
)
}
}
b.lessonChangesFrame.isVisible = lessonChanges.isNotEmpty()
val teacherAbsences = withContext(Dispatchers.Default) {
app.db.teacherAbsenceDao().getAllByDateNow(profileId, date)
}
teacherAbsences.ifNotEmpty {
b.teacherAbsenceContainer.root.visibility = View.VISIBLE
b.teacherAbsenceContainer.teacherAbsenceCount.text = it.size.toString()
TeacherAbsenceEventRenderer().render(
b.teacherAbsence, TeacherAbsenceEvent(
profileId = profileId,
date = date,
count = it.size
)
)
b.teacherAbsenceLayout.onClick {
b.teacherAbsenceFrame.onClick {
TeacherAbsenceDialog(
activity,
profileId,
@ -141,6 +158,7 @@ class DayDialog(
)
}
}
b.teacherAbsenceFrame.isVisible = teacherAbsences.isNotEmpty()
adapter = EventListAdapter(
activity,
@ -169,8 +187,12 @@ class DayDialog(
}
)
app.db.eventDao().getAllByDate(profileId, date).observe(activity, Observer { events ->
adapter.items = events
app.db.eventDao().getAllByDate(profileId, date).observe(activity) { events ->
adapter.items = if (eventTypeId != null)
events.filter { it.type == eventTypeId }
else
events
if (b.eventsView.adapter == null) {
b.eventsView.adapter = adapter
b.eventsView.apply {
@ -189,6 +211,6 @@ class DayDialog(
b.eventsView.visibility = View.GONE
b.eventsNoData.visibility = View.VISIBLE
}
})
}
}}
}

View File

@ -155,7 +155,7 @@ class AgendaFragmentDefault(
app.profileId,
date
)
is AgendaEventGroup -> DayDialog(activity, app.profileId, date)
is AgendaEventGroup -> DayDialog(activity, app.profileId, date, eventTypeId = event.typeId)
is BaseCalendarEvent -> if (event.isPlaceHolder)
DayDialog(activity, app.profileId, date)
}
@ -260,6 +260,7 @@ class AgendaFragmentDefault(
events.add(0, AgendaEventGroup(
profileId = event.profileId,
date = event.date,
typeId = event.type,
typeName = event.typeName ?: "-",
typeColor = event.typeColor ?: event.eventColor,
count = list.size,

View File

@ -10,6 +10,7 @@ import pl.szczodrzynski.edziennik.utils.models.Date
class AgendaEventGroup(
val profileId: Int,
val date: Date,
val typeId: Long,
val typeName: String,
val typeColor: Int,
val count: Int,
@ -20,5 +21,5 @@ class AgendaEventGroup(
color = typeColor,
showBadge = showBadge
) {
override fun copy() = AgendaEventGroup(profileId, date, typeName, typeColor, count, showBadge)
override fun copy() = AgendaEventGroup(profileId, date, typeId, typeName, typeColor, count, showBadge)
}

View File

@ -8,6 +8,7 @@ import android.view.View
import androidx.core.view.isVisible
import com.github.tibolte.agendacalendarview.render.EventRenderer
import pl.szczodrzynski.edziennik.R
import pl.szczodrzynski.edziennik.databinding.AgendaCounterItemBinding
import pl.szczodrzynski.edziennik.databinding.AgendaWrappedCounterBinding
import pl.szczodrzynski.edziennik.resolveAttr
import pl.szczodrzynski.edziennik.setTintColor
@ -33,5 +34,22 @@ class LessonChangesEventRenderer : EventRenderer<LessonChangesEvent>() {
b.badge.isVisible = event.showItemBadge
}
fun render(b: AgendaCounterItemBinding, event: LessonChangesEvent) {
val textColor = Colors.legibleTextColor(event.color)
b.card.foreground.setTintColor(event.color)
b.card.background.setTintColor(event.color)
b.name.setText(R.string.agenda_lesson_changes)
b.name.setTextColor(textColor)
b.count.text = event.count.toString()
b.count.setTextColor(textColor)
b.badgeBackground.isVisible = event.showItemBadge
b.badgeBackground.background.setTintColor(
android.R.attr.colorBackground.resolveAttr(b.root.context)
)
b.badge.isVisible = event.showItemBadge
}
override fun getEventLayout(): Int = R.layout.agenda_wrapped_counter
}

View File

@ -8,6 +8,7 @@ import android.view.View
import androidx.core.view.isVisible
import com.github.tibolte.agendacalendarview.render.EventRenderer
import pl.szczodrzynski.edziennik.R
import pl.szczodrzynski.edziennik.databinding.AgendaCounterItemBinding
import pl.szczodrzynski.edziennik.databinding.AgendaWrappedCounterBinding
import pl.szczodrzynski.edziennik.setTintColor
import pl.szczodrzynski.edziennik.utils.Colors
@ -29,5 +30,19 @@ class TeacherAbsenceEventRenderer : EventRenderer<TeacherAbsenceEvent>() {
b.badge.isVisible = false
}
fun render(b: AgendaCounterItemBinding, event: TeacherAbsenceEvent) {
val textColor = Colors.legibleTextColor(event.color)
b.card.foreground.setTintColor(event.color)
b.card.background.setTintColor(event.color)
b.name.setText(R.string.agenda_teacher_absence)
b.name.setTextColor(textColor)
b.count.text = event.count.toString()
b.count.setTextColor(textColor)
b.badgeBackground.isVisible = false
b.badge.isVisible = false
}
override fun getEventLayout(): Int = R.layout.agenda_wrapped_counter
}

View File

@ -1,33 +0,0 @@
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardBackgroundColor="#78909c"
app:cardCornerRadius="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:text="@string/agenda_lesson_changes"
android:textAppearance="@style/NavView.TextView.Medium"
android:textColor="@color/md_white_1000" />
<TextView
android:id="@+id/lessonChangeCount"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="@color/md_white_1000"
android:textSize="20sp"
tools:text="3" />
</LinearLayout>
</androidx.cardview.widget.CardView>

View File

@ -1,33 +0,0 @@
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardBackgroundColor="#ff1744"
app:cardCornerRadius="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:text="@string/agenda_teacher_absence"
android:textAppearance="@style/NavView.TextView.Medium"
android:textColor="@color/md_white_1000" />
<TextView
android:id="@+id/teacherAbsenceCount"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="@color/md_white_1000"
android:textSize="20sp"
tools:text="3" />
</LinearLayout>
</androidx.cardview.widget.CardView>

View File

@ -3,15 +3,12 @@
~ Copyright (c) Kuba Szczodrzyński 2019-12-16.
-->
<layout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
</data>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -41,47 +38,43 @@
tools:text="8:00 - 14:20 (7 lekcji, 6 godzin, 20 minut)"
tools:visibility="visible" />
<LinearLayout
android:id="@+id/lessonChangeLayout"
<FrameLayout
android:id="@+id/lessonChangesFrame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?selectableItemBackground">
android:foreground="?selectableItemBackground"
android:paddingHorizontal="8dp"
android:paddingVertical="5dp"
android:visibility="gone"
tools:visibility="visible">
<include
android:id="@+id/lessonChangeContainer"
layout="@layout/agenda_lesson_changes_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="8dp"
android:layout_marginVertical="5dp"
android:visibility="gone"
tools:visibility="visible" />
</LinearLayout>
android:id="@+id/lessonChanges"
layout="@layout/agenda_counter_item" />
</FrameLayout>
<LinearLayout
android:id="@+id/teacherAbsenceLayout"
<FrameLayout
android:id="@+id/teacherAbsenceFrame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?selectableItemBackground">
android:foreground="?selectableItemBackground"
android:paddingHorizontal="8dp"
android:paddingVertical="5dp"
android:visibility="gone"
tools:visibility="visible">
<include
android:id="@+id/teacherAbsenceContainer"
layout="@layout/agenda_teacher_absence_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="8dp"
android:layout_marginVertical="5dp"
android:visibility="gone"
tools:visibility="visible" />
</LinearLayout>
android:id="@+id/teacherAbsence"
layout="@layout/agenda_counter_item" />
</FrameLayout>
<LinearLayout
android:id="@+id/eventsNoData"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="8dp"
android:paddingVertical="16dp"
android:orientation="vertical"
android:paddingVertical="16dp"
android:visibility="gone"
tools:visibility="visible">
@ -89,21 +82,20 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
app:drawableTopCompat="@drawable/ic_no_events"
android:drawablePadding="16dp"
android:fontFamily="sans-serif-light"
android:gravity="center"
android:text="@string/dialog_day_no_events"
android:textSize="24sp" />
android:textSize="24sp"
app:drawableTopCompat="@drawable/ic_no_events" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/dialog_no_events_hint"
android:layout_gravity="center"
android:gravity="center"
android:textStyle="italic"/>
android:text="@string/dialog_no_events_hint"
android:textStyle="italic" />
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
@ -112,9 +104,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:clipToPadding="false"
tools:visibility="visible"
tools:listitem="@layout/event_list_item" />
tools:listitem="@layout/event_list_item"
tools:visibility="visible" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</layout>
</androidx.core.widget.NestedScrollView>