mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-01-31 13:48:20 +01:00
[Dialog/Day] Show lesson changes and teacher absences in the day dialog.
This commit is contained in:
parent
48898ab1d4
commit
453bcaa1f6
@ -41,6 +41,14 @@ interface TeacherAbsenceDao {
|
|||||||
"AND :date BETWEEN teacherAbsenceDateFrom AND teacherAbsenceDateTo")
|
"AND :date BETWEEN teacherAbsenceDateFrom AND teacherAbsenceDateTo")
|
||||||
fun getAllByDateFull(profileId: Int, date: Date): LiveData<List<TeacherAbsenceFull>>
|
fun getAllByDateFull(profileId: Int, date: Date): LiveData<List<TeacherAbsenceFull>>
|
||||||
|
|
||||||
|
@Query("SELECT *, teachers.teacherName || ' ' || teachers.teacherSurname as teacherFullName, " +
|
||||||
|
"metadata.seen, metadata.notified, metadata.addedDate FROM teacherAbsence " +
|
||||||
|
"LEFT JOIN teachers USING (profileId, teacherId) " +
|
||||||
|
"LEFT JOIN metadata ON teacherAbsenceId = thingId AND metadata.thingType = " + Metadata.TYPE_TEACHER_ABSENCE +
|
||||||
|
" AND metadata.profileId = :profileId WHERE teachers.profileId = :profileId " +
|
||||||
|
"AND :date BETWEEN teacherAbsenceDateFrom AND teacherAbsenceDateTo")
|
||||||
|
fun getAllByDateNow(profileId: Int, date: Date): List<TeacherAbsenceFull>
|
||||||
|
|
||||||
@Query("DELETE FROM teacherAbsence WHERE profileId = :profileId")
|
@Query("DELETE FROM teacherAbsence WHERE profileId = :profileId")
|
||||||
fun clear(profileId: Int)
|
fun clear(profileId: Int)
|
||||||
}
|
}
|
||||||
|
@ -10,17 +10,16 @@ import androidx.appcompat.app.AppCompatActivity
|
|||||||
import androidx.lifecycle.Observer
|
import androidx.lifecycle.Observer
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.android.synthetic.main.row_lesson_change_item.view.*
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.android.synthetic.main.row_teacher_absence_item.view.*
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.*
|
||||||
import pl.szczodrzynski.edziennik.App
|
import pl.szczodrzynski.edziennik.*
|
||||||
import pl.szczodrzynski.edziennik.R
|
|
||||||
import pl.szczodrzynski.edziennik.databinding.DialogDayBinding
|
import pl.szczodrzynski.edziennik.databinding.DialogDayBinding
|
||||||
import pl.szczodrzynski.edziennik.onClick
|
|
||||||
import pl.szczodrzynski.edziennik.setText
|
|
||||||
import pl.szczodrzynski.edziennik.ui.dialogs.event.EventDetailsDialog
|
import pl.szczodrzynski.edziennik.ui.dialogs.event.EventDetailsDialog
|
||||||
import pl.szczodrzynski.edziennik.ui.dialogs.event.EventListAdapter
|
import pl.szczodrzynski.edziennik.ui.dialogs.event.EventListAdapter
|
||||||
import pl.szczodrzynski.edziennik.ui.dialogs.event.EventManualDialog
|
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.utils.SimpleDividerItemDecoration
|
import pl.szczodrzynski.edziennik.utils.SimpleDividerItemDecoration
|
||||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||||
import pl.szczodrzynski.edziennik.utils.models.Week
|
import pl.szczodrzynski.edziennik.utils.models.Week
|
||||||
@ -77,13 +76,51 @@ class DayDialog(
|
|||||||
update()
|
update()
|
||||||
}}
|
}}
|
||||||
|
|
||||||
private fun update() {
|
private fun update() { launch {
|
||||||
b.dayDate.setText(
|
b.dayDate.setText(
|
||||||
R.string.dialog_day_date_format,
|
R.string.dialog_day_date_format,
|
||||||
Week.getFullDayName(date.weekDay),
|
Week.getFullDayName(date.weekDay),
|
||||||
date.formattedString
|
date.formattedString
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val lessonChanges = withContext(Dispatchers.Default) {
|
||||||
|
app.db.timetableDao().getChangesForDateNow(profileId, date)
|
||||||
|
}
|
||||||
|
|
||||||
|
lessonChanges.ifNotEmpty {
|
||||||
|
b.lessonChangeContainer.visibility = View.VISIBLE
|
||||||
|
b.lessonChangeContainer.lessonChangeCount.text = it.size.toString()
|
||||||
|
|
||||||
|
b.lessonChangeLayout.onClick {
|
||||||
|
LessonChangeDialog(
|
||||||
|
activity,
|
||||||
|
profileId,
|
||||||
|
date,
|
||||||
|
onShowListener = onShowListener,
|
||||||
|
onDismissListener = onDismissListener
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val teacherAbsences = withContext(Dispatchers.Default) {
|
||||||
|
app.db.teacherAbsenceDao().getAllByDateNow(profileId, date)
|
||||||
|
}
|
||||||
|
|
||||||
|
teacherAbsences.ifNotEmpty {
|
||||||
|
b.teacherAbsenceContainer.visibility = View.VISIBLE
|
||||||
|
b.teacherAbsenceContainer.teacherAbsenceCount.text = it.size.toString()
|
||||||
|
|
||||||
|
b.teacherAbsenceLayout.onClick {
|
||||||
|
TeacherAbsenceDialog(
|
||||||
|
activity,
|
||||||
|
profileId,
|
||||||
|
date,
|
||||||
|
onShowListener = onShowListener,
|
||||||
|
onDismissListener = onDismissListener
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
adapter = EventListAdapter(
|
adapter = EventListAdapter(
|
||||||
activity,
|
activity,
|
||||||
onItemClick = {
|
onItemClick = {
|
||||||
@ -126,5 +163,5 @@ class DayDialog(
|
|||||||
b.eventsNoData.visibility = View.VISIBLE
|
b.eventsNoData.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}}
|
||||||
}
|
}
|
||||||
|
@ -4,27 +4,29 @@
|
|||||||
|
|
||||||
package pl.szczodrzynski.edziennik.ui.dialogs.lessonchange
|
package pl.szczodrzynski.edziennik.ui.dialogs.lessonchange
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import android.graphics.PorterDuff
|
import android.graphics.PorterDuff
|
||||||
import android.graphics.PorterDuffColorFilter
|
import android.graphics.PorterDuffColorFilter
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
|
||||||
import androidx.core.view.updateLayoutParams
|
import androidx.core.view.updateLayoutParams
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import pl.szczodrzynski.edziennik.*
|
import pl.szczodrzynski.edziennik.*
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Lesson
|
import pl.szczodrzynski.edziennik.data.db.entity.Lesson
|
||||||
import pl.szczodrzynski.edziennik.data.db.full.LessonFull
|
import pl.szczodrzynski.edziennik.data.db.full.LessonFull
|
||||||
import pl.szczodrzynski.edziennik.databinding.TimetableLessonBinding
|
import pl.szczodrzynski.edziennik.databinding.TimetableLessonBinding
|
||||||
import pl.szczodrzynski.edziennik.ui.dialogs.timetable.LessonDetailsDialog
|
|
||||||
import pl.szczodrzynski.navlib.getColorFromAttr
|
import pl.szczodrzynski.navlib.getColorFromAttr
|
||||||
|
|
||||||
class LessonChangeAdapter(val activity: AppCompatActivity) : RecyclerView.Adapter<LessonChangeAdapter.ViewHolder>() {
|
class LessonChangeAdapter(
|
||||||
|
val context: Context,
|
||||||
|
private val onItemClick: ((lesson: LessonFull) -> Unit)? = null
|
||||||
|
) : RecyclerView.Adapter<LessonChangeAdapter.ViewHolder>() {
|
||||||
|
|
||||||
var items = listOf<LessonFull>()
|
var items = listOf<LessonFull>()
|
||||||
|
|
||||||
private val arrowRight = " → "
|
private val arrowRight = " → "
|
||||||
private val bullet = " • "
|
private val bullet = " • "
|
||||||
private val colorSecondary = android.R.attr.textColorSecondary.resolveAttr(activity)
|
private val colorSecondary = android.R.attr.textColorSecondary.resolveAttr(context)
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||||
val inflater = LayoutInflater.from(parent.context)
|
val inflater = LayoutInflater.from(parent.context)
|
||||||
@ -36,8 +38,8 @@ class LessonChangeAdapter(val activity: AppCompatActivity) : RecyclerView.Adapte
|
|||||||
val lesson = items[position]
|
val lesson = items[position]
|
||||||
val b = holder.b
|
val b = holder.b
|
||||||
|
|
||||||
b.root.setOnClickListener {
|
b.root.onClick {
|
||||||
LessonDetailsDialog(activity, lesson)
|
onItemClick?.invoke(lesson)
|
||||||
}
|
}
|
||||||
|
|
||||||
val startTime = lesson.displayStartTime ?: return
|
val startTime = lesson.displayStartTime ?: return
|
||||||
@ -99,7 +101,7 @@ class LessonChangeAdapter(val activity: AppCompatActivity) : RecyclerView.Adapte
|
|||||||
b.annotationVisible = true
|
b.annotationVisible = true
|
||||||
b.annotation.setText(R.string.timetable_lesson_cancelled)
|
b.annotation.setText(R.string.timetable_lesson_cancelled)
|
||||||
b.annotation.background.colorFilter = PorterDuffColorFilter(
|
b.annotation.background.colorFilter = PorterDuffColorFilter(
|
||||||
getColorFromAttr(activity, R.attr.timetable_lesson_cancelled_color),
|
getColorFromAttr(context, R.attr.timetable_lesson_cancelled_color),
|
||||||
PorterDuff.Mode.SRC_ATOP
|
PorterDuff.Mode.SRC_ATOP
|
||||||
)
|
)
|
||||||
//lb.subjectName.typeface = Typeface.DEFAULT
|
//lb.subjectName.typeface = Typeface.DEFAULT
|
||||||
@ -129,7 +131,7 @@ class LessonChangeAdapter(val activity: AppCompatActivity) : RecyclerView.Adapte
|
|||||||
}
|
}
|
||||||
|
|
||||||
b.annotation.background.colorFilter = PorterDuffColorFilter(
|
b.annotation.background.colorFilter = PorterDuffColorFilter(
|
||||||
getColorFromAttr(activity, R.attr.timetable_lesson_change_color),
|
getColorFromAttr(context, R.attr.timetable_lesson_change_color),
|
||||||
PorterDuff.Mode.SRC_ATOP
|
PorterDuff.Mode.SRC_ATOP
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -152,7 +154,7 @@ class LessonChangeAdapter(val activity: AppCompatActivity) : RecyclerView.Adapte
|
|||||||
else -> b.annotation.setText(R.string.timetable_lesson_shifted)
|
else -> b.annotation.setText(R.string.timetable_lesson_shifted)
|
||||||
}
|
}
|
||||||
|
|
||||||
b.annotation.background.setTintColor(R.attr.timetable_lesson_shifted_source_color.resolveAttr(activity))
|
b.annotation.background.setTintColor(R.attr.timetable_lesson_shifted_source_color.resolveAttr(context))
|
||||||
}
|
}
|
||||||
Lesson.TYPE_SHIFTED_TARGET -> {
|
Lesson.TYPE_SHIFTED_TARGET -> {
|
||||||
b.annotationVisible = true
|
b.annotationVisible = true
|
||||||
@ -174,7 +176,7 @@ class LessonChangeAdapter(val activity: AppCompatActivity) : RecyclerView.Adapte
|
|||||||
}
|
}
|
||||||
|
|
||||||
b.annotation.background.colorFilter = PorterDuffColorFilter(
|
b.annotation.background.colorFilter = PorterDuffColorFilter(
|
||||||
getColorFromAttr(activity, R.attr.timetable_lesson_shifted_target_color),
|
getColorFromAttr(context, R.attr.timetable_lesson_shifted_target_color),
|
||||||
PorterDuff.Mode.SRC_ATOP
|
PorterDuff.Mode.SRC_ATOP
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import kotlinx.coroutines.*
|
|||||||
import pl.szczodrzynski.edziennik.App
|
import pl.szczodrzynski.edziennik.App
|
||||||
import pl.szczodrzynski.edziennik.R
|
import pl.szczodrzynski.edziennik.R
|
||||||
import pl.szczodrzynski.edziennik.databinding.DialogLessonChangeListBinding
|
import pl.szczodrzynski.edziennik.databinding.DialogLessonChangeListBinding
|
||||||
|
import pl.szczodrzynski.edziennik.ui.dialogs.timetable.LessonDetailsDialog
|
||||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||||
import kotlin.coroutines.CoroutineContext
|
import kotlin.coroutines.CoroutineContext
|
||||||
|
|
||||||
@ -53,7 +54,21 @@ class LessonChangeDialog(
|
|||||||
app.db.timetableDao().getChangesForDateNow(profileId, defaultDate)
|
app.db.timetableDao().getChangesForDateNow(profileId, defaultDate)
|
||||||
}
|
}
|
||||||
|
|
||||||
b.lessonChangeView.adapter = LessonChangeAdapter(activity).apply { items = lessonChanges }
|
val adapter = LessonChangeAdapter(
|
||||||
|
activity,
|
||||||
|
onItemClick = {
|
||||||
|
LessonDetailsDialog(
|
||||||
|
activity,
|
||||||
|
it,
|
||||||
|
onShowListener = onShowListener,
|
||||||
|
onDismissListener = onDismissListener
|
||||||
|
)
|
||||||
|
}
|
||||||
|
).apply {
|
||||||
|
items = lessonChanges
|
||||||
|
}
|
||||||
|
|
||||||
|
b.lessonChangeView.adapter = adapter
|
||||||
b.lessonChangeView.layoutManager = LinearLayoutManager(activity)
|
b.lessonChangeView.layoutManager = LinearLayoutManager(activity)
|
||||||
|
|
||||||
dialog.show()
|
dialog.show()
|
||||||
|
@ -30,29 +30,43 @@
|
|||||||
android:textIsSelectable="true"
|
android:textIsSelectable="true"
|
||||||
tools:text="wtorek, 17 grudnia" />
|
tools:text="wtorek, 17 grudnia" />
|
||||||
|
|
||||||
<include
|
<LinearLayout
|
||||||
android:id="@+id/lessonChangeContainer"
|
android:id="@+id/lessonChangeLayout"
|
||||||
layout="@layout/row_lesson_change_item"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginLeft="8dp"
|
android:background="?selectableItemBackground">
|
||||||
android:layout_marginTop="5dp"
|
|
||||||
android:layout_marginRight="8dp"
|
|
||||||
android:layout_marginBottom="5dp"
|
|
||||||
android:visibility="gone"
|
|
||||||
tools:visibility="visible" />
|
|
||||||
|
|
||||||
<include
|
<include
|
||||||
android:id="@+id/teacherAbsenceContainer"
|
android:id="@+id/lessonChangeContainer"
|
||||||
layout="@layout/row_teacher_absence_item"
|
layout="@layout/row_lesson_change_item"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="8dp"
|
||||||
|
android:layout_marginTop="5dp"
|
||||||
|
android:layout_marginRight="8dp"
|
||||||
|
android:layout_marginBottom="5dp"
|
||||||
|
android:visibility="gone"
|
||||||
|
tools:visibility="visible" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/teacherAbsenceLayout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="5dp"
|
android:background="?selectableItemBackground">
|
||||||
android:layout_marginBottom="5dp"
|
|
||||||
android:layout_marginLeft="8dp"
|
<include
|
||||||
android:layout_marginRight="8dp"
|
android:id="@+id/teacherAbsenceContainer"
|
||||||
android:visibility="gone"
|
layout="@layout/row_teacher_absence_item"
|
||||||
tools:visibility="visible" />
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="5dp"
|
||||||
|
android:layout_marginBottom="5dp"
|
||||||
|
android:layout_marginLeft="8dp"
|
||||||
|
android:layout_marginRight="8dp"
|
||||||
|
android:visibility="gone"
|
||||||
|
tools:visibility="visible" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/eventsNoData"
|
android:id="@+id/eventsNoData"
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<androidx.cardview.widget.CardView android:id="@+id/lesson_change_card"
|
<androidx.cardview.widget.CardView android:id="@+id/lesson_change_card"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
tools:cardBackgroundColor="#78909c"
|
app:cardBackgroundColor="#78909c"
|
||||||
app:cardCornerRadius="5dp"
|
app:cardCornerRadius="5dp"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<androidx.cardview.widget.CardView android:id="@+id/teacherAbsenceCard"
|
<androidx.cardview.widget.CardView android:id="@+id/teacherAbsenceCard"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
tools:cardBackgroundColor="#ff1744"
|
app:cardBackgroundColor="#ff1744"
|
||||||
app:cardCornerRadius="5dp"
|
app:cardCornerRadius="5dp"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user