Skip to content

Commit 4317d6d

Browse files
committed
add category goals to goals tab
1 parent 8a19a27 commit 4317d6d

File tree

6 files changed

+58
-19
lines changed

6 files changed

+58
-19
lines changed

core/src/main/java/com/example/util/simpletimetracker/core/mapper/GoalViewDataMapper.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ class GoalViewDataMapper @Inject constructor(
152152
return StatisticsGoalViewData(
153153
id = goal.id,
154154
name = dataHolder.name,
155-
icon = dataHolder.icon.orEmpty()
156-
.let(iconMapper::mapIcon),
155+
icon = dataHolder.icon
156+
?.let(iconMapper::mapIcon),
157157
color = dataHolder.color
158158
.let { colorMapper.mapToColorInt(it, isDarkTheme) },
159159
goal = mapGoal(

features/feature_base_adapter/src/main/java/com/example/util/simpletimetracker/feature_base_adapter/statisticsGoal/StatisticsGoalAdapterDelegate.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,16 @@ fun createStatisticsGoalAdapterDelegate() = createRecyclerBindingAdapterDelegate
1313

1414
itemColor = item.color
1515
itemName = item.name
16-
itemIcon = item.icon
1716
itemGoalCurrent = item.goal.goalCurrent
1817
itemGoal = item.goal.goal
1918
itemGoalPercent = item.goal.goalPercent
2019
itemGoalTimeComplete = item.goal.goalComplete
20+
21+
if (item.icon != null) {
22+
itemIconVisible = true
23+
itemIcon = item.icon
24+
} else {
25+
itemIconVisible = false
26+
}
2127
}
2228
}

features/feature_base_adapter/src/main/java/com/example/util/simpletimetracker/feature_base_adapter/statisticsGoal/StatisticsGoalViewData.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ data class StatisticsGoalViewData(
88
val id: Long,
99
val name: String,
1010
@ColorInt val color: Int,
11-
val icon: RecordTypeIcon,
11+
val icon: RecordTypeIcon?,
1212
val goal: Goal,
1313
) : ViewHolderType {
1414

features/feature_goals/src/main/java/com/example/util/simpletimetracker/feature_goals/interactor/GoalsViewDataInteractor.kt

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,18 @@ class GoalsViewDataInteractor @Inject constructor(
2929
) {
3030

3131
suspend fun getViewData(): List<ViewHolderType> = withContext(Dispatchers.Default) {
32-
val filterType = ChartFilterType.ACTIVITY
3332
val isDarkTheme = prefsInteractor.getDarkMode()
3433
val useProportionalMinutes = prefsInteractor.getUseProportionalMinutes()
3534
val showSeconds = prefsInteractor.getShowSeconds()
3635
val types = recordTypeInteractor.getAll().associateBy(RecordType::id)
37-
val goals = recordTypeGoalInteractor.getAllTypeGoals()
36+
val goals = recordTypeGoalInteractor.getAll()
3837

39-
val dataHolders = statisticsMediator.getDataHolders(
40-
filterType = filterType,
38+
val typeDataHolders = statisticsMediator.getDataHolders(
39+
filterType = ChartFilterType.ACTIVITY,
40+
types = types,
41+
)
42+
val categoryDataHolders = statisticsMediator.getDataHolders(
43+
filterType = ChartFilterType.CATEGORY,
4144
types = types,
4245
)
4346

@@ -66,9 +69,9 @@ class GoalsViewDataInteractor @Inject constructor(
6669
getViewDataForRange(
6770
goals = goals,
6871
types = types,
69-
filterType = filterType,
7072
rangeLength = rangeLength,
71-
dataHolders = dataHolders,
73+
typeDataHolders = typeDataHolders,
74+
categoryDataHolders = categoryDataHolders,
7275
isDarkTheme = isDarkTheme,
7376
useProportionalMinutes = useProportionalMinutes,
7477
showSeconds = showSeconds,
@@ -85,32 +88,52 @@ class GoalsViewDataInteractor @Inject constructor(
8588
private suspend fun getViewDataForRange(
8689
goals: List<RecordTypeGoal>,
8790
types: Map<Long, RecordType>,
88-
filterType: ChartFilterType,
8991
rangeLength: RangeLength,
90-
dataHolders: Map<Long, StatisticsDataHolder>,
92+
typeDataHolders: Map<Long, StatisticsDataHolder>,
93+
categoryDataHolders: Map<Long, StatisticsDataHolder>,
9194
isDarkTheme: Boolean,
9295
useProportionalMinutes: Boolean,
9396
showSeconds: Boolean,
9497
): List<ViewHolderType> {
95-
val statistics = statisticsMediator.getStatistics(
96-
filterType = filterType,
98+
val result = mutableListOf<ViewHolderType>()
99+
val typeStatistics = statisticsMediator.getStatistics(
100+
filterType = ChartFilterType.ACTIVITY,
97101
filteredIds = emptyList(),
98102
rangeLength = rangeLength,
99103
shift = 0,
100104
)
101-
val result = mutableListOf<ViewHolderType>()
102-
val items = goalViewDataMapper.mapStatisticsList(
105+
val typeItems = goalViewDataMapper.mapStatisticsList(
106+
goals = goals,
107+
types = types,
108+
filterType = ChartFilterType.ACTIVITY,
109+
filteredIds = emptyList(),
110+
rangeLength = rangeLength,
111+
statistics = typeStatistics,
112+
data = typeDataHolders,
113+
isDarkTheme = isDarkTheme,
114+
useProportionalMinutes = useProportionalMinutes,
115+
showSeconds = showSeconds,
116+
)
117+
val categoryStatistics = statisticsMediator.getStatistics(
118+
filterType = ChartFilterType.CATEGORY,
119+
filteredIds = emptyList(),
120+
rangeLength = rangeLength,
121+
shift = 0,
122+
)
123+
val categoryItems = goalViewDataMapper.mapStatisticsList(
103124
goals = goals,
104125
types = types,
105-
filterType = filterType,
126+
filterType = ChartFilterType.CATEGORY,
106127
filteredIds = emptyList(),
107128
rangeLength = rangeLength,
108-
statistics = statistics,
109-
data = dataHolders,
129+
statistics = categoryStatistics,
130+
data = categoryDataHolders,
110131
isDarkTheme = isDarkTheme,
111132
useProportionalMinutes = useProportionalMinutes,
112133
showSeconds = showSeconds,
113134
)
135+
val items = (typeItems + categoryItems)
136+
.sortedBy { it.goal.percent }
114137

115138
if (items.isNotEmpty()) {
116139
val title = when (rangeLength) {

features/feature_views/src/main/java/com/example/util/simpletimetracker/feature_views/StatisticsGoalView.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ class StatisticsGoalView @JvmOverloads constructor(
4444
field = value
4545
}
4646

47+
var itemIconVisible: Boolean = false
48+
set(value) {
49+
binding.ivStatisticsGoalItemIcon.visible = value
50+
field = value
51+
}
52+
4753
var itemGoalCurrent: String = ""
4854
set(value) {
4955
binding.tvStatisticsGoalItemCurrent.text = value
@@ -105,6 +111,9 @@ class StatisticsGoalView @JvmOverloads constructor(
105111
getString(R.styleable.StatisticsGoalView_itemIconText).orEmpty()
106112
.let(RecordTypeIcon::Text)
107113

114+
if (hasValue(R.styleable.StatisticsGoalView_itemIconVisible)) itemIconVisible =
115+
getBoolean(R.styleable.StatisticsGoalView_itemIconVisible, false)
116+
108117
if (hasValue(R.styleable.StatisticsGoalView_itemGoalCurrent)) itemGoalCurrent =
109118
getString(R.styleable.StatisticsGoalView_itemGoalCurrent).orEmpty()
110119

features/feature_views/src/main/res/values/attrs.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
<attr name="itemIcon" />
9494
<attr name="itemIconText" />
9595
<attr name="itemColor" />
96+
<attr name="itemIconVisible" />
9697
<attr name="itemGoalCurrent" format="string" />
9798
<attr name="itemGoal" format="string" />
9899
<attr name="itemGoalPercent" format="string" />

0 commit comments

Comments
 (0)