forked from github/szkolny
[UI/Timetable] Add lesson type annotation in LessonDetailsDialog.
This commit is contained in:
parent
fdad3b9997
commit
54363ee919
@ -25,6 +25,7 @@ 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.modules.timetable.TimetableFragment
|
import pl.szczodrzynski.edziennik.ui.modules.timetable.TimetableFragment
|
||||||
|
import pl.szczodrzynski.edziennik.ui.modules.timetable.TimetableUtils
|
||||||
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
|
||||||
@ -49,6 +50,7 @@ class LessonDetailsDialog(
|
|||||||
get() = job + Dispatchers.Main
|
get() = job + Dispatchers.Main
|
||||||
|
|
||||||
private lateinit var adapter: EventListAdapter
|
private lateinit var adapter: EventListAdapter
|
||||||
|
private val utils by lazy { TimetableUtils() }
|
||||||
|
|
||||||
init { run {
|
init { run {
|
||||||
if (activity.isFinishing)
|
if (activity.isFinishing)
|
||||||
@ -89,6 +91,8 @@ class LessonDetailsDialog(
|
|||||||
val lessonTime = lesson.displayStartTime ?: return
|
val lessonTime = lesson.displayStartTime ?: return
|
||||||
b.lessonDate.text = Week.getFullDayName(lessonDate.weekDay) + ", " + lessonDate.formattedString
|
b.lessonDate.text = Week.getFullDayName(lessonDate.weekDay) + ", " + lessonDate.formattedString
|
||||||
|
|
||||||
|
b.annotationVisible = utils.getAnnotation(activity, lesson, b.annotation)
|
||||||
|
|
||||||
if (lesson.type >= Lesson.TYPE_SHIFTED_SOURCE) {
|
if (lesson.type >= Lesson.TYPE_SHIFTED_SOURCE) {
|
||||||
b.shiftedLayout.visibility = View.VISIBLE
|
b.shiftedLayout.visibility = View.VISIBLE
|
||||||
var otherLessonDate: Date? = null
|
var otherLessonDate: Date? = null
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
|
|
||||||
package pl.szczodrzynski.edziennik.ui.modules.timetable
|
package pl.szczodrzynski.edziennik.ui.modules.timetable
|
||||||
|
|
||||||
import android.graphics.PorterDuff
|
|
||||||
import android.graphics.PorterDuffColorFilter
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
@ -33,7 +31,6 @@ import pl.szczodrzynski.edziennik.ui.modules.timetable.TimetableFragment.Compani
|
|||||||
import pl.szczodrzynski.edziennik.ui.modules.timetable.TimetableFragment.Companion.DEFAULT_START_HOUR
|
import pl.szczodrzynski.edziennik.ui.modules.timetable.TimetableFragment.Companion.DEFAULT_START_HOUR
|
||||||
import pl.szczodrzynski.edziennik.utils.ListenerScrollView
|
import pl.szczodrzynski.edziennik.utils.ListenerScrollView
|
||||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||||
import pl.szczodrzynski.navlib.getColorFromAttr
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.coroutines.CoroutineContext
|
import kotlin.coroutines.CoroutineContext
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
@ -56,6 +53,8 @@ class TimetableDayFragment : Fragment(), CoroutineScope {
|
|||||||
private var endHour = DEFAULT_END_HOUR
|
private var endHour = DEFAULT_END_HOUR
|
||||||
private var firstEventMinute = 24 * 60
|
private var firstEventMinute = 24 * 60
|
||||||
|
|
||||||
|
private val utils by lazy { TimetableUtils() }
|
||||||
|
|
||||||
// find SwipeRefreshLayout in the hierarchy
|
// find SwipeRefreshLayout in the hierarchy
|
||||||
private val refreshLayout by lazy { view?.findParentById(R.id.refreshLayout) }
|
private val refreshLayout by lazy { view?.findParentById(R.id.refreshLayout) }
|
||||||
// the day ScrollView
|
// the day ScrollView
|
||||||
@ -167,6 +166,8 @@ class TimetableDayFragment : Fragment(), CoroutineScope {
|
|||||||
// Inflate a label view for each hour the day view will display
|
// Inflate a label view for each hour the day view will display
|
||||||
val hourLabelViews = ArrayList<View>()
|
val hourLabelViews = ArrayList<View>()
|
||||||
for (i in dayView.startHour..dayView.endHour) {
|
for (i in dayView.startHour..dayView.endHour) {
|
||||||
|
if (!isAdded)
|
||||||
|
continue
|
||||||
val hourLabelView = layoutInflater.inflate(R.layout.timetable_hour_label, dayView, false) as TextView
|
val hourLabelView = layoutInflater.inflate(R.layout.timetable_hour_label, dayView, false) as TextView
|
||||||
hourLabelView.text = "$i:00"
|
hourLabelView.text = "$i:00"
|
||||||
hourLabelViews.add(hourLabelView)
|
hourLabelViews.add(hourLabelView)
|
||||||
@ -277,95 +278,7 @@ class TimetableDayFragment : Fragment(), CoroutineScope {
|
|||||||
lb.unread = lesson.type != Lesson.TYPE_NORMAL && !lesson.seen
|
lb.unread = lesson.type != Lesson.TYPE_NORMAL && !lesson.seen
|
||||||
|
|
||||||
//lb.subjectName.typeface = Typeface.create("sans-serif-light", Typeface.BOLD)
|
//lb.subjectName.typeface = Typeface.create("sans-serif-light", Typeface.BOLD)
|
||||||
when (lesson.type) {
|
lb.annotationVisible = utils.getAnnotation(activity, lesson, lb.annotation)
|
||||||
Lesson.TYPE_NORMAL -> {
|
|
||||||
lb.annotationVisible = false
|
|
||||||
}
|
|
||||||
Lesson.TYPE_CANCELLED -> {
|
|
||||||
lb.annotationVisible = true
|
|
||||||
lb.annotation.setText(R.string.timetable_lesson_cancelled)
|
|
||||||
lb.annotation.background.colorFilter = PorterDuffColorFilter(
|
|
||||||
getColorFromAttr(activity, R.attr.timetable_lesson_cancelled_color),
|
|
||||||
PorterDuff.Mode.SRC_ATOP
|
|
||||||
)
|
|
||||||
//lb.subjectName.typeface = Typeface.DEFAULT
|
|
||||||
}
|
|
||||||
Lesson.TYPE_CHANGE -> {
|
|
||||||
lb.annotationVisible = true
|
|
||||||
when {
|
|
||||||
lesson.subjectId != lesson.oldSubjectId && lesson.teacherId != lesson.oldTeacherId
|
|
||||||
&& lesson.oldSubjectName != null && lesson.oldTeacherName != null ->
|
|
||||||
lb.annotation.setText(
|
|
||||||
R.string.timetable_lesson_change_format,
|
|
||||||
"${lesson.oldSubjectName ?: "?"}, ${lesson.oldTeacherName ?: "?"}"
|
|
||||||
)
|
|
||||||
|
|
||||||
lesson.subjectId != lesson.oldSubjectId && lesson.oldSubjectName != null ->
|
|
||||||
lb.annotation.setText(
|
|
||||||
R.string.timetable_lesson_change_format,
|
|
||||||
lesson.oldSubjectName ?: "?"
|
|
||||||
)
|
|
||||||
|
|
||||||
lesson.teacherId != lesson.oldTeacherId && lesson.oldTeacherName != null ->
|
|
||||||
lb.annotation.setText(
|
|
||||||
R.string.timetable_lesson_change_format,
|
|
||||||
lesson.oldTeacherName ?: "?"
|
|
||||||
)
|
|
||||||
else -> lb.annotation.setText(R.string.timetable_lesson_change)
|
|
||||||
}
|
|
||||||
|
|
||||||
lb.annotation.background.colorFilter = PorterDuffColorFilter(
|
|
||||||
getColorFromAttr(activity, R.attr.timetable_lesson_change_color),
|
|
||||||
PorterDuff.Mode.SRC_ATOP
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Lesson.TYPE_SHIFTED_SOURCE -> {
|
|
||||||
lb.annotationVisible = true
|
|
||||||
when {
|
|
||||||
lesson.date != lesson.oldDate && lesson.date != null ->
|
|
||||||
lb.annotation.setText(
|
|
||||||
R.string.timetable_lesson_shifted_other_day,
|
|
||||||
lesson.date?.stringY_m_d ?: "?",
|
|
||||||
lesson.startTime?.stringHM ?: ""
|
|
||||||
)
|
|
||||||
|
|
||||||
lesson.startTime != lesson.oldStartTime && lesson.startTime != null ->
|
|
||||||
lb.annotation.setText(
|
|
||||||
R.string.timetable_lesson_shifted_same_day,
|
|
||||||
lesson.startTime?.stringHM ?: "?"
|
|
||||||
)
|
|
||||||
|
|
||||||
else -> lb.annotation.setText(R.string.timetable_lesson_shifted)
|
|
||||||
}
|
|
||||||
|
|
||||||
lb.annotation.background.setTintColor(R.attr.timetable_lesson_shifted_source_color.resolveAttr(activity))
|
|
||||||
}
|
|
||||||
Lesson.TYPE_SHIFTED_TARGET -> {
|
|
||||||
lb.annotationVisible = true
|
|
||||||
when {
|
|
||||||
lesson.date != lesson.oldDate && lesson.oldDate != null ->
|
|
||||||
lb.annotation.setText(
|
|
||||||
R.string.timetable_lesson_shifted_from_other_day,
|
|
||||||
lesson.oldDate?.stringY_m_d ?: "?",
|
|
||||||
lesson.oldStartTime?.stringHM ?: ""
|
|
||||||
)
|
|
||||||
|
|
||||||
lesson.startTime != lesson.oldStartTime && lesson.oldStartTime != null ->
|
|
||||||
lb.annotation.setText(
|
|
||||||
R.string.timetable_lesson_shifted_from_same_day,
|
|
||||||
lesson.oldStartTime?.stringHM ?: "?"
|
|
||||||
)
|
|
||||||
|
|
||||||
else -> lb.annotation.setText(R.string.timetable_lesson_shifted_from)
|
|
||||||
}
|
|
||||||
|
|
||||||
lb.annotation.background.colorFilter = PorterDuffColorFilter(
|
|
||||||
getColorFromAttr(activity, R.attr.timetable_lesson_shifted_target_color),
|
|
||||||
PorterDuff.Mode.SRC_ATOP
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// The day view needs the event time ranges in the start minute/end minute format,
|
// The day view needs the event time ranges in the start minute/end minute format,
|
||||||
// so calculate those here
|
// so calculate those here
|
||||||
|
@ -0,0 +1,109 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Kuba Szczodrzyński 2020-2-16.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package pl.szczodrzynski.edziennik.ui.modules.timetable
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.graphics.PorterDuff
|
||||||
|
import android.graphics.PorterDuffColorFilter
|
||||||
|
import android.widget.TextView
|
||||||
|
import pl.szczodrzynski.edziennik.R
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.entity.Lesson
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.full.LessonFull
|
||||||
|
import pl.szczodrzynski.edziennik.resolveAttr
|
||||||
|
import pl.szczodrzynski.edziennik.setText
|
||||||
|
import pl.szczodrzynski.edziennik.setTintColor
|
||||||
|
import pl.szczodrzynski.navlib.getColorFromAttr
|
||||||
|
|
||||||
|
class TimetableUtils {
|
||||||
|
fun getAnnotation(context: Context, lesson: LessonFull, annotation: TextView): Boolean {
|
||||||
|
var annotationVisible = false
|
||||||
|
when (lesson.type) {
|
||||||
|
Lesson.TYPE_CANCELLED -> {
|
||||||
|
annotationVisible = true
|
||||||
|
annotation.setText(R.string.timetable_lesson_cancelled)
|
||||||
|
annotation.background.colorFilter = PorterDuffColorFilter(
|
||||||
|
getColorFromAttr(context, R.attr.timetable_lesson_cancelled_color),
|
||||||
|
PorterDuff.Mode.SRC_ATOP
|
||||||
|
)
|
||||||
|
//lb.subjectName.typeface = Typeface.DEFAULT
|
||||||
|
}
|
||||||
|
Lesson.TYPE_CHANGE -> {
|
||||||
|
annotationVisible = true
|
||||||
|
when {
|
||||||
|
lesson.subjectId != lesson.oldSubjectId && lesson.teacherId != lesson.oldTeacherId
|
||||||
|
&& lesson.oldSubjectName != null && lesson.oldTeacherName != null ->
|
||||||
|
annotation.setText(
|
||||||
|
R.string.timetable_lesson_change_format,
|
||||||
|
"${lesson.oldSubjectName ?: "?"}, ${lesson.oldTeacherName ?: "?"}"
|
||||||
|
)
|
||||||
|
|
||||||
|
lesson.subjectId != lesson.oldSubjectId && lesson.oldSubjectName != null ->
|
||||||
|
annotation.setText(
|
||||||
|
R.string.timetable_lesson_change_format,
|
||||||
|
lesson.oldSubjectName ?: "?"
|
||||||
|
)
|
||||||
|
|
||||||
|
lesson.teacherId != lesson.oldTeacherId && lesson.oldTeacherName != null ->
|
||||||
|
annotation.setText(
|
||||||
|
R.string.timetable_lesson_change_format,
|
||||||
|
lesson.oldTeacherName ?: "?"
|
||||||
|
)
|
||||||
|
else -> annotation.setText(R.string.timetable_lesson_change)
|
||||||
|
}
|
||||||
|
|
||||||
|
annotation.background.colorFilter = PorterDuffColorFilter(
|
||||||
|
getColorFromAttr(context, R.attr.timetable_lesson_change_color),
|
||||||
|
PorterDuff.Mode.SRC_ATOP
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Lesson.TYPE_SHIFTED_SOURCE -> {
|
||||||
|
annotationVisible = true
|
||||||
|
when {
|
||||||
|
lesson.date != lesson.oldDate && lesson.date != null ->
|
||||||
|
annotation.setText(
|
||||||
|
R.string.timetable_lesson_shifted_other_day,
|
||||||
|
lesson.date?.stringY_m_d ?: "?",
|
||||||
|
lesson.startTime?.stringHM ?: ""
|
||||||
|
)
|
||||||
|
|
||||||
|
lesson.startTime != lesson.oldStartTime && lesson.startTime != null ->
|
||||||
|
annotation.setText(
|
||||||
|
R.string.timetable_lesson_shifted_same_day,
|
||||||
|
lesson.startTime?.stringHM ?: "?"
|
||||||
|
)
|
||||||
|
|
||||||
|
else -> annotation.setText(R.string.timetable_lesson_shifted)
|
||||||
|
}
|
||||||
|
|
||||||
|
annotation.background.setTintColor(R.attr.timetable_lesson_shifted_source_color.resolveAttr(context))
|
||||||
|
}
|
||||||
|
Lesson.TYPE_SHIFTED_TARGET -> {
|
||||||
|
annotationVisible = true
|
||||||
|
when {
|
||||||
|
lesson.date != lesson.oldDate && lesson.oldDate != null ->
|
||||||
|
annotation.setText(
|
||||||
|
R.string.timetable_lesson_shifted_from_other_day,
|
||||||
|
lesson.oldDate?.stringY_m_d ?: "?",
|
||||||
|
lesson.oldStartTime?.stringHM ?: ""
|
||||||
|
)
|
||||||
|
|
||||||
|
lesson.startTime != lesson.oldStartTime && lesson.oldStartTime != null ->
|
||||||
|
annotation.setText(
|
||||||
|
R.string.timetable_lesson_shifted_from_same_day,
|
||||||
|
lesson.oldStartTime?.stringHM ?: "?"
|
||||||
|
)
|
||||||
|
|
||||||
|
else -> annotation.setText(R.string.timetable_lesson_shifted_from)
|
||||||
|
}
|
||||||
|
|
||||||
|
annotation.background.colorFilter = PorterDuffColorFilter(
|
||||||
|
getColorFromAttr(context, R.attr.timetable_lesson_shifted_target_color),
|
||||||
|
PorterDuff.Mode.SRC_ATOP
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return annotationVisible
|
||||||
|
}
|
||||||
|
}
|
@ -9,6 +9,9 @@
|
|||||||
<data>
|
<data>
|
||||||
<import type="android.view.View"/>
|
<import type="android.view.View"/>
|
||||||
<import type="pl.szczodrzynski.edziennik.App"/>
|
<import type="pl.szczodrzynski.edziennik.App"/>
|
||||||
|
<variable
|
||||||
|
name="annotationVisible"
|
||||||
|
type="boolean"/>
|
||||||
<variable
|
<variable
|
||||||
name="lesson"
|
name="lesson"
|
||||||
type="pl.szczodrzynski.edziennik.data.db.full.LessonFull" />
|
type="pl.szczodrzynski.edziennik.data.db.full.LessonFull" />
|
||||||
@ -32,6 +35,22 @@
|
|||||||
android:paddingTop="24dp"
|
android:paddingTop="24dp"
|
||||||
android:paddingRight="16dp">
|
android:paddingRight="16dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/annotation"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="@drawable/timetable_lesson_annotation"
|
||||||
|
android:fontFamily="sans-serif-condensed"
|
||||||
|
android:paddingStart="8dp"
|
||||||
|
android:paddingEnd="8dp"
|
||||||
|
android:text="@string/timetable_lesson_cancelled"
|
||||||
|
android:textColor="#000"
|
||||||
|
android:textSize="12sp"
|
||||||
|
android:textStyle="italic"
|
||||||
|
android:visibility="@{annotationVisible ? View.VISIBLE : View.GONE}"
|
||||||
|
tools:text="Zastępstwo: zamiast lekcji język polski z Adam Dodatkowy"
|
||||||
|
tools:visibility="visible" />
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user