Skip to content

Commit

Permalink
add category goals to goals tab
Browse files Browse the repository at this point in the history
  • Loading branch information
Razeeman committed Nov 4, 2023
1 parent 8a19a27 commit 4317d6d
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ class GoalViewDataMapper @Inject constructor(
return StatisticsGoalViewData(
id = goal.id,
name = dataHolder.name,
icon = dataHolder.icon.orEmpty()
.let(iconMapper::mapIcon),
icon = dataHolder.icon
?.let(iconMapper::mapIcon),
color = dataHolder.color
.let { colorMapper.mapToColorInt(it, isDarkTheme) },
goal = mapGoal(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@ fun createStatisticsGoalAdapterDelegate() = createRecyclerBindingAdapterDelegate

itemColor = item.color
itemName = item.name
itemIcon = item.icon
itemGoalCurrent = item.goal.goalCurrent
itemGoal = item.goal.goal
itemGoalPercent = item.goal.goalPercent
itemGoalTimeComplete = item.goal.goalComplete

if (item.icon != null) {
itemIconVisible = true
itemIcon = item.icon
} else {
itemIconVisible = false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ data class StatisticsGoalViewData(
val id: Long,
val name: String,
@ColorInt val color: Int,
val icon: RecordTypeIcon,
val icon: RecordTypeIcon?,
val goal: Goal,
) : ViewHolderType {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,18 @@ class GoalsViewDataInteractor @Inject constructor(
) {

suspend fun getViewData(): List<ViewHolderType> = withContext(Dispatchers.Default) {
val filterType = ChartFilterType.ACTIVITY
val isDarkTheme = prefsInteractor.getDarkMode()
val useProportionalMinutes = prefsInteractor.getUseProportionalMinutes()
val showSeconds = prefsInteractor.getShowSeconds()
val types = recordTypeInteractor.getAll().associateBy(RecordType::id)
val goals = recordTypeGoalInteractor.getAllTypeGoals()
val goals = recordTypeGoalInteractor.getAll()

val dataHolders = statisticsMediator.getDataHolders(
filterType = filterType,
val typeDataHolders = statisticsMediator.getDataHolders(
filterType = ChartFilterType.ACTIVITY,
types = types,
)
val categoryDataHolders = statisticsMediator.getDataHolders(
filterType = ChartFilterType.CATEGORY,
types = types,
)

Expand Down Expand Up @@ -66,9 +69,9 @@ class GoalsViewDataInteractor @Inject constructor(
getViewDataForRange(
goals = goals,
types = types,
filterType = filterType,
rangeLength = rangeLength,
dataHolders = dataHolders,
typeDataHolders = typeDataHolders,
categoryDataHolders = categoryDataHolders,
isDarkTheme = isDarkTheme,
useProportionalMinutes = useProportionalMinutes,
showSeconds = showSeconds,
Expand All @@ -85,32 +88,52 @@ class GoalsViewDataInteractor @Inject constructor(
private suspend fun getViewDataForRange(
goals: List<RecordTypeGoal>,
types: Map<Long, RecordType>,
filterType: ChartFilterType,
rangeLength: RangeLength,
dataHolders: Map<Long, StatisticsDataHolder>,
typeDataHolders: Map<Long, StatisticsDataHolder>,
categoryDataHolders: Map<Long, StatisticsDataHolder>,
isDarkTheme: Boolean,
useProportionalMinutes: Boolean,
showSeconds: Boolean,
): List<ViewHolderType> {
val statistics = statisticsMediator.getStatistics(
filterType = filterType,
val result = mutableListOf<ViewHolderType>()
val typeStatistics = statisticsMediator.getStatistics(
filterType = ChartFilterType.ACTIVITY,
filteredIds = emptyList(),
rangeLength = rangeLength,
shift = 0,
)
val result = mutableListOf<ViewHolderType>()
val items = goalViewDataMapper.mapStatisticsList(
val typeItems = goalViewDataMapper.mapStatisticsList(
goals = goals,
types = types,
filterType = ChartFilterType.ACTIVITY,
filteredIds = emptyList(),
rangeLength = rangeLength,
statistics = typeStatistics,
data = typeDataHolders,
isDarkTheme = isDarkTheme,
useProportionalMinutes = useProportionalMinutes,
showSeconds = showSeconds,
)
val categoryStatistics = statisticsMediator.getStatistics(
filterType = ChartFilterType.CATEGORY,
filteredIds = emptyList(),
rangeLength = rangeLength,
shift = 0,
)
val categoryItems = goalViewDataMapper.mapStatisticsList(
goals = goals,
types = types,
filterType = filterType,
filterType = ChartFilterType.CATEGORY,
filteredIds = emptyList(),
rangeLength = rangeLength,
statistics = statistics,
data = dataHolders,
statistics = categoryStatistics,
data = categoryDataHolders,
isDarkTheme = isDarkTheme,
useProportionalMinutes = useProportionalMinutes,
showSeconds = showSeconds,
)
val items = (typeItems + categoryItems)
.sortedBy { it.goal.percent }

if (items.isNotEmpty()) {
val title = when (rangeLength) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ class StatisticsGoalView @JvmOverloads constructor(
field = value
}

var itemIconVisible: Boolean = false
set(value) {
binding.ivStatisticsGoalItemIcon.visible = value
field = value
}

var itemGoalCurrent: String = ""
set(value) {
binding.tvStatisticsGoalItemCurrent.text = value
Expand Down Expand Up @@ -105,6 +111,9 @@ class StatisticsGoalView @JvmOverloads constructor(
getString(R.styleable.StatisticsGoalView_itemIconText).orEmpty()
.let(RecordTypeIcon::Text)

if (hasValue(R.styleable.StatisticsGoalView_itemIconVisible)) itemIconVisible =
getBoolean(R.styleable.StatisticsGoalView_itemIconVisible, false)

if (hasValue(R.styleable.StatisticsGoalView_itemGoalCurrent)) itemGoalCurrent =
getString(R.styleable.StatisticsGoalView_itemGoalCurrent).orEmpty()

Expand Down
1 change: 1 addition & 0 deletions features/feature_views/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
<attr name="itemIcon" />
<attr name="itemIconText" />
<attr name="itemColor" />
<attr name="itemIconVisible" />
<attr name="itemGoalCurrent" format="string" />
<attr name="itemGoal" format="string" />
<attr name="itemGoalPercent" format="string" />
Expand Down

0 comments on commit 4317d6d

Please sign in to comment.