diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/day/DayDialog.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/day/DayDialog.kt index e5b7768d..74ba0030 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/day/DayDialog.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/day/DayDialog.kt @@ -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,38 +114,51 @@ 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, - date, - onShowListener = onShowListener, - onDismissListener = onDismissListener + activity, + profileId, + date, + onShowListener = onShowListener, + onDismissListener = onDismissListener ) } } + 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, - date, - onShowListener = onShowListener, - onDismissListener = onDismissListener + activity, + profileId, + date, + onShowListener = onShowListener, + onDismissListener = onDismissListener ) } } + 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 } - }) + } }} } 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 cc25c42f..9167fb9a 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 @@ -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, 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 index e50be2c3..3ef4eb47 100644 --- 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 @@ -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) } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/lessonchanges/LessonChangesEventRenderer.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/lessonchanges/LessonChangesEventRenderer.kt index 2a904016..5f66cc27 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/lessonchanges/LessonChangesEventRenderer.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/lessonchanges/LessonChangesEventRenderer.kt @@ -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() { 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 } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/teacherabsence/TeacherAbsenceEventRenderer.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/teacherabsence/TeacherAbsenceEventRenderer.kt index 12dd1947..8d70f941 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/teacherabsence/TeacherAbsenceEventRenderer.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/teacherabsence/TeacherAbsenceEventRenderer.kt @@ -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() { 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 } diff --git a/app/src/main/res/layout/agenda_lesson_changes_item.xml b/app/src/main/res/layout/agenda_lesson_changes_item.xml deleted file mode 100644 index 8700a575..00000000 --- a/app/src/main/res/layout/agenda_lesson_changes_item.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - diff --git a/app/src/main/res/layout/agenda_teacher_absence_item.xml b/app/src/main/res/layout/agenda_teacher_absence_item.xml deleted file mode 100644 index 4b749e8c..00000000 --- a/app/src/main/res/layout/agenda_teacher_absence_item.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - diff --git a/app/src/main/res/layout/dialog_day.xml b/app/src/main/res/layout/dialog_day.xml index f1544f59..8bbc7b64 100644 --- a/app/src/main/res/layout/dialog_day.xml +++ b/app/src/main/res/layout/dialog_day.xml @@ -3,118 +3,108 @@ ~ Copyright (c) Kuba SzczodrzyƄski 2019-12-16. --> - - + android:layout_width="match_parent" + android:layout_height="match_parent"> - - - + + + + + + + + + + + + + + + + + android:paddingVertical="16dp" + android:visibility="gone" + tools:visibility="visible"> - + android:layout_gravity="center" + android:drawablePadding="16dp" + android:fontFamily="sans-serif-light" + android:gravity="center" + android:text="@string/dialog_day_no_events" + android:textSize="24sp" + app:drawableTopCompat="@drawable/ic_no_events" /> - - - - - - - - - - - - - - - - - - - - - + android:layout_gravity="center" + android:gravity="center" + android:text="@string/dialog_no_events_hint" + android:textStyle="italic" /> - - + + + +