[UI/Timetable] Add showing event indicators on lessons.

This commit is contained in:
Kuba Szczodrzyński 2019-12-02 21:25:18 +01:00
parent 3e97572100
commit 6a161b3c97
3 changed files with 103 additions and 35 deletions

View File

@ -5,6 +5,8 @@ import android.app.Activity
import android.content.Context
import android.content.pm.PackageManager
import android.content.res.Resources
import android.graphics.PorterDuff
import android.graphics.PorterDuffColorFilter
import android.graphics.Typeface
import android.graphics.drawable.Drawable
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.teams.Team
import pl.szczodrzynski.edziennik.utils.models.Time
import pl.szczodrzynski.navlib.getColorFromAttr
import pl.szczodrzynski.navlib.getColorFromRes
import java.text.SimpleDateFormat
import java.util.*
@ -595,3 +598,11 @@ inline fun <reified T> Any?.instanceOfOrNull(): T? {
else -> null
}
}
fun Drawable.setTintColor(color: Int): Drawable {
colorFilter = PorterDuffColorFilter(
color,
PorterDuff.Mode.SRC_ATOP
)
return this
}

View File

@ -15,13 +15,12 @@ import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import com.linkedin.android.tachyon.DayView
import com.linkedin.android.tachyon.DayViewConfig
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.*
import pl.szczodrzynski.edziennik.*
import pl.szczodrzynski.edziennik.MainActivity.Companion.DRAWER_ITEM_TIMETABLE
import pl.szczodrzynski.edziennik.api.v2.LOGIN_TYPE_LIBRUS
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.LessonFull
import pl.szczodrzynski.edziennik.databinding.TimetableLessonBinding
@ -109,11 +108,16 @@ class TimetableDayFragment : Fragment(), CoroutineScope {
// observe lesson database
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
if (lessons.isEmpty()) {
inflater.inflate(R.layout.timetable_no_timetable, view as FrameLayout) { view, _, parent ->
@ -166,10 +170,10 @@ class TimetableDayFragment : Fragment(), CoroutineScope {
}
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)
return
@ -206,6 +210,26 @@ class TimetableDayFragment : Fragment(), CoroutineScope {
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)
@ -311,10 +335,7 @@ class TimetableDayFragment : Fragment(), CoroutineScope {
else -> lb.annotation.setText(R.string.timetable_lesson_shifted)
}
lb.annotation.background.colorFilter = PorterDuffColorFilter(
getColorFromAttr(activity, R.attr.timetable_lesson_shifted_source_color),
PorterDuff.Mode.SRC_ATOP
)
lb.annotation.background.setTintColor(R.attr.timetable_lesson_shifted_source_color.resolveAttr(activity))
}
Lesson.TYPE_SHIFTED_TARGET -> {
lb.annotationVisible = true

View File

@ -73,16 +73,16 @@
tools:maxLines="2"
tools:text="pracownia urządzeń techniki komputerowej" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<View
android:layout_width="8dp"
android:layout_height="8dp"
android:layout_gravity="center_vertical"
android:paddingStart="8dp"
android:paddingLeft="8dp"
android:paddingEnd="8dp"
android:paddingRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:visibility="@{unread ? View.VISIBLE : View.GONE}"
app:srcCompat="@drawable/unread_red_circle" />
android:background="@drawable/unread_red_circle" />
<ImageView
android:id="@+id/attendanceIcon"
@ -125,29 +125,65 @@
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="bottom"
android:orientation="vertical"
android:orientation="horizontal"
android:paddingStart="8dp"
android:paddingEnd="8dp">
<TextView
android:id="@+id/detailsFirst"
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true"
tools:text="8:10 - 8:55 • 015 językowa → 016 językowa" />
android:orientation="vertical">
<TextView
android:id="@+id/detailsSecond"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="middle"
android:singleLine="true"
android:textAppearance="@style/NavView.TextView.Helper"
android:textSize="12sp"
tools:text="Paweł Informatyczny • 2b3T n1" />
<TextView
android:id="@+id/detailsFirst"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true"
tools:text="8:10 - 8:55 • 015 językowa → 016 językowa" />
<TextView
android:id="@+id/detailsSecond"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="middle"
android:singleLine="true"
android:textAppearance="@style/NavView.TextView.Helper"
android:textSize="12sp"
tools:text="Paweł Informatyczny • 2b3T n1" />
</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>
</FrameLayout>
</layout>