Skip to content

Commit 94a38a6

Browse files
committed
move external views update to one place
1 parent 7b93a7d commit 94a38a6

File tree

25 files changed

+408
-243
lines changed

25 files changed

+408
-243
lines changed
Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
package com.example.util.simpletimetracker.domain.interactor
22

33
import com.example.util.simpletimetracker.domain.model.Record
4-
import com.example.util.simpletimetracker.domain.model.WidgetType
54
import javax.inject.Inject
65

76
class AddRecordMediator @Inject constructor(
87
private val recordInteractor: RecordInteractor,
9-
private val notificationTypeInteractor: NotificationTypeInteractor,
10-
private val notificationActivitySwitchInteractor: NotificationActivitySwitchInteractor,
11-
private val notificationGoalTimeInteractor: NotificationGoalTimeInteractor,
12-
private val widgetInteractor: WidgetInteractor,
8+
private val externalViewsInteractor: UpdateExternalViewsInteractor,
139
) {
1410

1511
suspend fun add(
@@ -27,12 +23,9 @@ class AddRecordMediator @Inject constructor(
2723
typeId: Long,
2824
updateNotificationSwitch: Boolean = true,
2925
) {
30-
notificationTypeInteractor.checkAndShow(typeId)
31-
if (updateNotificationSwitch) {
32-
notificationActivitySwitchInteractor.updateNotification()
33-
}
34-
notificationGoalTimeInteractor.checkAndReschedule(listOf(typeId))
35-
widgetInteractor.updateWidgets(listOf(WidgetType.STATISTICS_CHART))
36-
widgetInteractor.updateSingleWidgets(typeIds = listOf(typeId))
26+
externalViewsInteractor.onRecordAddOrChange(
27+
typeId = typeId,
28+
updateNotificationSwitch = updateNotificationSwitch,
29+
)
3730
}
3831
}

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

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.example.util.simpletimetracker.domain.interactor
22

3-
import com.example.util.simpletimetracker.domain.extension.orZero
43
import com.example.util.simpletimetracker.domain.model.Range
54
import com.example.util.simpletimetracker.domain.model.Record
65
import com.example.util.simpletimetracker.domain.model.RecordType
@@ -17,18 +16,12 @@ class AddRunningRecordMediator @Inject constructor(
1716
private val recordTypeInteractor: RecordTypeInteractor,
1817
private val addRecordMediator: AddRecordMediator,
1918
private val recordTypeToDefaultTagInteractor: RecordTypeToDefaultTagInteractor,
20-
private val notificationTypeInteractor: NotificationTypeInteractor,
21-
private val notificationActivitySwitchInteractor: NotificationActivitySwitchInteractor,
22-
private val notificationInactivityInteractor: NotificationInactivityInteractor,
23-
private val notificationActivityInteractor: NotificationActivityInteractor,
24-
private val notificationGoalTimeInteractor: NotificationGoalTimeInteractor,
2519
private val notificationGoalCountInteractor: NotificationGoalCountInteractor,
26-
private val widgetInteractor: WidgetInteractor,
27-
private val wearInteractor: WearInteractor,
2820
private val activityStartedStoppedBroadcastInteractor: ActivityStartedStoppedBroadcastInteractor,
2921
private val shouldShowTagSelectionInteractor: ShouldShowTagSelectionInteractor,
3022
private val pomodoroStartInteractor: PomodoroStartInteractor,
3123
private val complexRuleProcessActionInteractor: ComplexRuleProcessActionInteractor,
24+
private val updateExternalViewsInteractor: UpdateExternalViewsInteractor,
3225
) {
3326

3427
/**
@@ -150,24 +143,18 @@ class AddRunningRecordMediator @Inject constructor(
150143
params: StartParams,
151144
) {
152145
if (runningRecordInteractor.get(params.typeId) == null && params.typeId > 0L) {
153-
RunningRecord(
146+
val data = RunningRecord(
154147
id = params.typeId,
155148
timeStarted = params.timeStarted,
156149
comment = params.comment,
157150
tagIds = params.tagIds,
158-
).let {
159-
runningRecordInteractor.add(it)
160-
notificationTypeInteractor.checkAndShow(params.typeId)
161-
if (params.updateNotificationSwitch) {
162-
notificationActivitySwitchInteractor.updateNotification()
163-
}
164-
notificationInactivityInteractor.cancel()
165-
// Schedule only on first activity start.
166-
if (runningRecordInteractor.getAll().size == 1) notificationActivityInteractor.checkAndSchedule()
167-
notificationGoalTimeInteractor.checkAndReschedule(listOf(params.typeId))
168-
widgetInteractor.updateWidgets()
169-
wearInteractor.update()
170-
}
151+
)
152+
153+
runningRecordInteractor.add(data)
154+
updateExternalViewsInteractor.onRunningRecordAdd(
155+
typeId = params.typeId,
156+
updateNotificationSwitch = params.updateNotificationSwitch,
157+
)
171158
}
172159
}
173160

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@ import javax.inject.Inject
88

99
class BackupInteractor @Inject constructor(
1010
private val backupRepo: BackupRepo,
11-
private val widgetInteractor: WidgetInteractor,
12-
private val notificationTypeInteractor: NotificationTypeInteractor,
13-
private val notificationActivitySwitchInteractor: NotificationActivitySwitchInteractor,
14-
private val notificationGoalTimeInteractor: NotificationGoalTimeInteractor,
15-
private val wearInteractor: WearInteractor,
11+
private val externalViewsInteractor: UpdateExternalViewsInteractor,
1612
) {
1713

1814
suspend fun saveBackupFile(
@@ -46,10 +42,6 @@ class BackupInteractor @Inject constructor(
4642
}
4743

4844
suspend fun doAfterRestore() {
49-
notificationTypeInteractor.updateNotifications()
50-
notificationActivitySwitchInteractor.updateNotification()
51-
notificationGoalTimeInteractor.checkAndReschedule()
52-
widgetInteractor.updateWidgets()
53-
wearInteractor.update()
45+
externalViewsInteractor.onBackupRestore()
5446
}
5547
}

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
package com.example.util.simpletimetracker.domain.interactor
22

33
import com.example.util.simpletimetracker.domain.model.Range
4-
import com.example.util.simpletimetracker.domain.model.WidgetType
54
import com.example.util.simpletimetracker.domain.resolver.CsvRepo
65
import com.example.util.simpletimetracker.domain.resolver.ResultCode
76
import javax.inject.Inject
87

98
class CsvExportInteractor @Inject constructor(
109
private val csvRepo: CsvRepo,
1110
private val runningRecordInteractor: RunningRecordInteractor,
12-
private val widgetInteractor: WidgetInteractor,
13-
private val notificationGoalTimeInteractor: NotificationGoalTimeInteractor,
11+
private val externalViewsInteractor: UpdateExternalViewsInteractor,
1412
) {
1513

1614
suspend fun saveCsvFile(uriString: String, range: Range?): ResultCode {
@@ -21,9 +19,7 @@ class CsvExportInteractor @Inject constructor(
2119
val resultCode = csvRepo.importCsvFile(uriString)
2220

2321
val runningRecords = runningRecordInteractor.getAll()
24-
notificationGoalTimeInteractor.checkAndReschedule(runningRecords.map { it.id })
25-
widgetInteractor.updateWidgets(listOf(WidgetType.STATISTICS_CHART))
26-
widgetInteractor.updateWidgets(listOf(WidgetType.RECORD_TYPE))
22+
externalViewsInteractor.onCsvImport(runningRecords.map { it.id })
2723

2824
return resultCode
2925
}
Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
package com.example.util.simpletimetracker.domain.interactor
22

3-
import com.example.util.simpletimetracker.domain.model.WidgetType
43
import javax.inject.Inject
54

65
class RemoveRecordMediator @Inject constructor(
76
private val recordInteractor: RecordInteractor,
8-
private val notificationTypeInteractor: NotificationTypeInteractor,
9-
private val notificationActivitySwitchInteractor: NotificationActivitySwitchInteractor,
10-
private val notificationGoalTimeInteractor: NotificationGoalTimeInteractor,
11-
private val widgetInteractor: WidgetInteractor,
7+
private val externalViewsInteractor: UpdateExternalViewsInteractor,
128
) {
139

1410
suspend fun remove(recordId: Long, typeId: Long) {
@@ -17,10 +13,6 @@ class RemoveRecordMediator @Inject constructor(
1713
}
1814

1915
suspend fun doAfterRemove(typeId: Long) {
20-
notificationTypeInteractor.checkAndShow(typeId)
21-
notificationActivitySwitchInteractor.updateNotification()
22-
notificationGoalTimeInteractor.checkAndReschedule(listOf(typeId))
23-
widgetInteractor.updateWidgets(listOf(WidgetType.STATISTICS_CHART))
24-
widgetInteractor.updateSingleWidgets(typeIds = listOf(typeId))
16+
externalViewsInteractor.onRecordRemove(typeId)
2517
}
2618
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import javax.inject.Inject
44

55
class RemoveRecordTagMediator @Inject constructor(
66
private val recordTagInteractor: RecordTagInteractor,
7-
private val wearInteractor: WearInteractor,
7+
private val externalViewsInteractor: UpdateExternalViewsInteractor,
88
) {
99

1010
suspend fun remove(tagId: Long) {
@@ -13,6 +13,6 @@ class RemoveRecordTagMediator @Inject constructor(
1313
}
1414

1515
private suspend fun doAfterRemove() {
16-
wearInteractor.update()
16+
externalViewsInteractor.onTagRemove()
1717
}
1818
}
Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
package com.example.util.simpletimetracker.domain.interactor
22

3-
import com.example.util.simpletimetracker.domain.model.RecordTypeGoal
4-
import com.example.util.simpletimetracker.domain.model.RunningRecord
5-
import com.example.util.simpletimetracker.domain.model.WidgetType
63
import javax.inject.Inject
74

85
class RemoveRecordTypeMediator @Inject constructor(
96
private val recordTypeInteractor: RecordTypeInteractor,
10-
private val notificationGoalTimeInteractor: NotificationGoalTimeInteractor,
11-
private val widgetInteractor: WidgetInteractor,
12-
private val wearInteractor: WearInteractor,
13-
private val runningRecordInteractor: RunningRecordInteractor,
7+
private val externalViewsInteractor: UpdateExternalViewsInteractor,
148
) {
159

1610
suspend fun remove(typeId: Long) {
@@ -19,10 +13,6 @@ class RemoveRecordTypeMediator @Inject constructor(
1913
}
2014

2115
private suspend fun doAfterRemove(typeId: Long) {
22-
val runningRecordIds = runningRecordInteractor.getAll().map(RunningRecord::id)
23-
notificationGoalTimeInteractor.cancel(RecordTypeGoal.IdData.Type(typeId))
24-
notificationGoalTimeInteractor.checkAndReschedule(runningRecordIds + typeId)
25-
widgetInteractor.updateWidgets(listOf(WidgetType.STATISTICS_CHART))
26-
wearInteractor.update()
16+
externalViewsInteractor.onTypeRemove(typeId)
2717
}
2818
}

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

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,10 @@ import javax.inject.Inject
77
class RemoveRunningRecordMediator @Inject constructor(
88
private val recordInteractor: RecordInteractor,
99
private val runningRecordInteractor: RunningRecordInteractor,
10-
private val notificationTypeInteractor: NotificationTypeInteractor,
11-
private val notificationActivitySwitchInteractor: NotificationActivitySwitchInteractor,
12-
private val notificationInactivityInteractor: NotificationInactivityInteractor,
13-
private val notificationActivityInteractor: NotificationActivityInteractor,
14-
private val notificationGoalTimeInteractor: NotificationGoalTimeInteractor,
15-
private val widgetInteractor: WidgetInteractor,
16-
private val wearInteractor: WearInteractor,
1710
private val prefsInteractor: PrefsInteractor,
1811
private val activityStartedStoppedBroadcastInteractor: ActivityStartedStoppedBroadcastInteractor,
1912
private val pomodoroStopInteractor: PomodoroStopInteractor,
13+
private val updateExternalViewsInteractor: UpdateExternalViewsInteractor,
2014
) {
2115

2216
suspend fun removeWithRecordAdd(
@@ -51,18 +45,10 @@ class RemoveRunningRecordMediator @Inject constructor(
5145
updateNotificationSwitch: Boolean = true,
5246
) {
5347
runningRecordInteractor.remove(typeId)
54-
notificationTypeInteractor.checkAndHide(typeId)
55-
if (updateNotificationSwitch) {
56-
notificationActivitySwitchInteractor.updateNotification()
57-
}
58-
notificationInactivityInteractor.checkAndSchedule()
59-
// Cancel if no activity tracked.
60-
val runningRecordIds = runningRecordInteractor.getAll().map { it.id }
61-
if (runningRecordIds.isEmpty()) notificationActivityInteractor.cancel()
62-
notificationGoalTimeInteractor.checkAndReschedule(runningRecordIds + typeId)
63-
if (updateWidgets) {
64-
widgetInteractor.updateWidgets()
65-
wearInteractor.update()
66-
}
48+
updateExternalViewsInteractor.onRunningRecordRemove(
49+
typeId = typeId,
50+
updateWidgets = updateWidgets,
51+
updateNotificationSwitch = updateNotificationSwitch
52+
)
6753
}
6854
}

0 commit comments

Comments
 (0)