[UI] Add long text for notification descriptions.

This commit is contained in:
Kuba Szczodrzyński 2021-05-26 19:00:09 +02:00
parent fd0fc652a3
commit 85d74bec1c
No known key found for this signature in database
GPG Key ID: 70CB8A85BA1633CB
5 changed files with 70 additions and 3 deletions

View File

@ -10,6 +10,7 @@ import pl.szczodrzynski.edziennik.R
import pl.szczodrzynski.edziennik.data.db.entity.* import pl.szczodrzynski.edziennik.data.db.entity.*
import pl.szczodrzynski.edziennik.getNotificationTitle import pl.szczodrzynski.edziennik.getNotificationTitle
import pl.szczodrzynski.edziennik.utils.models.Date import pl.szczodrzynski.edziennik.utils.models.Date
import pl.szczodrzynski.edziennik.utils.models.Week
class Notifications(val app: App, val notifications: MutableList<Notification>, val profiles: List<Profile>) { class Notifications(val app: App, val notifications: MutableList<Notification>, val profiles: List<Profile>) {
companion object { companion object {
@ -42,13 +43,22 @@ class Notifications(val app: App, val notifications: MutableList<Notification>,
val text = app.getString( val text = app.getString(
R.string.notification_lesson_change_format, R.string.notification_lesson_change_format,
lesson.getDisplayChangeType(app), lesson.getDisplayChangeType(app),
if (lesson.displayDate == null) "" else lesson.displayDate!!.formattedString, lesson.displayDate?.formattedString ?: "",
lesson.changeSubjectName 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( notifications += Notification(
id = Notification.buildId(lesson.profileId, Notification.TYPE_TIMETABLE_LESSON_CHANGE, lesson.id), id = Notification.buildId(lesson.profileId, Notification.TYPE_TIMETABLE_LESSON_CHANGE, lesson.id),
title = app.getNotificationTitle(Notification.TYPE_TIMETABLE_LESSON_CHANGE), title = app.getNotificationTitle(Notification.TYPE_TIMETABLE_LESSON_CHANGE),
text = text, text = text,
textLong = textLong,
type = Notification.TYPE_TIMETABLE_LESSON_CHANGE, type = Notification.TYPE_TIMETABLE_LESSON_CHANGE,
profileId = lesson.profileId, profileId = lesson.profileId,
profileName = profiles.singleOrNull { it.id == lesson.profileId }?.name, profileName = profiles.singleOrNull { it.id == lesson.profileId }?.name,
@ -79,11 +89,21 @@ class Notifications(val app: App, val notifications: MutableList<Notification>,
event.date.formattedString, event.date.formattedString,
event.subjectLongName 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 val type = if (event.type == Event.TYPE_HOMEWORK) Notification.TYPE_NEW_HOMEWORK else Notification.TYPE_NEW_EVENT
notifications += Notification( notifications += Notification(
id = Notification.buildId(event.profileId, type, event.id), id = Notification.buildId(event.profileId, type, event.id),
title = app.getNotificationTitle(type), title = app.getNotificationTitle(type),
text = text, text = text,
textLong = textLong,
type = type, type = type,
profileId = event.profileId, profileId = event.profileId,
profileName = profiles.singleOrNull { it.id == event.profileId }?.name, profileName = profiles.singleOrNull { it.id == event.profileId }?.name,
@ -102,11 +122,22 @@ class Notifications(val app: App, val notifications: MutableList<Notification>,
event.date.formattedString, event.date.formattedString,
event.topic 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 val type = if (event.type == Event.TYPE_HOMEWORK) Notification.TYPE_NEW_HOMEWORK else Notification.TYPE_NEW_EVENT
notifications += Notification( notifications += Notification(
id = Notification.buildId(event.profileId, type, event.id), id = Notification.buildId(event.profileId, type, event.id),
title = app.getNotificationTitle(type), title = app.getNotificationTitle(type),
text = text, text = text,
textLong = textLong,
type = type, type = type,
profileId = event.profileId, profileId = event.profileId,
profileName = profiles.singleOrNull { it.id == event.profileId }?.name, profileName = profiles.singleOrNull { it.id == event.profileId }?.name,
@ -130,10 +161,20 @@ class Notifications(val app: App, val notifications: MutableList<Notification>,
gradeName, gradeName,
grade.subjectLongName 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( notifications += Notification(
id = Notification.buildId(grade.profileId, Notification.TYPE_NEW_GRADE, grade.id), id = Notification.buildId(grade.profileId, Notification.TYPE_NEW_GRADE, grade.id),
title = app.getNotificationTitle(Notification.TYPE_NEW_GRADE), title = app.getNotificationTitle(Notification.TYPE_NEW_GRADE),
text = text, text = text,
textLong = textLong,
type = Notification.TYPE_NEW_GRADE, type = Notification.TYPE_NEW_GRADE,
profileId = grade.profileId, profileId = grade.profileId,
profileName = profiles.singleOrNull { it.id == grade.profileId }?.name, profileName = profiles.singleOrNull { it.id == grade.profileId }?.name,
@ -158,10 +199,17 @@ class Notifications(val app: App, val notifications: MutableList<Notification>,
notice.teacherName, notice.teacherName,
Date.fromMillis(notice.addedDate).formattedString Date.fromMillis(notice.addedDate).formattedString
) )
val textLong = app.getString(
R.string.notification_notice_long_format,
noticeTypeStr,
notice.teacherName ?: "-",
notice.text.take(200)
)
notifications += Notification( notifications += Notification(
id = Notification.buildId(notice.profileId, Notification.TYPE_NEW_NOTICE, notice.id), id = Notification.buildId(notice.profileId, Notification.TYPE_NEW_NOTICE, notice.id),
title = app.getNotificationTitle(Notification.TYPE_NEW_NOTICE), title = app.getNotificationTitle(Notification.TYPE_NEW_NOTICE),
text = text, text = text,
textLong = textLong,
type = Notification.TYPE_NEW_NOTICE, type = Notification.TYPE_NEW_NOTICE,
profileId = notice.profileId, profileId = notice.profileId,
profileName = profiles.singleOrNull { it.id == notice.profileId }?.name, profileName = profiles.singleOrNull { it.id == notice.profileId }?.name,
@ -193,10 +241,21 @@ class Notifications(val app: App, val notifications: MutableList<Notification>,
attendance.subjectLongName, attendance.subjectLongName,
attendance.date.formattedString 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( notifications += Notification(
id = Notification.buildId(attendance.profileId, Notification.TYPE_NEW_ATTENDANCE, attendance.id), id = Notification.buildId(attendance.profileId, Notification.TYPE_NEW_ATTENDANCE, attendance.id),
title = app.getNotificationTitle(Notification.TYPE_NEW_ATTENDANCE), title = app.getNotificationTitle(Notification.TYPE_NEW_ATTENDANCE),
text = text, text = text,
textLong = textLong,
type = Notification.TYPE_NEW_ATTENDANCE, type = Notification.TYPE_NEW_ATTENDANCE,
profileId = attendance.profileId, profileId = attendance.profileId,
profileName = profiles.singleOrNull { it.id == attendance.profileId }?.name, profileName = profiles.singleOrNull { it.id == attendance.profileId }?.name,

View File

@ -148,7 +148,7 @@ class PostNotifications(val app: App, nList: List<AppNotification>) {
colorRes = R.color.colorPrimary colorRes = R.color.colorPrimary
}.toBitmap()) }.toBitmap())
.setStyle(NotificationCompat.BigTextStyle() .setStyle(NotificationCompat.BigTextStyle()
.bigText(it.text)) .bigText(it.textLong ?: it.text))
.setWhen(it.addedDate) .setWhen(it.addedDate)
.addDefaults() .addDefaults()
.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_SUMMARY) .setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_SUMMARY)

View File

@ -21,6 +21,7 @@ data class Notification(
val title: String, val title: String,
val text: String, val text: String,
val textLong: String? = null,
val type: Int, val type: Int,

View File

@ -45,6 +45,7 @@ class WidgetNotificationsFactory(val app: App, val config: WidgetConfig) : Remot
getLong("id") ?: 0, getLong("id") ?: 0,
getString("title") ?: "", getString("title") ?: "",
getString("text") ?: "", getString("text") ?: "",
getString("textLong"),
getInt("type") ?: 0, getInt("type") ?: 0,
getInt("profileId"), getInt("profileId"),
getString("profileName"), getString("profileName"),
@ -74,4 +75,4 @@ class WidgetNotificationsFactory(val app: App, val config: WidgetConfig) : Remot
override fun hasStableIds() = true override fun hasStableIds() = true
override fun getViewTypeCount() = 1 override fun getViewTypeCount() = 1
override fun onDestroy() = cursor?.close() ?: Unit override fun onDestroy() = cursor?.close() ?: Unit
} }

View File

@ -1451,4 +1451,10 @@
<string name="messages_config_greeting_text">Treść podpisu</string> <string name="messages_config_greeting_text">Treść podpisu</string>
<string name="menu_messages_config">Ustawienia wiadomości</string> <string name="menu_messages_config">Ustawienia wiadomości</string>
<string name="event_type_elearning">lekcja online</string> <string name="event_type_elearning">lekcja online</string>
<string name="notification_lesson_change_long_format">Rodzaj: %s\nData: %s (%s)\nLekcja: %s\nNauczyciel: %s</string>
<string name="notification_event_long_format">Rodzaj: %s\nPrzedmiot: %s\nTermin: %s (%s), %s\nTreść: %s</string>
<string name="notification_shared_event_long_format">Dodane przez: %s\nRodzaj: %s\nPrzedmiot: %s\nTermin: %s (%s), %s\nTreść: %s</string>
<string name="notification_grade_long_format">Ocena: %s (waga %s)\nPrzedmiot: %s\nKategoria: %s\nOpis: %s\nNauczyciel: %s</string>
<string name="notification_notice_long_format">Rodzaj: %s\nNauczyciel: %s\nTreść: %s</string>
<string name="notification_attendance_long_format">Rodzaj: %s\nTermin: %s, %s\nNr lekcji: %s\nPrzedmiot: %s\nNauczyciel: %s\nTemat lekcji: %s</string>
</resources> </resources>