Skip to content

Commit 6467687

Browse files
committed
cancel reminders on data clear, disable reminder on type remove
1 parent a43ac6b commit 6467687

4 files changed

Lines changed: 27 additions & 1 deletion

File tree

domain/src/main/java/com/example/util/simpletimetracker/domain/backup/interactor/ClearDataInteractor.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import com.example.util.simpletimetracker.domain.favourite.repo.FavouriteColorRe
1010
import com.example.util.simpletimetracker.domain.favourite.repo.FavouriteCommentRepo
1111
import com.example.util.simpletimetracker.domain.favourite.repo.FavouriteIconRepo
1212
import com.example.util.simpletimetracker.domain.favourite.repo.RecordTypeToFavouriteCommentRepo
13+
import com.example.util.simpletimetracker.domain.notifications.interactor.NotificationGoalRangeEndInteractor
14+
import com.example.util.simpletimetracker.domain.notifications.interactor.NotificationGoalTimeInteractor
15+
import com.example.util.simpletimetracker.domain.notifications.interactor.ScheduledReminderNotificationInteractor
1316
import com.example.util.simpletimetracker.domain.record.repo.RecordRepo
1417
import com.example.util.simpletimetracker.domain.record.repo.RunningRecordRepo
1518
import com.example.util.simpletimetracker.domain.recordShortcut.repo.RecordShortcutRepo
@@ -49,9 +52,20 @@ class ClearDataInteractor @Inject constructor(
4952
private val recordShortcutToRecordTagRepo: RecordShortcutToRecordTagRepo,
5053
private val recordTypeToFavouriteCommentRepo: RecordTypeToFavouriteCommentRepo,
5154
private val scheduledReminderRepo: ScheduledReminderRepo,
55+
private val notificationGoalTimeInteractor: NotificationGoalTimeInteractor,
56+
private val notificationGoalRangeEndInteractor: NotificationGoalRangeEndInteractor,
57+
private val scheduledReminderNotificationInteractor: ScheduledReminderNotificationInteractor,
5258
) {
5359

5460
suspend fun execute() {
61+
// Cancel reminders.
62+
recordTypeGoalRepo.getAll().map { it.idData }.distinct()
63+
.forEach(notificationGoalTimeInteractor::cancel)
64+
notificationGoalRangeEndInteractor.cancel()
65+
scheduledReminderRepo.getAll().map { it.id }
66+
.forEach(scheduledReminderNotificationInteractor::cancel)
67+
68+
// Clear data.
5569
recordTypeRepo.clear()
5670
recordRepo.clear()
5771
recordShortcutRepo.clear()

domain/src/main/java/com/example/util/simpletimetracker/domain/recordType/interactor/RecordTypeInteractor.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import com.example.util.simpletimetracker.domain.recordShortcut.repo.RecordShort
1717
import com.example.util.simpletimetracker.domain.recordTag.repo.RecordShortcutToRecordTagRepo
1818
import com.example.util.simpletimetracker.domain.recordType.model.RecordType
1919
import com.example.util.simpletimetracker.domain.recordType.repo.RecordTypeRepo
20+
import com.example.util.simpletimetracker.domain.scheduledReminder.interactor.ScheduledReminderInteractor
2021
import javax.inject.Inject
2122

2223
class RecordTypeInteractor @Inject constructor(
@@ -37,6 +38,7 @@ class RecordTypeInteractor @Inject constructor(
3738
private val activitySuggestionInteractor: ActivitySuggestionInteractor,
3839
private val prefsInteractor: PrefsInteractor,
3940
private val sortCardsInteractor: SortCardsInteractor,
41+
private val scheduledReminderInteractor: ScheduledReminderInteractor,
4042
) {
4143

4244
suspend fun getAll(cardOrder: CardOrder? = null): List<RecordType> {
@@ -116,6 +118,7 @@ class RecordTypeInteractor @Inject constructor(
116118
complexRuleInteractor.removeTypeId(id)
117119
activityFilterInteractor.removeTypeId(id)
118120
activitySuggestionInteractor.removeTypeId(id)
121+
scheduledReminderInteractor.disableByTypeId(id)
119122
recordTypeRepo.remove(id)
120123
}
121124

domain/src/main/java/com/example/util/simpletimetracker/domain/scheduledReminder/interactor/ScheduledReminderInteractor.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ class ScheduledReminderInteractor @Inject constructor(
3131
if (enabled) notificationInteractor.schedule(id)
3232
}
3333

34+
suspend fun disableByTypeId(activityId: Long) {
35+
repo.getAll()
36+
.filter { reminder ->
37+
val activityCondition = reminder.condition as? ScheduledReminder.Condition.ActivityNotTrackedToday
38+
reminder.enabled && activityCondition?.activityId == activityId
39+
}
40+
.forEach { setEnabled(it.id, enabled = false) }
41+
}
42+
3443
suspend fun remove(id: Long) {
3544
notificationInteractor.cancel(id)
3645
repo.remove(id)

features/feature_notification/src/main/java/com/example/util/simpletimetracker/feature_notification/goalTime/interactor/NotificationGoalRangeEndInteractorImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class NotificationGoalRangeEndInteractorImpl @Inject constructor(
5555

5656
rangeEndScheduler.schedule(
5757
timestamp = forRange.timeEnded,
58-
goalRange = RecordTypeGoal.Range.Daily,
58+
goalRange = range,
5959
)
6060
}
6161
}

0 commit comments

Comments
 (0)