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(
|
) = networkBoundResource(
|
||||||
mutex = saveFetchResultMutex,
|
mutex = saveFetchResultMutex,
|
||||||
shouldFetch = {
|
shouldFetch = {
|
||||||
it.isEmpty() || forceRefresh
|
val isShouldBeRefreshed = refreshHelper.isShouldBeRefreshed(
|
||||||
|| refreshHelper.isShouldBeRefreshed(getRefreshKey(cacheKey, semester, start, end))
|
key = getRefreshKey(cacheKey, semester, start, end)
|
||||||
|
)
|
||||||
|
it.isEmpty() || forceRefresh || isShouldBeRefreshed
|
||||||
},
|
},
|
||||||
query = {
|
query = {
|
||||||
examDb.loadAll(
|
examDb.loadAll(
|
||||||
|
@ -36,8 +36,10 @@ class HomeworkRepository @Inject constructor(
|
|||||||
) = networkBoundResource(
|
) = networkBoundResource(
|
||||||
mutex = saveFetchResultMutex,
|
mutex = saveFetchResultMutex,
|
||||||
shouldFetch = {
|
shouldFetch = {
|
||||||
it.isEmpty() || forceRefresh ||
|
val isShouldBeRefreshed = refreshHelper.isShouldBeRefreshed(
|
||||||
refreshHelper.isShouldBeRefreshed(getRefreshKey(cacheKey, semester, start, end))
|
key = getRefreshKey(cacheKey, semester, start, end)
|
||||||
|
)
|
||||||
|
it.isEmpty() || forceRefresh || isShouldBeRefreshed
|
||||||
},
|
},
|
||||||
query = {
|
query = {
|
||||||
homeworkDb.loadAll(
|
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.db.entities.Student
|
||||||
import io.github.wulkanowy.data.pojos.MultipleNotifications
|
import io.github.wulkanowy.data.pojos.MultipleNotifications
|
||||||
import io.github.wulkanowy.ui.modules.main.MainView
|
import io.github.wulkanowy.ui.modules.main.MainView
|
||||||
|
import io.github.wulkanowy.utils.toFormattedString
|
||||||
|
import java.time.LocalDateTime
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class NewConferenceNotification @Inject constructor(
|
class NewConferenceNotification @Inject constructor(
|
||||||
@ -16,6 +18,11 @@ class NewConferenceNotification @Inject constructor(
|
|||||||
) : BaseNotification(context, notificationManager) {
|
) : BaseNotification(context, notificationManager) {
|
||||||
|
|
||||||
fun notify(items: List<Conference>, student: Student) {
|
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(
|
val notification = MultipleNotifications(
|
||||||
type = NotificationType.NEW_CONFERENCE,
|
type = NotificationType.NEW_CONFERENCE,
|
||||||
icon = R.drawable.ic_more_conferences,
|
icon = R.drawable.ic_more_conferences,
|
||||||
@ -23,9 +30,7 @@ class NewConferenceNotification @Inject constructor(
|
|||||||
contentStringRes = R.plurals.conference_notify_new_items,
|
contentStringRes = R.plurals.conference_notify_new_items,
|
||||||
summaryStringRes = R.plurals.conference_number_item,
|
summaryStringRes = R.plurals.conference_number_item,
|
||||||
startMenu = MainView.Section.CONFERENCE,
|
startMenu = MainView.Section.CONFERENCE,
|
||||||
lines = items.map {
|
lines = lines
|
||||||
"${it.title}: ${it.subject}"
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
sendNotification(notification, student)
|
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.db.entities.Student
|
||||||
import io.github.wulkanowy.data.pojos.MultipleNotifications
|
import io.github.wulkanowy.data.pojos.MultipleNotifications
|
||||||
import io.github.wulkanowy.ui.modules.main.MainView
|
import io.github.wulkanowy.ui.modules.main.MainView
|
||||||
|
import io.github.wulkanowy.utils.toFormattedString
|
||||||
|
import java.time.LocalDate
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class NewExamNotification @Inject constructor(
|
class NewExamNotification @Inject constructor(
|
||||||
@ -16,16 +18,19 @@ class NewExamNotification @Inject constructor(
|
|||||||
) : BaseNotification(context, notificationManager) {
|
) : BaseNotification(context, notificationManager) {
|
||||||
|
|
||||||
fun notify(items: List<Exam>, student: Student) {
|
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(
|
val notification = MultipleNotifications(
|
||||||
type = NotificationType.NEW_EXAM,
|
type = NotificationType.NEW_EXAM,
|
||||||
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_content,
|
||||||
summaryStringRes = R.plurals.exam_number_item,
|
summaryStringRes = R.plurals.exam_number_item,
|
||||||
startMenu = MainView.Section.EXAM,
|
startMenu = MainView.Section.EXAM,
|
||||||
lines = items.map {
|
lines = lines
|
||||||
"${it.subject}: ${it.description}"
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
sendNotification(notification, student)
|
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.db.entities.Student
|
||||||
import io.github.wulkanowy.data.pojos.MultipleNotifications
|
import io.github.wulkanowy.data.pojos.MultipleNotifications
|
||||||
import io.github.wulkanowy.ui.modules.main.MainView
|
import io.github.wulkanowy.ui.modules.main.MainView
|
||||||
|
import io.github.wulkanowy.utils.toFormattedString
|
||||||
|
import java.time.LocalDate
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class NewHomeworkNotification @Inject constructor(
|
class NewHomeworkNotification @Inject constructor(
|
||||||
@ -16,16 +18,19 @@ class NewHomeworkNotification @Inject constructor(
|
|||||||
) : BaseNotification(context, notificationManager) {
|
) : BaseNotification(context, notificationManager) {
|
||||||
|
|
||||||
fun notify(items: List<Homework>, student: Student) {
|
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(
|
val notification = MultipleNotifications(
|
||||||
type = NotificationType.NEW_HOMEWORK,
|
type = NotificationType.NEW_HOMEWORK,
|
||||||
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_content,
|
||||||
summaryStringRes = R.plurals.homework_number_item,
|
summaryStringRes = R.plurals.homework_number_item,
|
||||||
startMenu = MainView.Section.HOMEWORK,
|
startMenu = MainView.Section.HOMEWORK,
|
||||||
lines = items.map {
|
lines = lines
|
||||||
"${it.subject}: ${it.content}"
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
sendNotification(notification, student)
|
sendNotification(notification, student)
|
||||||
|
@ -53,6 +53,6 @@ private fun generateConference(title: String, subject: String) = Conference(
|
|||||||
diaryId = 0,
|
diaryId = 0,
|
||||||
agenda = "",
|
agenda = "",
|
||||||
conferenceId = 0,
|
conferenceId = 0,
|
||||||
date = LocalDateTime.now(),
|
date = LocalDateTime.now().plusMinutes(10),
|
||||||
presentOnConference = "",
|
presentOnConference = "",
|
||||||
)
|
)
|
||||||
|
@ -206,6 +206,10 @@
|
|||||||
<item quantity="one">New exam</item>
|
<item quantity="one">New exam</item>
|
||||||
<item quantity="other">New exams</item>
|
<item quantity="other">New exams</item>
|
||||||
</plurals>
|
</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">
|
<plurals name="exam_number_item">
|
||||||
<item quantity="one">%d exam</item>
|
<item quantity="one">%d exam</item>
|
||||||
<item quantity="other">%d exams</item>
|
<item quantity="other">%d exams</item>
|
||||||
@ -312,6 +316,10 @@
|
|||||||
<item quantity="one">New homework</item>
|
<item quantity="one">New homework</item>
|
||||||
<item quantity="other">New homework</item>
|
<item quantity="other">New homework</item>
|
||||||
</plurals>
|
</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">
|
<plurals name="homework_number_item">
|
||||||
<item quantity="one">%d homework</item>
|
<item quantity="one">%d homework</item>
|
||||||
<item quantity="other">%d homework</item>
|
<item quantity="other">%d homework</item>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user