forked from github/szkolny
[UI/Timetable] Add showing event indicators on lessons.
This commit is contained in:
parent
3e97572100
commit
6a161b3c97
@ -5,6 +5,8 @@ import android.app.Activity
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.content.res.Resources
|
import android.content.res.Resources
|
||||||
|
import android.graphics.PorterDuff
|
||||||
|
import android.graphics.PorterDuffColorFilter
|
||||||
import android.graphics.Typeface
|
import android.graphics.Typeface
|
||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
@ -36,6 +38,7 @@ import pl.szczodrzynski.edziennik.data.db.modules.profiles.Profile
|
|||||||
import pl.szczodrzynski.edziennik.data.db.modules.teachers.Teacher
|
import pl.szczodrzynski.edziennik.data.db.modules.teachers.Teacher
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.teams.Team
|
import pl.szczodrzynski.edziennik.data.db.modules.teams.Team
|
||||||
import pl.szczodrzynski.edziennik.utils.models.Time
|
import pl.szczodrzynski.edziennik.utils.models.Time
|
||||||
|
import pl.szczodrzynski.navlib.getColorFromAttr
|
||||||
import pl.szczodrzynski.navlib.getColorFromRes
|
import pl.szczodrzynski.navlib.getColorFromRes
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
@ -595,3 +598,11 @@ inline fun <reified T> Any?.instanceOfOrNull(): T? {
|
|||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Drawable.setTintColor(color: Int): Drawable {
|
||||||
|
colorFilter = PorterDuffColorFilter(
|
||||||
|
color,
|
||||||
|
PorterDuff.Mode.SRC_ATOP
|
||||||
|
)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
@ -15,13 +15,12 @@ import androidx.fragment.app.Fragment
|
|||||||
import androidx.lifecycle.Observer
|
import androidx.lifecycle.Observer
|
||||||
import com.linkedin.android.tachyon.DayView
|
import com.linkedin.android.tachyon.DayView
|
||||||
import com.linkedin.android.tachyon.DayViewConfig
|
import com.linkedin.android.tachyon.DayViewConfig
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.*
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.Job
|
|
||||||
import pl.szczodrzynski.edziennik.*
|
import pl.szczodrzynski.edziennik.*
|
||||||
import pl.szczodrzynski.edziennik.MainActivity.Companion.DRAWER_ITEM_TIMETABLE
|
import pl.szczodrzynski.edziennik.MainActivity.Companion.DRAWER_ITEM_TIMETABLE
|
||||||
import pl.szczodrzynski.edziennik.api.v2.LOGIN_TYPE_LIBRUS
|
import pl.szczodrzynski.edziennik.api.v2.LOGIN_TYPE_LIBRUS
|
||||||
import pl.szczodrzynski.edziennik.api.v2.events.task.EdziennikTask
|
import pl.szczodrzynski.edziennik.api.v2.events.task.EdziennikTask
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.events.EventFull
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.timetable.Lesson
|
import pl.szczodrzynski.edziennik.data.db.modules.timetable.Lesson
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.timetable.LessonFull
|
import pl.szczodrzynski.edziennik.data.db.modules.timetable.LessonFull
|
||||||
import pl.szczodrzynski.edziennik.databinding.TimetableLessonBinding
|
import pl.szczodrzynski.edziennik.databinding.TimetableLessonBinding
|
||||||
@ -109,11 +108,16 @@ class TimetableDayFragment : Fragment(), CoroutineScope {
|
|||||||
|
|
||||||
// observe lesson database
|
// observe lesson database
|
||||||
app.db.timetableDao().getForDate(App.profileId, date).observe(this, Observer { lessons ->
|
app.db.timetableDao().getForDate(App.profileId, date).observe(this, Observer { lessons ->
|
||||||
processLessonList(lessons)
|
launch {
|
||||||
|
val events = withContext(Dispatchers.Default) {
|
||||||
|
app.db.eventDao().getAllByDateNow(App.profileId, date)
|
||||||
|
}
|
||||||
|
processLessonList(lessons, events)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun processLessonList(lessons: List<LessonFull>) {
|
private fun processLessonList(lessons: List<LessonFull>, events: List<EventFull>) {
|
||||||
// no lessons - timetable not downloaded yet
|
// no lessons - timetable not downloaded yet
|
||||||
if (lessons.isEmpty()) {
|
if (lessons.isEmpty()) {
|
||||||
inflater.inflate(R.layout.timetable_no_timetable, view as FrameLayout) { view, _, parent ->
|
inflater.inflate(R.layout.timetable_no_timetable, view as FrameLayout) { view, _, parent ->
|
||||||
@ -166,10 +170,10 @@ class TimetableDayFragment : Fragment(), CoroutineScope {
|
|||||||
}
|
}
|
||||||
dayView.setHourLabelViews(hourLabelViews)
|
dayView.setHourLabelViews(hourLabelViews)
|
||||||
|
|
||||||
buildLessonViews(lessons)
|
buildLessonViews(lessons, events)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun buildLessonViews(lessons: List<LessonFull>) {
|
private fun buildLessonViews(lessons: List<LessonFull>, events: List<EventFull>) {
|
||||||
if (!isAdded)
|
if (!isAdded)
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -206,6 +210,26 @@ class TimetableDayFragment : Fragment(), CoroutineScope {
|
|||||||
LessonDetailsDialog(activity, it.tag as LessonFull)
|
LessonDetailsDialog(activity, it.tag as LessonFull)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val eventList = events.filter { it.startTime != null && it.startTime == lesson.displayStartTime }.take(3)
|
||||||
|
eventList.getOrNull(0).let {
|
||||||
|
lb.event1.visibility = if (it == null) View.GONE else View.VISIBLE
|
||||||
|
lb.event1.background = it?.let {
|
||||||
|
R.drawable.bg_circle.resolveDrawable(activity).setTintColor(it.getColor())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
eventList.getOrNull(1).let {
|
||||||
|
lb.event2.visibility = if (it == null) View.GONE else View.VISIBLE
|
||||||
|
lb.event2.background = it?.let {
|
||||||
|
R.drawable.bg_circle.resolveDrawable(activity).setTintColor(it.getColor())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
eventList.getOrNull(2).let {
|
||||||
|
lb.event3.visibility = if (it == null) View.GONE else View.VISIBLE
|
||||||
|
lb.event3.background = it?.let {
|
||||||
|
R.drawable.bg_circle.resolveDrawable(activity).setTintColor(it.getColor())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
val timeRange = "${startTime.stringHM} - ${endTime.stringHM}".asColoredSpannable(colorSecondary)
|
val timeRange = "${startTime.stringHM} - ${endTime.stringHM}".asColoredSpannable(colorSecondary)
|
||||||
|
|
||||||
@ -311,10 +335,7 @@ class TimetableDayFragment : Fragment(), CoroutineScope {
|
|||||||
else -> lb.annotation.setText(R.string.timetable_lesson_shifted)
|
else -> lb.annotation.setText(R.string.timetable_lesson_shifted)
|
||||||
}
|
}
|
||||||
|
|
||||||
lb.annotation.background.colorFilter = PorterDuffColorFilter(
|
lb.annotation.background.setTintColor(R.attr.timetable_lesson_shifted_source_color.resolveAttr(activity))
|
||||||
getColorFromAttr(activity, R.attr.timetable_lesson_shifted_source_color),
|
|
||||||
PorterDuff.Mode.SRC_ATOP
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
Lesson.TYPE_SHIFTED_TARGET -> {
|
Lesson.TYPE_SHIFTED_TARGET -> {
|
||||||
lb.annotationVisible = true
|
lb.annotationVisible = true
|
||||||
|
@ -73,16 +73,16 @@
|
|||||||
tools:maxLines="2"
|
tools:maxLines="2"
|
||||||
tools:text="pracownia urządzeń techniki komputerowej" />
|
tools:text="pracownia urządzeń techniki komputerowej" />
|
||||||
|
|
||||||
<ImageView
|
<View
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="8dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="8dp"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
android:paddingStart="8dp"
|
android:layout_marginStart="8dp"
|
||||||
android:paddingLeft="8dp"
|
android:layout_marginLeft="8dp"
|
||||||
android:paddingEnd="8dp"
|
android:layout_marginEnd="8dp"
|
||||||
android:paddingRight="8dp"
|
android:layout_marginRight="8dp"
|
||||||
android:visibility="@{unread ? View.VISIBLE : View.GONE}"
|
android:visibility="@{unread ? View.VISIBLE : View.GONE}"
|
||||||
app:srcCompat="@drawable/unread_red_circle" />
|
android:background="@drawable/unread_red_circle" />
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/attendanceIcon"
|
android:id="@+id/attendanceIcon"
|
||||||
@ -125,10 +125,15 @@
|
|||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:gravity="bottom"
|
android:gravity="bottom"
|
||||||
android:orientation="vertical"
|
android:orientation="horizontal"
|
||||||
android:paddingStart="8dp"
|
android:paddingStart="8dp"
|
||||||
android:paddingEnd="8dp">
|
android:paddingEnd="8dp">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/detailsFirst"
|
android:id="@+id/detailsFirst"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
@ -148,6 +153,37 @@
|
|||||||
tools:text="Paweł Informatyczny • 2b3T n1" />
|
tools:text="Paweł Informatyczny • 2b3T n1" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:gravity="end|bottom"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:id="@+id/event3"
|
||||||
|
android:layout_width="10dp"
|
||||||
|
android:layout_height="10dp"
|
||||||
|
android:layout_marginLeft="4dp"
|
||||||
|
android:layout_marginStart="4dp"
|
||||||
|
tools:background="@drawable/unread_red_circle" />
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:id="@+id/event2"
|
||||||
|
android:layout_width="10dp"
|
||||||
|
android:layout_height="10dp"
|
||||||
|
android:layout_marginLeft="4dp"
|
||||||
|
android:layout_marginStart="4dp"
|
||||||
|
tools:background="@drawable/unread_red_circle" />
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:id="@+id/event1"
|
||||||
|
android:layout_width="10dp"
|
||||||
|
android:layout_height="10dp"
|
||||||
|
android:layout_marginLeft="4dp"
|
||||||
|
android:layout_marginStart="4dp"
|
||||||
|
tools:background="@drawable/unread_red_circle" />
|
||||||
|
</LinearLayout>
|
||||||
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
</layout>
|
</layout>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user