mirror of
https://github.com/wulkanowy/wulkanowy.git
synced 2025-02-20 20:44:44 +01:00
Add student nick-or-name to notification summary (#1425)
This commit is contained in:
parent
2bc6d7ad0d
commit
14f4808434
@ -2,7 +2,7 @@
|
||||
|
||||
# Wulkanowy
|
||||
|
||||
[](https://github.com/wulkanowy/wulkanowy/actions)
|
||||
[](https://github.com/wulkanowy/wulkanowy/actions)
|
||||
[](https://codecov.io/gh/wulkanowy/wulkanowy)
|
||||
[](https://discord.gg/vccAQBr)
|
||||
[](https://f-droid.org/packages/io.github.wulkanowy/)
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
# Wulkanowy
|
||||
|
||||
[](https://github.com/wulkanowy/wulkanowy/actions)
|
||||
[](https://github.com/wulkanowy/wulkanowy/actions)
|
||||
[](https://codecov.io/gh/wulkanowy/wulkanowy)
|
||||
[](https://discord.gg/vccAQBr)
|
||||
[](https://f-droid.org/packages/io.github.wulkanowy/)
|
||||
|
@ -3,11 +3,11 @@ package io.github.wulkanowy.data.pojos
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.annotation.PluralsRes
|
||||
import androidx.annotation.StringRes
|
||||
import io.github.wulkanowy.services.sync.notifications.NotificationType
|
||||
import io.github.wulkanowy.ui.modules.main.MainView
|
||||
|
||||
sealed interface Notification {
|
||||
val channelId: String
|
||||
val group: String
|
||||
val type: NotificationType
|
||||
val startMenu: MainView.Section
|
||||
val icon: Int
|
||||
val titleStringRes: Int
|
||||
@ -15,8 +15,7 @@ sealed interface Notification {
|
||||
}
|
||||
|
||||
data class MultipleNotifications(
|
||||
override val channelId: String,
|
||||
override val group: String,
|
||||
override val type: NotificationType,
|
||||
override val startMenu: MainView.Section,
|
||||
@DrawableRes override val icon: Int,
|
||||
@PluralsRes override val titleStringRes: Int,
|
||||
@ -27,8 +26,7 @@ data class MultipleNotifications(
|
||||
) : Notification
|
||||
|
||||
data class OneNotification(
|
||||
override val channelId: String,
|
||||
override val group: String,
|
||||
override val type: NotificationType,
|
||||
override val startMenu: MainView.Section,
|
||||
@DrawableRes override val icon: Int,
|
||||
@StringRes override val titleStringRes: Int,
|
||||
|
@ -18,7 +18,6 @@ class LuckyNumberChannel @Inject constructor(
|
||||
|
||||
companion object {
|
||||
const val CHANNEL_ID = "lucky_number_channel"
|
||||
const val GROUP_ID = "lucky_number_group"
|
||||
}
|
||||
|
||||
override fun create() {
|
||||
|
@ -18,7 +18,6 @@ class NewConferencesChannel @Inject constructor(
|
||||
|
||||
companion object {
|
||||
const val CHANNEL_ID = "new_conferences_channel"
|
||||
const val GROUP_ID = "new_conferences_group"
|
||||
}
|
||||
|
||||
override fun create() {
|
||||
|
@ -18,7 +18,6 @@ class NewExamChannel @Inject constructor(
|
||||
|
||||
companion object {
|
||||
const val CHANNEL_ID = "new_exam_channel"
|
||||
const val GROUP_ID = "new_exam_group"
|
||||
}
|
||||
|
||||
override fun create() {
|
||||
|
@ -18,9 +18,6 @@ class NewGradesChannel @Inject constructor(
|
||||
|
||||
companion object {
|
||||
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() {
|
||||
|
@ -18,7 +18,6 @@ class NewHomeworkChannel @Inject constructor(
|
||||
|
||||
companion object {
|
||||
const val CHANNEL_ID = "new_homework_channel"
|
||||
const val GROUP_ID = "new_homework_group"
|
||||
}
|
||||
|
||||
override fun create() {
|
||||
|
@ -18,7 +18,6 @@ class NewMessagesChannel @Inject constructor(
|
||||
|
||||
companion object {
|
||||
const val CHANNEL_ID = "new_message_channel"
|
||||
const val GROUP_ID = "new_message_group"
|
||||
}
|
||||
|
||||
override fun create() {
|
||||
|
@ -18,7 +18,6 @@ class NewNotesChannel @Inject constructor(
|
||||
|
||||
companion object {
|
||||
const val CHANNEL_ID = "new_notes_channel"
|
||||
const val GROUP_ID = "new_notes_group"
|
||||
}
|
||||
|
||||
override fun create() {
|
||||
|
@ -18,7 +18,6 @@ class NewSchoolAnnouncementsChannel @Inject constructor(
|
||||
|
||||
companion object {
|
||||
const val CHANNEL_ID = "new_school_announcements_channel"
|
||||
const val GROUP_ID = "new_school_announcements_group"
|
||||
}
|
||||
|
||||
override fun create() {
|
||||
|
@ -7,12 +7,14 @@ import androidx.annotation.PluralsRes
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.app.NotificationManagerCompat
|
||||
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.Notification
|
||||
import io.github.wulkanowy.data.pojos.OneNotification
|
||||
import io.github.wulkanowy.ui.modules.main.MainActivity
|
||||
import io.github.wulkanowy.utils.getCompatBitmap
|
||||
import io.github.wulkanowy.utils.getCompatColor
|
||||
import io.github.wulkanowy.utils.nickOrName
|
||||
import kotlin.random.Random
|
||||
|
||||
abstract class BaseNotification(
|
||||
@ -20,12 +22,13 @@ abstract class BaseNotification(
|
||||
private val notificationManager: NotificationManagerCompat,
|
||||
) {
|
||||
|
||||
protected fun sendNotification(notification: Notification) = when (notification) {
|
||||
is OneNotification -> sendOneNotification(notification)
|
||||
is MultipleNotifications -> sendMultipleNotifications(notification)
|
||||
}
|
||||
protected fun sendNotification(notification: Notification, student: Student) =
|
||||
when (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(
|
||||
Random.nextInt(Int.MAX_VALUE),
|
||||
getNotificationBuilder(notification).apply {
|
||||
@ -35,20 +38,31 @@ abstract class BaseNotification(
|
||||
)
|
||||
setContentTitle(context.getString(notification.titleStringRes))
|
||||
setContentText(content)
|
||||
setStyle(NotificationCompat.BigTextStyle().bigText(content))
|
||||
setStyle(
|
||||
NotificationCompat.BigTextStyle()
|
||||
.setSummaryText(student?.nickOrName)
|
||||
.bigText(content)
|
||||
)
|
||||
}.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 ->
|
||||
notificationManager.notify(
|
||||
Random.nextInt(Int.MAX_VALUE),
|
||||
getNotificationBuilder(notification).apply {
|
||||
setContentTitle(getQuantityString(notification.titleStringRes, 1))
|
||||
setContentText(item)
|
||||
setStyle(NotificationCompat.BigTextStyle().bigText(item))
|
||||
setGroup(notification.group)
|
||||
setStyle(
|
||||
NotificationCompat.BigTextStyle()
|
||||
.setSummaryText(student.nickOrName)
|
||||
.bigText(item)
|
||||
)
|
||||
setGroup(group)
|
||||
}.build()
|
||||
)
|
||||
}
|
||||
@ -56,17 +70,18 @@ abstract class BaseNotification(
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) return
|
||||
|
||||
notificationManager.notify(
|
||||
notification.group.hashCode(),
|
||||
groupId.toInt(),
|
||||
getNotificationBuilder(notification).apply {
|
||||
setSmallIcon(notification.icon)
|
||||
setGroup(notification.group)
|
||||
setGroup(group)
|
||||
setStyle(NotificationCompat.InboxStyle().setSummaryText(student.nickOrName))
|
||||
setGroupSummary(true)
|
||||
}.build()
|
||||
)
|
||||
}
|
||||
|
||||
private fun getNotificationBuilder(notification: Notification) = NotificationCompat
|
||||
.Builder(context, notification.channelId)
|
||||
.Builder(context, notification.type.channel)
|
||||
.setLargeIcon(context.getCompatBitmap(notification.icon, R.color.colorPrimary))
|
||||
.setSmallIcon(R.drawable.ic_stat_all)
|
||||
.setAutoCancel(true)
|
||||
|
@ -5,8 +5,8 @@ import androidx.core.app.NotificationManagerCompat
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import io.github.wulkanowy.R
|
||||
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.services.sync.channels.NewConferencesChannel
|
||||
import io.github.wulkanowy.ui.modules.main.MainView
|
||||
import javax.inject.Inject
|
||||
|
||||
@ -15,10 +15,9 @@ class NewConferenceNotification @Inject constructor(
|
||||
notificationManager: NotificationManagerCompat,
|
||||
) : BaseNotification(context, notificationManager) {
|
||||
|
||||
fun notify(items: List<Conference>) {
|
||||
fun notify(items: List<Conference>, student: Student) {
|
||||
val notification = MultipleNotifications(
|
||||
channelId = NewConferencesChannel.CHANNEL_ID,
|
||||
group = NewConferencesChannel.GROUP_ID,
|
||||
type = NotificationType.NEW_CONFERENCE,
|
||||
icon = R.drawable.ic_more_conferences,
|
||||
titleStringRes = R.plurals.conference_notify_new_item_title,
|
||||
contentStringRes = R.plurals.conference_notify_new_items,
|
||||
@ -29,6 +28,6 @@ class NewConferenceNotification @Inject constructor(
|
||||
}
|
||||
)
|
||||
|
||||
sendNotification(notification)
|
||||
sendNotification(notification, student)
|
||||
}
|
||||
}
|
||||
|
@ -5,8 +5,8 @@ import androidx.core.app.NotificationManagerCompat
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import io.github.wulkanowy.R
|
||||
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.services.sync.channels.NewExamChannel
|
||||
import io.github.wulkanowy.ui.modules.main.MainView
|
||||
import javax.inject.Inject
|
||||
|
||||
@ -15,10 +15,9 @@ class NewExamNotification @Inject constructor(
|
||||
notificationManager: NotificationManagerCompat,
|
||||
) : BaseNotification(context, notificationManager) {
|
||||
|
||||
fun notify(items: List<Exam>) {
|
||||
fun notify(items: List<Exam>, student: Student) {
|
||||
val notification = MultipleNotifications(
|
||||
channelId = NewExamChannel.CHANNEL_ID,
|
||||
group = NewExamChannel.GROUP_ID,
|
||||
type = NotificationType.NEW_EXAM,
|
||||
icon = R.drawable.ic_main_exam,
|
||||
titleStringRes = R.plurals.exam_notify_new_item_title,
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
@ -6,8 +6,8 @@ import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import io.github.wulkanowy.R
|
||||
import io.github.wulkanowy.data.db.entities.Grade
|
||||
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.services.sync.channels.NewGradesChannel
|
||||
import io.github.wulkanowy.ui.modules.main.MainView
|
||||
import javax.inject.Inject
|
||||
|
||||
@ -16,10 +16,9 @@ class NewGradeNotification @Inject constructor(
|
||||
notificationManager: NotificationManagerCompat,
|
||||
) : BaseNotification(context, notificationManager) {
|
||||
|
||||
fun notifyDetails(items: List<Grade>) {
|
||||
fun notifyDetails(items: List<Grade>, student: Student) {
|
||||
val notification = MultipleNotifications(
|
||||
channelId = NewGradesChannel.CHANNEL_ID,
|
||||
group = NewGradesChannel.GROUP_DETAILS_ID,
|
||||
type = NotificationType.NEW_GRADE_DETAILS,
|
||||
icon = R.drawable.ic_stat_grade,
|
||||
titleStringRes = R.plurals.grade_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(
|
||||
channelId = NewGradesChannel.CHANNEL_ID,
|
||||
group = NewGradesChannel.GROUP_PREDICTED_ID,
|
||||
type = NotificationType.NEW_GRADE_PREDICTED,
|
||||
icon = R.drawable.ic_stat_grade,
|
||||
titleStringRes = R.plurals.grade_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(
|
||||
channelId = NewGradesChannel.CHANNEL_ID,
|
||||
group = NewGradesChannel.GROUP_FINAL_ID,
|
||||
type = NotificationType.NEW_GRADE_FINAL,
|
||||
icon = R.drawable.ic_stat_grade,
|
||||
titleStringRes = R.plurals.grade_new_items_final,
|
||||
contentStringRes = R.plurals.grade_notify_new_items_final,
|
||||
@ -64,6 +61,6 @@ class NewGradeNotification @Inject constructor(
|
||||
}
|
||||
)
|
||||
|
||||
sendNotification(notification)
|
||||
sendNotification(notification, student)
|
||||
}
|
||||
}
|
||||
|
@ -5,8 +5,8 @@ import androidx.core.app.NotificationManagerCompat
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import io.github.wulkanowy.R
|
||||
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.services.sync.channels.NewHomeworkChannel
|
||||
import io.github.wulkanowy.ui.modules.main.MainView
|
||||
import javax.inject.Inject
|
||||
|
||||
@ -15,10 +15,9 @@ class NewHomeworkNotification @Inject constructor(
|
||||
notificationManager: NotificationManagerCompat,
|
||||
) : BaseNotification(context, notificationManager) {
|
||||
|
||||
fun notify(items: List<Homework>) {
|
||||
fun notify(items: List<Homework>, student: Student) {
|
||||
val notification = MultipleNotifications(
|
||||
channelId = NewHomeworkChannel.CHANNEL_ID,
|
||||
group = NewHomeworkChannel.GROUP_ID,
|
||||
type = NotificationType.NEW_HOMEWORK,
|
||||
icon = R.drawable.ic_more_homework,
|
||||
titleStringRes = R.plurals.homework_notify_new_item_title,
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
@ -5,8 +5,8 @@ import androidx.core.app.NotificationManagerCompat
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import io.github.wulkanowy.R
|
||||
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.services.sync.channels.LuckyNumberChannel
|
||||
import io.github.wulkanowy.ui.modules.main.MainView
|
||||
import javax.inject.Inject
|
||||
|
||||
@ -15,10 +15,9 @@ class NewLuckyNumberNotification @Inject constructor(
|
||||
notificationManager: NotificationManagerCompat,
|
||||
) : BaseNotification(context, notificationManager) {
|
||||
|
||||
fun notify(item: LuckyNumber) {
|
||||
fun notify(item: LuckyNumber, student: Student) {
|
||||
val notification = OneNotification(
|
||||
channelId = LuckyNumberChannel.CHANNEL_ID,
|
||||
group = LuckyNumberChannel.GROUP_ID,
|
||||
type = NotificationType.NEW_LUCKY_NUMBER,
|
||||
icon = R.drawable.ic_stat_luckynumber,
|
||||
titleStringRes = R.string.lucky_number_notify_new_item_title,
|
||||
contentStringRes = R.string.lucky_number_notify_new_item,
|
||||
@ -26,6 +25,6 @@ class NewLuckyNumberNotification @Inject constructor(
|
||||
contentValues = listOf(item.luckyNumber.toString())
|
||||
)
|
||||
|
||||
sendNotification(notification)
|
||||
sendNotification(notification, student)
|
||||
}
|
||||
}
|
||||
|
@ -5,8 +5,8 @@ import androidx.core.app.NotificationManagerCompat
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import io.github.wulkanowy.R
|
||||
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.services.sync.channels.NewMessagesChannel
|
||||
import io.github.wulkanowy.ui.modules.main.MainView
|
||||
import javax.inject.Inject
|
||||
|
||||
@ -15,10 +15,9 @@ class NewMessageNotification @Inject constructor(
|
||||
notificationManager: NotificationManagerCompat,
|
||||
) : BaseNotification(context, notificationManager) {
|
||||
|
||||
fun notify(items: List<Message>) {
|
||||
fun notify(items: List<Message>, student: Student) {
|
||||
val notification = MultipleNotifications(
|
||||
channelId = NewMessagesChannel.CHANNEL_ID,
|
||||
group = NewMessagesChannel.GROUP_ID,
|
||||
type = NotificationType.NEW_MESSAGE,
|
||||
icon = R.drawable.ic_stat_message,
|
||||
titleStringRes = R.plurals.message_new_items,
|
||||
contentStringRes = R.plurals.message_notify_new_items,
|
||||
@ -29,6 +28,6 @@ class NewMessageNotification @Inject constructor(
|
||||
}
|
||||
)
|
||||
|
||||
sendNotification(notification)
|
||||
sendNotification(notification, student)
|
||||
}
|
||||
}
|
||||
|
@ -5,9 +5,9 @@ import androidx.core.app.NotificationManagerCompat
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import io.github.wulkanowy.R
|
||||
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.sdk.scrapper.notes.NoteCategory
|
||||
import io.github.wulkanowy.services.sync.channels.NewNotesChannel
|
||||
import io.github.wulkanowy.ui.modules.main.MainView
|
||||
import javax.inject.Inject
|
||||
|
||||
@ -16,10 +16,9 @@ class NewNoteNotification @Inject constructor(
|
||||
notificationManager: NotificationManagerCompat,
|
||||
) : BaseNotification(context, notificationManager) {
|
||||
|
||||
fun notify(items: List<Note>) {
|
||||
fun notify(items: List<Note>, student: Student) {
|
||||
val notification = MultipleNotifications(
|
||||
channelId = NewNotesChannel.CHANNEL_ID,
|
||||
group = NewNotesChannel.GROUP_ID,
|
||||
type = NotificationType.NEW_NOTE,
|
||||
icon = R.drawable.ic_stat_note,
|
||||
titleStringRes = when (NoteCategory.getByValue(items.first().categoryType)) {
|
||||
NoteCategory.POSITIVE -> R.plurals.praise_new_items
|
||||
@ -42,6 +41,6 @@ class NewNoteNotification @Inject constructor(
|
||||
}
|
||||
)
|
||||
|
||||
sendNotification(notification)
|
||||
sendNotification(notification, student)
|
||||
}
|
||||
}
|
||||
|
@ -5,8 +5,8 @@ import androidx.core.app.NotificationManagerCompat
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import io.github.wulkanowy.R
|
||||
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.services.sync.channels.NewSchoolAnnouncementsChannel
|
||||
import io.github.wulkanowy.ui.modules.main.MainView
|
||||
import javax.inject.Inject
|
||||
|
||||
@ -15,10 +15,9 @@ class NewSchoolAnnouncementNotification @Inject constructor(
|
||||
notificationManager: NotificationManagerCompat,
|
||||
) : BaseNotification(context, notificationManager) {
|
||||
|
||||
fun notify(items: List<SchoolAnnouncement>) {
|
||||
fun notify(items: List<SchoolAnnouncement>, student: Student) {
|
||||
val notification = MultipleNotifications(
|
||||
channelId = NewSchoolAnnouncementsChannel.CHANNEL_ID,
|
||||
group = NewSchoolAnnouncementsChannel.GROUP_ID,
|
||||
type = NotificationType.NEW_ANNOUNCEMENT,
|
||||
icon = R.drawable.ic_all_about,
|
||||
titleStringRes = R.plurals.school_announcement_notify_new_item_title,
|
||||
contentStringRes = R.plurals.school_announcement_notify_new_items,
|
||||
@ -29,6 +28,6 @@ class NewSchoolAnnouncementNotification @Inject constructor(
|
||||
}
|
||||
)
|
||||
|
||||
sendNotification(notification)
|
||||
sendNotification(notification, student)
|
||||
}
|
||||
}
|
||||
|
@ -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),
|
||||
}
|
@ -25,7 +25,7 @@ class ConferenceWork @Inject constructor(
|
||||
|
||||
conferenceRepository.getConferenceFromDatabase(semester).first()
|
||||
.filter { !it.isNotified }.let {
|
||||
if (it.isNotEmpty()) newConferenceNotification.notify(it)
|
||||
if (it.isNotEmpty()) newConferenceNotification.notify(it, student)
|
||||
|
||||
conferenceRepository.updateConference(it.onEach { conference ->
|
||||
conference.isNotified = true
|
||||
|
@ -28,7 +28,7 @@ class ExamWork @Inject constructor(
|
||||
|
||||
examRepository.getExamsFromDatabase(semester, now()).first()
|
||||
.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 })
|
||||
}
|
||||
|
@ -25,14 +25,14 @@ class GradeWork @Inject constructor(
|
||||
|
||||
gradeRepository.getGradesFromDatabase(semester).first()
|
||||
.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.getGradesPredictedFromDatabase(semester).first()
|
||||
.filter { !it.isPredictedGradeNotified }.let {
|
||||
if (it.isNotEmpty()) newGradeNotification.notifyPredicted(it)
|
||||
if (it.isNotEmpty()) newGradeNotification.notifyPredicted(it, student)
|
||||
|
||||
gradeRepository.updateGradesSummary(it.onEach { grade ->
|
||||
grade.isPredictedGradeNotified = true
|
||||
@ -41,7 +41,7 @@ class GradeWork @Inject constructor(
|
||||
|
||||
gradeRepository.getGradesFinalFromDatabase(semester).first()
|
||||
.filter { !it.isFinalGradeNotified }.let {
|
||||
if (it.isNotEmpty()) newGradeNotification.notifyFinal(it)
|
||||
if (it.isNotEmpty()) newGradeNotification.notifyFinal(it, student)
|
||||
|
||||
gradeRepository.updateGradesSummary(it.onEach { grade ->
|
||||
grade.isFinalGradeNotified = true
|
||||
|
@ -30,7 +30,7 @@ class HomeworkWork @Inject constructor(
|
||||
|
||||
homeworkRepository.getHomeworkFromDatabase(semester, now().monday, now().sunday).first()
|
||||
.filter { !it.isNotified }.let {
|
||||
if (it.isNotEmpty()) newHomeworkNotification.notify(it)
|
||||
if (it.isNotEmpty()) newHomeworkNotification.notify(it, student)
|
||||
|
||||
homeworkRepository.updateHomework(it.onEach { homework ->
|
||||
homework.isNotified = true
|
||||
|
@ -22,7 +22,7 @@ class LuckyNumberWork @Inject constructor(
|
||||
).waitForResult()
|
||||
|
||||
luckyNumberRepository.getNotNotifiedLuckyNumber(student)?.let {
|
||||
newLuckyNumberNotification.notify(it)
|
||||
newLuckyNumberNotification.notify(it, student)
|
||||
luckyNumberRepository.updateLuckyNumber(it.apply { isNotified = true })
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ class MessageWork @Inject constructor(
|
||||
|
||||
messageRepository.getMessagesFromDatabase(student).first()
|
||||
.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 })
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ class NoteWork @Inject constructor(
|
||||
|
||||
noteRepository.getNotesFromDatabase(student).first()
|
||||
.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 })
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ class SchoolAnnouncementWork @Inject constructor(
|
||||
|
||||
schoolAnnouncementRepository.getSchoolAnnouncementFromDatabase(student).first()
|
||||
.filter { !it.isNotified }.let {
|
||||
if (it.isNotEmpty()) newSchoolAnnouncementNotification.notify(it)
|
||||
if (it.isNotEmpty()) newSchoolAnnouncementNotification.notify(it, student)
|
||||
|
||||
schoolAnnouncementRepository.updateSchoolAnnouncement(it.onEach { schoolAnnouncement ->
|
||||
schoolAnnouncement.isNotified = true
|
||||
|
@ -1,6 +1,7 @@
|
||||
package io.github.wulkanowy.ui.modules.debug.notification
|
||||
|
||||
import io.github.wulkanowy.R
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.data.repositories.StudentRepository
|
||||
import io.github.wulkanowy.services.sync.notifications.NewConferenceNotification
|
||||
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.debugNoteItems
|
||||
import io.github.wulkanowy.ui.modules.debug.notification.mock.debugSchoolAnnouncementItems
|
||||
import kotlinx.coroutines.launch
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
@ -38,36 +40,40 @@ class NotificationDebugPresenter @Inject constructor(
|
||||
) : BasePresenter<NotificationDebugView>(errorHandler, studentRepository) {
|
||||
|
||||
private val items = listOf(
|
||||
NotificationDebugItem(R.string.grade_title) {
|
||||
newGradeNotification.notifyDetails(debugGradeDetailsItems.take(it))
|
||||
NotificationDebugItem(R.string.grade_title) { n ->
|
||||
withStudent { newGradeNotification.notifyDetails(debugGradeDetailsItems.take(n), it) }
|
||||
},
|
||||
NotificationDebugItem(R.string.grade_summary_predicted_grade) {
|
||||
newGradeNotification.notifyPredicted(debugGradeSummaryItems.take(it))
|
||||
NotificationDebugItem(R.string.grade_summary_predicted_grade) { n ->
|
||||
withStudent { newGradeNotification.notifyPredicted(debugGradeSummaryItems.take(n), it) }
|
||||
},
|
||||
NotificationDebugItem(R.string.grade_summary_final_grade) {
|
||||
newGradeNotification.notifyFinal(debugGradeSummaryItems.take(it))
|
||||
NotificationDebugItem(R.string.grade_summary_final_grade) { n ->
|
||||
withStudent { newGradeNotification.notifyFinal(debugGradeSummaryItems.take(n), it) }
|
||||
},
|
||||
NotificationDebugItem(R.string.homework_title) {
|
||||
newHomeworkNotification.notify(debugHomeworkItems.take(it))
|
||||
NotificationDebugItem(R.string.homework_title) { n ->
|
||||
withStudent { newHomeworkNotification.notify(debugHomeworkItems.take(n), it) }
|
||||
},
|
||||
NotificationDebugItem(R.string.conferences_title) {
|
||||
newConferenceNotification.notify(debugConferenceItems.take(it))
|
||||
NotificationDebugItem(R.string.conferences_title) { n ->
|
||||
withStudent { newConferenceNotification.notify(debugConferenceItems.take(n), it) }
|
||||
},
|
||||
NotificationDebugItem(R.string.exam_title) {
|
||||
newExamNotification.notify(debugExamItems.take(it))
|
||||
NotificationDebugItem(R.string.exam_title) { n ->
|
||||
withStudent { newExamNotification.notify(debugExamItems.take(n), it) }
|
||||
},
|
||||
NotificationDebugItem(R.string.message_title) {
|
||||
newMessageNotification.notify(debugMessageItems.take(it))
|
||||
NotificationDebugItem(R.string.message_title) { n ->
|
||||
withStudent { newMessageNotification.notify(debugMessageItems.take(n), it) }
|
||||
},
|
||||
NotificationDebugItem(R.string.note_title) {
|
||||
newNoteNotification.notify(debugNoteItems.take(it))
|
||||
NotificationDebugItem(R.string.note_title) { n ->
|
||||
withStudent { newNoteNotification.notify(debugNoteItems.take(n), it) }
|
||||
},
|
||||
NotificationDebugItem(R.string.school_announcement_title) {
|
||||
newSchoolAnnouncementNotification.notify(debugSchoolAnnouncementItems.take(it))
|
||||
NotificationDebugItem(R.string.school_announcement_title) { n ->
|
||||
withStudent {
|
||||
newSchoolAnnouncementNotification.notify(debugSchoolAnnouncementItems.take(n), it)
|
||||
}
|
||||
},
|
||||
NotificationDebugItem(R.string.lucky_number_title) {
|
||||
repeat(it) {
|
||||
newLuckyNumberNotification.notify(debugLuckyNumber)
|
||||
NotificationDebugItem(R.string.lucky_number_title) { n ->
|
||||
withStudent {
|
||||
repeat(n) { _ ->
|
||||
newLuckyNumberNotification.notify(debugLuckyNumber, it)
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
@ -80,4 +86,10 @@ class NotificationDebugPresenter @Inject constructor(
|
||||
setItems(items)
|
||||
}
|
||||
}
|
||||
|
||||
private fun withStudent(block: (Student) -> Unit) {
|
||||
launch {
|
||||
block(studentRepository.getCurrentStudent(false))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user