Skip to content

Commit 3106197

Browse files
committed
change value tag selection on notifications
1 parent 4fdbefa commit 3106197

File tree

14 files changed

+449
-187
lines changed

14 files changed

+449
-187
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@ interface NotificationActivitySwitchInteractor {
66
typesShift: Int = 0,
77
tagsShift: Int = 0,
88
selectedTypeId: Long = 0,
9+
selectedTagId: Long = 0,
10+
selectedTagValue: String? = null,
911
)
1012
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ interface NotificationTypeInteractor {
88
tagsShift: Int = 0,
99
selectedTypeId: Long = 0,
1010
selectedTagId: Long = 0,
11-
autoCancel: Boolean = false,
11+
selectedTagValue: String? = null,
1212
)
1313

1414
suspend fun checkAndHide(typeId: Long)

features/feature_dialogs/src/main/java/com/example/util/simpletimetracker/feature_dialogs/recordQuickActions/interactor/RecordQuickActionsInteractor.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@ class RecordQuickActionsInteractor @Inject constructor(
7070
.mapNotNull { recordInteractor.get(it) }
7171
.filter {
7272
// TODO TAG translate strings
73-
// TODO TAG add to widget single
74-
// TODO TAG add to widget universal
75-
// TODO TAG add to notification
7673
// TODO TAG add to wear
7774
it.tags.sortedBy(RecordBase.Tag::tagId) !=
7875
newTags.sortedBy(RecordBase.Tag::tagId)

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

Lines changed: 123 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ import com.example.util.simpletimetracker.core.mapper.RecordTagViewDataMapper
88
import com.example.util.simpletimetracker.core.mapper.RecordTypeViewDataMapper
99
import com.example.util.simpletimetracker.core.repo.ResourceRepo
1010
import com.example.util.simpletimetracker.domain.base.REPEAT_BUTTON_ITEM_ID
11+
import com.example.util.simpletimetracker.domain.recordTag.interactor.GetSelectableTagsInteractor
1112
import com.example.util.simpletimetracker.domain.recordTag.model.RecordTag
1213
import com.example.util.simpletimetracker.domain.recordType.model.RecordType
1314
import com.example.util.simpletimetracker.domain.recordType.model.RecordTypeGoal
1415
import com.example.util.simpletimetracker.feature_notification.R
1516
import com.example.util.simpletimetracker.feature_notification.activitySwitch.manager.NotificationControlsManager.Companion.TAGS_LIST_SIZE
1617
import com.example.util.simpletimetracker.feature_notification.activitySwitch.manager.NotificationControlsManager.Companion.TYPES_LIST_SIZE
1718
import com.example.util.simpletimetracker.feature_notification.activitySwitch.manager.NotificationControlsParams
19+
import com.example.util.simpletimetracker.feature_notification.core.TAG_VALUE_DECIMAL_DELIMITER
1820
import com.example.util.simpletimetracker.feature_views.GoalCheckmarkView
1921
import com.example.util.simpletimetracker.feature_views.viewData.RecordTypeIcon
2022
import javax.inject.Inject
@@ -26,34 +28,69 @@ class GetNotificationActivitySwitchControlsInteractor @Inject constructor(
2628
private val resourceRepo: ResourceRepo,
2729
private val recordTagViewDataMapper: RecordTagViewDataMapper,
2830
private val completeTypesStateInteractor: CompleteTypesStateInteractor,
31+
private val getSelectableTagsInteractor: GetSelectableTagsInteractor,
2932
) {
3033

31-
fun getControls(
34+
suspend fun getControls(
35+
hint: String,
36+
isDarkTheme: Boolean,
37+
types: List<RecordType>,
38+
suggestions: List<RecordType>,
39+
showRepeatButton: Boolean,
40+
typesShift: Int,
41+
tagsShift: Int,
42+
selectedTypeId: Long?,
43+
selectedTagId: Long?,
44+
selectedTagValue: String?,
45+
goals: Map<Long, List<RecordTypeGoal>>,
46+
allDailyCurrents: Map<Long, GetCurrentRecordsDurationInteractor.Result>,
47+
): NotificationControlsParams {
48+
val viewState = if (selectedTagId != null && selectedTagId != 0L) {
49+
mapTagSelectionViewState(
50+
isDarkTheme = isDarkTheme,
51+
currentValueString = selectedTagValue,
52+
)
53+
} else {
54+
mapTypesViewState(
55+
hint = hint,
56+
isDarkTheme = isDarkTheme,
57+
types = types,
58+
suggestions = suggestions,
59+
showRepeatButton = showRepeatButton,
60+
typesShift = typesShift,
61+
selectedTypeId = selectedTypeId,
62+
goals = goals,
63+
allDailyCurrents = allDailyCurrents,
64+
)
65+
}
66+
67+
return NotificationControlsParams.Enabled(
68+
typesShift = typesShift,
69+
tagsShift = tagsShift,
70+
controlIconColor = colorMapper.toInactiveColor(isDarkTheme),
71+
selectedTypeId = selectedTypeId,
72+
selectedTagId = selectedTagId,
73+
selectedTagValue = selectedTagValue,
74+
viewState = viewState,
75+
)
76+
}
77+
78+
private suspend fun mapTypesViewState(
3279
hint: String,
3380
isDarkTheme: Boolean,
3481
types: List<RecordType>,
3582
suggestions: List<RecordType>,
3683
showRepeatButton: Boolean,
3784
typesShift: Int = 0,
38-
tags: List<RecordTag> = emptyList(),
39-
tagsShift: Int = 0,
4085
selectedTypeId: Long? = null,
41-
selectedTagId: Long? = null,
42-
autoCancel: Boolean = false,
4386
goals: Map<Long, List<RecordTypeGoal>>,
4487
allDailyCurrents: Map<Long, GetCurrentRecordsDurationInteractor.Result>,
45-
): NotificationControlsParams {
46-
// Populate container with empty items to preserve prev next controls position.
47-
fun <T> populateWithEmpty(
48-
data: List<T>,
49-
pageSize: Int,
50-
emptyValueProducer: () -> T,
51-
): List<T> {
52-
if (data.isEmpty()) return data
53-
if (data.size % pageSize == 0) return data
54-
val emptyCount = pageSize - (data.size % pageSize)
55-
val emptyData = List(emptyCount) { emptyValueProducer() }
56-
return data + emptyData
88+
): NotificationControlsParams.ViewState {
89+
val tags = if (selectedTypeId != null && selectedTypeId != 0L) {
90+
getSelectableTagsInteractor.execute(selectedTypeId)
91+
.filterNot { it.archived }
92+
} else {
93+
emptyList()
5794
}
5895

5996
val typesMap = types.associateBy { it.id }
@@ -121,25 +158,71 @@ class GetNotificationActivitySwitchControlsInteractor @Inject constructor(
121158
} else {
122159
""
123160
}
124-
125-
return NotificationControlsParams.Enabled(
126-
hint = hint,
127-
pagesHint = pagesHint,
161+
val fullHint = if (hint.isNotEmpty()) {
162+
"$hint $pagesHint"
163+
} else {
164+
pagesHint
165+
}
166+
return NotificationControlsParams.ViewState.TypeSelection(
167+
hint = fullHint,
128168
types = allTypesViewData,
129-
typesShift = typesShift,
130169
tags = populateWithEmpty(
131170
data = tagsViewData,
132171
pageSize = TAGS_LIST_SIZE,
133172
emptyValueProducer = { NotificationControlsParams.Tag.Empty },
134173
),
135-
tagsShift = tagsShift,
136174
controlIconPrev = RecordTypeIcon.Image(R.drawable.arrow_left),
137175
controlIconNext = RecordTypeIcon.Image(R.drawable.arrow_right),
138-
controlIconColor = colorMapper.toInactiveColor(isDarkTheme),
139176
filteredTypeColor = colorMapper.toInactiveColor(isDarkTheme),
140-
selectedTypeId = selectedTypeId,
141-
selectedTagId = selectedTagId,
142-
autoCancel = autoCancel,
177+
)
178+
}
179+
180+
private fun mapTagSelectionViewState(
181+
isDarkTheme: Boolean,
182+
currentValueString: String?,
183+
): NotificationControlsParams.ViewState {
184+
val hint = if (currentValueString.isNullOrEmpty()) {
185+
resourceRepo.getString(R.string.change_record_type_value_selection_hint)
186+
} else {
187+
currentValueString // TODO TAG add suffix
188+
}
189+
190+
val controlIconColor = colorMapper.toInactiveColor(isDarkTheme)
191+
192+
val numbers = (0..9).map { number ->
193+
NotificationControlsParams.TagValueControls.Present(
194+
type = NotificationControlsParams.TagValueControls.Present.Type.Number(number),
195+
text = number.toString(),
196+
color = controlIconColor,
197+
)
198+
}.plus(
199+
NotificationControlsParams.TagValueControls.Present(
200+
type = NotificationControlsParams.TagValueControls.Present.Type.DoubleZero,
201+
text = "00",
202+
color = controlIconColor,
203+
),
204+
).plus(
205+
NotificationControlsParams.TagValueControls.Present(
206+
type = NotificationControlsParams.TagValueControls.Present.Type.Dot,
207+
text = TAG_VALUE_DECIMAL_DELIMITER.toString(),
208+
color = controlIconColor,
209+
),
210+
).let {
211+
populateWithEmpty(
212+
data = it,
213+
pageSize = 12,
214+
emptyValueProducer = { NotificationControlsParams.TagValueControls.Empty },
215+
)
216+
}
217+
218+
return NotificationControlsParams.ViewState.TagValueSelection(
219+
hint = hint,
220+
numbers = numbers,
221+
controlIconBack = RecordTypeIcon.Image(R.drawable.record_type_check_cross),
222+
controlBackColor = resourceRepo.getThemedAttr(R.attr.appNegativeColor, isDarkTheme),
223+
controlIconSave = RecordTypeIcon.Image(R.drawable.record_type_check_mark),
224+
controlSaveColor = resourceRepo.getThemedAttr(R.attr.appPositiveColor, isDarkTheme),
225+
controlIconRemove = RecordTypeIcon.Image(R.drawable.backspace),
143226
)
144227
}
145228

@@ -202,4 +285,17 @@ class GetNotificationActivitySwitchControlsInteractor @Inject constructor(
202285
color = colorMapper.toUntrackedColor(isDarkTheme),
203286
).let(::listOf)
204287
}
288+
289+
// Populate container with empty items to preserve prev next controls position.
290+
private fun <T> populateWithEmpty(
291+
data: List<T>,
292+
pageSize: Int,
293+
emptyValueProducer: () -> T,
294+
): List<T> {
295+
if (data.isEmpty()) return data
296+
if (data.size % pageSize == 0) return data
297+
val emptyCount = pageSize - (data.size % pageSize)
298+
val emptyData = List(emptyCount) { emptyValueProducer() }
299+
return data + emptyData
300+
}
205301
}

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

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import com.example.util.simpletimetracker.core.mapper.IconMapper
88
import com.example.util.simpletimetracker.core.mapper.TimeMapper
99
import com.example.util.simpletimetracker.core.repo.ResourceRepo
1010
import com.example.util.simpletimetracker.domain.activitySuggestion.interactor.GetCurrentActivitySuggestionsInteractor
11-
import com.example.util.simpletimetracker.domain.recordTag.interactor.GetSelectableTagsInteractor
1211
import com.example.util.simpletimetracker.domain.notifications.interactor.NotificationActivitySwitchInteractor
1312
import com.example.util.simpletimetracker.domain.prefs.interactor.PrefsInteractor
1413
import com.example.util.simpletimetracker.domain.record.interactor.RecordInteractor
@@ -21,7 +20,6 @@ import com.example.util.simpletimetracker.domain.recordType.model.RecordType
2120
import com.example.util.simpletimetracker.feature_notification.R
2221
import com.example.util.simpletimetracker.feature_notification.activitySwitch.manager.NotificationActivitySwitchManager
2322
import com.example.util.simpletimetracker.feature_notification.activitySwitch.manager.NotificationActivitySwitchParams
24-
import com.example.util.simpletimetracker.feature_notification.activitySwitch.manager.NotificationControlsParams
2523
import com.example.util.simpletimetracker.feature_notification.core.NotificationCommonMapper
2624
import com.example.util.simpletimetracker.feature_views.viewData.RecordTypeIcon
2725
import javax.inject.Inject
@@ -39,7 +37,6 @@ class NotificationActivitySwitchInteractorImpl @Inject constructor(
3937
private val getCurrentRecordsDurationInteractor: GetCurrentRecordsDurationInteractor,
4038
private val timeMapper: TimeMapper,
4139
private val filterGoalsByDayOfWeekInteractor: FilterGoalsByDayOfWeekInteractor,
42-
private val getSelectableTagsInteractor: GetSelectableTagsInteractor,
4340
private val getNotificationActivitySwitchControlsInteractor: GetNotificationActivitySwitchControlsInteractor,
4441
private val recordInteractor: RecordInteractor,
4542
private val notificationCommonMapper: NotificationCommonMapper,
@@ -50,6 +47,8 @@ class NotificationActivitySwitchInteractorImpl @Inject constructor(
5047
typesShift: Int,
5148
tagsShift: Int,
5249
selectedTypeId: Long,
50+
selectedTagId: Long,
51+
selectedTagValue: String?,
5352
) {
5453
val shouldShow = prefsInteractor.getShowNotifications() &&
5554
prefsInteractor.getShowNotificationEvenWithNoTimers() &&
@@ -60,6 +59,8 @@ class NotificationActivitySwitchInteractorImpl @Inject constructor(
6059
typesShift = typesShift,
6160
tagsShift = tagsShift,
6261
selectedTypeId = selectedTypeId,
62+
selectedTagId = selectedTagId,
63+
selectedTagValue = selectedTagValue,
6364
)
6465
} else {
6566
cancel()
@@ -70,6 +71,8 @@ class NotificationActivitySwitchInteractorImpl @Inject constructor(
7071
typesShift: Int,
7172
tagsShift: Int,
7273
selectedTypeId: Long,
74+
selectedTagId: Long,
75+
selectedTagValue: String?,
7376
) {
7477
val isDarkTheme = prefsInteractor.getDarkMode()
7578
val showRepeatButton = prefsInteractor.getEnableRepeatButton()
@@ -82,12 +85,6 @@ class NotificationActivitySwitchInteractorImpl @Inject constructor(
8285
firstDayOfWeek = firstDayOfWeek,
8386
startOfDayShift = startOfDayShift,
8487
)
85-
val viewedTags = if (selectedTypeId != 0L) {
86-
getSelectableTagsInteractor.execute(selectedTypeId)
87-
.filterNot { it.archived }
88-
} else {
89-
emptyList()
90-
}
9188
val runningRecords = runningRecordInteractor.getAll()
9289
val recordTypes = recordTypeInteractor.getAll().associateBy(RecordType::id)
9390
val recordTags = recordTagInteractor.getAll()
@@ -117,19 +114,6 @@ class NotificationActivitySwitchInteractorImpl @Inject constructor(
117114
// No goals - no need to calculate durations.
118115
emptyMap()
119116
}
120-
val controls = getNotificationActivitySwitchControlsInteractor.getControls(
121-
hint = "", // Replaced later.
122-
isDarkTheme = isDarkTheme,
123-
types = recordTypes.values.toList(),
124-
suggestions = suggestions,
125-
showRepeatButton = showRepeatButton,
126-
typesShift = typesShift,
127-
tags = viewedTags,
128-
tagsShift = tagsShift,
129-
selectedTypeId = selectedTypeId,
130-
goals = goals,
131-
allDailyCurrents = allDailyCurrents,
132-
)
133117
val hint: String
134118
val icon: RecordTypeIcon?
135119
val color: Int?
@@ -180,6 +164,20 @@ class NotificationActivitySwitchInteractorImpl @Inject constructor(
180164
prevRecordDuration = null
181165
}
182166
}
167+
val controls = getNotificationActivitySwitchControlsInteractor.getControls(
168+
hint = hint,
169+
isDarkTheme = isDarkTheme,
170+
types = recordTypes.values.toList(),
171+
suggestions = suggestions,
172+
showRepeatButton = showRepeatButton,
173+
typesShift = typesShift,
174+
tagsShift = tagsShift,
175+
selectedTypeId = selectedTypeId,
176+
selectedTagId = selectedTagId,
177+
selectedTagValue = selectedTagValue,
178+
goals = goals,
179+
allDailyCurrents = allDailyCurrents,
180+
)
183181

184182
NotificationActivitySwitchParams(
185183
icon = icon,
@@ -188,10 +186,7 @@ class NotificationActivitySwitchInteractorImpl @Inject constructor(
188186
subtitle = subtitle,
189187
untrackedStartedTimeStamp = untrackedTimeStarted,
190188
prevRecordDuration = prevRecordDuration,
191-
controls = when (controls) {
192-
is NotificationControlsParams.Disabled -> controls
193-
is NotificationControlsParams.Enabled -> controls.copy(hint = hint)
194-
},
189+
controls = controls,
195190
).let(manager::show)
196191
}
197192

0 commit comments

Comments
 (0)