diff --git a/app/src/main/java/io/github/wulkanowy/data/repositories/ExamRepository.kt b/app/src/main/java/io/github/wulkanowy/data/repositories/ExamRepository.kt index 9406c77c..93d5a47c 100644 --- a/app/src/main/java/io/github/wulkanowy/data/repositories/ExamRepository.kt +++ b/app/src/main/java/io/github/wulkanowy/data/repositories/ExamRepository.kt @@ -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( diff --git a/app/src/main/java/io/github/wulkanowy/data/repositories/HomeworkRepository.kt b/app/src/main/java/io/github/wulkanowy/data/repositories/HomeworkRepository.kt index 476a810c..23dd74c2 100644 --- a/app/src/main/java/io/github/wulkanowy/data/repositories/HomeworkRepository.kt +++ b/app/src/main/java/io/github/wulkanowy/data/repositories/HomeworkRepository.kt @@ -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( diff --git a/app/src/main/java/io/github/wulkanowy/services/sync/notifications/NewConferenceNotification.kt b/app/src/main/java/io/github/wulkanowy/services/sync/notifications/NewConferenceNotification.kt index 25648b93..fda2922f 100644 --- a/app/src/main/java/io/github/wulkanowy/services/sync/notifications/NewConferenceNotification.kt +++ b/app/src/main/java/io/github/wulkanowy/services/sync/notifications/NewConferenceNotification.kt @@ -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, 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) diff --git a/app/src/main/java/io/github/wulkanowy/services/sync/notifications/NewExamNotification.kt b/app/src/main/java/io/github/wulkanowy/services/sync/notifications/NewExamNotification.kt index a41c44e5..d493c4d2 100644 --- a/app/src/main/java/io/github/wulkanowy/services/sync/notifications/NewExamNotification.kt +++ b/app/src/main/java/io/github/wulkanowy/services/sync/notifications/NewExamNotification.kt @@ -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, 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) diff --git a/app/src/main/java/io/github/wulkanowy/services/sync/notifications/NewHomeworkNotification.kt b/app/src/main/java/io/github/wulkanowy/services/sync/notifications/NewHomeworkNotification.kt index 844aed97..fe973cad 100644 --- a/app/src/main/java/io/github/wulkanowy/services/sync/notifications/NewHomeworkNotification.kt +++ b/app/src/main/java/io/github/wulkanowy/services/sync/notifications/NewHomeworkNotification.kt @@ -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, 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) diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/debug/notification/mock/conference.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/debug/notification/mock/conference.kt index 969b1cf2..40af6bfb 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/debug/notification/mock/conference.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/debug/notification/mock/conference.kt @@ -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 = "", ) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 39478a2e..ea1187c8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -206,6 +206,10 @@ New exam New exams + + You received %d new exam + You received %d new exams + %d exam %d exams @@ -312,6 +316,10 @@ New homework New homework + + You received %d new homework + You received %d new homework + %d homework %d homework