Skip to content

Commit cdb7ce9

Browse files
committed
tag value on start in notifications
1 parent 9f64622 commit cdb7ce9

File tree

21 files changed

+139
-48
lines changed

21 files changed

+139
-48
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ interface NotificationActivitySwitchInteractor {
1212
editingTagId: Long? = null,
1313
editingTagValueInput: String? = null,
1414
isMultipleTagAvailable: Boolean = false,
15+
requiredValueSelectionTagIds: List<Long> = emptyList(),
1516
)
1617
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ interface NotificationTypeInteractor {
1313
editingTagId: Long? = null,
1414
editingTagValueInput: String? = null,
1515
isMultipleTagAvailable: Boolean = false,
16+
requiredValueSelectionTagIds: List<Long> = emptyList(),
1617
)
1718

1819
suspend fun checkAndHide(typeId: Long)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ class ShouldShowRecordDataSelectionInteractor @Inject constructor(
3939
prevRecords = suspendLazy { recordInteractor.getAllPrev(currentTime) },
4040
retroactiveTrackingMode = prefsInteractor.getRetroactiveTrackingMode(),
4141
)
42-
val requiredTagValueSelectionTagIds = filterNumericTagValueSelectionTagIds(
42+
val requiredValueSelectionTagIds = filterNumericTagValueSelectionTagIds(
4343
tagIds = rulesResult.tagIdsToSelectValueOnStart,
4444
)
45-
if (requiredTagValueSelectionTagIds.isNotEmpty()) {
45+
if (requiredValueSelectionTagIds.isNotEmpty()) {
4646
// Force tag selection dialog if any tags need value.
4747
fields += RecordDataSelectionDialogResult.Field.Tags
4848
}
@@ -55,7 +55,7 @@ class ShouldShowRecordDataSelectionInteractor @Inject constructor(
5555
return RecordDataSelectionDialogResult(
5656
fields = fields.toList(),
5757
preselectedTags = allTags,
58-
requiredTagValueSelectionTagIds = requiredTagValueSelectionTagIds
58+
requiredValueSelectionTagIds = requiredValueSelectionTagIds,
5959
)
6060
}
6161

domain/src/main/java/com/example/util/simpletimetracker/domain/record/model/RecordDataSelectionDialogResult.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package com.example.util.simpletimetracker.domain.record.model
33
data class RecordDataSelectionDialogResult(
44
val fields: List<Field>,
55
val preselectedTags: List<RecordBase.Tag>,
6-
val requiredTagValueSelectionTagIds: List<Long>,
6+
val requiredValueSelectionTagIds: List<Long>,
77
) {
88
sealed interface Field {
99
object Tags : Field

domain/src/test/java/com/example/util/simpletimetracker/domain/mapper/AddRunningRecordMediatorTest.kt

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import com.example.util.simpletimetracker.domain.recordType.model.RecordType
2121
import com.example.util.simpletimetracker.domain.base.ResultContainer
2222
import com.example.util.simpletimetracker.domain.record.model.RunningRecord
2323
import com.example.util.simpletimetracker.domain.base.CurrentTimestampProvider
24+
import com.example.util.simpletimetracker.domain.record.interactor.ProcessRulesInteractor
2425
import com.example.util.simpletimetracker.domain.record.model.RecordBase
2526
import kotlinx.coroutines.runBlocking
2627
import org.junit.Before
@@ -53,19 +54,24 @@ class AddRunningRecordMediatorTest {
5354
private val updateExternalViewsInteractor: UpdateExternalViewsInteractor = mock()
5455
private val currentTimestampProvider: CurrentTimestampProvider = mock()
5556

57+
private val processRulesInteractor = ProcessRulesInteractor(
58+
runningRecordInteractor = runningRecordInteractor,
59+
complexRuleProcessActionInteractor = complexRuleProcessActionInteractor,
60+
recordTypeToDefaultTagInteractor = recordTypeToDefaultTagInteractor,
61+
)
62+
5663
private val subject = AddRunningRecordMediator(
5764
prefsInteractor = prefsInteractor,
5865
removeRunningRecordMediator = removeRunningRecordMediator,
5966
recordInteractor = recordInteractor,
6067
runningRecordInteractor = runningRecordInteractor,
6168
recordTypeInteractor = recordTypeInteractor,
6269
addRecordMediator = addRecordMediator,
63-
recordTypeToDefaultTagInteractor = recordTypeToDefaultTagInteractor,
6470
notificationGoalCountInteractor = notificationGoalCountInteractor,
6571
activityStartedStoppedBroadcastInteractor = activityStartedStoppedBroadcastInteractor,
6672
shouldShowRecordDataSelectionInteractor = shouldShowRecordDataSelectionInteractor,
6773
pomodoroStartInteractor = pomodoroStartInteractor,
68-
complexRuleProcessActionInteractor = complexRuleProcessActionInteractor,
74+
processRulesInteractor = processRulesInteractor,
6975
updateExternalViewsInteractor = updateExternalViewsInteractor,
7076
currentTimestampProvider = currentTimestampProvider,
7177
).let(::spy)
@@ -139,7 +145,7 @@ class AddRunningRecordMediatorTest {
139145

140146
`when`(runningRecordInteractor.get(typeId)).thenReturn(null)
141147
`when`(shouldShowRecordDataSelectionInteractor.execute(any(), any())).thenReturn(
142-
RecordDataSelectionDialogResult(emptyList()),
148+
RecordDataSelectionDialogResult(emptyList(), emptyList(), emptyList()),
143149
)
144150
subject.tryStartTimer(
145151
typeId = typeId,
@@ -169,6 +175,8 @@ class AddRunningRecordMediatorTest {
169175
RecordDataSelectionDialogResult.Field.Tags,
170176
RecordDataSelectionDialogResult.Field.Comment,
171177
),
178+
emptyList(),
179+
emptyList(),
172180
)
173181

174182
`when`(runningRecordInteractor.get(typeId)).thenReturn(null)
@@ -202,10 +210,15 @@ class AddRunningRecordMediatorTest {
202210
tags = emptyList(),
203211
tagIdsToSelectValueOnStart = setOf(tagId2),
204212
)
213+
val expected = RecordDataSelectionDialogResult(
214+
fields = listOf(RecordDataSelectionDialogResult.Field.Tags),
215+
preselectedTags = emptyList(),
216+
requiredValueSelectionTagIds = listOf(tagId2),
217+
)
205218

206219
`when`(runningRecordInteractor.get(typeId)).thenReturn(null)
207220
`when`(shouldShowRecordDataSelectionInteractor.execute(any(), any())).thenReturn(
208-
RecordDataSelectionDialogResult(emptyList()),
221+
expected,
209222
)
210223
`when`(complexRuleProcessActionInteractor.hasRules()).thenReturn(true)
211224
`when`(complexRuleProcessActionInteractor.processRules(any(), any(), any())).thenReturn(
@@ -219,10 +232,6 @@ class AddRunningRecordMediatorTest {
219232
onNeedToShowTagSelection = { tagSelectionResult.invoke(it) },
220233
)
221234

222-
val expected = RecordDataSelectionDialogResult(
223-
fields = listOf(RecordDataSelectionDialogResult.Field.Tags),
224-
requiredTagValueSelectionTagIds = listOf(tagId2),
225-
)
226235
verify(tagSelectionResult).invoke(eq(expected))
227236
verify(subject, never()).startTimer(
228237
typeId = any(),
@@ -242,7 +251,7 @@ class AddRunningRecordMediatorTest {
242251

243252
`when`(runningRecordInteractor.get(typeId)).thenReturn(null)
244253
`when`(shouldShowRecordDataSelectionInteractor.execute(any(), any())).thenReturn(
245-
RecordDataSelectionDialogResult(emptyList()),
254+
RecordDataSelectionDialogResult(emptyList(), emptyList(), emptyList()),
246255
)
247256
subject.tryStartTimer(
248257
typeId = typeId,

features/feature_notification/src/main/java/com/example/util/simpletimetracker/feature_notification/activitySwitch/interactor/GetNotificationActivitySwitchControlsInteractor.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ class GetNotificationActivitySwitchControlsInteractor @Inject constructor(
5151
selectedTags: List<RecordBase.Tag>,
5252
editingTagId: Long?,
5353
editingTagValueInput: String?,
54+
requiredValueSelectionTagIds: List<Long>,
5455
goals: Map<Long, List<RecordTypeGoal>>,
5556
allDailyCurrents: Map<Long, GetCurrentRecordsDurationInteractor.Result>,
5657
): NotificationControlsParams {
5758
val viewState = if (editingTagId != null) {
5859
mapTagSelectionViewState(
5960
isDarkTheme = isDarkTheme,
6061
currentValueString = editingTagValueInput,
61-
valueSuffix = recordTagInteractor.get(editingTagId)
62-
?.valueSuffix.orEmpty(),
62+
editingTag = recordTagInteractor.get(editingTagId),
6363
)
6464
} else {
6565
mapTypesViewState(
@@ -84,6 +84,7 @@ class GetNotificationActivitySwitchControlsInteractor @Inject constructor(
8484
isMultipleTagAvailable = isMultipleTagAvailable,
8585
selectedTypeId = selectedTypeId,
8686
selectedTags = selectedTags,
87+
requiredValueSelectionTagIds = requiredValueSelectionTagIds,
8788
editingTagId = editingTagId,
8889
editingTagValueInput = editingTagValueInput,
8990
viewState = viewState,
@@ -199,11 +200,16 @@ class GetNotificationActivitySwitchControlsInteractor @Inject constructor(
199200
private fun mapTagSelectionViewState(
200201
isDarkTheme: Boolean,
201202
currentValueString: String?,
202-
valueSuffix: String,
203+
editingTag: RecordTag?,
203204
): NotificationControlsParams.ViewState {
205+
val valueSuffix = editingTag?.valueSuffix.orEmpty()
204206
val hint = when {
205207
currentValueString.isNullOrEmpty() -> {
206-
resourceRepo.getString(R.string.change_record_type_value_selection_hint)
208+
resourceRepo.getString(
209+
R.string.separator_template,
210+
resourceRepo.getString(R.string.change_record_type_value_selection_hint),
211+
"(${editingTag?.name.orEmpty()})",
212+
)
207213
}
208214
valueSuffix.isEmpty() -> {
209215
currentValueString

features/feature_notification/src/main/java/com/example/util/simpletimetracker/feature_notification/activitySwitch/interactor/NotificationActivitySwitchInteractorImpl.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class NotificationActivitySwitchInteractorImpl @Inject constructor(
5252
editingTagId: Long?,
5353
editingTagValueInput: String?,
5454
isMultipleTagAvailable: Boolean,
55+
requiredValueSelectionTagIds: List<Long>,
5556
) {
5657
val shouldShow = prefsInteractor.getShowNotifications() &&
5758
prefsInteractor.getShowNotificationEvenWithNoTimers() &&
@@ -66,6 +67,7 @@ class NotificationActivitySwitchInteractorImpl @Inject constructor(
6667
editingTagId = editingTagId,
6768
editingTagValueInput = editingTagValueInput,
6869
isMultipleTagAvailable = isMultipleTagAvailable,
70+
requiredValueSelectionTagIds = requiredValueSelectionTagIds,
6971
)
7072
} else {
7173
cancel()
@@ -80,6 +82,7 @@ class NotificationActivitySwitchInteractorImpl @Inject constructor(
8082
editingTagId: Long?,
8183
editingTagValueInput: String?,
8284
isMultipleTagAvailable: Boolean,
85+
requiredValueSelectionTagIds: List<Long>,
8386
) {
8487
val isDarkTheme = prefsInteractor.getDarkMode()
8588
val showRepeatButton = prefsInteractor.getEnableRepeatButton()
@@ -185,6 +188,7 @@ class NotificationActivitySwitchInteractorImpl @Inject constructor(
185188
selectedTags = selectedTags,
186189
editingTagId = editingTagId,
187190
editingTagValueInput = editingTagValueInput,
191+
requiredValueSelectionTagIds = requiredValueSelectionTagIds,
188192
goals = goals,
189193
allDailyCurrents = allDailyCurrents,
190194
)

features/feature_notification/src/main/java/com/example/util/simpletimetracker/feature_notification/activitySwitch/manager/NotificationControlsManager.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ class NotificationControlsManager @Inject constructor(
126126
.coerceAtLeast(0),
127127
recordTagsShift = params.tagsShift,
128128
isMultipleTagAvailable = params.isMultipleTagAvailable,
129+
requiredValueSelectionTagIds = params.requiredValueSelectionTagIds,
129130
),
130131
)
131132

@@ -171,6 +172,7 @@ class NotificationControlsManager @Inject constructor(
171172
recordTagsShift = params.tagsShift,
172173
selectedTypeId = data.id,
173174
isMultipleTagAvailable = params.isMultipleTagAvailable,
175+
requiredValueSelectionTagIds = params.requiredValueSelectionTagIds,
174176
),
175177
).let {
176178
addView(R.id.containerNotificationTypes, it)
@@ -217,6 +219,7 @@ class NotificationControlsManager @Inject constructor(
217219
.orZero(),
218220
recordTagsShift = params.tagsShift,
219221
isMultipleTagAvailable = params.isMultipleTagAvailable,
222+
requiredValueSelectionTagIds = params.requiredValueSelectionTagIds,
220223
),
221224
)
222225
}
@@ -248,6 +251,7 @@ class NotificationControlsManager @Inject constructor(
248251
.ifNull { viewState.tags.size - TAGS_LIST_SIZE }
249252
.coerceAtLeast(0),
250253
isMultipleTagAvailable = params.isMultipleTagAvailable,
254+
requiredValueSelectionTagIds = params.requiredValueSelectionTagIds,
251255
),
252256
)
253257

@@ -274,6 +278,7 @@ class NotificationControlsManager @Inject constructor(
274278
recordTagsShift = params.tagsShift,
275279
tagId = data.id,
276280
isMultipleTagAvailable = params.isMultipleTagAvailable,
281+
requiredValueSelectionTagIds = params.requiredValueSelectionTagIds,
277282
),
278283
isSelected = data.isSelected,
279284
).let {
@@ -320,6 +325,7 @@ class NotificationControlsManager @Inject constructor(
320325
.takeUnless { it >= viewState.tags.size }
321326
.orZero(),
322327
isMultipleTagAvailable = params.isMultipleTagAvailable,
328+
requiredValueSelectionTagIds = params.requiredValueSelectionTagIds,
323329
),
324330
)
325331
}
@@ -346,6 +352,7 @@ class NotificationControlsManager @Inject constructor(
346352
recordTypesShift = params.typesShift,
347353
recordTagsShift = params.tagsShift,
348354
isMultipleTagAvailable = params.isMultipleTagAvailable,
355+
requiredValueSelectionTagIds = params.requiredValueSelectionTagIds,
349356
),
350357
)
351358

@@ -389,6 +396,7 @@ class NotificationControlsManager @Inject constructor(
389396
recordTypesShift = params.typesShift,
390397
recordTagsShift = params.tagsShift,
391398
isMultipleTagAvailable = params.isMultipleTagAvailable,
399+
requiredValueSelectionTagIds = params.requiredValueSelectionTagIds,
392400
),
393401
).let {
394402
addView(containerId, it)
@@ -453,6 +461,7 @@ class NotificationControlsManager @Inject constructor(
453461
recordTypesShift = params.typesShift,
454462
recordTagsShift = params.tagsShift,
455463
isMultipleTagAvailable = params.isMultipleTagAvailable,
464+
requiredValueSelectionTagIds = params.requiredValueSelectionTagIds,
456465
),
457466
)
458467

@@ -476,6 +485,7 @@ class NotificationControlsManager @Inject constructor(
476485
recordTypesShift = params.typesShift,
477486
recordTagsShift = params.tagsShift,
478487
isMultipleTagAvailable = params.isMultipleTagAvailable,
488+
requiredValueSelectionTagIds = params.requiredValueSelectionTagIds,
479489
),
480490
)
481491
}
@@ -555,6 +565,7 @@ class NotificationControlsManager @Inject constructor(
555565
recordTagsShift: Int? = null,
556566
tagId: Long? = null,
557567
isMultipleTagAvailable: Boolean,
568+
requiredValueSelectionTagIds: List<Long> = emptyList(),
558569
): PendingIntent {
559570
val intent = Intent(context, NotificationReceiver::class.java)
560571
intent.action = action
@@ -567,6 +578,7 @@ class NotificationControlsManager @Inject constructor(
567578
tagId?.let { intent.putExtra(ARGS_CLICKED_TAG_ID, it) }
568579
recordTypesShift.let { intent.putExtra(ARGS_TYPES_SHIFT, it) }
569580
recordTagsShift?.let { intent.putExtra(ARGS_TAGS_SHIFT, it) }
581+
intent.putExtra(ARGS_REQUIRED_VALUE_SELECTION_TAGS, requiredValueSelectionTagIds.toLongArray())
570582
intent.putExtra(ARGS_MULTIPLE_TAG_AVAILABLE, isMultipleTagAvailable)
571583
return PendingIntent.getBroadcast(
572584
context,
@@ -658,6 +670,7 @@ class NotificationControlsManager @Inject constructor(
658670
const val ARGS_SELECTED_TAGS = "selectedTags"
659671
const val ARGS_EDITING_TAG_ID = "editingTagId"
660672
const val ARGS_EDITING_TAG_VALUE_INPUT = "editingTagValueInput"
673+
const val ARGS_REQUIRED_VALUE_SELECTION_TAGS = "requiredTagSelectionTags"
661674
const val ARGS_CLICKED_TAG_ID = "clickedTagId"
662675
const val ARGS_TYPES_SHIFT = "typesShift"
663676
const val ARGS_TAGS_SHIFT = "tagsShift"

features/feature_notification/src/main/java/com/example/util/simpletimetracker/feature_notification/activitySwitch/manager/NotificationControlsParams.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ sealed interface NotificationControlsParams {
1313
val controlIconColor: Int,
1414
val isMultipleTagAvailable: Boolean,
1515
val selectedTypeId: Long?,
16-
val selectedTags: List<RecordBase.Tag> = emptyList(),
17-
val editingTagId: Long? = null,
18-
val editingTagValueInput: String? = null,
16+
val selectedTags: List<RecordBase.Tag>,
17+
val requiredValueSelectionTagIds: List<Long>,
18+
val editingTagId: Long?,
19+
val editingTagValueInput: String?,
1920
val viewState: ViewState,
2021
) : NotificationControlsParams
2122

0 commit comments

Comments
 (0)