Do not show student's name in notifications if there's only one student (#1609)

This commit is contained in:
Michael 2021-11-13 10:06:59 +01:00 committed by GitHub
parent 66e58ab74e
commit 9230db3f99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,6 +13,7 @@ import io.github.wulkanowy.data.db.entities.Student
import io.github.wulkanowy.data.pojos.GroupNotificationData import io.github.wulkanowy.data.pojos.GroupNotificationData
import io.github.wulkanowy.data.pojos.NotificationData import io.github.wulkanowy.data.pojos.NotificationData
import io.github.wulkanowy.data.repositories.NotificationRepository import io.github.wulkanowy.data.repositories.NotificationRepository
import io.github.wulkanowy.data.repositories.StudentRepository
import io.github.wulkanowy.utils.PendingIntentCompat import io.github.wulkanowy.utils.PendingIntentCompat
import io.github.wulkanowy.utils.getCompatBitmap import io.github.wulkanowy.utils.getCompatBitmap
import io.github.wulkanowy.utils.getCompatColor import io.github.wulkanowy.utils.getCompatColor
@ -24,6 +25,7 @@ import kotlin.random.Random
class AppNotificationManager @Inject constructor( class AppNotificationManager @Inject constructor(
private val notificationManager: NotificationManagerCompat, private val notificationManager: NotificationManagerCompat,
@ApplicationContext private val context: Context, @ApplicationContext private val context: Context,
private val studentRepository: StudentRepository,
private val notificationRepository: NotificationRepository private val notificationRepository: NotificationRepository
) { ) {
@ -53,8 +55,12 @@ class AppNotificationManager @Inject constructor(
.setContentText(notificationData.content) .setContentText(notificationData.content)
.setStyle( .setStyle(
NotificationCompat.BigTextStyle() NotificationCompat.BigTextStyle()
.setSummaryText(student.nickOrName)
.bigText(notificationData.content) .bigText(notificationData.content)
.also { builder ->
if (shouldShowStudentName()) {
builder.setSummaryText(student.nickOrName)
}
}
) )
.build() .build()
@ -94,8 +100,12 @@ class AppNotificationManager @Inject constructor(
.setContentText(notificationData.content) .setContentText(notificationData.content)
.setStyle( .setStyle(
NotificationCompat.BigTextStyle() NotificationCompat.BigTextStyle()
.setSummaryText(student.nickOrName)
.bigText(notificationData.content) .bigText(notificationData.content)
.also { builder ->
if (shouldShowStudentName()) {
builder.setSummaryText(student.nickOrName)
}
}
) )
.setGroup(group) .setGroup(group)
.build() .build()
@ -105,7 +115,7 @@ class AppNotificationManager @Inject constructor(
} }
} }
private fun sendSummaryNotification( private suspend fun sendSummaryNotification(
groupNotificationData: GroupNotificationData, groupNotificationData: GroupNotificationData,
group: String, group: String,
student: Student student: Student
@ -123,8 +133,10 @@ class AppNotificationManager @Inject constructor(
.setColor(context.getCompatColor(R.color.colorPrimary)) .setColor(context.getCompatColor(R.color.colorPrimary))
.setStyle( .setStyle(
NotificationCompat.InboxStyle() NotificationCompat.InboxStyle()
.setSummaryText(student.nickOrName)
.also { builder -> .also { builder ->
if (shouldShowStudentName()) {
builder.setSummaryText(student.nickOrName)
}
groupNotificationData.notificationDataList.forEach { groupNotificationData.notificationDataList.forEach {
builder.addLine(it.content) builder.addLine(it.content)
} }
@ -162,4 +174,7 @@ class AppNotificationManager @Inject constructor(
notificationRepository.saveNotification(notificationEntity) notificationRepository.saveNotification(notificationEntity)
} }
private suspend fun shouldShowStudentName(): Boolean =
studentRepository.getSavedStudents(decryptPass = false).size > 1
} }