mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-01-31 05:48:19 +01:00
[API/Liburs] Fix unseen teacher absence metadata and add notifications for new teacher absences.
This commit is contained in:
parent
d4d548846f
commit
55ff9173be
@ -1008,6 +1008,7 @@ fun Context.getNotificationTitle(type: Int): String {
|
||||
Notification.TYPE_FEEDBACK_MESSAGE -> R.string.notification_type_feedback_message
|
||||
Notification.TYPE_NEW_ANNOUNCEMENT -> R.string.notification_type_new_announcement
|
||||
Notification.TYPE_AUTO_ARCHIVING -> R.string.notification_type_auto_archiving
|
||||
Notification.TYPE_TEACHER_ABSENCE -> R.string.notification_type_new_teacher_absence
|
||||
Notification.TYPE_GENERAL -> R.string.notification_type_general
|
||||
else -> R.string.notification_type_general
|
||||
})
|
||||
|
@ -59,7 +59,7 @@ class LibrusApiTeacherFreeDays(override val data: DataLibrus,
|
||||
profileId,
|
||||
Metadata.TYPE_TEACHER_ABSENCE,
|
||||
id,
|
||||
profile?.empty ?: false,
|
||||
true,
|
||||
profile?.empty ?: false,
|
||||
System.currentTimeMillis()
|
||||
))
|
||||
|
@ -34,6 +34,7 @@ class Notifications(val app: App, val notifications: MutableList<Notification>,
|
||||
announcementNotifications()
|
||||
messageNotifications()
|
||||
luckyNumberNotifications()
|
||||
teacherAbsenceNotifications()
|
||||
}
|
||||
|
||||
private fun timetableNotifications() {
|
||||
@ -274,4 +275,23 @@ class Notifications(val app: App, val notifications: MutableList<Notification>,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun teacherAbsenceNotifications() {
|
||||
for (teacherAbsence in app.db.teacherAbsenceDao().getNotNotifiedNow()) {
|
||||
val message = app.getString(
|
||||
R.string.notification_teacher_absence_new_format,
|
||||
teacherAbsence.teacherFullName
|
||||
)
|
||||
notifications += Notification(
|
||||
id = Notification.buildId(teacherAbsence.profileId, Notification.TYPE_TEACHER_ABSENCE, teacherAbsence.id),
|
||||
title = app.getNotificationTitle(Notification.TYPE_TEACHER_ABSENCE),
|
||||
text = message,
|
||||
type = Notification.TYPE_TEACHER_ABSENCE,
|
||||
profileId = teacherAbsence.profileId,
|
||||
profileName = profiles.singleOrNull { it.id == teacherAbsence.profileId }?.name,
|
||||
viewId = MainActivity.DRAWER_ITEM_AGENDA,
|
||||
addedDate = teacherAbsence.addedDate
|
||||
).addExtra("eventDate", teacherAbsence.dateFrom.value.toLong())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ import pl.szczodrzynski.edziennik.data.db.migration.*
|
||||
LibrusLesson::class,
|
||||
TimetableManual::class,
|
||||
Metadata::class
|
||||
], version = 80)
|
||||
], version = 81)
|
||||
@TypeConverters(
|
||||
ConverterTime::class,
|
||||
ConverterDate::class,
|
||||
@ -165,7 +165,8 @@ abstract class AppDb : RoomDatabase() {
|
||||
Migration77(),
|
||||
Migration78(),
|
||||
Migration79(),
|
||||
Migration80()
|
||||
Migration80(),
|
||||
Migration81()
|
||||
).allowMainThreadQueries().build()
|
||||
}
|
||||
}
|
||||
|
@ -49,6 +49,17 @@ interface TeacherAbsenceDao {
|
||||
"AND :date BETWEEN teacherAbsenceDateFrom AND teacherAbsenceDateTo")
|
||||
fun getAllByDateNow(profileId: Int, date: Date): List<TeacherAbsenceFull>
|
||||
|
||||
@Query("""
|
||||
SELECT *,
|
||||
teachers.teacherName || ' ' || teachers.teacherSurname as teacherFullName
|
||||
FROM teacherAbsence
|
||||
LEFT JOIN teachers USING (profileId, teacherId)
|
||||
LEFT JOIN metadata ON teacherAbsenceId = thingId AND metadata.thingType = ${Metadata.TYPE_TEACHER_ABSENCE}
|
||||
AND teachers.profileId = metadata.profileId WHERE metadata.notified = 0
|
||||
ORDER BY addedDate DESC
|
||||
""")
|
||||
fun getNotNotifiedNow(): List<TeacherAbsenceFull>
|
||||
|
||||
@Query("DELETE FROM teacherAbsence WHERE profileId = :profileId")
|
||||
fun clear(profileId: Int)
|
||||
}
|
||||
|
@ -52,6 +52,7 @@ data class Notification(
|
||||
const val TYPE_NEW_ANNOUNCEMENT = 15
|
||||
const val TYPE_FEEDBACK_MESSAGE = 16
|
||||
const val TYPE_AUTO_ARCHIVING = 17
|
||||
const val TYPE_TEACHER_ABSENCE = 19
|
||||
|
||||
fun buildId(profileId: Int, type: Int, itemId: Long): Long {
|
||||
return 1000000000000 + profileId*10000000000 + type*100000000 + itemId;
|
||||
|
@ -0,0 +1,11 @@
|
||||
package pl.szczodrzynski.edziennik.data.db.migration
|
||||
|
||||
import androidx.room.migration.Migration
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Metadata
|
||||
|
||||
class Migration81 : Migration(80, 81) {
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("UPDATE metadata SET seen = 1, notified = 1 WHERE thingType = ${Metadata.TYPE_TEACHER_ABSENCE}")
|
||||
}
|
||||
}
|
@ -37,7 +37,8 @@ class NotificationFilterDialog(
|
||||
Notification.TYPE_NEW_ANNOUNCEMENT to R.string.notification_type_new_announcement,
|
||||
Notification.TYPE_NEW_SHARED_EVENT to R.string.notification_type_new_shared_event,
|
||||
Notification.TYPE_NEW_SHARED_HOMEWORK to R.string.notification_type_new_shared_homework,
|
||||
Notification.TYPE_REMOVED_SHARED_EVENT to R.string.notification_type_removed_shared_event
|
||||
Notification.TYPE_REMOVED_SHARED_EVENT to R.string.notification_type_removed_shared_event,
|
||||
Notification.TYPE_TEACHER_ABSENCE to R.string.notification_type_new_teacher_absence
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -493,6 +493,7 @@
|
||||
<string name="notification_shared_event_format">%s shared %s on %s - %s</string>
|
||||
<string name="notification_shared_event_modified_format">%s changed %s na %s - %s</string>
|
||||
<string name="notification_shared_event_removed_format">%s removed %s na %s - %s</string>
|
||||
<string name="notification_teacher_absence_new_format">New teacher absence for %s</string>
|
||||
<string name="notification_ticker_format">Szkolny.eu: %s</string>
|
||||
<string name="notification_type_attendance">Attendance</string>
|
||||
<string name="notification_type_auto_archiving">Profile archiving</string>
|
||||
@ -506,6 +507,7 @@
|
||||
<string name="notification_type_new_homework">New homework</string>
|
||||
<string name="notification_type_new_message">New message</string>
|
||||
<string name="notification_type_new_shared_event">New shared event</string>
|
||||
<string name="notification_type_new_teacher_absence">New teacher absence</string>
|
||||
<string name="notification_type_notice">New notice</string>
|
||||
<string name="notification_type_server_message">Server message</string>
|
||||
<string name="notification_type_timetable_change">Timetable change</string>
|
||||
|
@ -554,6 +554,7 @@
|
||||
<string name="notification_shared_event_format">%s udostępnił %s na %s: %s</string>
|
||||
<string name="notification_shared_event_modified_format">%s zmienił %s na %s: %s</string>
|
||||
<string name="notification_shared_event_removed_format">%s usunął %s na %s: %s</string>
|
||||
<string name="notification_teacher_absence_new_format">Nowa nieobecność nauczyciela dla %s</string>
|
||||
<string name="notification_ticker_format">Szkolny.eu: %s</string>
|
||||
<string name="notification_type_attendance">Wpis frekwencji</string>
|
||||
<string name="notification_type_auto_archiving">Archiwizacja profilu</string>
|
||||
@ -567,6 +568,7 @@
|
||||
<string name="notification_type_new_homework">Nowe zadanie domowe</string>
|
||||
<string name="notification_type_new_message">Nowa wiadomość</string>
|
||||
<string name="notification_type_new_shared_event">Udostępniono wydarzenie</string>
|
||||
<string name="notification_type_new_teacher_absence">Nowa nieobecność nauczyciela</string>
|
||||
<string name="notification_type_notice">Wpis zachowania</string>
|
||||
<string name="notification_type_server_message">Wiadomość z serwera</string>
|
||||
<string name="notification_type_timetable_change">Zmiana planu zajęć</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user