diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/Extensions.kt b/app/src/main/java/pl/szczodrzynski/edziennik/Extensions.kt index 0d7b1f56..7e802ae4 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/Extensions.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/Extensions.kt @@ -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 }) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/api/LibrusApiTeacherFreeDays.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/api/LibrusApiTeacherFreeDays.kt index 04c44efb..3d4db1aa 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/api/LibrusApiTeacherFreeDays.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/api/LibrusApiTeacherFreeDays.kt @@ -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() )) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/task/Notifications.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/task/Notifications.kt index deeb5337..c29d96bb 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/task/Notifications.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/task/Notifications.kt @@ -34,6 +34,7 @@ class Notifications(val app: App, val notifications: MutableList, announcementNotifications() messageNotifications() luckyNumberNotifications() + teacherAbsenceNotifications() } private fun timetableNotifications() { @@ -274,4 +275,23 @@ class Notifications(val app: App, val notifications: MutableList, ) } } + + 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()) + } + } } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/AppDb.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/AppDb.kt index a02e8913..836e6d84 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/AppDb.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/AppDb.kt @@ -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() } } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/dao/TeacherAbsenceDao.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/dao/TeacherAbsenceDao.kt index 3da88080..1d4881bb 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/dao/TeacherAbsenceDao.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/dao/TeacherAbsenceDao.kt @@ -49,6 +49,17 @@ interface TeacherAbsenceDao { "AND :date BETWEEN teacherAbsenceDateFrom AND teacherAbsenceDateTo") fun getAllByDateNow(profileId: Int, date: Date): List + @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 + @Query("DELETE FROM teacherAbsence WHERE profileId = :profileId") fun clear(profileId: Int) } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/entity/Notification.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/entity/Notification.kt index 242d5999..1e8b8e0e 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/entity/Notification.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/entity/Notification.kt @@ -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; diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration81.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration81.kt new file mode 100644 index 00000000..bf547244 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration81.kt @@ -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}") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/sync/NotificationFilterDialog.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/sync/NotificationFilterDialog.kt index eb8aecd3..ad31c02d 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/sync/NotificationFilterDialog.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/sync/NotificationFilterDialog.kt @@ -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 ) } diff --git a/app/src/main/res/values-en/strings.xml b/app/src/main/res/values-en/strings.xml index a5e3c23a..f8bc7c51 100644 --- a/app/src/main/res/values-en/strings.xml +++ b/app/src/main/res/values-en/strings.xml @@ -493,6 +493,7 @@ %s shared %s on %s - %s %s changed %s na %s - %s %s removed %s na %s - %s + New teacher absence for %s Szkolny.eu: %s Attendance Profile archiving @@ -506,6 +507,7 @@ New homework New message New shared event + New teacher absence New notice Server message Timetable change diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ccb3a8fc..3be507cc 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -554,6 +554,7 @@ %s udostępnił %s na %s: %s %s zmienił %s na %s: %s %s usunął %s na %s: %s + Nowa nieobecność nauczyciela dla %s Szkolny.eu: %s Wpis frekwencji Archiwizacja profilu @@ -567,6 +568,7 @@ Nowe zadanie domowe Nowa wiadomość Udostępniono wydarzenie + Nowa nieobecność nauczyciela Wpis zachowania Wiadomość z serwera Zmiana planu zajęć