forked from github/wulkanowy-mirror
Exams and homework notification fixes (#1292)
This commit is contained in:
parent
55518cb044
commit
04c727a0c8
@ -40,8 +40,10 @@ class ExamRepository @Inject constructor(
|
||||
) = networkBoundResource(
|
||||
mutex = saveFetchResultMutex,
|
||||
shouldFetch = {
|
||||
it.isEmpty() || forceRefresh
|
||||
|| refreshHelper.isShouldBeRefreshed(getRefreshKey(cacheKey, semester, start, end))
|
||||
val isShouldBeRefreshed = refreshHelper.isShouldBeRefreshed(
|
||||
key = getRefreshKey(cacheKey, semester, start, end)
|
||||
)
|
||||
it.isEmpty() || forceRefresh || isShouldBeRefreshed
|
||||
},
|
||||
query = {
|
||||
examDb.loadAll(
|
||||
|
@ -36,8 +36,10 @@ class HomeworkRepository @Inject constructor(
|
||||
) = networkBoundResource(
|
||||
mutex = saveFetchResultMutex,
|
||||
shouldFetch = {
|
||||
it.isEmpty() || forceRefresh ||
|
||||
refreshHelper.isShouldBeRefreshed(getRefreshKey(cacheKey, semester, start, end))
|
||||
val isShouldBeRefreshed = refreshHelper.isShouldBeRefreshed(
|
||||
key = getRefreshKey(cacheKey, semester, start, end)
|
||||
)
|
||||
it.isEmpty() || forceRefresh || isShouldBeRefreshed
|
||||
},
|
||||
query = {
|
||||
homeworkDb.loadAll(
|
||||
|
@ -8,6 +8,8 @@ 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.ui.modules.main.MainView
|
||||
import io.github.wulkanowy.utils.toFormattedString
|
||||
import java.time.LocalDateTime
|
||||
import javax.inject.Inject
|
||||
|
||||
class NewConferenceNotification @Inject constructor(
|
||||
@ -16,6 +18,11 @@ class NewConferenceNotification @Inject constructor(
|
||||
) : BaseNotification(context, notificationManager) {
|
||||
|
||||
fun notify(items: List<Conference>, student: Student) {
|
||||
val today = LocalDateTime.now()
|
||||
val lines = items.filter { !it.date.isBefore(today) }.map {
|
||||
"${it.date.toFormattedString("dd.MM")} - ${it.title}: ${it.subject}"
|
||||
}.ifEmpty { return }
|
||||
|
||||
val notification = MultipleNotifications(
|
||||
type = NotificationType.NEW_CONFERENCE,
|
||||
icon = R.drawable.ic_more_conferences,
|
||||
@ -23,9 +30,7 @@ class NewConferenceNotification @Inject constructor(
|
||||
contentStringRes = R.plurals.conference_notify_new_items,
|
||||
summaryStringRes = R.plurals.conference_number_item,
|
||||
startMenu = MainView.Section.CONFERENCE,
|
||||
lines = items.map {
|
||||
"${it.title}: ${it.subject}"
|
||||
}
|
||||
lines = lines
|
||||
)
|
||||
|
||||
sendNotification(notification, student)
|
||||
|
@ -8,6 +8,8 @@ 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.ui.modules.main.MainView
|
||||
import io.github.wulkanowy.utils.toFormattedString
|
||||
import java.time.LocalDate
|
||||
import javax.inject.Inject
|
||||
|
||||
class NewExamNotification @Inject constructor(
|
||||
@ -16,16 +18,19 @@ class NewExamNotification @Inject constructor(
|
||||
) : BaseNotification(context, notificationManager) {
|
||||
|
||||
fun notify(items: List<Exam>, student: Student) {
|
||||
val today = LocalDate.now()
|
||||
val lines = items.filter { !it.date.isBefore(today) }.map {
|
||||
"${it.date.toFormattedString("dd.MM")} - ${it.subject}: ${it.description}"
|
||||
}.ifEmpty { return }
|
||||
|
||||
val notification = MultipleNotifications(
|
||||
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
|
||||
contentStringRes = R.plurals.exam_notify_new_item_content,
|
||||
summaryStringRes = R.plurals.exam_number_item,
|
||||
startMenu = MainView.Section.EXAM,
|
||||
lines = items.map {
|
||||
"${it.subject}: ${it.description}"
|
||||
}
|
||||
lines = lines
|
||||
)
|
||||
|
||||
sendNotification(notification, student)
|
||||
|
@ -8,6 +8,8 @@ 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.ui.modules.main.MainView
|
||||
import io.github.wulkanowy.utils.toFormattedString
|
||||
import java.time.LocalDate
|
||||
import javax.inject.Inject
|
||||
|
||||
class NewHomeworkNotification @Inject constructor(
|
||||
@ -16,16 +18,19 @@ class NewHomeworkNotification @Inject constructor(
|
||||
) : BaseNotification(context, notificationManager) {
|
||||
|
||||
fun notify(items: List<Homework>, student: Student) {
|
||||
val today = LocalDate.now()
|
||||
val lines = items.filter { !it.date.isBefore(today) }.map {
|
||||
"${it.date.toFormattedString("dd.MM")} - ${it.subject}: ${it.content}"
|
||||
}.ifEmpty { return }
|
||||
|
||||
val notification = MultipleNotifications(
|
||||
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
|
||||
contentStringRes = R.plurals.homework_notify_new_item_content,
|
||||
summaryStringRes = R.plurals.homework_number_item,
|
||||
startMenu = MainView.Section.HOMEWORK,
|
||||
lines = items.map {
|
||||
"${it.subject}: ${it.content}"
|
||||
}
|
||||
lines = lines
|
||||
)
|
||||
|
||||
sendNotification(notification, student)
|
||||
|
@ -53,6 +53,6 @@ private fun generateConference(title: String, subject: String) = Conference(
|
||||
diaryId = 0,
|
||||
agenda = "",
|
||||
conferenceId = 0,
|
||||
date = LocalDateTime.now(),
|
||||
date = LocalDateTime.now().plusMinutes(10),
|
||||
presentOnConference = "",
|
||||
)
|
||||
|
@ -206,6 +206,10 @@
|
||||
<item quantity="one">New exam</item>
|
||||
<item quantity="other">New exams</item>
|
||||
</plurals>
|
||||
<plurals name="exam_notify_new_item_content">
|
||||
<item quantity="one">You received %d new exam</item>
|
||||
<item quantity="other">You received %d new exams</item>
|
||||
</plurals>
|
||||
<plurals name="exam_number_item">
|
||||
<item quantity="one">%d exam</item>
|
||||
<item quantity="other">%d exams</item>
|
||||
@ -312,6 +316,10 @@
|
||||
<item quantity="one">New homework</item>
|
||||
<item quantity="other">New homework</item>
|
||||
</plurals>
|
||||
<plurals name="homework_notify_new_item_content">
|
||||
<item quantity="one">You received %d new homework</item>
|
||||
<item quantity="other">You received %d new homework</item>
|
||||
</plurals>
|
||||
<plurals name="homework_number_item">
|
||||
<item quantity="one">%d homework</item>
|
||||
<item quantity="other">%d homework</item>
|
||||
|
Loading…
x
Reference in New Issue
Block a user