forked from github/szkolny
[APIv2/Timetable] Add searching for the next lesson by team id
This commit is contained in:
parent
cd379e4175
commit
3ca051983f
@ -60,6 +60,14 @@ interface TimetableDao {
|
|||||||
""")
|
""")
|
||||||
fun getNextWithSubject(profileId: Int, today: Date, subjectId: Long) : LiveData<LessonFull?>
|
fun getNextWithSubject(profileId: Int, today: Date, subjectId: Long) : LiveData<LessonFull?>
|
||||||
|
|
||||||
|
@Query("""
|
||||||
|
$QUERY
|
||||||
|
WHERE timetable.profileId = :profileId AND ((type != 3 AND date > :today) OR ((type = 3 OR type = 1) AND oldDate > :today)) AND timetable.subjectId = :subjectId AND timetable.teamId = :teamId
|
||||||
|
ORDER BY id, type
|
||||||
|
LIMIT 1
|
||||||
|
""")
|
||||||
|
fun getNextWithSubjectAndTeam(profileId: Int, today: Date, subjectId: Long, teamId: Long): LiveData<LessonFull?>
|
||||||
|
|
||||||
@Query("""
|
@Query("""
|
||||||
$QUERY
|
$QUERY
|
||||||
WHERE (type != 3 AND date >= :dateFrom AND date <= :dateTo) OR ((type = 3 OR type = 1) AND oldDate >= :dateFrom AND oldDate <= :dateTo)
|
WHERE (type != 3 AND date >= :dateFrom AND date <= :dateTo) OR ((type = 3 OR type = 1) AND oldDate >= :dateFrom AND oldDate <= :dateTo)
|
||||||
|
@ -57,7 +57,8 @@ class EventManualV2Dialog(
|
|||||||
private lateinit var event: Event
|
private lateinit var event: Event
|
||||||
private var customColor: Int? = null
|
private var customColor: Int? = null
|
||||||
|
|
||||||
init { run {
|
init {
|
||||||
|
run {
|
||||||
if (activity.isFinishing)
|
if (activity.isFinishing)
|
||||||
return@run
|
return@run
|
||||||
job = Job()
|
job = Job()
|
||||||
@ -88,7 +89,8 @@ class EventManualV2Dialog(
|
|||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
b.showMore.onClick { // TODO iconics is broken
|
b.showMore.onClick {
|
||||||
|
// TODO iconics is broken
|
||||||
it.apply {
|
it.apply {
|
||||||
refreshDrawableState()
|
refreshDrawableState()
|
||||||
|
|
||||||
@ -100,9 +102,11 @@ class EventManualV2Dialog(
|
|||||||
}
|
}
|
||||||
|
|
||||||
loadLists()
|
loadLists()
|
||||||
}}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun loadLists() { launch {
|
private fun loadLists() {
|
||||||
|
launch {
|
||||||
val deferred = async(Dispatchers.Default) {
|
val deferred = async(Dispatchers.Default) {
|
||||||
// get the team list
|
// get the team list
|
||||||
val teams = app.db.teamDao().getAllNow(profileId)
|
val teams = app.db.teamDao().getAllNow(profileId)
|
||||||
@ -178,7 +182,8 @@ class EventManualV2Dialog(
|
|||||||
b.typeDropdown.background.colorFilter = PorterDuffColorFilter(it, PorterDuff.Mode.SRC_ATOP)
|
b.typeDropdown.background.colorFilter = PorterDuffColorFilter(it, PorterDuff.Mode.SRC_ATOP)
|
||||||
}
|
}
|
||||||
b.typeColor.onClick {
|
b.typeColor.onClick {
|
||||||
val currentColor = (b.typeDropdown?.selected?.tag as EventType?)?.color ?: Event.COLOR_DEFAULT
|
val currentColor = (b.typeDropdown?.selected?.tag as EventType?)?.color
|
||||||
|
?: Event.COLOR_DEFAULT
|
||||||
val colorPickerDialog = ColorPickerDialog.newBuilder()
|
val colorPickerDialog = ColorPickerDialog.newBuilder()
|
||||||
.setColor(currentColor)
|
.setColor(currentColor)
|
||||||
.create()
|
.create()
|
||||||
@ -194,9 +199,11 @@ class EventManualV2Dialog(
|
|||||||
}
|
}
|
||||||
|
|
||||||
loadDates()
|
loadDates()
|
||||||
}}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun loadDates() { launch {
|
private fun loadDates() {
|
||||||
|
launch {
|
||||||
val date = Date.getToday()
|
val date = Date.getToday()
|
||||||
val today = date.value
|
val today = date.value
|
||||||
var weekDay = date.weekDay
|
var weekDay = date.weekDay
|
||||||
@ -289,8 +296,13 @@ class EventManualV2Dialog(
|
|||||||
when {
|
when {
|
||||||
// next lesson with specified subject
|
// next lesson with specified subject
|
||||||
item.id < -1 -> {
|
item.id < -1 -> {
|
||||||
// TODO include lesson team in search
|
val teamId = defaultLesson?.teamId ?: -1
|
||||||
app.db.timetableDao().getNextWithSubject(profileId, Date.getToday(), -item.id).observeOnce(activity, Observer {
|
val selectedLessonDate = defaultLesson?.date ?: Date.getToday()
|
||||||
|
|
||||||
|
when (teamId) {
|
||||||
|
-1L -> app.db.timetableDao().getNextWithSubject(profileId, selectedLessonDate, -item.id)
|
||||||
|
else -> app.db.timetableDao().getNextWithSubjectAndTeam(profileId, selectedLessonDate, -item.id, teamId)
|
||||||
|
}.observeOnce(activity, Observer {
|
||||||
val lessonDate = it?.displayDate ?: return@Observer
|
val lessonDate = it?.displayDate ?: return@Observer
|
||||||
b.dateDropdown.select(TextInputDropDown.Item(
|
b.dateDropdown.select(TextInputDropDown.Item(
|
||||||
lessonDate.value.toLong(),
|
lessonDate.value.toLong(),
|
||||||
@ -309,7 +321,8 @@ class EventManualV2Dialog(
|
|||||||
item.id == -1L -> {
|
item.id == -1L -> {
|
||||||
MaterialDatePicker.Builder
|
MaterialDatePicker.Builder
|
||||||
.datePicker()
|
.datePicker()
|
||||||
.setSelection((b.dateDropdown.selectedId?.let { Date.fromValue(it.toInt()) } ?: Date.getToday()).inMillis)
|
.setSelection((b.dateDropdown.selectedId?.let { Date.fromValue(it.toInt()) }
|
||||||
|
?: Date.getToday()).inMillis)
|
||||||
.build()
|
.build()
|
||||||
.apply {
|
.apply {
|
||||||
addOnPositiveButtonClickListener {
|
addOnPositiveButtonClickListener {
|
||||||
@ -336,7 +349,8 @@ class EventManualV2Dialog(
|
|||||||
}
|
}
|
||||||
|
|
||||||
loadHours()
|
loadHours()
|
||||||
}}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun loadHours(defaultHour: Time? = null) {
|
private fun loadHours(defaultHour: Time? = null) {
|
||||||
b.timeDropdown.isEnabled = false
|
b.timeDropdown.isEnabled = false
|
||||||
@ -391,8 +405,7 @@ class EventManualV2Dialog(
|
|||||||
// clear subject, teacher selection
|
// clear subject, teacher selection
|
||||||
b.subjectDropdown.deselect()
|
b.subjectDropdown.deselect()
|
||||||
b.teacherDropdown.deselect()
|
b.teacherDropdown.deselect()
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
editingEvent?.let {
|
editingEvent?.let {
|
||||||
b.timeDropdown.select(it.startTime?.value?.toLong())
|
b.timeDropdown.select(it.startTime?.value?.toLong())
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user