[Agenda] Add teachers absence dialog

This commit is contained in:
Kacper Ziubryniewicz 2019-09-29 01:17:08 +02:00
parent 0b0cd4c76e
commit c8f24611ba
13 changed files with 180 additions and 36 deletions

View File

@ -1,10 +1,12 @@
package pl.szczodrzynski.edziennik.data.db.modules.teachers
import androidx.lifecycle.LiveData
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
import pl.szczodrzynski.edziennik.utils.models.Date
@Dao
interface TeacherAbsenceDao {
@ -24,4 +26,12 @@ interface TeacherAbsenceDao {
"LEFT JOIN metadata ON teacherAbsenceId = thingId AND metadata.thingType = " + Metadata.TYPE_TEACHER_ABSENCE +
" AND metadata.profileId = :profileId WHERE teachers.profileId = :profileId")
fun getAllFull(profileId: Int): 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 getAllByDateFull(profileId: Int, date: Date): LiveData<List<TeacherAbsenceFull>>
}

View File

@ -5,6 +5,8 @@ import pl.szczodrzynski.edziennik.utils.models.Date
class TeacherAbsenceFull(profileId: Int, id: Long, teacherId: Long, type: Long, dateFrom: Date, dateTo: Date)
: TeacherAbsence(profileId, id, teacherId, type, dateFrom, dateTo) {
var teacherFullName = ""
// metadata
var seen: Boolean = false
var notified: Boolean = false

View File

@ -0,0 +1,38 @@
package pl.szczodrzynski.edziennik.ui.dialogs.teacherabsence
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import pl.szczodrzynski.edziennik.R
import pl.szczodrzynski.edziennik.data.db.modules.teachers.TeacherAbsenceFull
import pl.szczodrzynski.edziennik.utils.models.Date
class TeacherAbsenceAdapter(
private val context: Context,
private val date: Date,
private val teacherAbsenceList: List<TeacherAbsenceFull>
) : RecyclerView.Adapter<TeacherAbsenceAdapter.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val inflater: LayoutInflater = LayoutInflater.from(context)
val view: View = inflater.inflate(R.layout.row_dialog_teacher_absence_item, parent, false)
return ViewHolder(view)
}
override fun getItemCount(): Int {
return teacherAbsenceList.size
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val teacherAbsence: TeacherAbsenceFull = teacherAbsenceList[position]
holder.teacherAbsenceTeacher.text = teacherAbsence.teacherFullName
}
class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
var teacherAbsenceTeacher: TextView = itemView.findViewById(R.id.teacherAbsenceTeacher)
}
}

View File

@ -0,0 +1,43 @@
package pl.szczodrzynski.edziennik.ui.dialogs.teacherabsence
import android.content.Context
import android.view.View
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.LinearLayoutManager
import com.afollestad.materialdialogs.MaterialDialog
import pl.szczodrzynski.edziennik.App
import pl.szczodrzynski.edziennik.R
import pl.szczodrzynski.edziennik.databinding.DialogTeacherAbsenceListBinding
import pl.szczodrzynski.edziennik.utils.models.Date
class TeacherAbsenceDialog(val context: Context) {
val profileId: Int = App.profileId
private lateinit var b: DialogTeacherAbsenceListBinding
fun show(app: App, date: Date) {
val dialog = MaterialDialog.Builder(context)
.title(date.formattedString)
.customView(R.layout.dialog_teacher_absence_list, true)
.positiveText(R.string.close)
.autoDismiss(false)
.onPositive { dialog, _ -> dialog.dismiss()}
.show()
val customView: View = dialog.customView ?: return
b = DataBindingUtil.bind(customView) ?: return
b.teacherAbsenceView.setHasFixedSize(false)
b.teacherAbsenceView.isNestedScrollingEnabled = false
b.teacherAbsenceView.layoutManager = LinearLayoutManager(context)
app.db.teacherAbsenceDao().getAllByDateFull(profileId, date).observe(context as LifecycleOwner, Observer { absenceList ->
val adapter = TeacherAbsenceAdapter(context, date, absenceList)
b.teacherAbsenceView.adapter = adapter
b.teacherAbsenceView.visibility = View.VISIBLE
})
}
}

View File

@ -44,6 +44,7 @@ import pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonFull;
import pl.szczodrzynski.edziennik.ui.dialogs.event.EventListDialog;
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.lessonchange.LessonChangeCounter;
import pl.szczodrzynski.edziennik.ui.modules.agenda.lessonchange.LessonChangeEvent;
import pl.szczodrzynski.edziennik.ui.modules.agenda.lessonchange.LessonChangeEventRenderer;
@ -322,6 +323,8 @@ public class AgendaFragment extends Fragment {
} else if (calendarEvent instanceof LessonChangeEvent) {
new LessonChangeDialog(activity).show(app, Date.fromCalendar(calendarEvent.getInstanceDay()));
//Toast.makeText(app, "Clicked "+((LessonChangeEvent) calendarEvent).getLessonChangeDate().getFormattedString(), Toast.LENGTH_SHORT).show();
} else if (calendarEvent instanceof TeacherAbsenceEvent) {
new TeacherAbsenceDialog(activity).show(app, Date.fromCalendar(calendarEvent.getInstanceDay()));
}
}
}, new LessonChangeEventRenderer(), new TeacherAbsenceEventRenderer());

View File

@ -8,9 +8,9 @@ import pl.szczodrzynski.edziennik.R
class TeacherAbsenceEventRenderer : EventRenderer<TeacherAbsenceEvent>() {
override fun render(view: View?, event: TeacherAbsenceEvent) {
val card = view?.findViewById<CardView>(R.id.teacher_absence_card)
val changeText = view?.findViewById<TextView>(R.id.teacher_absence_text)
val changeCount = view?.findViewById<TextView>(R.id.teacher_absence_count)
val card = view?.findViewById<CardView>(R.id.teacherAbsenceCard)
val changeText = view?.findViewById<TextView>(R.id.teacherAbsenceText)
val changeCount = view?.findViewById<TextView>(R.id.teacherAbsenceCount)
card?.setCardBackgroundColor(event.color)
changeText?.setTextColor(event.textColor)
changeCount?.setTextColor(event.textColor)

View File

@ -9,7 +9,7 @@
<include
layout="@layout/row_dialog_lesson_change_item"
layout="@layout/row_lesson_change_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />

View File

@ -7,7 +7,7 @@
<include
layout="@layout/row_dialog_teacher_absence_item"
layout="@layout/row_teacher_absence_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />

View File

@ -16,7 +16,7 @@
<include
android:id="@+id/lesson_change_container"
layout="@layout/row_dialog_lesson_change_item"
layout="@layout/row_lesson_change_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/teacherAbsenceView"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:listitem="@layout/row_dialog_teacher_absence_item" />
</LinearLayout>
</layout>

View File

@ -1,35 +1,34 @@
<androidx.cardview.widget.CardView android:id="@+id/teacher_absence_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:cardBackgroundColor="@color/blue_selected"
app:cardCornerRadius="5dp"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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">
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp">
android:layout_marginStart="8dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="4dp"
android:background="?selectableItemBackground"
app:cardCornerRadius="5dp"
app:cardElevation="4dp">
<TextView
android:id="@+id/teacher_absence_text"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:textAppearance="@style/NavView.TextView.Medium"
android:text="@string/agenda_teacher_absence" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg_rounded_8dp_outline"
android:padding="8dp">
<TextView
android:id="@+id/teacher_absence_count"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:textSize="20sp"
tools:text="3" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<TextView
android:id="@+id/teacherAbsenceTeacher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="Jan Kowalski"/>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
</LinearLayout>

View File

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