Skip to content

Commit f0baba3

Browse files
committed
add tag value from rules to preselected tags
1 parent 0231fda commit f0baba3

File tree

11 files changed

+25
-20
lines changed

11 files changed

+25
-20
lines changed

buildSrc/src/main/kotlin/com/example/util/simpletimetracker/Base.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ object Base {
1717
const val targetSDKWear = 34
1818

1919
// Raise after wear api changes.
20-
const val wearApiVersion = 3
20+
const val wearApiVersion = 4
2121
}

core/src/main/java/com/example/util/simpletimetracker/core/interactor/LoadPreselectedTagsInteractor.kt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,25 @@ import com.example.util.simpletimetracker.domain.base.CurrentTimestampProvider
44
import com.example.util.simpletimetracker.domain.base.suspendLazy
55
import com.example.util.simpletimetracker.domain.record.interactor.AddRunningRecordMediator
66
import com.example.util.simpletimetracker.domain.record.model.RecordBase
7-
import com.example.util.simpletimetracker.domain.recordTag.interactor.RecordTypeToDefaultTagInteractor
87
import kotlinx.coroutines.coroutineScope
98
import javax.inject.Inject
109

1110
class LoadPreselectedTagsInteractor @Inject constructor(
1211
private val addRunningRecordMediator: AddRunningRecordMediator,
13-
private val recordTypeToDefaultTagInteractor: RecordTypeToDefaultTagInteractor,
1412
private val currentTimestampProvider: CurrentTimestampProvider,
1513
) {
1614

17-
suspend fun execute(typeId: Long) = coroutineScope {
18-
val defaultTags = recordTypeToDefaultTagInteractor.getTags(typeId)
19-
val timeStarted = currentTimestampProvider.get()
15+
suspend fun execute(typeId: Long): List<RecordBase.Tag> = coroutineScope {
2016
val ruleTags = addRunningRecordMediator.processRules(
2117
typeId = typeId,
22-
timeStarted = timeStarted,
18+
timeStarted = currentTimestampProvider.get(),
2319
prevRecords = suspendLazy { emptyList() },
24-
).tags.map(RecordBase.Tag::tagId).toSet()
25-
defaultTags + ruleTags
20+
).tags
21+
22+
addRunningRecordMediator.getAllTags(
23+
typeId = typeId,
24+
currentTags = emptyList(),
25+
tagValuesFromRules = ruleTags,
26+
)
2627
}
2728
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ class AddRunningRecordMediator @Inject constructor(
377377
}
378378
}
379379

380-
private suspend fun getAllTags(
380+
suspend fun getAllTags(
381381
typeId: Long,
382382
currentTags: List<RecordBase.Tag>,
383383
tagValuesFromRules: List<RecordBase.Tag>,

features/feature_notification/src/main/java/com/example/util/simpletimetracker/feature_notification/recordType/interactor/ActivityStartStopFromBroadcastInteractor.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ class ActivityStartStopFromBroadcastInteractor @Inject constructor(
6969
commentInputAvailable = false, // TODO open activity? Or RemoteInput?
7070
) {
7171
val preselectedTags = loadPreselectedTagsInteractor.execute(selectedTypeId)
72-
.map { RecordBase.Tag(tagId = it, numericValue = null) }
7372
val isMultipleTagAvailable = isMultipleTagChoiceAvailable(
7473
selectedTypeId = selectedTypeId,
7574
selectedTags = preselectedTags,

features/feature_tag_selection/src/main/java/com/example/util/simpletimetracker/feature_tag_selection/viewModel/RecordTagSelectionViewModel.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,7 @@ class RecordTagSelectionViewModel @Inject constructor(
162162
// TODO TAG ability to deselect preselected tags
163163
private suspend fun initializeData() {
164164
if (initialDataLoaded) return
165-
val initialIds = loadPreselectedTagsInteractor.execute(extra.typeId)
166-
if (initialIds.isNotEmpty()) {
167-
newTags = initialIds.map { RecordBase.Tag(tagId = it, numericValue = null) }
168-
}
165+
newTags = loadPreselectedTagsInteractor.execute(extra.typeId)
169166
val shouldCloseAfterOne = shouldCloseAfterOneTagInteractor.execute(
170167
typeId = extra.typeId,
171168
closeAfterOne = prefsInteractor.getRecordTagSelectionCloseAfterOne(),

features/feature_wear/src/main/java/com/example/util/simpletimetracker/feature_wear/WearDataLocalMapper.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class WearDataLocalMapper @Inject constructor(
7171
fun map(
7272
recordTag: RecordTag,
7373
types: Map<Long, RecordType>,
74-
preselectedTagIds: Set<Long>,
74+
preselectedTags: Map<Long, RecordBase.Tag>,
7575
): WearTagDTO {
7676
return WearTagDTO(
7777
id = recordTag.id,
@@ -80,7 +80,8 @@ class WearDataLocalMapper @Inject constructor(
8080
tag = recordTag,
8181
types = types,
8282
).let(::mapColor),
83-
preselected = recordTag.id in preselectedTagIds,
83+
preselected = recordTag.id in preselectedTags.keys,
84+
value = preselectedTags[recordTag.id]?.numericValue,
8485
)
8586
}
8687

features/feature_wear/src/main/java/com/example/util/simpletimetracker/feature_wear/WearDataRepo.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,14 +189,15 @@ class WearDataRepo @Inject constructor(
189189

190190
override suspend fun queryTagsForActivity(activityId: Long): List<WearTagDTO> {
191191
val types = recordTypeInteractor.getAll().associateBy { it.id }
192-
val preselectedTagIds = loadPreselectedTagsInteractor.get().execute(activityId)
192+
val preselectedTags = loadPreselectedTagsInteractor.get().execute(activityId)
193+
.associateBy { it.tagId }
193194
return getSelectableTagsInteractor.execute(activityId)
194195
.filterNot { it.archived }
195196
.map {
196197
wearDataLocalMapper.map(
197198
recordTag = it,
198199
types = types,
199-
preselectedTagIds = preselectedTagIds,
200+
preselectedTags = preselectedTags,
200201
)
201202
}
202203
}

wear/src/main/java/com/example/util/simpletimetracker/data/WearDataLocalMapper.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class WearDataLocalMapper @Inject constructor() {
8383
name = dto.name,
8484
color = dto.color,
8585
preselected = dto.preselected,
86+
value = dto.value,
8687
)
8788
}
8889

wear/src/main/java/com/example/util/simpletimetracker/domain/model/WearTag.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ data class WearTag(
1010
val name: String,
1111
val color: Long,
1212
val preselected: Boolean,
13+
val value: Double?,
1314
)

wear/src/main/java/com/example/util/simpletimetracker/features/tagsSelection/viewModel/TagsViewModel.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ class TagsViewModel @Inject constructor(
123123
if (settingsResult != null && tagsResult != null) {
124124
settings = settingsResult
125125
tags = tagsResult
126-
selectedTags = tags.filter { it.preselected }.map { WearRecordTag(it.id, null) }
126+
selectedTags = tags.filter { it.preselected }.map {
127+
WearRecordTag(tagId = it.id, numericValue = it.value)
128+
}
127129
val shouldCloseAfterOne = shouldCloseAfterOneTagInteractor.execute(
128130
typeId = activityId,
129131
closeAfterOne = settings?.recordTagSelectionCloseAfterOne.orFalse(),

0 commit comments

Comments
 (0)