forked from github/wulkanowy-mirror
Fix notification spam after login (#1715)
This commit is contained in:
parent
684c258e2d
commit
496641f594
@ -74,10 +74,12 @@ class SyncManager @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun startOneTimeSyncWorker(): Flow<WorkInfo?> {
|
// if quiet, no notifications will be sent
|
||||||
|
fun startOneTimeSyncWorker(quiet: Boolean = false): Flow<WorkInfo?> {
|
||||||
val work = OneTimeWorkRequestBuilder<SyncWorker>()
|
val work = OneTimeWorkRequestBuilder<SyncWorker>()
|
||||||
.setInputData(
|
.setInputData(
|
||||||
Data.Builder()
|
Data.Builder()
|
||||||
|
.putBoolean("quiet", quiet)
|
||||||
.putBoolean("one_time", true)
|
.putBoolean("one_time", true)
|
||||||
.build()
|
.build()
|
||||||
)
|
)
|
||||||
|
@ -54,7 +54,7 @@ class SyncWorker @AssistedInject constructor(
|
|||||||
val exceptions = works.mapNotNull { work ->
|
val exceptions = works.mapNotNull { work ->
|
||||||
try {
|
try {
|
||||||
Timber.i("${work::class.java.simpleName} is starting")
|
Timber.i("${work::class.java.simpleName} is starting")
|
||||||
work.doWork(student, semester)
|
work.doWork(student, semester, isNotificationsEnabled())
|
||||||
Timber.i("${work::class.java.simpleName} result: Success")
|
Timber.i("${work::class.java.simpleName} result: Success")
|
||||||
null
|
null
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
@ -75,6 +75,11 @@ class SyncWorker @AssistedInject constructor(
|
|||||||
return@withContext result
|
return@withContext result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun isNotificationsEnabled(): Boolean {
|
||||||
|
val quiet = inputData.getBoolean("quiet", false)
|
||||||
|
return preferencesRepository.isNotificationsEnable && !quiet
|
||||||
|
}
|
||||||
|
|
||||||
private fun getResultFromErrors(errors: List<Throwable>): Result = when {
|
private fun getResultFromErrors(errors: List<Throwable>): Result = when {
|
||||||
errors.isNotEmpty() && inputData.getBoolean("one_time", false) -> {
|
errors.isNotEmpty() && inputData.getBoolean("one_time", false) -> {
|
||||||
Result.failure(
|
Result.failure(
|
||||||
|
@ -10,7 +10,12 @@ class AttendanceSummaryWork @Inject constructor(
|
|||||||
private val attendanceSummaryRepository: AttendanceSummaryRepository
|
private val attendanceSummaryRepository: AttendanceSummaryRepository
|
||||||
) : Work {
|
) : Work {
|
||||||
|
|
||||||
override suspend fun doWork(student: Student, semester: Semester) {
|
override suspend fun doWork(student: Student, semester: Semester, notify: Boolean) {
|
||||||
attendanceSummaryRepository.getAttendanceSummary(student, semester, -1, true).waitForResult()
|
attendanceSummaryRepository.getAttendanceSummary(
|
||||||
|
student = student,
|
||||||
|
semester = semester,
|
||||||
|
subjectId = -1,
|
||||||
|
forceRefresh = true,
|
||||||
|
).waitForResult()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package io.github.wulkanowy.services.sync.works
|
|||||||
import io.github.wulkanowy.data.db.entities.Semester
|
import io.github.wulkanowy.data.db.entities.Semester
|
||||||
import io.github.wulkanowy.data.db.entities.Student
|
import io.github.wulkanowy.data.db.entities.Student
|
||||||
import io.github.wulkanowy.data.repositories.AttendanceRepository
|
import io.github.wulkanowy.data.repositories.AttendanceRepository
|
||||||
import io.github.wulkanowy.data.repositories.PreferencesRepository
|
|
||||||
import io.github.wulkanowy.services.sync.notifications.NewAttendanceNotification
|
import io.github.wulkanowy.services.sync.notifications.NewAttendanceNotification
|
||||||
import io.github.wulkanowy.utils.previousOrSameSchoolDay
|
import io.github.wulkanowy.utils.previousOrSameSchoolDay
|
||||||
import io.github.wulkanowy.utils.waitForResult
|
import io.github.wulkanowy.utils.waitForResult
|
||||||
@ -14,17 +13,16 @@ import javax.inject.Inject
|
|||||||
class AttendanceWork @Inject constructor(
|
class AttendanceWork @Inject constructor(
|
||||||
private val attendanceRepository: AttendanceRepository,
|
private val attendanceRepository: AttendanceRepository,
|
||||||
private val newAttendanceNotification: NewAttendanceNotification,
|
private val newAttendanceNotification: NewAttendanceNotification,
|
||||||
private val preferencesRepository: PreferencesRepository
|
|
||||||
) : Work {
|
) : Work {
|
||||||
|
|
||||||
override suspend fun doWork(student: Student, semester: Semester) {
|
override suspend fun doWork(student: Student, semester: Semester, notify: Boolean) {
|
||||||
attendanceRepository.getAttendance(
|
attendanceRepository.getAttendance(
|
||||||
student = student,
|
student = student,
|
||||||
semester = semester,
|
semester = semester,
|
||||||
start = now().previousOrSameSchoolDay,
|
start = now().previousOrSameSchoolDay,
|
||||||
end = now().previousOrSameSchoolDay,
|
end = now().previousOrSameSchoolDay,
|
||||||
forceRefresh = true,
|
forceRefresh = true,
|
||||||
notify = preferencesRepository.isNotificationsEnable
|
notify = notify,
|
||||||
)
|
)
|
||||||
.waitForResult()
|
.waitForResult()
|
||||||
|
|
||||||
|
@ -13,7 +13,13 @@ class CompletedLessonWork @Inject constructor(
|
|||||||
private val completedLessonsRepository: CompletedLessonsRepository
|
private val completedLessonsRepository: CompletedLessonsRepository
|
||||||
) : Work {
|
) : Work {
|
||||||
|
|
||||||
override suspend fun doWork(student: Student, semester: Semester) {
|
override suspend fun doWork(student: Student, semester: Semester, notify: Boolean) {
|
||||||
completedLessonsRepository.getCompletedLessons(student, semester, now().monday, now().sunday, true).waitForResult()
|
completedLessonsRepository.getCompletedLessons(
|
||||||
|
student = student,
|
||||||
|
semester = semester,
|
||||||
|
start = now().monday,
|
||||||
|
end = now().sunday,
|
||||||
|
forceRefresh = true,
|
||||||
|
).waitForResult()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package io.github.wulkanowy.services.sync.works
|
|||||||
import io.github.wulkanowy.data.db.entities.Semester
|
import io.github.wulkanowy.data.db.entities.Semester
|
||||||
import io.github.wulkanowy.data.db.entities.Student
|
import io.github.wulkanowy.data.db.entities.Student
|
||||||
import io.github.wulkanowy.data.repositories.ConferenceRepository
|
import io.github.wulkanowy.data.repositories.ConferenceRepository
|
||||||
import io.github.wulkanowy.data.repositories.PreferencesRepository
|
|
||||||
import io.github.wulkanowy.services.sync.notifications.NewConferenceNotification
|
import io.github.wulkanowy.services.sync.notifications.NewConferenceNotification
|
||||||
import io.github.wulkanowy.utils.waitForResult
|
import io.github.wulkanowy.utils.waitForResult
|
||||||
import kotlinx.coroutines.flow.first
|
import kotlinx.coroutines.flow.first
|
||||||
@ -11,16 +10,15 @@ import javax.inject.Inject
|
|||||||
|
|
||||||
class ConferenceWork @Inject constructor(
|
class ConferenceWork @Inject constructor(
|
||||||
private val conferenceRepository: ConferenceRepository,
|
private val conferenceRepository: ConferenceRepository,
|
||||||
private val preferencesRepository: PreferencesRepository,
|
|
||||||
private val newConferenceNotification: NewConferenceNotification,
|
private val newConferenceNotification: NewConferenceNotification,
|
||||||
) : Work {
|
) : Work {
|
||||||
|
|
||||||
override suspend fun doWork(student: Student, semester: Semester) {
|
override suspend fun doWork(student: Student, semester: Semester, notify: Boolean) {
|
||||||
conferenceRepository.getConferences(
|
conferenceRepository.getConferences(
|
||||||
student = student,
|
student = student,
|
||||||
semester = semester,
|
semester = semester,
|
||||||
forceRefresh = true,
|
forceRefresh = true,
|
||||||
notify = preferencesRepository.isNotificationsEnable
|
notify = notify
|
||||||
).waitForResult()
|
).waitForResult()
|
||||||
|
|
||||||
conferenceRepository.getConferenceFromDatabase(semester).first()
|
conferenceRepository.getConferenceFromDatabase(semester).first()
|
||||||
|
@ -3,7 +3,6 @@ package io.github.wulkanowy.services.sync.works
|
|||||||
import io.github.wulkanowy.data.db.entities.Semester
|
import io.github.wulkanowy.data.db.entities.Semester
|
||||||
import io.github.wulkanowy.data.db.entities.Student
|
import io.github.wulkanowy.data.db.entities.Student
|
||||||
import io.github.wulkanowy.data.repositories.ExamRepository
|
import io.github.wulkanowy.data.repositories.ExamRepository
|
||||||
import io.github.wulkanowy.data.repositories.PreferencesRepository
|
|
||||||
import io.github.wulkanowy.services.sync.notifications.NewExamNotification
|
import io.github.wulkanowy.services.sync.notifications.NewExamNotification
|
||||||
import io.github.wulkanowy.utils.waitForResult
|
import io.github.wulkanowy.utils.waitForResult
|
||||||
import kotlinx.coroutines.flow.first
|
import kotlinx.coroutines.flow.first
|
||||||
@ -12,18 +11,17 @@ import javax.inject.Inject
|
|||||||
|
|
||||||
class ExamWork @Inject constructor(
|
class ExamWork @Inject constructor(
|
||||||
private val examRepository: ExamRepository,
|
private val examRepository: ExamRepository,
|
||||||
private val preferencesRepository: PreferencesRepository,
|
|
||||||
private val newExamNotification: NewExamNotification,
|
private val newExamNotification: NewExamNotification,
|
||||||
) : Work {
|
) : Work {
|
||||||
|
|
||||||
override suspend fun doWork(student: Student, semester: Semester) {
|
override suspend fun doWork(student: Student, semester: Semester, notify: Boolean) {
|
||||||
examRepository.getExams(
|
examRepository.getExams(
|
||||||
student = student,
|
student = student,
|
||||||
semester = semester,
|
semester = semester,
|
||||||
start = now(),
|
start = now(),
|
||||||
end = now(),
|
end = now(),
|
||||||
forceRefresh = true,
|
forceRefresh = true,
|
||||||
notify = preferencesRepository.isNotificationsEnable
|
notify = notify,
|
||||||
).waitForResult()
|
).waitForResult()
|
||||||
|
|
||||||
examRepository.getExamsFromDatabase(semester, now()).first()
|
examRepository.getExamsFromDatabase(semester, now()).first()
|
||||||
|
@ -10,7 +10,7 @@ class GradeStatisticsWork @Inject constructor(
|
|||||||
private val gradeStatisticsRepository: GradeStatisticsRepository
|
private val gradeStatisticsRepository: GradeStatisticsRepository
|
||||||
) : Work {
|
) : Work {
|
||||||
|
|
||||||
override suspend fun doWork(student: Student, semester: Semester) {
|
override suspend fun doWork(student: Student, semester: Semester, notify: Boolean) {
|
||||||
with(gradeStatisticsRepository) {
|
with(gradeStatisticsRepository) {
|
||||||
getGradesPartialStatistics(student, semester, "Wszystkie", forceRefresh = true).waitForResult()
|
getGradesPartialStatistics(student, semester, "Wszystkie", forceRefresh = true).waitForResult()
|
||||||
getGradesSemesterStatistics(student, semester, "Wszystkie", forceRefresh = true).waitForResult()
|
getGradesSemesterStatistics(student, semester, "Wszystkie", forceRefresh = true).waitForResult()
|
||||||
|
@ -3,7 +3,6 @@ package io.github.wulkanowy.services.sync.works
|
|||||||
import io.github.wulkanowy.data.db.entities.Semester
|
import io.github.wulkanowy.data.db.entities.Semester
|
||||||
import io.github.wulkanowy.data.db.entities.Student
|
import io.github.wulkanowy.data.db.entities.Student
|
||||||
import io.github.wulkanowy.data.repositories.GradeRepository
|
import io.github.wulkanowy.data.repositories.GradeRepository
|
||||||
import io.github.wulkanowy.data.repositories.PreferencesRepository
|
|
||||||
import io.github.wulkanowy.services.sync.notifications.NewGradeNotification
|
import io.github.wulkanowy.services.sync.notifications.NewGradeNotification
|
||||||
import io.github.wulkanowy.utils.waitForResult
|
import io.github.wulkanowy.utils.waitForResult
|
||||||
import kotlinx.coroutines.flow.first
|
import kotlinx.coroutines.flow.first
|
||||||
@ -11,16 +10,15 @@ import javax.inject.Inject
|
|||||||
|
|
||||||
class GradeWork @Inject constructor(
|
class GradeWork @Inject constructor(
|
||||||
private val gradeRepository: GradeRepository,
|
private val gradeRepository: GradeRepository,
|
||||||
private val preferencesRepository: PreferencesRepository,
|
|
||||||
private val newGradeNotification: NewGradeNotification,
|
private val newGradeNotification: NewGradeNotification,
|
||||||
) : Work {
|
) : Work {
|
||||||
|
|
||||||
override suspend fun doWork(student: Student, semester: Semester) {
|
override suspend fun doWork(student: Student, semester: Semester, notify: Boolean) {
|
||||||
gradeRepository.getGrades(
|
gradeRepository.getGrades(
|
||||||
student = student,
|
student = student,
|
||||||
semester = semester,
|
semester = semester,
|
||||||
forceRefresh = true,
|
forceRefresh = true,
|
||||||
notify = preferencesRepository.isNotificationsEnable
|
notify = notify,
|
||||||
).waitForResult()
|
).waitForResult()
|
||||||
|
|
||||||
gradeRepository.getGradesFromDatabase(semester).first()
|
gradeRepository.getGradesFromDatabase(semester).first()
|
||||||
|
@ -3,7 +3,6 @@ package io.github.wulkanowy.services.sync.works
|
|||||||
import io.github.wulkanowy.data.db.entities.Semester
|
import io.github.wulkanowy.data.db.entities.Semester
|
||||||
import io.github.wulkanowy.data.db.entities.Student
|
import io.github.wulkanowy.data.db.entities.Student
|
||||||
import io.github.wulkanowy.data.repositories.HomeworkRepository
|
import io.github.wulkanowy.data.repositories.HomeworkRepository
|
||||||
import io.github.wulkanowy.data.repositories.PreferencesRepository
|
|
||||||
import io.github.wulkanowy.services.sync.notifications.NewHomeworkNotification
|
import io.github.wulkanowy.services.sync.notifications.NewHomeworkNotification
|
||||||
import io.github.wulkanowy.utils.nextOrSameSchoolDay
|
import io.github.wulkanowy.utils.nextOrSameSchoolDay
|
||||||
import io.github.wulkanowy.utils.waitForResult
|
import io.github.wulkanowy.utils.waitForResult
|
||||||
@ -13,18 +12,17 @@ import javax.inject.Inject
|
|||||||
|
|
||||||
class HomeworkWork @Inject constructor(
|
class HomeworkWork @Inject constructor(
|
||||||
private val homeworkRepository: HomeworkRepository,
|
private val homeworkRepository: HomeworkRepository,
|
||||||
private val preferencesRepository: PreferencesRepository,
|
|
||||||
private val newHomeworkNotification: NewHomeworkNotification,
|
private val newHomeworkNotification: NewHomeworkNotification,
|
||||||
) : Work {
|
) : Work {
|
||||||
|
|
||||||
override suspend fun doWork(student: Student, semester: Semester) {
|
override suspend fun doWork(student: Student, semester: Semester, notify: Boolean) {
|
||||||
homeworkRepository.getHomework(
|
homeworkRepository.getHomework(
|
||||||
student = student,
|
student = student,
|
||||||
semester = semester,
|
semester = semester,
|
||||||
start = now().nextOrSameSchoolDay,
|
start = now().nextOrSameSchoolDay,
|
||||||
end = now().nextOrSameSchoolDay,
|
end = now().nextOrSameSchoolDay,
|
||||||
forceRefresh = true,
|
forceRefresh = true,
|
||||||
notify = preferencesRepository.isNotificationsEnable
|
notify = notify,
|
||||||
).waitForResult()
|
).waitForResult()
|
||||||
|
|
||||||
homeworkRepository.getHomeworkFromDatabase(semester, now(), now().plusDays(7)).first()
|
homeworkRepository.getHomeworkFromDatabase(semester, now(), now().plusDays(7)).first()
|
||||||
|
@ -3,22 +3,20 @@ package io.github.wulkanowy.services.sync.works
|
|||||||
import io.github.wulkanowy.data.db.entities.Semester
|
import io.github.wulkanowy.data.db.entities.Semester
|
||||||
import io.github.wulkanowy.data.db.entities.Student
|
import io.github.wulkanowy.data.db.entities.Student
|
||||||
import io.github.wulkanowy.data.repositories.LuckyNumberRepository
|
import io.github.wulkanowy.data.repositories.LuckyNumberRepository
|
||||||
import io.github.wulkanowy.data.repositories.PreferencesRepository
|
|
||||||
import io.github.wulkanowy.services.sync.notifications.NewLuckyNumberNotification
|
import io.github.wulkanowy.services.sync.notifications.NewLuckyNumberNotification
|
||||||
import io.github.wulkanowy.utils.waitForResult
|
import io.github.wulkanowy.utils.waitForResult
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class LuckyNumberWork @Inject constructor(
|
class LuckyNumberWork @Inject constructor(
|
||||||
private val luckyNumberRepository: LuckyNumberRepository,
|
private val luckyNumberRepository: LuckyNumberRepository,
|
||||||
private val preferencesRepository: PreferencesRepository,
|
|
||||||
private val newLuckyNumberNotification: NewLuckyNumberNotification,
|
private val newLuckyNumberNotification: NewLuckyNumberNotification,
|
||||||
) : Work {
|
) : Work {
|
||||||
|
|
||||||
override suspend fun doWork(student: Student, semester: Semester) {
|
override suspend fun doWork(student: Student, semester: Semester, notify: Boolean) {
|
||||||
luckyNumberRepository.getLuckyNumber(
|
luckyNumberRepository.getLuckyNumber(
|
||||||
student = student,
|
student = student,
|
||||||
forceRefresh = true,
|
forceRefresh = true,
|
||||||
notify = preferencesRepository.isNotificationsEnable
|
notify = notify,
|
||||||
).waitForResult()
|
).waitForResult()
|
||||||
|
|
||||||
luckyNumberRepository.getNotNotifiedLuckyNumber(student)?.let {
|
luckyNumberRepository.getNotNotifiedLuckyNumber(student)?.let {
|
||||||
|
@ -4,7 +4,6 @@ import io.github.wulkanowy.data.db.entities.Semester
|
|||||||
import io.github.wulkanowy.data.db.entities.Student
|
import io.github.wulkanowy.data.db.entities.Student
|
||||||
import io.github.wulkanowy.data.enums.MessageFolder.RECEIVED
|
import io.github.wulkanowy.data.enums.MessageFolder.RECEIVED
|
||||||
import io.github.wulkanowy.data.repositories.MessageRepository
|
import io.github.wulkanowy.data.repositories.MessageRepository
|
||||||
import io.github.wulkanowy.data.repositories.PreferencesRepository
|
|
||||||
import io.github.wulkanowy.services.sync.notifications.NewMessageNotification
|
import io.github.wulkanowy.services.sync.notifications.NewMessageNotification
|
||||||
import io.github.wulkanowy.utils.waitForResult
|
import io.github.wulkanowy.utils.waitForResult
|
||||||
import kotlinx.coroutines.flow.first
|
import kotlinx.coroutines.flow.first
|
||||||
@ -12,17 +11,16 @@ import javax.inject.Inject
|
|||||||
|
|
||||||
class MessageWork @Inject constructor(
|
class MessageWork @Inject constructor(
|
||||||
private val messageRepository: MessageRepository,
|
private val messageRepository: MessageRepository,
|
||||||
private val preferencesRepository: PreferencesRepository,
|
|
||||||
private val newMessageNotification: NewMessageNotification,
|
private val newMessageNotification: NewMessageNotification,
|
||||||
) : Work {
|
) : Work {
|
||||||
|
|
||||||
override suspend fun doWork(student: Student, semester: Semester) {
|
override suspend fun doWork(student: Student, semester: Semester, notify: Boolean) {
|
||||||
messageRepository.getMessages(
|
messageRepository.getMessages(
|
||||||
student = student,
|
student = student,
|
||||||
semester = semester,
|
semester = semester,
|
||||||
folder = RECEIVED,
|
folder = RECEIVED,
|
||||||
forceRefresh = true,
|
forceRefresh = true,
|
||||||
notify = preferencesRepository.isNotificationsEnable
|
notify = notify
|
||||||
).waitForResult()
|
).waitForResult()
|
||||||
|
|
||||||
messageRepository.getMessagesFromDatabase(student).first()
|
messageRepository.getMessagesFromDatabase(student).first()
|
||||||
|
@ -3,7 +3,6 @@ package io.github.wulkanowy.services.sync.works
|
|||||||
import io.github.wulkanowy.data.db.entities.Semester
|
import io.github.wulkanowy.data.db.entities.Semester
|
||||||
import io.github.wulkanowy.data.db.entities.Student
|
import io.github.wulkanowy.data.db.entities.Student
|
||||||
import io.github.wulkanowy.data.repositories.NoteRepository
|
import io.github.wulkanowy.data.repositories.NoteRepository
|
||||||
import io.github.wulkanowy.data.repositories.PreferencesRepository
|
|
||||||
import io.github.wulkanowy.services.sync.notifications.NewNoteNotification
|
import io.github.wulkanowy.services.sync.notifications.NewNoteNotification
|
||||||
import io.github.wulkanowy.utils.waitForResult
|
import io.github.wulkanowy.utils.waitForResult
|
||||||
import kotlinx.coroutines.flow.first
|
import kotlinx.coroutines.flow.first
|
||||||
@ -11,16 +10,15 @@ import javax.inject.Inject
|
|||||||
|
|
||||||
class NoteWork @Inject constructor(
|
class NoteWork @Inject constructor(
|
||||||
private val noteRepository: NoteRepository,
|
private val noteRepository: NoteRepository,
|
||||||
private val preferencesRepository: PreferencesRepository,
|
|
||||||
private val newNoteNotification: NewNoteNotification,
|
private val newNoteNotification: NewNoteNotification,
|
||||||
) : Work {
|
) : Work {
|
||||||
|
|
||||||
override suspend fun doWork(student: Student, semester: Semester) {
|
override suspend fun doWork(student: Student, semester: Semester, notify: Boolean) {
|
||||||
noteRepository.getNotes(
|
noteRepository.getNotes(
|
||||||
student = student,
|
student = student,
|
||||||
semester = semester,
|
semester = semester,
|
||||||
forceRefresh = true,
|
forceRefresh = true,
|
||||||
notify = preferencesRepository.isNotificationsEnable
|
notify = notify,
|
||||||
).waitForResult()
|
).waitForResult()
|
||||||
|
|
||||||
noteRepository.getNotesFromDatabase(student).first()
|
noteRepository.getNotesFromDatabase(student).first()
|
||||||
|
@ -11,7 +11,7 @@ class RecipientWork @Inject constructor(
|
|||||||
private val recipientRepository: RecipientRepository
|
private val recipientRepository: RecipientRepository
|
||||||
) : Work {
|
) : Work {
|
||||||
|
|
||||||
override suspend fun doWork(student: Student, semester: Semester) {
|
override suspend fun doWork(student: Student, semester: Semester, notify: Boolean) {
|
||||||
reportingUnitRepository.refreshReportingUnits(student)
|
reportingUnitRepository.refreshReportingUnits(student)
|
||||||
|
|
||||||
reportingUnitRepository.getReportingUnits(student).let { units ->
|
reportingUnitRepository.getReportingUnits(student).let { units ->
|
||||||
|
@ -2,7 +2,6 @@ package io.github.wulkanowy.services.sync.works
|
|||||||
|
|
||||||
import io.github.wulkanowy.data.db.entities.Semester
|
import io.github.wulkanowy.data.db.entities.Semester
|
||||||
import io.github.wulkanowy.data.db.entities.Student
|
import io.github.wulkanowy.data.db.entities.Student
|
||||||
import io.github.wulkanowy.data.repositories.PreferencesRepository
|
|
||||||
import io.github.wulkanowy.data.repositories.SchoolAnnouncementRepository
|
import io.github.wulkanowy.data.repositories.SchoolAnnouncementRepository
|
||||||
import io.github.wulkanowy.services.sync.notifications.NewSchoolAnnouncementNotification
|
import io.github.wulkanowy.services.sync.notifications.NewSchoolAnnouncementNotification
|
||||||
import io.github.wulkanowy.utils.waitForResult
|
import io.github.wulkanowy.utils.waitForResult
|
||||||
@ -11,15 +10,14 @@ import javax.inject.Inject
|
|||||||
|
|
||||||
class SchoolAnnouncementWork @Inject constructor(
|
class SchoolAnnouncementWork @Inject constructor(
|
||||||
private val schoolAnnouncementRepository: SchoolAnnouncementRepository,
|
private val schoolAnnouncementRepository: SchoolAnnouncementRepository,
|
||||||
private val preferencesRepository: PreferencesRepository,
|
|
||||||
private val newSchoolAnnouncementNotification: NewSchoolAnnouncementNotification,
|
private val newSchoolAnnouncementNotification: NewSchoolAnnouncementNotification,
|
||||||
) : Work {
|
) : Work {
|
||||||
|
|
||||||
override suspend fun doWork(student: Student, semester: Semester) {
|
override suspend fun doWork(student: Student, semester: Semester, notify: Boolean) {
|
||||||
schoolAnnouncementRepository.getSchoolAnnouncements(
|
schoolAnnouncementRepository.getSchoolAnnouncements(
|
||||||
student = student,
|
student = student,
|
||||||
forceRefresh = true,
|
forceRefresh = true,
|
||||||
notify = preferencesRepository.isNotificationsEnable
|
notify = notify,
|
||||||
).waitForResult()
|
).waitForResult()
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ import javax.inject.Inject
|
|||||||
|
|
||||||
class TeacherWork @Inject constructor(private val teacherRepository: TeacherRepository) : Work {
|
class TeacherWork @Inject constructor(private val teacherRepository: TeacherRepository) : Work {
|
||||||
|
|
||||||
override suspend fun doWork(student: Student, semester: Semester) {
|
override suspend fun doWork(student: Student, semester: Semester, notify: Boolean) {
|
||||||
teacherRepository.getTeachers(student, semester, true).waitForResult()
|
teacherRepository.getTeachers(student, semester, true).waitForResult()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package io.github.wulkanowy.services.sync.works
|
|||||||
|
|
||||||
import io.github.wulkanowy.data.db.entities.Semester
|
import io.github.wulkanowy.data.db.entities.Semester
|
||||||
import io.github.wulkanowy.data.db.entities.Student
|
import io.github.wulkanowy.data.db.entities.Student
|
||||||
import io.github.wulkanowy.data.repositories.PreferencesRepository
|
|
||||||
import io.github.wulkanowy.data.repositories.TimetableRepository
|
import io.github.wulkanowy.data.repositories.TimetableRepository
|
||||||
import io.github.wulkanowy.services.sync.notifications.ChangeTimetableNotification
|
import io.github.wulkanowy.services.sync.notifications.ChangeTimetableNotification
|
||||||
import io.github.wulkanowy.utils.nextOrSameSchoolDay
|
import io.github.wulkanowy.utils.nextOrSameSchoolDay
|
||||||
@ -14,17 +13,16 @@ import javax.inject.Inject
|
|||||||
class TimetableWork @Inject constructor(
|
class TimetableWork @Inject constructor(
|
||||||
private val timetableRepository: TimetableRepository,
|
private val timetableRepository: TimetableRepository,
|
||||||
private val changeTimetableNotification: ChangeTimetableNotification,
|
private val changeTimetableNotification: ChangeTimetableNotification,
|
||||||
private val preferencesRepository: PreferencesRepository
|
|
||||||
) : Work {
|
) : Work {
|
||||||
|
|
||||||
override suspend fun doWork(student: Student, semester: Semester) {
|
override suspend fun doWork(student: Student, semester: Semester, notify: Boolean) {
|
||||||
timetableRepository.getTimetable(
|
timetableRepository.getTimetable(
|
||||||
student = student,
|
student = student,
|
||||||
semester = semester,
|
semester = semester,
|
||||||
start = now().nextOrSameSchoolDay,
|
start = now().nextOrSameSchoolDay,
|
||||||
end = now().nextOrSameSchoolDay,
|
end = now().nextOrSameSchoolDay,
|
||||||
forceRefresh = true,
|
forceRefresh = true,
|
||||||
notify = preferencesRepository.isNotificationsEnable
|
notify = notify,
|
||||||
)
|
)
|
||||||
.waitForResult()
|
.waitForResult()
|
||||||
|
|
||||||
|
@ -5,5 +5,5 @@ import io.github.wulkanowy.data.db.entities.Student
|
|||||||
|
|
||||||
interface Work {
|
interface Work {
|
||||||
|
|
||||||
suspend fun doWork(student: Student, semester: Semester)
|
suspend fun doWork(student: Student, semester: Semester, notify: Boolean)
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import io.github.wulkanowy.data.Status
|
|||||||
import io.github.wulkanowy.data.db.entities.Student
|
import io.github.wulkanowy.data.db.entities.Student
|
||||||
import io.github.wulkanowy.data.db.entities.StudentWithSemesters
|
import io.github.wulkanowy.data.db.entities.StudentWithSemesters
|
||||||
import io.github.wulkanowy.data.repositories.StudentRepository
|
import io.github.wulkanowy.data.repositories.StudentRepository
|
||||||
|
import io.github.wulkanowy.services.sync.SyncManager
|
||||||
import io.github.wulkanowy.ui.base.BasePresenter
|
import io.github.wulkanowy.ui.base.BasePresenter
|
||||||
import io.github.wulkanowy.ui.modules.login.LoginErrorHandler
|
import io.github.wulkanowy.ui.modules.login.LoginErrorHandler
|
||||||
import io.github.wulkanowy.utils.AnalyticsHelper
|
import io.github.wulkanowy.utils.AnalyticsHelper
|
||||||
@ -16,6 +17,7 @@ import javax.inject.Inject
|
|||||||
class LoginStudentSelectPresenter @Inject constructor(
|
class LoginStudentSelectPresenter @Inject constructor(
|
||||||
studentRepository: StudentRepository,
|
studentRepository: StudentRepository,
|
||||||
private val loginErrorHandler: LoginErrorHandler,
|
private val loginErrorHandler: LoginErrorHandler,
|
||||||
|
private val syncManager: SyncManager,
|
||||||
private val analytics: AnalyticsHelper
|
private val analytics: AnalyticsHelper
|
||||||
) : BasePresenter<LoginStudentSelectView>(loginErrorHandler, studentRepository) {
|
) : BasePresenter<LoginStudentSelectView>(loginErrorHandler, studentRepository) {
|
||||||
|
|
||||||
@ -97,6 +99,7 @@ class LoginStudentSelectPresenter @Inject constructor(
|
|||||||
}
|
}
|
||||||
Status.SUCCESS -> {
|
Status.SUCCESS -> {
|
||||||
Timber.i("Registration result: Success")
|
Timber.i("Registration result: Success")
|
||||||
|
syncManager.startOneTimeSyncWorker(quiet = true)
|
||||||
view?.openMainView()
|
view?.openMainView()
|
||||||
logRegisterEvent(studentsWithSemesters)
|
logRegisterEvent(studentsWithSemesters)
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import io.github.wulkanowy.MainCoroutineRule
|
|||||||
import io.github.wulkanowy.data.db.entities.Student
|
import io.github.wulkanowy.data.db.entities.Student
|
||||||
import io.github.wulkanowy.data.db.entities.StudentWithSemesters
|
import io.github.wulkanowy.data.db.entities.StudentWithSemesters
|
||||||
import io.github.wulkanowy.data.repositories.StudentRepository
|
import io.github.wulkanowy.data.repositories.StudentRepository
|
||||||
|
import io.github.wulkanowy.services.sync.SyncManager
|
||||||
import io.github.wulkanowy.ui.modules.login.LoginErrorHandler
|
import io.github.wulkanowy.ui.modules.login.LoginErrorHandler
|
||||||
import io.github.wulkanowy.utils.AnalyticsHelper
|
import io.github.wulkanowy.utils.AnalyticsHelper
|
||||||
import io.mockk.MockKAnnotations
|
import io.mockk.MockKAnnotations
|
||||||
@ -36,6 +37,9 @@ class LoginStudentSelectPresenterTest {
|
|||||||
@MockK(relaxed = true)
|
@MockK(relaxed = true)
|
||||||
lateinit var analytics: AnalyticsHelper
|
lateinit var analytics: AnalyticsHelper
|
||||||
|
|
||||||
|
@MockK(relaxed = true)
|
||||||
|
lateinit var syncManager: SyncManager
|
||||||
|
|
||||||
private lateinit var presenter: LoginStudentSelectPresenter
|
private lateinit var presenter: LoginStudentSelectPresenter
|
||||||
|
|
||||||
private val testStudent by lazy {
|
private val testStudent by lazy {
|
||||||
@ -77,7 +81,7 @@ class LoginStudentSelectPresenterTest {
|
|||||||
every { loginStudentSelectView.showProgress(any()) } just Runs
|
every { loginStudentSelectView.showProgress(any()) } just Runs
|
||||||
every { loginStudentSelectView.showContent(any()) } just Runs
|
every { loginStudentSelectView.showContent(any()) } just Runs
|
||||||
|
|
||||||
presenter = LoginStudentSelectPresenter(studentRepository, errorHandler, analytics)
|
presenter = LoginStudentSelectPresenter(studentRepository, errorHandler, syncManager, analytics)
|
||||||
presenter.onAttachView(loginStudentSelectView, emptyList())
|
presenter.onAttachView(loginStudentSelectView, emptyList())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user