From 85d74bec1c1deed645e5a06a2c82c2916f431ea1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Wed, 26 May 2021 19:00:09 +0200 Subject: [PATCH] [UI] Add long text for notification descriptions. --- .../edziennik/data/api/task/Notifications.kt | 61 ++++++++++++++++++- .../data/api/task/PostNotifications.kt | 2 +- .../edziennik/data/db/entity/Notification.kt | 1 + .../WidgetNotificationsFactory.kt | 3 +- app/src/main/res/values/strings.xml | 6 ++ 5 files changed, 70 insertions(+), 3 deletions(-) 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 21a5c112..28b5c9e9 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 @@ -10,6 +10,7 @@ import pl.szczodrzynski.edziennik.R import pl.szczodrzynski.edziennik.data.db.entity.* import pl.szczodrzynski.edziennik.getNotificationTitle import pl.szczodrzynski.edziennik.utils.models.Date +import pl.szczodrzynski.edziennik.utils.models.Week class Notifications(val app: App, val notifications: MutableList, val profiles: List) { companion object { @@ -42,13 +43,22 @@ class Notifications(val app: App, val notifications: MutableList, val text = app.getString( R.string.notification_lesson_change_format, lesson.getDisplayChangeType(app), - if (lesson.displayDate == null) "" else lesson.displayDate!!.formattedString, + lesson.displayDate?.formattedString ?: "", lesson.changeSubjectName ) + val textLong = app.getString( + R.string.notification_lesson_change_long_format, + lesson.getDisplayChangeType(app), + lesson.displayDate?.formattedString ?: "-", + lesson.displayDate?.weekDay?.let { Week.getFullDayName(it) } ?: "-", + lesson.changeSubjectName, + lesson.changeTeacherName + ) notifications += Notification( id = Notification.buildId(lesson.profileId, Notification.TYPE_TIMETABLE_LESSON_CHANGE, lesson.id), title = app.getNotificationTitle(Notification.TYPE_TIMETABLE_LESSON_CHANGE), text = text, + textLong = textLong, type = Notification.TYPE_TIMETABLE_LESSON_CHANGE, profileId = lesson.profileId, profileName = profiles.singleOrNull { it.id == lesson.profileId }?.name, @@ -79,11 +89,21 @@ class Notifications(val app: App, val notifications: MutableList, event.date.formattedString, event.subjectLongName ) + val textLong = app.getString( + R.string.notification_event_long_format, + event.typeName ?: "-", + event.subjectLongName ?: "-", + event.date.formattedString, + Week.getFullDayName(event.date.weekDay), + event.time?.stringHM ?: app.getString(R.string.event_all_day), + event.topic.take(200) + ) val type = if (event.type == Event.TYPE_HOMEWORK) Notification.TYPE_NEW_HOMEWORK else Notification.TYPE_NEW_EVENT notifications += Notification( id = Notification.buildId(event.profileId, type, event.id), title = app.getNotificationTitle(type), text = text, + textLong = textLong, type = type, profileId = event.profileId, profileName = profiles.singleOrNull { it.id == event.profileId }?.name, @@ -102,11 +122,22 @@ class Notifications(val app: App, val notifications: MutableList, event.date.formattedString, event.topic ) + val textLong = app.getString( + R.string.notification_shared_event_long_format, + event.sharedByName, + event.typeName ?: "-", + event.subjectLongName ?: "-", + event.date.formattedString, + Week.getFullDayName(event.date.weekDay), + event.time?.stringHM ?: app.getString(R.string.event_all_day), + event.topic.take(200) + ) val type = if (event.type == Event.TYPE_HOMEWORK) Notification.TYPE_NEW_HOMEWORK else Notification.TYPE_NEW_EVENT notifications += Notification( id = Notification.buildId(event.profileId, type, event.id), title = app.getNotificationTitle(type), text = text, + textLong = textLong, type = type, profileId = event.profileId, profileName = profiles.singleOrNull { it.id == event.profileId }?.name, @@ -130,10 +161,20 @@ class Notifications(val app: App, val notifications: MutableList, gradeName, grade.subjectLongName ) + val textLong = app.getString( + R.string.notification_grade_long_format, + gradeName, + grade.weight.toString(), + grade.subjectLongName ?: "-", + grade.category ?: "-", + grade.description ?: "-", + grade.teacherName ?: "-" + ) notifications += Notification( id = Notification.buildId(grade.profileId, Notification.TYPE_NEW_GRADE, grade.id), title = app.getNotificationTitle(Notification.TYPE_NEW_GRADE), text = text, + textLong = textLong, type = Notification.TYPE_NEW_GRADE, profileId = grade.profileId, profileName = profiles.singleOrNull { it.id == grade.profileId }?.name, @@ -158,10 +199,17 @@ class Notifications(val app: App, val notifications: MutableList, notice.teacherName, Date.fromMillis(notice.addedDate).formattedString ) + val textLong = app.getString( + R.string.notification_notice_long_format, + noticeTypeStr, + notice.teacherName ?: "-", + notice.text.take(200) + ) notifications += Notification( id = Notification.buildId(notice.profileId, Notification.TYPE_NEW_NOTICE, notice.id), title = app.getNotificationTitle(Notification.TYPE_NEW_NOTICE), text = text, + textLong = textLong, type = Notification.TYPE_NEW_NOTICE, profileId = notice.profileId, profileName = profiles.singleOrNull { it.id == notice.profileId }?.name, @@ -193,10 +241,21 @@ class Notifications(val app: App, val notifications: MutableList, attendance.subjectLongName, attendance.date.formattedString ) + val textLong = app.getString( + R.string.notification_attendance_long_format, + attendanceTypeStr, + attendance.date.formattedString, + attendance.startTime?.stringHM ?: "-", + attendance.lessonNumber ?: "-", + attendance.subjectLongName ?: "-", + attendance.teacherName ?: "-", + attendance.lessonTopic ?: "-" + ) notifications += Notification( id = Notification.buildId(attendance.profileId, Notification.TYPE_NEW_ATTENDANCE, attendance.id), title = app.getNotificationTitle(Notification.TYPE_NEW_ATTENDANCE), text = text, + textLong = textLong, type = Notification.TYPE_NEW_ATTENDANCE, profileId = attendance.profileId, profileName = profiles.singleOrNull { it.id == attendance.profileId }?.name, diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/task/PostNotifications.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/task/PostNotifications.kt index 28e62d59..6597125a 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/task/PostNotifications.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/task/PostNotifications.kt @@ -148,7 +148,7 @@ class PostNotifications(val app: App, nList: List) { colorRes = R.color.colorPrimary }.toBitmap()) .setStyle(NotificationCompat.BigTextStyle() - .bigText(it.text)) + .bigText(it.textLong ?: it.text)) .setWhen(it.addedDate) .addDefaults() .setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_SUMMARY) 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 6a2a787b..0a049216 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 @@ -21,6 +21,7 @@ data class Notification( val title: String, val text: String, + val textLong: String? = null, val type: Int, diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/widgets/notifications/WidgetNotificationsFactory.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/widgets/notifications/WidgetNotificationsFactory.kt index b5207300..1b6d58e0 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/widgets/notifications/WidgetNotificationsFactory.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/widgets/notifications/WidgetNotificationsFactory.kt @@ -45,6 +45,7 @@ class WidgetNotificationsFactory(val app: App, val config: WidgetConfig) : Remot getLong("id") ?: 0, getString("title") ?: "", getString("text") ?: "", + getString("textLong"), getInt("type") ?: 0, getInt("profileId"), getString("profileName"), @@ -74,4 +75,4 @@ class WidgetNotificationsFactory(val app: App, val config: WidgetConfig) : Remot override fun hasStableIds() = true override fun getViewTypeCount() = 1 override fun onDestroy() = cursor?.close() ?: Unit -} \ No newline at end of file +} diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 42be8272..5aa206af 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1451,4 +1451,10 @@ Treść podpisu Ustawienia wiadomości lekcja online + Rodzaj: %s\nData: %s (%s)\nLekcja: %s\nNauczyciel: %s + Rodzaj: %s\nPrzedmiot: %s\nTermin: %s (%s), %s\nTreść: %s + Dodane przez: %s\nRodzaj: %s\nPrzedmiot: %s\nTermin: %s (%s), %s\nTreść: %s + Ocena: %s (waga %s)\nPrzedmiot: %s\nKategoria: %s\nOpis: %s\nNauczyciel: %s + Rodzaj: %s\nNauczyciel: %s\nTreść: %s + Rodzaj: %s\nTermin: %s, %s\nNr lekcji: %s\nPrzedmiot: %s\nNauczyciel: %s\nTemat lekcji: %s