1
0
mirror of https://github.com/wulkanowy/wulkanowy.git synced 2025-02-21 19:24:44 +01:00

Add student nick-or-name to notification summary (#1425)

This commit is contained in:
Mikołaj Pich 2021-08-03 15:48:11 +02:00 committed by GitHub
parent 2bc6d7ad0d
commit 14f4808434
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
30 changed files with 137 additions and 109 deletions

View File

@ -2,7 +2,7 @@
# Wulkanowy # Wulkanowy
[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/wulkanowy/wulkanowy/Test%20and%20deploy/develop?style=flat-square)](https://github.com/wulkanowy/wulkanowy/actions) [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/wulkanowy/wulkanowy/Tests/develop?style=flat-square)](https://github.com/wulkanowy/wulkanowy/actions)
[![Codecov](https://img.shields.io/codecov/c/github/wulkanowy/wulkanowy/master.svg?style=flat-square)](https://codecov.io/gh/wulkanowy/wulkanowy) [![Codecov](https://img.shields.io/codecov/c/github/wulkanowy/wulkanowy/master.svg?style=flat-square)](https://codecov.io/gh/wulkanowy/wulkanowy)
[![Discord](https://img.shields.io/discord/390889354199040011.svg?style=flat-square)](https://discord.gg/vccAQBr) [![Discord](https://img.shields.io/discord/390889354199040011.svg?style=flat-square)](https://discord.gg/vccAQBr)
[![F-Droid](https://img.shields.io/f-droid/v/io.github.wulkanowy.svg?style=flat-square)](https://f-droid.org/packages/io.github.wulkanowy/) [![F-Droid](https://img.shields.io/f-droid/v/io.github.wulkanowy.svg?style=flat-square)](https://f-droid.org/packages/io.github.wulkanowy/)

View File

@ -2,7 +2,7 @@
# Wulkanowy # Wulkanowy
[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/wulkanowy/wulkanowy/Test%20and%20deploy/develop?style=flat-square)](https://github.com/wulkanowy/wulkanowy/actions) [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/wulkanowy/wulkanowy/Tests/develop?style=flat-square)](https://github.com/wulkanowy/wulkanowy/actions)
[![Codecov](https://img.shields.io/codecov/c/github/wulkanowy/wulkanowy/master.svg?style=flat-square)](https://codecov.io/gh/wulkanowy/wulkanowy) [![Codecov](https://img.shields.io/codecov/c/github/wulkanowy/wulkanowy/master.svg?style=flat-square)](https://codecov.io/gh/wulkanowy/wulkanowy)
[![Discord](https://img.shields.io/discord/390889354199040011.svg?style=flat-square)](https://discord.gg/vccAQBr) [![Discord](https://img.shields.io/discord/390889354199040011.svg?style=flat-square)](https://discord.gg/vccAQBr)
[![F-Droid](https://img.shields.io/f-droid/v/io.github.wulkanowy.svg?style=flat-square)](https://f-droid.org/packages/io.github.wulkanowy/) [![F-Droid](https://img.shields.io/f-droid/v/io.github.wulkanowy.svg?style=flat-square)](https://f-droid.org/packages/io.github.wulkanowy/)

View File

@ -3,11 +3,11 @@ package io.github.wulkanowy.data.pojos
import androidx.annotation.DrawableRes import androidx.annotation.DrawableRes
import androidx.annotation.PluralsRes import androidx.annotation.PluralsRes
import androidx.annotation.StringRes import androidx.annotation.StringRes
import io.github.wulkanowy.services.sync.notifications.NotificationType
import io.github.wulkanowy.ui.modules.main.MainView import io.github.wulkanowy.ui.modules.main.MainView
sealed interface Notification { sealed interface Notification {
val channelId: String val type: NotificationType
val group: String
val startMenu: MainView.Section val startMenu: MainView.Section
val icon: Int val icon: Int
val titleStringRes: Int val titleStringRes: Int
@ -15,8 +15,7 @@ sealed interface Notification {
} }
data class MultipleNotifications( data class MultipleNotifications(
override val channelId: String, override val type: NotificationType,
override val group: String,
override val startMenu: MainView.Section, override val startMenu: MainView.Section,
@DrawableRes override val icon: Int, @DrawableRes override val icon: Int,
@PluralsRes override val titleStringRes: Int, @PluralsRes override val titleStringRes: Int,
@ -27,8 +26,7 @@ data class MultipleNotifications(
) : Notification ) : Notification
data class OneNotification( data class OneNotification(
override val channelId: String, override val type: NotificationType,
override val group: String,
override val startMenu: MainView.Section, override val startMenu: MainView.Section,
@DrawableRes override val icon: Int, @DrawableRes override val icon: Int,
@StringRes override val titleStringRes: Int, @StringRes override val titleStringRes: Int,

View File

@ -18,7 +18,6 @@ class LuckyNumberChannel @Inject constructor(
companion object { companion object {
const val CHANNEL_ID = "lucky_number_channel" const val CHANNEL_ID = "lucky_number_channel"
const val GROUP_ID = "lucky_number_group"
} }
override fun create() { override fun create() {

View File

@ -18,7 +18,6 @@ class NewConferencesChannel @Inject constructor(
companion object { companion object {
const val CHANNEL_ID = "new_conferences_channel" const val CHANNEL_ID = "new_conferences_channel"
const val GROUP_ID = "new_conferences_group"
} }
override fun create() { override fun create() {

View File

@ -18,7 +18,6 @@ class NewExamChannel @Inject constructor(
companion object { companion object {
const val CHANNEL_ID = "new_exam_channel" const val CHANNEL_ID = "new_exam_channel"
const val GROUP_ID = "new_exam_group"
} }
override fun create() { override fun create() {

View File

@ -18,9 +18,6 @@ class NewGradesChannel @Inject constructor(
companion object { companion object {
const val CHANNEL_ID = "new_grade_channel" const val CHANNEL_ID = "new_grade_channel"
const val GROUP_DETAILS_ID = "new_grade_details_group"
const val GROUP_PREDICTED_ID = "new_grade_predicted_group"
const val GROUP_FINAL_ID = "new_grade_final_group"
} }
override fun create() { override fun create() {

View File

@ -18,7 +18,6 @@ class NewHomeworkChannel @Inject constructor(
companion object { companion object {
const val CHANNEL_ID = "new_homework_channel" const val CHANNEL_ID = "new_homework_channel"
const val GROUP_ID = "new_homework_group"
} }
override fun create() { override fun create() {

View File

@ -18,7 +18,6 @@ class NewMessagesChannel @Inject constructor(
companion object { companion object {
const val CHANNEL_ID = "new_message_channel" const val CHANNEL_ID = "new_message_channel"
const val GROUP_ID = "new_message_group"
} }
override fun create() { override fun create() {

View File

@ -18,7 +18,6 @@ class NewNotesChannel @Inject constructor(
companion object { companion object {
const val CHANNEL_ID = "new_notes_channel" const val CHANNEL_ID = "new_notes_channel"
const val GROUP_ID = "new_notes_group"
} }
override fun create() { override fun create() {

View File

@ -18,7 +18,6 @@ class NewSchoolAnnouncementsChannel @Inject constructor(
companion object { companion object {
const val CHANNEL_ID = "new_school_announcements_channel" const val CHANNEL_ID = "new_school_announcements_channel"
const val GROUP_ID = "new_school_announcements_group"
} }
override fun create() { override fun create() {

View File

@ -7,12 +7,14 @@ import androidx.annotation.PluralsRes
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat import androidx.core.app.NotificationManagerCompat
import io.github.wulkanowy.R import io.github.wulkanowy.R
import io.github.wulkanowy.data.db.entities.Student
import io.github.wulkanowy.data.pojos.MultipleNotifications import io.github.wulkanowy.data.pojos.MultipleNotifications
import io.github.wulkanowy.data.pojos.Notification import io.github.wulkanowy.data.pojos.Notification
import io.github.wulkanowy.data.pojos.OneNotification import io.github.wulkanowy.data.pojos.OneNotification
import io.github.wulkanowy.ui.modules.main.MainActivity import io.github.wulkanowy.ui.modules.main.MainActivity
import io.github.wulkanowy.utils.getCompatBitmap import io.github.wulkanowy.utils.getCompatBitmap
import io.github.wulkanowy.utils.getCompatColor import io.github.wulkanowy.utils.getCompatColor
import io.github.wulkanowy.utils.nickOrName
import kotlin.random.Random import kotlin.random.Random
abstract class BaseNotification( abstract class BaseNotification(
@ -20,12 +22,13 @@ abstract class BaseNotification(
private val notificationManager: NotificationManagerCompat, private val notificationManager: NotificationManagerCompat,
) { ) {
protected fun sendNotification(notification: Notification) = when (notification) { protected fun sendNotification(notification: Notification, student: Student) =
is OneNotification -> sendOneNotification(notification) when (notification) {
is MultipleNotifications -> sendMultipleNotifications(notification) is OneNotification -> sendOneNotification(notification, student)
} is MultipleNotifications -> sendMultipleNotifications(notification, student)
}
private fun sendOneNotification(notification: OneNotification) { private fun sendOneNotification(notification: OneNotification, student: Student?) {
notificationManager.notify( notificationManager.notify(
Random.nextInt(Int.MAX_VALUE), Random.nextInt(Int.MAX_VALUE),
getNotificationBuilder(notification).apply { getNotificationBuilder(notification).apply {
@ -35,20 +38,31 @@ abstract class BaseNotification(
) )
setContentTitle(context.getString(notification.titleStringRes)) setContentTitle(context.getString(notification.titleStringRes))
setContentText(content) setContentText(content)
setStyle(NotificationCompat.BigTextStyle().bigText(content)) setStyle(
NotificationCompat.BigTextStyle()
.setSummaryText(student?.nickOrName)
.bigText(content)
)
}.build() }.build()
) )
} }
private fun sendMultipleNotifications(notification: MultipleNotifications) { private fun sendMultipleNotifications(notification: MultipleNotifications, student: Student) {
val group = notification.type.group + student.id
val groupId = student.id * 100 + notification.type.ordinal
notification.lines.forEach { item -> notification.lines.forEach { item ->
notificationManager.notify( notificationManager.notify(
Random.nextInt(Int.MAX_VALUE), Random.nextInt(Int.MAX_VALUE),
getNotificationBuilder(notification).apply { getNotificationBuilder(notification).apply {
setContentTitle(getQuantityString(notification.titleStringRes, 1)) setContentTitle(getQuantityString(notification.titleStringRes, 1))
setContentText(item) setContentText(item)
setStyle(NotificationCompat.BigTextStyle().bigText(item)) setStyle(
setGroup(notification.group) NotificationCompat.BigTextStyle()
.setSummaryText(student.nickOrName)
.bigText(item)
)
setGroup(group)
}.build() }.build()
) )
} }
@ -56,17 +70,18 @@ abstract class BaseNotification(
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) return if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) return
notificationManager.notify( notificationManager.notify(
notification.group.hashCode(), groupId.toInt(),
getNotificationBuilder(notification).apply { getNotificationBuilder(notification).apply {
setSmallIcon(notification.icon) setSmallIcon(notification.icon)
setGroup(notification.group) setGroup(group)
setStyle(NotificationCompat.InboxStyle().setSummaryText(student.nickOrName))
setGroupSummary(true) setGroupSummary(true)
}.build() }.build()
) )
} }
private fun getNotificationBuilder(notification: Notification) = NotificationCompat private fun getNotificationBuilder(notification: Notification) = NotificationCompat
.Builder(context, notification.channelId) .Builder(context, notification.type.channel)
.setLargeIcon(context.getCompatBitmap(notification.icon, R.color.colorPrimary)) .setLargeIcon(context.getCompatBitmap(notification.icon, R.color.colorPrimary))
.setSmallIcon(R.drawable.ic_stat_all) .setSmallIcon(R.drawable.ic_stat_all)
.setAutoCancel(true) .setAutoCancel(true)

View File

@ -5,8 +5,8 @@ import androidx.core.app.NotificationManagerCompat
import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.android.qualifiers.ApplicationContext
import io.github.wulkanowy.R import io.github.wulkanowy.R
import io.github.wulkanowy.data.db.entities.Conference import io.github.wulkanowy.data.db.entities.Conference
import io.github.wulkanowy.data.db.entities.Student
import io.github.wulkanowy.data.pojos.MultipleNotifications import io.github.wulkanowy.data.pojos.MultipleNotifications
import io.github.wulkanowy.services.sync.channels.NewConferencesChannel
import io.github.wulkanowy.ui.modules.main.MainView import io.github.wulkanowy.ui.modules.main.MainView
import javax.inject.Inject import javax.inject.Inject
@ -15,10 +15,9 @@ class NewConferenceNotification @Inject constructor(
notificationManager: NotificationManagerCompat, notificationManager: NotificationManagerCompat,
) : BaseNotification(context, notificationManager) { ) : BaseNotification(context, notificationManager) {
fun notify(items: List<Conference>) { fun notify(items: List<Conference>, student: Student) {
val notification = MultipleNotifications( val notification = MultipleNotifications(
channelId = NewConferencesChannel.CHANNEL_ID, type = NotificationType.NEW_CONFERENCE,
group = NewConferencesChannel.GROUP_ID,
icon = R.drawable.ic_more_conferences, icon = R.drawable.ic_more_conferences,
titleStringRes = R.plurals.conference_notify_new_item_title, titleStringRes = R.plurals.conference_notify_new_item_title,
contentStringRes = R.plurals.conference_notify_new_items, contentStringRes = R.plurals.conference_notify_new_items,
@ -29,6 +28,6 @@ class NewConferenceNotification @Inject constructor(
} }
) )
sendNotification(notification) sendNotification(notification, student)
} }
} }

View File

@ -5,8 +5,8 @@ import androidx.core.app.NotificationManagerCompat
import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.android.qualifiers.ApplicationContext
import io.github.wulkanowy.R import io.github.wulkanowy.R
import io.github.wulkanowy.data.db.entities.Exam import io.github.wulkanowy.data.db.entities.Exam
import io.github.wulkanowy.data.db.entities.Student
import io.github.wulkanowy.data.pojos.MultipleNotifications import io.github.wulkanowy.data.pojos.MultipleNotifications
import io.github.wulkanowy.services.sync.channels.NewExamChannel
import io.github.wulkanowy.ui.modules.main.MainView import io.github.wulkanowy.ui.modules.main.MainView
import javax.inject.Inject import javax.inject.Inject
@ -15,10 +15,9 @@ class NewExamNotification @Inject constructor(
notificationManager: NotificationManagerCompat, notificationManager: NotificationManagerCompat,
) : BaseNotification(context, notificationManager) { ) : BaseNotification(context, notificationManager) {
fun notify(items: List<Exam>) { fun notify(items: List<Exam>, student: Student) {
val notification = MultipleNotifications( val notification = MultipleNotifications(
channelId = NewExamChannel.CHANNEL_ID, type = NotificationType.NEW_EXAM,
group = NewExamChannel.GROUP_ID,
icon = R.drawable.ic_main_exam, icon = R.drawable.ic_main_exam,
titleStringRes = R.plurals.exam_notify_new_item_title, titleStringRes = R.plurals.exam_notify_new_item_title,
contentStringRes = R.plurals.exam_notify_new_item_title, // TODO add missing string contentStringRes = R.plurals.exam_notify_new_item_title, // TODO add missing string
@ -29,6 +28,6 @@ class NewExamNotification @Inject constructor(
} }
) )
sendNotification(notification) sendNotification(notification, student)
} }
} }

View File

@ -6,8 +6,8 @@ import dagger.hilt.android.qualifiers.ApplicationContext
import io.github.wulkanowy.R import io.github.wulkanowy.R
import io.github.wulkanowy.data.db.entities.Grade import io.github.wulkanowy.data.db.entities.Grade
import io.github.wulkanowy.data.db.entities.GradeSummary import io.github.wulkanowy.data.db.entities.GradeSummary
import io.github.wulkanowy.data.db.entities.Student
import io.github.wulkanowy.data.pojos.MultipleNotifications import io.github.wulkanowy.data.pojos.MultipleNotifications
import io.github.wulkanowy.services.sync.channels.NewGradesChannel
import io.github.wulkanowy.ui.modules.main.MainView import io.github.wulkanowy.ui.modules.main.MainView
import javax.inject.Inject import javax.inject.Inject
@ -16,10 +16,9 @@ class NewGradeNotification @Inject constructor(
notificationManager: NotificationManagerCompat, notificationManager: NotificationManagerCompat,
) : BaseNotification(context, notificationManager) { ) : BaseNotification(context, notificationManager) {
fun notifyDetails(items: List<Grade>) { fun notifyDetails(items: List<Grade>, student: Student) {
val notification = MultipleNotifications( val notification = MultipleNotifications(
channelId = NewGradesChannel.CHANNEL_ID, type = NotificationType.NEW_GRADE_DETAILS,
group = NewGradesChannel.GROUP_DETAILS_ID,
icon = R.drawable.ic_stat_grade, icon = R.drawable.ic_stat_grade,
titleStringRes = R.plurals.grade_new_items, titleStringRes = R.plurals.grade_new_items,
contentStringRes = R.plurals.grade_notify_new_items, contentStringRes = R.plurals.grade_notify_new_items,
@ -30,13 +29,12 @@ class NewGradeNotification @Inject constructor(
} }
) )
sendNotification(notification) sendNotification(notification, student)
} }
fun notifyPredicted(items: List<GradeSummary>) { fun notifyPredicted(items: List<GradeSummary>, student: Student) {
val notification = MultipleNotifications( val notification = MultipleNotifications(
channelId = NewGradesChannel.CHANNEL_ID, type = NotificationType.NEW_GRADE_PREDICTED,
group = NewGradesChannel.GROUP_PREDICTED_ID,
icon = R.drawable.ic_stat_grade, icon = R.drawable.ic_stat_grade,
titleStringRes = R.plurals.grade_new_items_predicted, titleStringRes = R.plurals.grade_new_items_predicted,
contentStringRes = R.plurals.grade_notify_new_items_predicted, contentStringRes = R.plurals.grade_notify_new_items_predicted,
@ -47,13 +45,12 @@ class NewGradeNotification @Inject constructor(
} }
) )
sendNotification(notification) sendNotification(notification, student)
} }
fun notifyFinal(items: List<GradeSummary>) { fun notifyFinal(items: List<GradeSummary>, student: Student) {
val notification = MultipleNotifications( val notification = MultipleNotifications(
channelId = NewGradesChannel.CHANNEL_ID, type = NotificationType.NEW_GRADE_FINAL,
group = NewGradesChannel.GROUP_FINAL_ID,
icon = R.drawable.ic_stat_grade, icon = R.drawable.ic_stat_grade,
titleStringRes = R.plurals.grade_new_items_final, titleStringRes = R.plurals.grade_new_items_final,
contentStringRes = R.plurals.grade_notify_new_items_final, contentStringRes = R.plurals.grade_notify_new_items_final,
@ -64,6 +61,6 @@ class NewGradeNotification @Inject constructor(
} }
) )
sendNotification(notification) sendNotification(notification, student)
} }
} }

View File

@ -5,8 +5,8 @@ import androidx.core.app.NotificationManagerCompat
import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.android.qualifiers.ApplicationContext
import io.github.wulkanowy.R import io.github.wulkanowy.R
import io.github.wulkanowy.data.db.entities.Homework import io.github.wulkanowy.data.db.entities.Homework
import io.github.wulkanowy.data.db.entities.Student
import io.github.wulkanowy.data.pojos.MultipleNotifications import io.github.wulkanowy.data.pojos.MultipleNotifications
import io.github.wulkanowy.services.sync.channels.NewHomeworkChannel
import io.github.wulkanowy.ui.modules.main.MainView import io.github.wulkanowy.ui.modules.main.MainView
import javax.inject.Inject import javax.inject.Inject
@ -15,10 +15,9 @@ class NewHomeworkNotification @Inject constructor(
notificationManager: NotificationManagerCompat, notificationManager: NotificationManagerCompat,
) : BaseNotification(context, notificationManager) { ) : BaseNotification(context, notificationManager) {
fun notify(items: List<Homework>) { fun notify(items: List<Homework>, student: Student) {
val notification = MultipleNotifications( val notification = MultipleNotifications(
channelId = NewHomeworkChannel.CHANNEL_ID, type = NotificationType.NEW_HOMEWORK,
group = NewHomeworkChannel.GROUP_ID,
icon = R.drawable.ic_more_homework, icon = R.drawable.ic_more_homework,
titleStringRes = R.plurals.homework_notify_new_item_title, titleStringRes = R.plurals.homework_notify_new_item_title,
contentStringRes = R.plurals.homework_notify_new_item_title, // todo: you received %d new homework contentStringRes = R.plurals.homework_notify_new_item_title, // todo: you received %d new homework
@ -29,6 +28,6 @@ class NewHomeworkNotification @Inject constructor(
} }
) )
sendNotification(notification) sendNotification(notification, student)
} }
} }

View File

@ -5,8 +5,8 @@ import androidx.core.app.NotificationManagerCompat
import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.android.qualifiers.ApplicationContext
import io.github.wulkanowy.R import io.github.wulkanowy.R
import io.github.wulkanowy.data.db.entities.LuckyNumber import io.github.wulkanowy.data.db.entities.LuckyNumber
import io.github.wulkanowy.data.db.entities.Student
import io.github.wulkanowy.data.pojos.OneNotification import io.github.wulkanowy.data.pojos.OneNotification
import io.github.wulkanowy.services.sync.channels.LuckyNumberChannel
import io.github.wulkanowy.ui.modules.main.MainView import io.github.wulkanowy.ui.modules.main.MainView
import javax.inject.Inject import javax.inject.Inject
@ -15,10 +15,9 @@ class NewLuckyNumberNotification @Inject constructor(
notificationManager: NotificationManagerCompat, notificationManager: NotificationManagerCompat,
) : BaseNotification(context, notificationManager) { ) : BaseNotification(context, notificationManager) {
fun notify(item: LuckyNumber) { fun notify(item: LuckyNumber, student: Student) {
val notification = OneNotification( val notification = OneNotification(
channelId = LuckyNumberChannel.CHANNEL_ID, type = NotificationType.NEW_LUCKY_NUMBER,
group = LuckyNumberChannel.GROUP_ID,
icon = R.drawable.ic_stat_luckynumber, icon = R.drawable.ic_stat_luckynumber,
titleStringRes = R.string.lucky_number_notify_new_item_title, titleStringRes = R.string.lucky_number_notify_new_item_title,
contentStringRes = R.string.lucky_number_notify_new_item, contentStringRes = R.string.lucky_number_notify_new_item,
@ -26,6 +25,6 @@ class NewLuckyNumberNotification @Inject constructor(
contentValues = listOf(item.luckyNumber.toString()) contentValues = listOf(item.luckyNumber.toString())
) )
sendNotification(notification) sendNotification(notification, student)
} }
} }

View File

@ -5,8 +5,8 @@ import androidx.core.app.NotificationManagerCompat
import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.android.qualifiers.ApplicationContext
import io.github.wulkanowy.R import io.github.wulkanowy.R
import io.github.wulkanowy.data.db.entities.Message import io.github.wulkanowy.data.db.entities.Message
import io.github.wulkanowy.data.db.entities.Student
import io.github.wulkanowy.data.pojos.MultipleNotifications import io.github.wulkanowy.data.pojos.MultipleNotifications
import io.github.wulkanowy.services.sync.channels.NewMessagesChannel
import io.github.wulkanowy.ui.modules.main.MainView import io.github.wulkanowy.ui.modules.main.MainView
import javax.inject.Inject import javax.inject.Inject
@ -15,10 +15,9 @@ class NewMessageNotification @Inject constructor(
notificationManager: NotificationManagerCompat, notificationManager: NotificationManagerCompat,
) : BaseNotification(context, notificationManager) { ) : BaseNotification(context, notificationManager) {
fun notify(items: List<Message>) { fun notify(items: List<Message>, student: Student) {
val notification = MultipleNotifications( val notification = MultipleNotifications(
channelId = NewMessagesChannel.CHANNEL_ID, type = NotificationType.NEW_MESSAGE,
group = NewMessagesChannel.GROUP_ID,
icon = R.drawable.ic_stat_message, icon = R.drawable.ic_stat_message,
titleStringRes = R.plurals.message_new_items, titleStringRes = R.plurals.message_new_items,
contentStringRes = R.plurals.message_notify_new_items, contentStringRes = R.plurals.message_notify_new_items,
@ -29,6 +28,6 @@ class NewMessageNotification @Inject constructor(
} }
) )
sendNotification(notification) sendNotification(notification, student)
} }
} }

View File

@ -5,9 +5,9 @@ import androidx.core.app.NotificationManagerCompat
import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.android.qualifiers.ApplicationContext
import io.github.wulkanowy.R import io.github.wulkanowy.R
import io.github.wulkanowy.data.db.entities.Note import io.github.wulkanowy.data.db.entities.Note
import io.github.wulkanowy.data.db.entities.Student
import io.github.wulkanowy.data.pojos.MultipleNotifications import io.github.wulkanowy.data.pojos.MultipleNotifications
import io.github.wulkanowy.sdk.scrapper.notes.NoteCategory import io.github.wulkanowy.sdk.scrapper.notes.NoteCategory
import io.github.wulkanowy.services.sync.channels.NewNotesChannel
import io.github.wulkanowy.ui.modules.main.MainView import io.github.wulkanowy.ui.modules.main.MainView
import javax.inject.Inject import javax.inject.Inject
@ -16,10 +16,9 @@ class NewNoteNotification @Inject constructor(
notificationManager: NotificationManagerCompat, notificationManager: NotificationManagerCompat,
) : BaseNotification(context, notificationManager) { ) : BaseNotification(context, notificationManager) {
fun notify(items: List<Note>) { fun notify(items: List<Note>, student: Student) {
val notification = MultipleNotifications( val notification = MultipleNotifications(
channelId = NewNotesChannel.CHANNEL_ID, type = NotificationType.NEW_NOTE,
group = NewNotesChannel.GROUP_ID,
icon = R.drawable.ic_stat_note, icon = R.drawable.ic_stat_note,
titleStringRes = when (NoteCategory.getByValue(items.first().categoryType)) { titleStringRes = when (NoteCategory.getByValue(items.first().categoryType)) {
NoteCategory.POSITIVE -> R.plurals.praise_new_items NoteCategory.POSITIVE -> R.plurals.praise_new_items
@ -42,6 +41,6 @@ class NewNoteNotification @Inject constructor(
} }
) )
sendNotification(notification) sendNotification(notification, student)
} }
} }

View File

@ -5,8 +5,8 @@ import androidx.core.app.NotificationManagerCompat
import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.android.qualifiers.ApplicationContext
import io.github.wulkanowy.R import io.github.wulkanowy.R
import io.github.wulkanowy.data.db.entities.SchoolAnnouncement import io.github.wulkanowy.data.db.entities.SchoolAnnouncement
import io.github.wulkanowy.data.db.entities.Student
import io.github.wulkanowy.data.pojos.MultipleNotifications import io.github.wulkanowy.data.pojos.MultipleNotifications
import io.github.wulkanowy.services.sync.channels.NewSchoolAnnouncementsChannel
import io.github.wulkanowy.ui.modules.main.MainView import io.github.wulkanowy.ui.modules.main.MainView
import javax.inject.Inject import javax.inject.Inject
@ -15,10 +15,9 @@ class NewSchoolAnnouncementNotification @Inject constructor(
notificationManager: NotificationManagerCompat, notificationManager: NotificationManagerCompat,
) : BaseNotification(context, notificationManager) { ) : BaseNotification(context, notificationManager) {
fun notify(items: List<SchoolAnnouncement>) { fun notify(items: List<SchoolAnnouncement>, student: Student) {
val notification = MultipleNotifications( val notification = MultipleNotifications(
channelId = NewSchoolAnnouncementsChannel.CHANNEL_ID, type = NotificationType.NEW_ANNOUNCEMENT,
group = NewSchoolAnnouncementsChannel.GROUP_ID,
icon = R.drawable.ic_all_about, icon = R.drawable.ic_all_about,
titleStringRes = R.plurals.school_announcement_notify_new_item_title, titleStringRes = R.plurals.school_announcement_notify_new_item_title,
contentStringRes = R.plurals.school_announcement_notify_new_items, contentStringRes = R.plurals.school_announcement_notify_new_items,
@ -29,6 +28,6 @@ class NewSchoolAnnouncementNotification @Inject constructor(
} }
) )
sendNotification(notification) sendNotification(notification, student)
} }
} }

View File

@ -0,0 +1,23 @@
package io.github.wulkanowy.services.sync.notifications
import io.github.wulkanowy.services.sync.channels.LuckyNumberChannel
import io.github.wulkanowy.services.sync.channels.NewConferencesChannel
import io.github.wulkanowy.services.sync.channels.NewExamChannel
import io.github.wulkanowy.services.sync.channels.NewGradesChannel
import io.github.wulkanowy.services.sync.channels.NewHomeworkChannel
import io.github.wulkanowy.services.sync.channels.NewMessagesChannel
import io.github.wulkanowy.services.sync.channels.NewNotesChannel
import io.github.wulkanowy.services.sync.channels.NewSchoolAnnouncementsChannel
enum class NotificationType(val group: String, val channel: String) {
NEW_CONFERENCE("new_conferences_group", NewConferencesChannel.CHANNEL_ID),
NEW_EXAM("new_exam_group", NewExamChannel.CHANNEL_ID),
NEW_GRADE_DETAILS("new_grade_details_group", NewGradesChannel.CHANNEL_ID),
NEW_GRADE_PREDICTED("new_grade_predicted_group", NewGradesChannel.CHANNEL_ID),
NEW_GRADE_FINAL("new_grade_final_group", NewGradesChannel.CHANNEL_ID),
NEW_HOMEWORK("new_homework_group", NewHomeworkChannel.CHANNEL_ID),
NEW_LUCKY_NUMBER("lucky_number_group", LuckyNumberChannel.CHANNEL_ID),
NEW_MESSAGE("new_message_group", NewMessagesChannel.CHANNEL_ID),
NEW_NOTE("new_notes_group", NewNotesChannel.CHANNEL_ID),
NEW_ANNOUNCEMENT("new_school_announcements_group", NewSchoolAnnouncementsChannel.CHANNEL_ID),
}

View File

@ -25,7 +25,7 @@ class ConferenceWork @Inject constructor(
conferenceRepository.getConferenceFromDatabase(semester).first() conferenceRepository.getConferenceFromDatabase(semester).first()
.filter { !it.isNotified }.let { .filter { !it.isNotified }.let {
if (it.isNotEmpty()) newConferenceNotification.notify(it) if (it.isNotEmpty()) newConferenceNotification.notify(it, student)
conferenceRepository.updateConference(it.onEach { conference -> conferenceRepository.updateConference(it.onEach { conference ->
conference.isNotified = true conference.isNotified = true

View File

@ -28,7 +28,7 @@ class ExamWork @Inject constructor(
examRepository.getExamsFromDatabase(semester, now()).first() examRepository.getExamsFromDatabase(semester, now()).first()
.filter { !it.isNotified }.let { .filter { !it.isNotified }.let {
if (it.isNotEmpty()) newExamNotification.notify(it) if (it.isNotEmpty()) newExamNotification.notify(it, student)
examRepository.updateExam(it.onEach { exam -> exam.isNotified = true }) examRepository.updateExam(it.onEach { exam -> exam.isNotified = true })
} }

View File

@ -25,14 +25,14 @@ class GradeWork @Inject constructor(
gradeRepository.getGradesFromDatabase(semester).first() gradeRepository.getGradesFromDatabase(semester).first()
.filter { !it.isNotified }.let { .filter { !it.isNotified }.let {
if (it.isNotEmpty()) newGradeNotification.notifyDetails(it) if (it.isNotEmpty()) newGradeNotification.notifyDetails(it, student)
gradeRepository.updateGrades(it.onEach { grade -> grade.isNotified = true }) gradeRepository.updateGrades(it.onEach { grade -> grade.isNotified = true })
} }
gradeRepository.getGradesPredictedFromDatabase(semester).first() gradeRepository.getGradesPredictedFromDatabase(semester).first()
.filter { !it.isPredictedGradeNotified }.let { .filter { !it.isPredictedGradeNotified }.let {
if (it.isNotEmpty()) newGradeNotification.notifyPredicted(it) if (it.isNotEmpty()) newGradeNotification.notifyPredicted(it, student)
gradeRepository.updateGradesSummary(it.onEach { grade -> gradeRepository.updateGradesSummary(it.onEach { grade ->
grade.isPredictedGradeNotified = true grade.isPredictedGradeNotified = true
@ -41,7 +41,7 @@ class GradeWork @Inject constructor(
gradeRepository.getGradesFinalFromDatabase(semester).first() gradeRepository.getGradesFinalFromDatabase(semester).first()
.filter { !it.isFinalGradeNotified }.let { .filter { !it.isFinalGradeNotified }.let {
if (it.isNotEmpty()) newGradeNotification.notifyFinal(it) if (it.isNotEmpty()) newGradeNotification.notifyFinal(it, student)
gradeRepository.updateGradesSummary(it.onEach { grade -> gradeRepository.updateGradesSummary(it.onEach { grade ->
grade.isFinalGradeNotified = true grade.isFinalGradeNotified = true

View File

@ -30,7 +30,7 @@ class HomeworkWork @Inject constructor(
homeworkRepository.getHomeworkFromDatabase(semester, now().monday, now().sunday).first() homeworkRepository.getHomeworkFromDatabase(semester, now().monday, now().sunday).first()
.filter { !it.isNotified }.let { .filter { !it.isNotified }.let {
if (it.isNotEmpty()) newHomeworkNotification.notify(it) if (it.isNotEmpty()) newHomeworkNotification.notify(it, student)
homeworkRepository.updateHomework(it.onEach { homework -> homeworkRepository.updateHomework(it.onEach { homework ->
homework.isNotified = true homework.isNotified = true

View File

@ -22,7 +22,7 @@ class LuckyNumberWork @Inject constructor(
).waitForResult() ).waitForResult()
luckyNumberRepository.getNotNotifiedLuckyNumber(student)?.let { luckyNumberRepository.getNotNotifiedLuckyNumber(student)?.let {
newLuckyNumberNotification.notify(it) newLuckyNumberNotification.notify(it, student)
luckyNumberRepository.updateLuckyNumber(it.apply { isNotified = true }) luckyNumberRepository.updateLuckyNumber(it.apply { isNotified = true })
} }
} }

View File

@ -27,7 +27,7 @@ class MessageWork @Inject constructor(
messageRepository.getMessagesFromDatabase(student).first() messageRepository.getMessagesFromDatabase(student).first()
.filter { !it.isNotified && it.unread }.let { .filter { !it.isNotified && it.unread }.let {
if (it.isNotEmpty()) newMessageNotification.notify(it) if (it.isNotEmpty()) newMessageNotification.notify(it, student)
messageRepository.updateMessages(it.onEach { message -> message.isNotified = true }) messageRepository.updateMessages(it.onEach { message -> message.isNotified = true })
} }
} }

View File

@ -25,7 +25,7 @@ class NoteWork @Inject constructor(
noteRepository.getNotesFromDatabase(student).first() noteRepository.getNotesFromDatabase(student).first()
.filter { !it.isNotified }.let { .filter { !it.isNotified }.let {
if (it.isNotEmpty()) newNoteNotification.notify(it) if (it.isNotEmpty()) newNoteNotification.notify(it, student)
noteRepository.updateNotes(it.onEach { note -> note.isNotified = true }) noteRepository.updateNotes(it.onEach { note -> note.isNotified = true })
} }

View File

@ -25,7 +25,7 @@ class SchoolAnnouncementWork @Inject constructor(
schoolAnnouncementRepository.getSchoolAnnouncementFromDatabase(student).first() schoolAnnouncementRepository.getSchoolAnnouncementFromDatabase(student).first()
.filter { !it.isNotified }.let { .filter { !it.isNotified }.let {
if (it.isNotEmpty()) newSchoolAnnouncementNotification.notify(it) if (it.isNotEmpty()) newSchoolAnnouncementNotification.notify(it, student)
schoolAnnouncementRepository.updateSchoolAnnouncement(it.onEach { schoolAnnouncement -> schoolAnnouncementRepository.updateSchoolAnnouncement(it.onEach { schoolAnnouncement ->
schoolAnnouncement.isNotified = true schoolAnnouncement.isNotified = true

View File

@ -1,6 +1,7 @@
package io.github.wulkanowy.ui.modules.debug.notification package io.github.wulkanowy.ui.modules.debug.notification
import io.github.wulkanowy.R import io.github.wulkanowy.R
import io.github.wulkanowy.data.db.entities.Student
import io.github.wulkanowy.data.repositories.StudentRepository import io.github.wulkanowy.data.repositories.StudentRepository
import io.github.wulkanowy.services.sync.notifications.NewConferenceNotification import io.github.wulkanowy.services.sync.notifications.NewConferenceNotification
import io.github.wulkanowy.services.sync.notifications.NewExamNotification import io.github.wulkanowy.services.sync.notifications.NewExamNotification
@ -21,6 +22,7 @@ import io.github.wulkanowy.ui.modules.debug.notification.mock.debugLuckyNumber
import io.github.wulkanowy.ui.modules.debug.notification.mock.debugMessageItems import io.github.wulkanowy.ui.modules.debug.notification.mock.debugMessageItems
import io.github.wulkanowy.ui.modules.debug.notification.mock.debugNoteItems import io.github.wulkanowy.ui.modules.debug.notification.mock.debugNoteItems
import io.github.wulkanowy.ui.modules.debug.notification.mock.debugSchoolAnnouncementItems import io.github.wulkanowy.ui.modules.debug.notification.mock.debugSchoolAnnouncementItems
import kotlinx.coroutines.launch
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
@ -38,36 +40,40 @@ class NotificationDebugPresenter @Inject constructor(
) : BasePresenter<NotificationDebugView>(errorHandler, studentRepository) { ) : BasePresenter<NotificationDebugView>(errorHandler, studentRepository) {
private val items = listOf( private val items = listOf(
NotificationDebugItem(R.string.grade_title) { NotificationDebugItem(R.string.grade_title) { n ->
newGradeNotification.notifyDetails(debugGradeDetailsItems.take(it)) withStudent { newGradeNotification.notifyDetails(debugGradeDetailsItems.take(n), it) }
}, },
NotificationDebugItem(R.string.grade_summary_predicted_grade) { NotificationDebugItem(R.string.grade_summary_predicted_grade) { n ->
newGradeNotification.notifyPredicted(debugGradeSummaryItems.take(it)) withStudent { newGradeNotification.notifyPredicted(debugGradeSummaryItems.take(n), it) }
}, },
NotificationDebugItem(R.string.grade_summary_final_grade) { NotificationDebugItem(R.string.grade_summary_final_grade) { n ->
newGradeNotification.notifyFinal(debugGradeSummaryItems.take(it)) withStudent { newGradeNotification.notifyFinal(debugGradeSummaryItems.take(n), it) }
}, },
NotificationDebugItem(R.string.homework_title) { NotificationDebugItem(R.string.homework_title) { n ->
newHomeworkNotification.notify(debugHomeworkItems.take(it)) withStudent { newHomeworkNotification.notify(debugHomeworkItems.take(n), it) }
}, },
NotificationDebugItem(R.string.conferences_title) { NotificationDebugItem(R.string.conferences_title) { n ->
newConferenceNotification.notify(debugConferenceItems.take(it)) withStudent { newConferenceNotification.notify(debugConferenceItems.take(n), it) }
}, },
NotificationDebugItem(R.string.exam_title) { NotificationDebugItem(R.string.exam_title) { n ->
newExamNotification.notify(debugExamItems.take(it)) withStudent { newExamNotification.notify(debugExamItems.take(n), it) }
}, },
NotificationDebugItem(R.string.message_title) { NotificationDebugItem(R.string.message_title) { n ->
newMessageNotification.notify(debugMessageItems.take(it)) withStudent { newMessageNotification.notify(debugMessageItems.take(n), it) }
}, },
NotificationDebugItem(R.string.note_title) { NotificationDebugItem(R.string.note_title) { n ->
newNoteNotification.notify(debugNoteItems.take(it)) withStudent { newNoteNotification.notify(debugNoteItems.take(n), it) }
}, },
NotificationDebugItem(R.string.school_announcement_title) { NotificationDebugItem(R.string.school_announcement_title) { n ->
newSchoolAnnouncementNotification.notify(debugSchoolAnnouncementItems.take(it)) withStudent {
newSchoolAnnouncementNotification.notify(debugSchoolAnnouncementItems.take(n), it)
}
}, },
NotificationDebugItem(R.string.lucky_number_title) { NotificationDebugItem(R.string.lucky_number_title) { n ->
repeat(it) { withStudent {
newLuckyNumberNotification.notify(debugLuckyNumber) repeat(n) { _ ->
newLuckyNumberNotification.notify(debugLuckyNumber, it)
}
} }
}, },
) )
@ -80,4 +86,10 @@ class NotificationDebugPresenter @Inject constructor(
setItems(items) setItems(items)
} }
} }
private fun withStudent(block: (Student) -> Unit) {
launch {
block(studentRepository.getCurrentStudent(false))
}
}
} }