forked from github/szkolny
[Notifications/Timetable] Make notifications for timetable changes
This commit is contained in:
parent
f689f4d427
commit
07ae37167d
@ -45,8 +45,8 @@ class DataNotifications(val data: Data) {
|
|||||||
return@run
|
return@run
|
||||||
}
|
}
|
||||||
|
|
||||||
for (change in app.db.lessonChangeDao().getNotNotifiedNow(profileId)) {
|
for (lesson in app.db.timetableDao().getNotNotifiedNow(profileId)) {
|
||||||
val text = app.getString(R.string.notification_lesson_change_format, change.changeTypeStr(app), if (change.lessonDate == null) "" else change.lessonDate!!.formattedString, change.subjectLongName)
|
val text = app.getString(R.string.notification_lesson_change_format, lesson.getDisplayChangeType(app), if (lesson.displayDate == null) "" else lesson.displayDate!!.formattedString, lesson.changeSubjectName)
|
||||||
data.notifications += Notification(
|
data.notifications += Notification(
|
||||||
title = app.getNotificationTitle(TYPE_TIMETABLE_LESSON_CHANGE),
|
title = app.getNotificationTitle(TYPE_TIMETABLE_LESSON_CHANGE),
|
||||||
text = text,
|
text = text,
|
||||||
@ -54,8 +54,8 @@ class DataNotifications(val data: Data) {
|
|||||||
profileId = profileId,
|
profileId = profileId,
|
||||||
profileName = profileName,
|
profileName = profileName,
|
||||||
viewId = DRAWER_ITEM_TIMETABLE,
|
viewId = DRAWER_ITEM_TIMETABLE,
|
||||||
addedDate = change.addedDate
|
addedDate = lesson.addedDate
|
||||||
).addExtra("timetableDate", change.lessonDate?.value?.toLong())
|
).addExtra("timetableDate", lesson.displayDate?.value?.toLong())
|
||||||
}
|
}
|
||||||
|
|
||||||
for (event in app.db.eventDao().getNotNotifiedNow(profileId)) {
|
for (event in app.db.eventDao().getNotNotifiedNow(profileId)) {
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package pl.szczodrzynski.edziennik.data.db.modules.timetable
|
package pl.szczodrzynski.edziennik.data.db.modules.timetable
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import pl.szczodrzynski.edziennik.R
|
||||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||||
import pl.szczodrzynski.edziennik.utils.models.Time
|
import pl.szczodrzynski.edziennik.utils.models.Time
|
||||||
|
|
||||||
@ -17,18 +19,21 @@ class LessonFull(profileId: Int, id: Long) : Lesson(profileId, id) {
|
|||||||
return oldDate
|
return oldDate
|
||||||
return date ?: oldDate
|
return date ?: oldDate
|
||||||
}
|
}
|
||||||
|
|
||||||
val displayLessonNumber: Int?
|
val displayLessonNumber: Int?
|
||||||
get() {
|
get() {
|
||||||
if (type == TYPE_SHIFTED_SOURCE)
|
if (type == TYPE_SHIFTED_SOURCE)
|
||||||
return oldLessonNumber
|
return oldLessonNumber
|
||||||
return lessonNumber ?: oldLessonNumber
|
return lessonNumber ?: oldLessonNumber
|
||||||
}
|
}
|
||||||
|
|
||||||
val displayStartTime: Time?
|
val displayStartTime: Time?
|
||||||
get() {
|
get() {
|
||||||
if (type == TYPE_SHIFTED_SOURCE)
|
if (type == TYPE_SHIFTED_SOURCE)
|
||||||
return oldStartTime
|
return oldStartTime
|
||||||
return startTime ?: oldStartTime
|
return startTime ?: oldStartTime
|
||||||
}
|
}
|
||||||
|
|
||||||
val displayEndTime: Time?
|
val displayEndTime: Time?
|
||||||
get() {
|
get() {
|
||||||
if (type == TYPE_SHIFTED_SOURCE)
|
if (type == TYPE_SHIFTED_SOURCE)
|
||||||
@ -42,12 +47,14 @@ class LessonFull(profileId: Int, id: Long) : Lesson(profileId, id) {
|
|||||||
return oldSubjectName
|
return oldSubjectName
|
||||||
return subjectName ?: oldSubjectName
|
return subjectName ?: oldSubjectName
|
||||||
}
|
}
|
||||||
|
|
||||||
val displayTeacherName: String?
|
val displayTeacherName: String?
|
||||||
get() {
|
get() {
|
||||||
if (type == TYPE_SHIFTED_SOURCE)
|
if (type == TYPE_SHIFTED_SOURCE)
|
||||||
return oldTeacherName
|
return oldTeacherName
|
||||||
return teacherName ?: oldTeacherName
|
return teacherName ?: oldTeacherName
|
||||||
}
|
}
|
||||||
|
|
||||||
val displayTeamName: String?
|
val displayTeamName: String?
|
||||||
get() {
|
get() {
|
||||||
if (type == TYPE_SHIFTED_SOURCE)
|
if (type == TYPE_SHIFTED_SOURCE)
|
||||||
@ -68,12 +75,14 @@ class LessonFull(profileId: Int, id: Long) : Lesson(profileId, id) {
|
|||||||
return oldTeamId
|
return oldTeamId
|
||||||
return teamId ?: oldTeamId
|
return teamId ?: oldTeamId
|
||||||
}
|
}
|
||||||
|
|
||||||
val displaySubjectId: Long?
|
val displaySubjectId: Long?
|
||||||
get() {
|
get() {
|
||||||
if (type == TYPE_SHIFTED_SOURCE)
|
if (type == TYPE_SHIFTED_SOURCE)
|
||||||
return oldSubjectId
|
return oldSubjectId
|
||||||
return subjectId ?: oldSubjectId
|
return subjectId ?: oldSubjectId
|
||||||
}
|
}
|
||||||
|
|
||||||
val displayTeacherId: Long?
|
val displayTeacherId: Long?
|
||||||
get() {
|
get() {
|
||||||
if (type == TYPE_SHIFTED_SOURCE)
|
if (type == TYPE_SHIFTED_SOURCE)
|
||||||
@ -81,6 +90,33 @@ class LessonFull(profileId: Int, id: Long) : Lesson(profileId, id) {
|
|||||||
return teacherId ?: oldTeacherId
|
return teacherId ?: oldTeacherId
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getDisplayChangeType(context: Context): String {
|
||||||
|
return context.getString(when (type) {
|
||||||
|
TYPE_CHANGE -> R.string.lesson_change
|
||||||
|
TYPE_CANCELLED -> R.string.lesson_cancelled
|
||||||
|
TYPE_SHIFTED_TARGET, TYPE_SHIFTED_SOURCE -> R.string.lesson_shifted
|
||||||
|
else -> R.string.lesson_timetable_change
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
val changeSubjectName: String
|
||||||
|
get() {
|
||||||
|
val first = when (type) {
|
||||||
|
TYPE_CHANGE, TYPE_CANCELLED, TYPE_SHIFTED_SOURCE -> oldSubjectName
|
||||||
|
else -> subjectName
|
||||||
|
}
|
||||||
|
|
||||||
|
val second = when (type) {
|
||||||
|
TYPE_CHANGE -> subjectName
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
|
||||||
|
return when (second) {
|
||||||
|
null -> first ?: ""
|
||||||
|
else -> "$first -> $second"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// metadata
|
// metadata
|
||||||
var seen: Boolean = false
|
var seen: Boolean = false
|
||||||
var notified: Boolean = false
|
var notified: Boolean = false
|
||||||
|
@ -81,4 +81,10 @@ interface TimetableDao {
|
|||||||
ORDER BY id, type
|
ORDER BY id, type
|
||||||
""")
|
""")
|
||||||
fun getByIdNow(profileId: Int, lessonId: Long) : LessonFull?
|
fun getByIdNow(profileId: Int, lessonId: Long) : LessonFull?
|
||||||
|
|
||||||
|
@Query("""
|
||||||
|
$QUERY
|
||||||
|
WHERE timetable.profileId = :profileId AND timetable.type NOT IN (${Lesson.TYPE_NORMAL}, ${Lesson.TYPE_NO_LESSONS}, ${Lesson.TYPE_SHIFTED_SOURCE}) AND metadata.notified = 0
|
||||||
|
""")
|
||||||
|
fun getNotNotifiedNow(profileId: Int): List<LessonFull>
|
||||||
}
|
}
|
||||||
|
@ -295,6 +295,7 @@
|
|||||||
<string name="lesson_break">Break</string>
|
<string name="lesson_break">Break</string>
|
||||||
<string name="lesson_cancelled">Lesson cancelled</string>
|
<string name="lesson_cancelled">Lesson cancelled</string>
|
||||||
<string name="lesson_change">Lesson change</string>
|
<string name="lesson_change">Lesson change</string>
|
||||||
|
<string name="lesson_shifted">Shifted lesson</string>
|
||||||
<string name="lesson_timetable_change">Timetable change</string>
|
<string name="lesson_timetable_change">Timetable change</string>
|
||||||
<string name="loading">Loading…</string>
|
<string name="loading">Loading…</string>
|
||||||
<string name="login_allow_registration">Allow registration</string>
|
<string name="login_allow_registration">Allow registration</string>
|
||||||
|
@ -318,6 +318,7 @@
|
|||||||
<string name="lesson_break">Przerwa</string>
|
<string name="lesson_break">Przerwa</string>
|
||||||
<string name="lesson_cancelled">Lekcja odwołana</string>
|
<string name="lesson_cancelled">Lekcja odwołana</string>
|
||||||
<string name="lesson_change">Zastępstwo</string>
|
<string name="lesson_change">Zastępstwo</string>
|
||||||
|
<string name="lesson_shifted">Lekcja przeniesiona</string>
|
||||||
<string name="lesson_timetable_change">Zmiana planu</string>
|
<string name="lesson_timetable_change">Zmiana planu</string>
|
||||||
<string name="loading">Ładowanie…</string>
|
<string name="loading">Ładowanie…</string>
|
||||||
<string name="login_allow_registration">Zezwól na rejestrację</string>
|
<string name="login_allow_registration">Zezwól na rejestrację</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user