[Timetable] Add lesson details dialog.

This commit is contained in:
Kuba Szczodrzyński 2019-11-11 23:59:45 +01:00
parent 810976d976
commit 74db524db6
8 changed files with 448 additions and 23 deletions

View File

@ -6,8 +6,9 @@
</configurations>
</component>
<component name="EntryPointsManager">
<list size="1">
<item index="0" class="java.lang.String" itemvalue="org.greenrobot.eventbus.Subscribe" />
<list size="2">
<item index="0" class="java.lang.String" itemvalue="androidx.databinding.BindingAdapter" />
<item index="1" class="java.lang.String" itemvalue="org.greenrobot.eventbus.Subscribe" />
</list>
</component>
<component name="NullableNotNullManager">

View File

@ -0,0 +1,21 @@
/*
* Copyright (c) Kuba Szczodrzyński 2019-11-11.
*/
package pl.szczodrzynski.edziennik;
import android.graphics.Paint;
import android.widget.TextView;
import androidx.databinding.BindingAdapter;
public class Binding {
@BindingAdapter("strikeThrough")
public static void strikeThrough(TextView textView, Boolean strikeThrough) {
if (strikeThrough) {
textView.setPaintFlags(textView.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
} else {
textView.setPaintFlags(textView.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
}
}
}

View File

@ -345,7 +345,7 @@ class MainActivity : AppCompatActivity() {
if (!profileListEmpty) {
handleIntent(intent?.extras)
}
app.db.profileDao().getAllFull().observe(this, Observer { profiles ->
app.db.profileDao().allFull.observe(this, Observer { profiles ->
// TODO fix weird -1 profiles ???
profiles.removeAll { it.id < 0 }
drawer.setProfileList(profiles)
@ -362,7 +362,7 @@ class MainActivity : AppCompatActivity() {
if (app.profile != null)
setDrawerItems()
app.db.metadataDao().getUnreadCounts().observe(this, Observer { unreadCounters ->
app.db.metadataDao().unreadCounts.observe(this, Observer { unreadCounters ->
unreadCounters.map {
it.type = it.thingType
}
@ -701,7 +701,8 @@ class MainActivity : AppCompatActivity() {
}
intentTargetId != -1 -> {
drawer.currentProfile = app.profile.id
loadTarget(intentTargetId, extras)
if (navTargetId != intentTargetId)
loadTarget(intentTargetId, extras)
}
else -> {
drawer.currentProfile = app.profile.id

View File

@ -0,0 +1,139 @@
/*
* Copyright (c) Kuba Szczodrzyński 2019-11-11.
*/
package pl.szczodrzynski.edziennik.ui.dialogs.timetable
import android.app.Activity
import android.content.Intent
import android.view.View
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import pl.szczodrzynski.edziennik.App
import pl.szczodrzynski.edziennik.R
import pl.szczodrzynski.edziennik.data.db.modules.timetable.Lesson
import pl.szczodrzynski.edziennik.data.db.modules.timetable.LessonFull
import pl.szczodrzynski.edziennik.databinding.DialogLessonDetailsBinding
import pl.szczodrzynski.edziennik.setText
import pl.szczodrzynski.edziennik.ui.dialogs.event.EventManualDialog
import pl.szczodrzynski.edziennik.ui.modules.timetable.v2.TimetableFragment
import pl.szczodrzynski.edziennik.utils.models.Date
import pl.szczodrzynski.edziennik.utils.models.Week
class LessonDetailsDialog(
val activity: Activity,
val lesson: LessonFull
) {
companion object {
private const val TAG = "LessonDetailsDialog"
}
init { run {
val b = DialogLessonDetailsBinding.inflate(activity.layoutInflater)
val dialog = MaterialAlertDialogBuilder(activity)
.setView(b.root)
.setPositiveButton(R.string.close) { dialog, _ ->
dialog.dismiss()
}
.setNeutralButton(R.string.add) { dialog, _ ->
dialog.dismiss()
MaterialAlertDialogBuilder(activity)
.setItems(R.array.main_menu_add_options) { dialog2, which ->
dialog2.dismiss()
EventManualDialog(activity, lesson.profileId)
.show(
activity.application as App,
null,
lesson.displayDate,
lesson.displayStartTime,
when (which) {
1 -> EventManualDialog.DIALOG_HOMEWORK
else -> EventManualDialog.DIALOG_EVENT
}
)
}
.setNegativeButton(R.string.cancel) { dialog2, _ -> dialog2.dismiss() }
.show()
}
.show()
b.lesson = lesson
val lessonDate = lesson.displayDate ?: return@run
b.lessonDate.text = Week.getFullDayName(lessonDate.weekDay) + ", " + lessonDate.formattedString
if (lesson.type >= Lesson.TYPE_SHIFTED_SOURCE) {
b.shiftedLayout.visibility = View.VISIBLE
var otherLessonDate: Date? = null
when (lesson.type) {
Lesson.TYPE_SHIFTED_SOURCE -> {
otherLessonDate = lesson.date
when {
lesson.date != lesson.oldDate -> b.shiftedText.setText(
R.string.timetable_lesson_shifted_other_day,
lesson.date?.stringY_m_d ?: "?",
lesson.startTime?.stringHM ?: "?"
)
lesson.startTime != lesson.oldStartTime -> b.shiftedText.setText(
R.string.timetable_lesson_shifted_same_day,
lesson.startTime?.stringHM ?: "?"
)
else -> b.shiftedText.setText(R.string.timetable_lesson_shifted)
}
}
Lesson.TYPE_SHIFTED_TARGET -> {
otherLessonDate = lesson.oldDate
when {
lesson.date != lesson.oldDate -> b.shiftedText.setText(
R.string.timetable_lesson_shifted_from_other_day,
lesson.oldDate?.stringY_m_d ?: "?",
lesson.oldStartTime?.stringHM ?: "?"
)
lesson.startTime != lesson.oldStartTime -> b.shiftedText.setText(
R.string.timetable_lesson_shifted_from_same_day,
lesson.oldStartTime?.stringHM ?: "?"
)
else -> b.shiftedText.setText(R.string.timetable_lesson_shifted_from)
}
}
}
b.shiftedGoTo.setOnClickListener {
dialog.dismiss()
val dateStr = otherLessonDate?.stringY_m_d ?: return@setOnClickListener
val intent = Intent(TimetableFragment.ACTION_SCROLL_TO_DATE).apply {
putExtra("date", dateStr)
}
activity.sendBroadcast(intent)
}
}
else {
b.shiftedLayout.visibility = View.GONE
}
if (lesson.type < Lesson.TYPE_SHIFTED_SOURCE && lesson.oldSubjectId != null && lesson.subjectId != lesson.oldSubjectId) {
b.oldSubjectName = lesson.oldSubjectName
}
if (lesson.type != Lesson.TYPE_CANCELLED && lesson.subjectId != null) {
b.subjectName = lesson.subjectName
}
if (lesson.type < Lesson.TYPE_SHIFTED_SOURCE && lesson.oldTeacherId != null && lesson.teacherId != lesson.oldTeacherId) {
b.oldTeacherName = lesson.oldTeacherName
}
if (lesson.type != Lesson.TYPE_CANCELLED && lesson.teacherId != null) {
b.teacherName = lesson.teacherName
}
if (lesson.oldClassroom != null && lesson.classroom != lesson.oldClassroom) {
b.oldClassroom = lesson.oldClassroom
}
if (lesson.type != Lesson.TYPE_CANCELLED && lesson.classroom != null) {
b.classroom = lesson.classroom
}
if (lesson.type < Lesson.TYPE_SHIFTED_SOURCE && lesson.oldTeamId != null && lesson.teamId != lesson.oldTeamId) {
b.oldTeamName = lesson.oldTeamName
}
if (lesson.type != Lesson.TYPE_CANCELLED && lesson.teamId != null) {
b.teamName = lesson.teamName
}
}}
}

View File

@ -1,5 +1,9 @@
package pl.szczodrzynski.edziennik.ui.modules.timetable.v2
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
@ -18,12 +22,14 @@ import pl.szczodrzynski.edziennik.utils.models.Date
class TimetableFragment : Fragment() {
companion object {
private const val TAG = "TimetableFragment"
const val ACTION_SCROLL_TO_DATE = "pl.szczodrzynski.edziennik.timetable.SCROLL_TO_DATE"
}
private lateinit var app: App
private lateinit var activity: MainActivity
private lateinit var b: FragmentTimetableV2Binding
private var fabShown = false
private val items = mutableListOf<Date>()
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
activity = (getActivity() as MainActivity?) ?: return null
@ -38,6 +44,24 @@ class TimetableFragment : Fragment() {
return b.root
}
private val broadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, i: Intent) {
if (!isAdded)
return
val dateStr = i.extras?.getString("date", null) ?: return
val date = Date.fromY_m_d(dateStr)
b.viewPager.setCurrentItem(items.indexOf(date), true)
}
}
override fun onResume() {
super.onResume()
activity.registerReceiver(broadcastReceiver, IntentFilter(ACTION_SCROLL_TO_DATE))
}
override fun onPause() {
super.onPause()
activity.unregisterReceiver(broadcastReceiver)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
// TODO check if app, activity, b can be null
if (app.profile == null || !isAdded)
@ -51,7 +75,7 @@ class TimetableFragment : Fragment() {
b.timetableLayout.visibility = View.VISIBLE
b.timetableNotPublicLayout.visibility = View.GONE
val items = mutableListOf<Date>()
items.clear()
val monthDayCount = listOf(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
@ -99,7 +123,7 @@ class TimetableFragment : Fragment() {
b.tabLayout.setCurrentItem(items.indexOfFirst { it.value == today }, false)
//activity.navView.bottomBar.fabEnable = true
activity.navView.bottomBar.fabExtendedText = getString(R.string.timetable_today)
activity.navView.bottomBar.fabExtendedText = getString(pl.szczodrzynski.edziennik.R.string.timetable_today)
activity.navView.bottomBar.fabIcon = CommunityMaterial.Icon.cmd_calendar_today
activity.navView.setFabOnClickListener(View.OnClickListener {
b.tabLayout.setCurrentItem(items.indexOfFirst { it.value == today }, true)

View File

@ -19,6 +19,7 @@ import pl.szczodrzynski.edziennik.data.db.modules.timetable.Lesson
import pl.szczodrzynski.edziennik.data.db.modules.timetable.LessonFull
import pl.szczodrzynski.edziennik.databinding.FragmentTimetableV2DayBinding
import pl.szczodrzynski.edziennik.databinding.TimetableLessonBinding
import pl.szczodrzynski.edziennik.ui.dialogs.timetable.LessonDetailsDialog
import pl.szczodrzynski.edziennik.utils.models.Date
import pl.szczodrzynski.navlib.getColorFromAttr
import java.util.*
@ -133,6 +134,8 @@ class TimetableDayFragment(val date: Date) : Fragment() {
eventView.setOnClickListener {
Log.d(TAG, "Clicked ${it.tag}")
if (isAdded && it.tag is LessonFull)
LessonDetailsDialog(activity, it.tag as LessonFull)
}
@ -221,21 +224,17 @@ class TimetableDayFragment(val date: Date) : Fragment() {
}
Lesson.TYPE_SHIFTED_SOURCE -> {
lb.annotationVisible = true
if (lesson.date != lesson.oldDate) {
lb.annotation.setText(
when {
lesson.date != lesson.oldDate -> lb.annotation.setText(
R.string.timetable_lesson_shifted_other_day,
lesson.date?.stringY_m_d ?: "?",
lesson.startTime?.stringHM ?: "?"
)
}
else if (lesson.startTime != lesson.oldStartTime) {
lb.annotation.setText(
lesson.startTime != lesson.oldStartTime -> lb.annotation.setText(
R.string.timetable_lesson_shifted_same_day,
lesson.startTime?.stringHM ?: "?"
)
}
else {
lb.annotation.setText(R.string.timetable_lesson_shifted)
else -> lb.annotation.setText(R.string.timetable_lesson_shifted)
}
lb.annotation.background.colorFilter = PorterDuffColorFilter(
@ -245,21 +244,17 @@ class TimetableDayFragment(val date: Date) : Fragment() {
}
Lesson.TYPE_SHIFTED_TARGET -> {
lb.annotationVisible = true
if (lesson.date != lesson.oldDate) {
lb.annotation.setText(
when {
lesson.date != lesson.oldDate -> lb.annotation.setText(
R.string.timetable_lesson_shifted_from_other_day,
lesson.oldDate?.stringY_m_d ?: "?",
lesson.oldStartTime?.stringHM ?: "?"
)
}
else if (lesson.startTime != lesson.oldStartTime) {
lb.annotation.setText(
lesson.startTime != lesson.oldStartTime -> lb.annotation.setText(
R.string.timetable_lesson_shifted_from_same_day,
lesson.oldStartTime?.stringHM ?: "?"
)
}
else {
lb.annotation.setText(R.string.timetable_lesson_shifted_from)
else -> lb.annotation.setText(R.string.timetable_lesson_shifted_from)
}
lb.annotation.background.colorFilter = PorterDuffColorFilter(

View File

@ -0,0 +1,237 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) Kuba Szczodrzyński 2019-11-11.
-->
<layout 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">
<data>
<import type="android.view.View"/>
<import type="pl.szczodrzynski.edziennik.App"/>
<variable
name="lesson"
type="pl.szczodrzynski.edziennik.data.db.modules.timetable.LessonFull" />
<variable name="oldSubjectName" type="String" />
<variable name="subjectName" type="String" />
<variable name="oldTeacherName" type="String" />
<variable name="teacherName" type="String" />
<variable name="oldClassroom" type="String" />
<variable name="classroom" type="String" />
<variable name="oldTeamName" type="String" />
<variable name="teamName" type="String" />
</data>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="24dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:baselineAligned="false">
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{oldSubjectName}"
android:textIsSelectable="true"
android:textAppearance="@style/NavView.TextView.Medium"
android:textColor="?android:textColorTertiary"
android:visibility="@{oldSubjectName == null ? View.GONE : View.VISIBLE}"
app:strikeThrough="@{true}"
tools:text="pracownia urządzeń techniki komputerowej" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{subjectName}"
android:textIsSelectable="true"
android:textAppearance="@style/NavView.TextView.Title"
android:visibility="@{subjectName == null ? View.GONE : View.VISIBLE}"
tools:text="pracownia urządzeń techniki komputerowej" />
<TextView
android:id="@+id/lessonDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:textAppearance="@style/NavView.TextView.Subtitle"
tools:text="czwartek, 14 listopada 2019"
tools:visibility="visible" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/NavView.TextView.Helper"
android:text="@string/dialog_lesson_details_number"
android:visibility="@{lesson.displayLessonNumber == null ? View.GONE : View.VISIBLE}"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:text="@{lesson.displayLessonNumber.toString()}"
android:textSize="36sp"
android:visibility="@{lesson.displayLessonNumber == null ? View.GONE : View.VISIBLE}"
tools:text="4" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{lesson.displayStartTime.stringHM + ` - ` + lesson.displayEndTime.stringHM}"
tools:text="14:55 - 15:40" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/shiftedLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:baselineAligned="false"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="@+id/shiftedText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="16sp"
android:textStyle="italic"
tools:text="Lekcja przeniesiona na czwartek, 17 października" />
<Button
android:id="@+id/shiftedGoTo"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Przejdź" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:textAppearance="@style/NavView.TextView.Helper"
android:text="@string/dialog_lesson_details_teacher"
android:visibility="@{teacherName != null || oldTeacherName != null ? View.VISIBLE : View.GONE}"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/NavView.TextView.Helper"
android:text="@{oldTeacherName}"
android:textIsSelectable="true"
android:visibility="@{oldTeacherName != null ? View.VISIBLE : View.GONE}"
app:strikeThrough="@{true}"
tools:text="Janósz Kowalski" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@{teacherName}"
android:textIsSelectable="true"
android:visibility="@{teacherName != null ? View.VISIBLE : View.GONE}"
tools:text="Janósz Kowalski" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:textAppearance="@style/NavView.TextView.Helper"
android:text="@string/dialog_lesson_details_classroom"
android:visibility="@{classroom != null || oldClassroom != null ? View.VISIBLE : View.GONE}"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/NavView.TextView.Helper"
android:text="@{oldClassroom}"
android:textIsSelectable="true"
android:visibility="@{oldClassroom != null ? View.VISIBLE : View.GONE}"
app:strikeThrough="@{true}"
tools:text="013 informatyczna" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@{classroom}"
android:textIsSelectable="true"
android:visibility="@{classroom != null ? View.VISIBLE : View.GONE}"
tools:text="013 informatyczna" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:textAppearance="@style/NavView.TextView.Helper"
android:text="@string/dialog_lesson_details_team"
android:visibility="@{teamName != null || oldTeamName != null ? View.VISIBLE : View.GONE}"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/NavView.TextView.Helper"
android:text="@{oldTeamName}"
android:textIsSelectable="true"
android:visibility="@{oldTeamName != null ? View.VISIBLE : View.GONE}"
app:strikeThrough="@{true}"
tools:text="013 informatyczna" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@{teamName}"
android:textIsSelectable="true"
android:visibility="@{teamName != null ? View.VISIBLE : View.GONE}"
tools:text="013 informatyczna" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:textAppearance="@style/NavView.TextView.Helper"
android:visibility="@{App.devMode ? View.VISIBLE : View.GONE}"
android:text="@string/dialog_lesson_details_id" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
android:text="@{Long.toString(lesson.id)}"
android:textIsSelectable="true"
android:visibility="@{App.devMode ? View.VISIBLE : View.GONE}"
tools:text="12345" />
<!--<androidx.core.widget.NestedScrollView
android:id="@+id/gradeHistoryNest"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="@{historyVisible ? View.VISIBLE : View.GONE}">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/gradeHistoryList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:listitem="@layout/row_grades_list_item" />
</androidx.core.widget.NestedScrollView>-->
</LinearLayout>
</layout>

View File

@ -1006,4 +1006,11 @@
<string name="timetable_no_timetable_text">Nie pobrano planu lekcji na ten tydzień.</string>
<string name="timetable_no_timetable_sync">Pobierz plan lekcji</string>
<string name="timetable_no_timetable_week">na tydzień %s</string>
<string name="dialog_lesson_details_teacher">Nauczyciel</string>
<string name="dialog_lesson_details_classroom">Sala lekcyjna</string>
<string name="dialog_lesson_details_team">Grupa</string>
<string name="dialog_lesson_details_id">ID lekcji</string>
<string name="dialog_lesson_details_number">Nr lekcji</string>
<string name="dialog_lesson_details_shifted_to">Lekcja przeniesiona na %s</string>
<string name="dialog_lesson_details_shifted_from">Lekcja przeniesiona z %s</string>
</resources>