mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-06-11 13:10:47 +02:00
[UI/Events] Update Day Dialog. Add Event List Adapter to Timetable Lesson Dialog.
This commit is contained in:
@ -92,7 +92,7 @@ class DayDialog(
|
||||
onEventEditClick = {
|
||||
EventManualDialog(
|
||||
activity,
|
||||
profileId,
|
||||
it.profileId,
|
||||
editingEvent = it,
|
||||
onShowListener = onShowListener,
|
||||
onDismissListener = onDismissListener
|
||||
@ -105,6 +105,7 @@ class DayDialog(
|
||||
if (b.eventsView.adapter == null) {
|
||||
b.eventsView.adapter = adapter
|
||||
b.eventsView.apply {
|
||||
isNestedScrollingEnabled = false
|
||||
setHasFixedSize(true)
|
||||
layoutManager = LinearLayoutManager(context)
|
||||
addItemDecoration(SimpleDividerItemDecoration(context))
|
||||
|
@ -461,7 +461,7 @@ class EventManualDialog(
|
||||
b.teacherDropdown.deselect()
|
||||
}
|
||||
else {
|
||||
defaultTime?.let {
|
||||
val setTime: (Time) -> Unit = {
|
||||
event.startTime = it
|
||||
if (b.timeDropdown.select(it) == null)
|
||||
b.timeDropdown.select(TextInputDropDown.Item(
|
||||
@ -470,23 +470,10 @@ class EventManualDialog(
|
||||
tag = it
|
||||
))
|
||||
}
|
||||
|
||||
editingEvent?.startTime?.let {
|
||||
if (b.timeDropdown.select(it) == null)
|
||||
b.timeDropdown.select(TextInputDropDown.Item(
|
||||
it.value.toLong(),
|
||||
it.stringHM,
|
||||
tag = it
|
||||
))
|
||||
}
|
||||
|
||||
defaultLesson?.let {
|
||||
b.timeDropdown.select(it.displayStartTime?.value?.toLong())
|
||||
}
|
||||
|
||||
defaultHour?.let {
|
||||
b.timeDropdown.select(it.value.toLong())
|
||||
}
|
||||
defaultTime?.let(setTime)
|
||||
editingEvent?.startTime?.let(setTime)
|
||||
defaultLesson?.displayStartTime?.let(setTime)
|
||||
defaultHour?.let(setTime)
|
||||
}
|
||||
defaultLoaded = true
|
||||
b.timeDropdown.isEnabled = true
|
||||
@ -554,7 +541,7 @@ class EventManualDialog(
|
||||
|
||||
private fun saveEvent() {
|
||||
val date = b.dateDropdown.selected?.tag.instanceOfOrNull<Date>()
|
||||
val lesson = b.timeDropdown.selected?.tag.instanceOfOrNull<LessonFull>()
|
||||
val startTime = b.timeDropdown.selected?.tag.instanceOfOrNull<Time>()
|
||||
val teamId = b.teamDropdown.selected?.id
|
||||
val type = b.typeDropdown.selected?.id
|
||||
val topic = b.topic.text?.toString()
|
||||
@ -592,7 +579,7 @@ class EventManualDialog(
|
||||
profileId,
|
||||
editingEvent?.id ?: id,
|
||||
date,
|
||||
lesson?.displayStartTime,
|
||||
startTime,
|
||||
topic,
|
||||
customColor ?: -1,
|
||||
type?.toInt() ?: Event.TYPE_DEFAULT,
|
||||
|
@ -6,61 +6,84 @@ package pl.szczodrzynski.edziennik.ui.dialogs.timetable
|
||||
|
||||
import android.content.Intent
|
||||
import android.view.View
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
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.onClick
|
||||
import pl.szczodrzynski.edziennik.setText
|
||||
import pl.szczodrzynski.edziennik.ui.dialogs.event.EventListAdapter
|
||||
import pl.szczodrzynski.edziennik.ui.dialogs.event.EventManualDialog
|
||||
import pl.szczodrzynski.edziennik.ui.modules.timetable.v2.TimetableFragment
|
||||
import pl.szczodrzynski.edziennik.utils.SimpleDividerItemDecoration
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
import pl.szczodrzynski.edziennik.utils.models.Week
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
|
||||
class LessonDetailsDialog(
|
||||
val activity: AppCompatActivity,
|
||||
val lesson: LessonFull,
|
||||
val onShowListener: ((tag: String) -> Unit)? = null,
|
||||
val onDismissListener: ((tag: String) -> Unit)? = null
|
||||
) {
|
||||
) : CoroutineScope {
|
||||
companion object {
|
||||
private const val TAG = "LessonDetailsDialog"
|
||||
}
|
||||
|
||||
private lateinit var app: App
|
||||
private lateinit var b: DialogLessonDetailsBinding
|
||||
private lateinit var dialog: AlertDialog
|
||||
|
||||
private val job = Job()
|
||||
override val coroutineContext: CoroutineContext
|
||||
get() = job + Dispatchers.Main
|
||||
|
||||
private lateinit var adapter: EventListAdapter
|
||||
|
||||
init { run {
|
||||
if (activity.isFinishing)
|
||||
return@run
|
||||
onShowListener?.invoke(TAG)
|
||||
app = activity.applicationContext as App
|
||||
b = DialogLessonDetailsBinding.inflate(activity.layoutInflater)
|
||||
dialog = MaterialAlertDialogBuilder(activity)
|
||||
.setView(b.root)
|
||||
.setPositiveButton(R.string.close) { dialog, _ ->
|
||||
dialog.dismiss()
|
||||
}
|
||||
.setNeutralButton(R.string.add) { _, _ ->
|
||||
EventManualDialog(
|
||||
activity,
|
||||
lesson.profileId,
|
||||
lesson,
|
||||
onShowListener = onShowListener,
|
||||
onDismissListener = onDismissListener
|
||||
)
|
||||
}
|
||||
.setNeutralButton(R.string.add, null)
|
||||
.setOnDismissListener {
|
||||
onDismissListener?.invoke(TAG)
|
||||
}
|
||||
.show()
|
||||
|
||||
dialog.getButton(AlertDialog.BUTTON_NEUTRAL)?.onClick {
|
||||
EventManualDialog(
|
||||
activity,
|
||||
lesson.profileId,
|
||||
defaultLesson = lesson,
|
||||
onShowListener = onShowListener,
|
||||
onDismissListener = onDismissListener
|
||||
)
|
||||
}
|
||||
|
||||
update()
|
||||
}}
|
||||
|
||||
private fun update() {
|
||||
b.lesson = lesson
|
||||
val lessonDate = lesson.displayDate ?: return
|
||||
val lessonTime = lesson.displayStartTime ?: return
|
||||
b.lessonDate.text = Week.getFullDayName(lessonDate.weekDay) + ", " + lessonDate.formattedString
|
||||
|
||||
if (lesson.type >= Lesson.TYPE_SHIFTED_SOURCE) {
|
||||
@ -138,5 +161,43 @@ class LessonDetailsDialog(
|
||||
if (lesson.type != Lesson.TYPE_CANCELLED && lesson.displayTeamId != null) {
|
||||
b.teamName = lesson.teamName
|
||||
}
|
||||
|
||||
adapter = EventListAdapter(
|
||||
activity,
|
||||
onItemClick = {
|
||||
Toast.makeText(activity, "Event clicked ${it.topic}", Toast.LENGTH_SHORT).show()
|
||||
},
|
||||
onEventEditClick = {
|
||||
EventManualDialog(
|
||||
activity,
|
||||
it.profileId,
|
||||
editingEvent = it,
|
||||
onShowListener = onShowListener,
|
||||
onDismissListener = onDismissListener
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
app.db.eventDao().getAllByDateTime(lesson.profileId, lessonDate, lessonTime).observe(activity, Observer { events ->
|
||||
adapter.items = events
|
||||
if (b.eventsView.adapter == null) {
|
||||
b.eventsView.adapter = adapter
|
||||
b.eventsView.apply {
|
||||
isNestedScrollingEnabled = false
|
||||
setHasFixedSize(true)
|
||||
layoutManager = LinearLayoutManager(context)
|
||||
addItemDecoration(SimpleDividerItemDecoration(context))
|
||||
}
|
||||
}
|
||||
adapter.notifyDataSetChanged()
|
||||
|
||||
if (events != null && events.isNotEmpty()) {
|
||||
b.eventsView.visibility = View.VISIBLE
|
||||
b.eventsNoData.visibility = View.GONE
|
||||
} else {
|
||||
b.eventsView.visibility = View.GONE
|
||||
b.eventsNoData.visibility = View.VISIBLE
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user