forked from github/szkolny
[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")
|
||||
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")
|
||||
fun clear(profileId: Int)
|
||||
}
|
||||
|
@ -10,17 +10,16 @@ import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.R
|
||||
import kotlinx.android.synthetic.main.row_lesson_change_item.view.*
|
||||
import kotlinx.android.synthetic.main.row_teacher_absence_item.view.*
|
||||
import kotlinx.coroutines.*
|
||||
import pl.szczodrzynski.edziennik.*
|
||||
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.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.utils.SimpleDividerItemDecoration
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
import pl.szczodrzynski.edziennik.utils.models.Week
|
||||
@ -77,13 +76,51 @@ class DayDialog(
|
||||
update()
|
||||
}}
|
||||
|
||||
private fun update() {
|
||||
private fun update() { launch {
|
||||
b.dayDate.setText(
|
||||
R.string.dialog_day_date_format,
|
||||
Week.getFullDayName(date.weekDay),
|
||||
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(
|
||||
activity,
|
||||
onItemClick = {
|
||||
@ -126,5 +163,5 @@ class DayDialog(
|
||||
b.eventsNoData.visibility = View.VISIBLE
|
||||
}
|
||||
})
|
||||
}
|
||||
}}
|
||||
}
|
||||
|
@ -4,27 +4,29 @@
|
||||
|
||||
package pl.szczodrzynski.edziennik.ui.dialogs.lessonchange
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.PorterDuff
|
||||
import android.graphics.PorterDuffColorFilter
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.view.updateLayoutParams
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import pl.szczodrzynski.edziennik.*
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Lesson
|
||||
import pl.szczodrzynski.edziennik.data.db.full.LessonFull
|
||||
import pl.szczodrzynski.edziennik.databinding.TimetableLessonBinding
|
||||
import pl.szczodrzynski.edziennik.ui.dialogs.timetable.LessonDetailsDialog
|
||||
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>()
|
||||
|
||||
private val arrowRight = " → "
|
||||
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 {
|
||||
val inflater = LayoutInflater.from(parent.context)
|
||||
@ -36,8 +38,8 @@ class LessonChangeAdapter(val activity: AppCompatActivity) : RecyclerView.Adapte
|
||||
val lesson = items[position]
|
||||
val b = holder.b
|
||||
|
||||
b.root.setOnClickListener {
|
||||
LessonDetailsDialog(activity, lesson)
|
||||
b.root.onClick {
|
||||
onItemClick?.invoke(lesson)
|
||||
}
|
||||
|
||||
val startTime = lesson.displayStartTime ?: return
|
||||
@ -99,7 +101,7 @@ class LessonChangeAdapter(val activity: AppCompatActivity) : RecyclerView.Adapte
|
||||
b.annotationVisible = true
|
||||
b.annotation.setText(R.string.timetable_lesson_cancelled)
|
||||
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
|
||||
)
|
||||
//lb.subjectName.typeface = Typeface.DEFAULT
|
||||
@ -129,7 +131,7 @@ class LessonChangeAdapter(val activity: AppCompatActivity) : RecyclerView.Adapte
|
||||
}
|
||||
|
||||
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
|
||||
)
|
||||
}
|
||||
@ -152,7 +154,7 @@ class LessonChangeAdapter(val activity: AppCompatActivity) : RecyclerView.Adapte
|
||||
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 -> {
|
||||
b.annotationVisible = true
|
||||
@ -174,7 +176,7 @@ class LessonChangeAdapter(val activity: AppCompatActivity) : RecyclerView.Adapte
|
||||
}
|
||||
|
||||
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
|
||||
)
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import kotlinx.coroutines.*
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.R
|
||||
import pl.szczodrzynski.edziennik.databinding.DialogLessonChangeListBinding
|
||||
import pl.szczodrzynski.edziennik.ui.dialogs.timetable.LessonDetailsDialog
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
|
||||
@ -53,7 +54,21 @@ class LessonChangeDialog(
|
||||
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)
|
||||
|
||||
dialog.show()
|
||||
|
@ -30,29 +30,43 @@
|
||||
android:textIsSelectable="true"
|
||||
tools:text="wtorek, 17 grudnia" />
|
||||
|
||||
<include
|
||||
android:id="@+id/lessonChangeContainer"
|
||||
layout="@layout/row_lesson_change_item"
|
||||
<LinearLayout
|
||||
android:id="@+id/lessonChangeLayout"
|
||||
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" />
|
||||
android:background="?selectableItemBackground">
|
||||
|
||||
<include
|
||||
android:id="@+id/teacherAbsenceContainer"
|
||||
layout="@layout/row_teacher_absence_item"
|
||||
<include
|
||||
android:id="@+id/lessonChangeContainer"
|
||||
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_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" />
|
||||
android:background="?selectableItemBackground">
|
||||
|
||||
<include
|
||||
android:id="@+id/teacherAbsenceContainer"
|
||||
layout="@layout/row_teacher_absence_item"
|
||||
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
|
||||
android:id="@+id/eventsNoData"
|
||||
|
@ -1,7 +1,7 @@
|
||||
<androidx.cardview.widget.CardView android:id="@+id/lesson_change_card"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
tools:cardBackgroundColor="#78909c"
|
||||
app:cardBackgroundColor="#78909c"
|
||||
app:cardCornerRadius="5dp"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
|
@ -1,7 +1,7 @@
|
||||
<androidx.cardview.widget.CardView android:id="@+id/teacherAbsenceCard"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
tools:cardBackgroundColor="#ff1744"
|
||||
app:cardBackgroundColor="#ff1744"
|
||||
app:cardCornerRadius="5dp"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
|
Loading…
x
Reference in New Issue
Block a user