5
5
*/
6
6
package com.example.util.simpletimetracker.feature_wear
7
7
8
+ import com.example.util.simpletimetracker.domain.extension.orZero
8
9
import com.example.util.simpletimetracker.domain.interactor.PrefsInteractor
9
10
import com.example.util.simpletimetracker.domain.interactor.RecordTagInteractor
10
11
import com.example.util.simpletimetracker.domain.interactor.RecordTypeInteractor
@@ -30,32 +31,32 @@ class WearCommunicationInteractor @Inject constructor(
30
31
private val appColorMapper : AppColorMapper ,
31
32
) : WearCommunicationAPI {
32
33
33
- override suspend fun queryActivities (): Array <Activity > {
34
+ override suspend fun queryActivities (): List <Activity > {
34
35
return recordTypeInteractor.getAll()
35
36
.filter { recordType -> ! recordType.hidden }
36
37
.map { recordType ->
37
38
Activity (
38
39
id = recordType.id,
39
40
name = recordType.name,
40
41
icon = recordType.icon,
41
- color = asColor (recordType.color),
42
+ color = mapColor (recordType.color),
42
43
)
43
- }.toTypedArray()
44
+ }
44
45
}
45
46
46
- override suspend fun queryCurrentActivities (): Array <CurrentActivity > {
47
+ override suspend fun queryCurrentActivities (): List <CurrentActivity > {
47
48
return runningRecordInteractor.getAll().map { record ->
48
49
CurrentActivity (
49
- record.id,
50
- record.timeStarted,
51
- record.tagIds.map { tagId ->
52
- asTag( recordTagInteractor.get(tagId))
53
- }.filter { it.id > 0 }.toTypedArray() ,
50
+ id = record.id,
51
+ startedAt = record.timeStarted,
52
+ tags = record.tagIds.mapNotNull { tagId ->
53
+ recordTagInteractor.get(tagId)?. let (::mapTag )
54
+ },
54
55
)
55
- }.toTypedArray()
56
+ }
56
57
}
57
58
58
- override suspend fun setCurrentActivities (activities : Array <CurrentActivity >) {
59
+ override suspend fun setCurrentActivities (activities : List <CurrentActivity >) {
59
60
val currents = queryCurrentActivities()
60
61
val unchanged = currents.filter { c -> activities.any { a -> a == c } }
61
62
val stopped = currents.filter { c -> unchanged.none { u -> u == c } }
@@ -73,41 +74,37 @@ class WearCommunicationInteractor @Inject constructor(
73
74
)
74
75
}
75
76
76
- override suspend fun queryTagsForActivity (activityId : Long ): Array <Tag > {
77
- val activityColor = recordTypeInteractor.get(activityId)?.color
77
+ override suspend fun queryTagsForActivity (activityId : Long ): List <Tag > {
78
+ val activity = recordTypeInteractor.get(activityId) ? : return emptyList()
79
+ val activityColor = mapColor(activity.color)
78
80
return recordTagInteractor.getByTypeOrUntyped(activityId)
79
81
.filter { ! it.archived }
80
- .map { asTag (it, asColor( activityColor) ) }
82
+ .map { mapTag (it, activityColor) }
81
83
.sortedBy { it.name }
82
84
.sortedBy { it.isGeneral }
83
- .toTypedArray()
84
85
}
85
86
86
- private fun asTag (recordTag : RecordTag ? , activityColor : Long = 0x00000000): Tag {
87
- return if (recordTag != null ) {
88
- val isGeneral = recordTag.typeId == 0L
89
- val tagColor = if (isGeneral) {
90
- asColor(recordTag.color)
91
- } else {
92
- activityColor
93
- }
94
- Tag (
95
- id = recordTag.id,
96
- name = recordTag.name,
97
- isGeneral = isGeneral,
98
- color = tagColor,
99
- )
87
+ private fun mapTag (
88
+ recordTag : RecordTag ,
89
+ activityColor : Long? = null,
90
+ ): Tag {
91
+ val isGeneral = recordTag.typeId == 0L
92
+ val tagColor = if (isGeneral) {
93
+ mapColor(recordTag.color)
100
94
} else {
101
- Tag (id = - 1 , name = " " , isGeneral = true , color = 0xFF555555 )
95
+ activityColor
102
96
}
97
+
98
+ return Tag (
99
+ id = recordTag.id,
100
+ name = recordTag.name,
101
+ isGeneral = isGeneral,
102
+ color = tagColor.orZero(),
103
+ )
103
104
}
104
105
105
- private fun asColor (appColor : AppColor ? ): Long {
106
- return if (appColor == null ) {
107
- 0x00000000
108
- } else {
109
- appColorMapper.mapToColorInt(appColor).toLong()
110
- }
106
+ private fun mapColor (appColor : AppColor ): Long {
107
+ return appColorMapper.mapToColorInt(appColor).toLong()
111
108
}
112
109
113
110
override suspend fun querySettings (): Settings {
0 commit comments