Skip to content

Commit 8149918

Browse files
committed
change goal checkmark and percentage visibility
1 parent 0a935ae commit 8149918

6 files changed

Lines changed: 136 additions & 139 deletions

File tree

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,10 @@ class GoalViewDataMapper @Inject constructor(
198198
is RecordTypeGoal.Subtype.Limit -> GoalCheckmarkView.CheckState.LIMIT_REACHED
199199
}
200200
} else {
201-
GoalCheckmarkView.CheckState.HIDDEN
201+
when (goalSubtype) {
202+
is RecordTypeGoal.Subtype.Goal -> GoalCheckmarkView.CheckState.GOAL_NOT_REACHED
203+
is RecordTypeGoal.Subtype.Limit -> GoalCheckmarkView.CheckState.LIMIT_NOT_REACHED
204+
}
202205
}
203206
val (currentValueString, goalValueString) = when (goal.type) {
204207
is RecordTypeGoal.Type.Duration -> {
@@ -216,13 +219,13 @@ class GoalViewDataMapper @Inject constructor(
216219
val goalPercent = if (goalValue == 0L) {
217220
0
218221
} else {
219-
(current * 100f / goalValue).roundToLong().coerceAtMost(100)
222+
(current * 100f / goalValue).roundToLong()
220223
}
221224

222225
return StatisticsGoalViewData.Goal(
223226
goalCurrent = currentValueString,
224227
goal = goalString,
225-
goalPercent = goalPercent.let { "$it%" },
228+
goalPercent = formatGoalPercent(goalPercent),
226229
goalState = goalState,
227230
percent = goalPercent,
228231
)
@@ -248,4 +251,13 @@ class GoalViewDataMapper @Inject constructor(
248251
quantity = goalValue.toInt(),
249252
)
250253
}
254+
255+
private fun formatGoalPercent(goalPercent: Long): String {
256+
val text = when {
257+
goalPercent >= 100_000f -> ""
258+
goalPercent >= 1_000 -> "${goalPercent / 1000}K"
259+
else -> goalPercent.toString()
260+
}
261+
return "$text%"
262+
}
251263
}

features/feature_statistics/src/main/res/layout/statistics_container_fragment.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
android:layout_width="0dp"
2626
android:layout_height="0dp"
2727
app:layout_constraintBottom_toBottomOf="@id/btnStatisticsContainerToday"
28-
app:layout_constraintEnd_toEndOf="@id/btnStatisticsContainerToday"
28+
app:layout_constraintEnd_toEndOf="@id/btnStatisticsContainerOptions"
2929
app:layout_constraintStart_toStartOf="@id/btnStatisticsContainerToday"
3030
app:layout_constraintTop_toTopOf="@id/btnStatisticsContainerToday" />
3131

features/feature_statistics_detail/src/main/java/com/example/util/simpletimetracker/feature_statistics_detail/mapper/StatisticsDetailViewDataMapper.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -601,8 +601,8 @@ class StatisticsDetailViewDataMapper @Inject constructor(
601601
val text = when {
602602
abs >= 1_000_000f -> ""
603603
abs >= 1_000f -> "${(abs / 1000).toLong()}K"
604-
abs >= 10 -> abs.toLong()
605-
(abs * 10).roundToLong() % 10L == 0L -> abs.toLong()
604+
abs >= 10 -> abs.toLong().toString()
605+
(abs * 10).roundToLong() % 10L == 0L -> abs.toLong().toString()
606606
else -> String.format("%.1f", abs)
607607
}
608608
return if (value >= 0) "+$text%" else "-$text%"

features/feature_statistics_detail/src/main/res/layout/statistics_detail_fragment.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
android:layout_width="0dp"
6868
android:layout_height="0dp"
6969
app:layout_constraintBottom_toBottomOf="@id/btnStatisticsDetailToday"
70-
app:layout_constraintEnd_toEndOf="@id/btnStatisticsDetailToday"
70+
app:layout_constraintEnd_toEndOf="@id/btnStatisticsDetailOptions"
7171
app:layout_constraintStart_toStartOf="@id/btnStatisticsDetailToday"
7272
app:layout_constraintTop_toTopOf="@id/btnStatisticsDetailToday" />
7373

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

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ package com.example.util.simpletimetracker.feature_views
33
import android.content.Context
44
import android.graphics.Color
55
import android.util.AttributeSet
6-
import android.view.View
7-
import androidx.cardview.widget.CardView
8-
import androidx.core.content.ContextCompat
6+
import android.widget.RelativeLayout
97
import com.example.util.simpletimetracker.feature_views.ColorUtils.normalizeLightness
108
import com.example.util.simpletimetracker.feature_views.GoalCheckmarkView.CheckState
119
import com.example.util.simpletimetracker.feature_views.databinding.StatisticsGoalViewLayoutBinding
@@ -17,7 +15,7 @@ class StatisticsGoalView @JvmOverloads constructor(
1715
context: Context,
1816
attrs: AttributeSet? = null,
1917
defStyleAttr: Int = 0,
20-
) : CardView(
18+
) : RelativeLayout(
2119
context,
2220
attrs,
2321
defStyleAttr,
@@ -34,7 +32,7 @@ class StatisticsGoalView @JvmOverloads constructor(
3432
var itemColor: Int = Color.BLACK
3533
set(value) {
3634
field = value
37-
setCardBackgroundColor(value)
35+
binding.containerStatisticsGoalItem.setCardBackgroundColor(value)
3836
setDividerColor()
3937
}
4038

@@ -66,30 +64,18 @@ class StatisticsGoalView @JvmOverloads constructor(
6664
set(value) {
6765
field = value
6866
binding.tvStatisticsGoalItemPercent.text = value
69-
setGoalPercentVisibility()
7067
}
7168

7269
var itemGoalState: CheckState = CheckState.HIDDEN
7370
set(value) {
7471
field = value
7572
binding.ivStatisticsGoalItemCheck.itemCheckState = value
76-
setGoalPercentVisibility()
7773
}
7874

7975
init {
80-
initProps()
8176
initAttrs(context, attrs, defStyleAttr)
8277
}
8378

84-
private fun initProps() {
85-
ContextCompat.getColor(context, R.color.black).let(::setCardBackgroundColor)
86-
radius = resources.getDimensionPixelOffset(R.dimen.record_type_card_corner_radius).toFloat()
87-
// TODO doesn't work here for some reason, need to set in the layout
88-
cardElevation = resources.getDimensionPixelOffset(R.dimen.record_type_card_elevation).toFloat()
89-
preventCornerOverlap = false
90-
useCompatPadding = true
91-
}
92-
9379
private fun initAttrs(
9480
context: Context,
9581
attrs: AttributeSet?,
@@ -146,12 +132,4 @@ class StatisticsGoalView @JvmOverloads constructor(
146132
normalizeLightness(itemColor)
147133
.let(binding.dividerStatisticsGoalPercent::setBackgroundColor)
148134
}
149-
150-
private fun setGoalPercentVisibility() {
151-
binding.tvStatisticsGoalItemPercent.visibility = when {
152-
itemGoalState != CheckState.HIDDEN -> View.INVISIBLE
153-
itemGoalPercent.isEmpty() -> View.GONE
154-
else -> View.VISIBLE
155-
}
156-
}
157135
}

features/feature_views/src/main/res/layout/statistics_goal_view_layout.xml

Lines changed: 114 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -4,124 +4,131 @@
44
xmlns:tools="http://schemas.android.com/tools"
55
android:layout_width="match_parent"
66
android:layout_height="wrap_content"
7-
app:cardBackgroundColor="@color/black"
8-
app:cardCornerRadius="@dimen/record_type_card_corner_radius"
9-
app:cardElevation="@dimen/record_type_card_elevation"
10-
app:cardPreventCornerOverlap="false"
11-
app:cardUseCompatPadding="true"
12-
tools:parentTag="androidx.cardview.widget.CardView">
7+
tools:parentTag="android.widget.RelativeLayout">
138

14-
<androidx.constraintlayout.widget.ConstraintLayout
9+
<androidx.cardview.widget.CardView
10+
android:id="@+id/containerStatisticsGoalItem"
1511
android:layout_width="match_parent"
1612
android:layout_height="wrap_content"
17-
android:background="?selectableItemBackground"
18-
android:minHeight="40dp"
19-
android:paddingTop="8dp"
20-
android:paddingBottom="8dp">
13+
app:cardBackgroundColor="@color/black"
14+
app:cardCornerRadius="@dimen/record_type_card_corner_radius"
15+
app:cardElevation="@dimen/record_type_card_elevation"
16+
app:cardPreventCornerOverlap="false"
17+
app:cardUseCompatPadding="true">
2118

22-
<com.example.util.simpletimetracker.feature_views.IconView
23-
android:id="@+id/ivStatisticsGoalItemIcon"
24-
android:layout_width="24dp"
25-
android:layout_height="0dp"
26-
android:layout_marginStart="8dp"
27-
app:layout_constraintBottom_toBottomOf="parent"
28-
app:layout_constraintDimensionRatio="h,1:1"
29-
app:layout_constraintStart_toStartOf="parent"
30-
app:layout_constraintTop_toTopOf="parent" />
31-
32-
<androidx.appcompat.widget.AppCompatTextView
33-
android:id="@+id/tvStatisticsGoalItemName"
34-
android:layout_width="0dp"
19+
<androidx.constraintlayout.widget.ConstraintLayout
20+
android:layout_width="match_parent"
3521
android:layout_height="wrap_content"
36-
android:layout_marginStart="8dp"
37-
android:textColor="?appLightTextColor"
38-
android:textStyle="bold"
39-
app:layout_constraintBottom_toBottomOf="parent"
40-
app:layout_constraintEnd_toStartOf="@id/barrierStatisticsGoalItemGoal"
41-
app:layout_constraintStart_toEndOf="@id/ivStatisticsGoalItemIcon"
42-
app:layout_constraintTop_toTopOf="parent"
43-
tools:text="Item name" />
22+
android:background="?selectableItemBackground"
23+
android:minHeight="40dp"
24+
android:paddingTop="8dp"
25+
android:paddingBottom="8dp">
4426

45-
<View
46-
android:id="@+id/dividerStatisticsGoalPercent"
47-
android:layout_width="2dp"
48-
android:layout_height="0dp"
49-
android:layout_marginEnd="8dp"
50-
app:layout_constraintBottom_toBottomOf="parent"
51-
app:layout_constraintEnd_toStartOf="@id/tvStatisticsGoalItemPercentWidth"
52-
app:layout_constraintTop_toTopOf="parent"
53-
tools:background="@color/white" />
27+
<com.example.util.simpletimetracker.feature_views.IconView
28+
android:id="@+id/ivStatisticsGoalItemIcon"
29+
android:layout_width="24dp"
30+
android:layout_height="0dp"
31+
android:layout_marginStart="8dp"
32+
app:layout_constraintBottom_toBottomOf="parent"
33+
app:layout_constraintDimensionRatio="h,1:1"
34+
app:layout_constraintStart_toStartOf="parent"
35+
app:layout_constraintTop_toTopOf="parent" />
5436

55-
<androidx.constraintlayout.widget.Barrier
56-
android:id="@+id/barrierStatisticsGoalItemGoal"
57-
android:layout_width="wrap_content"
58-
android:layout_height="wrap_content"
59-
app:barrierDirection="start"
60-
app:constraint_referenced_ids="tvStatisticsGoalItemCurrent, tvStatisticsGoalItemGoal" />
37+
<androidx.appcompat.widget.AppCompatTextView
38+
android:id="@+id/tvStatisticsGoalItemName"
39+
android:layout_width="0dp"
40+
android:layout_height="wrap_content"
41+
android:layout_marginStart="8dp"
42+
android:textColor="?appLightTextColor"
43+
android:textStyle="bold"
44+
app:layout_constraintBottom_toBottomOf="parent"
45+
app:layout_constraintEnd_toStartOf="@id/barrierStatisticsGoalItemGoal"
46+
app:layout_constraintStart_toEndOf="@id/ivStatisticsGoalItemIcon"
47+
app:layout_constraintTop_toTopOf="parent"
48+
tools:text="Item name" />
6149

62-
<androidx.appcompat.widget.AppCompatTextView
63-
android:id="@+id/tvStatisticsGoalItemCurrent"
64-
android:layout_width="wrap_content"
65-
android:layout_height="wrap_content"
66-
android:layout_marginEnd="10dp"
67-
android:gravity="center"
68-
android:textColor="?appLightTextColor"
69-
android:textSize="12sp"
70-
android:textStyle="bold"
71-
app:layout_constraintBottom_toTopOf="@id/barrierStatisticsGoalItemGoal"
72-
app:layout_constraintEnd_toStartOf="@id/dividerStatisticsGoalPercent"
73-
app:layout_constraintTop_toTopOf="parent"
74-
tools:text="1h 30m" />
50+
<View
51+
android:id="@+id/dividerStatisticsGoalPercent"
52+
android:layout_width="2dp"
53+
android:layout_height="0dp"
54+
android:layout_marginEnd="8dp"
55+
app:layout_constraintBottom_toBottomOf="parent"
56+
app:layout_constraintEnd_toStartOf="@id/tvStatisticsGoalItemPercentWidth"
57+
app:layout_constraintTop_toTopOf="parent"
58+
tools:background="@color/white" />
7559

76-
<androidx.appcompat.widget.AppCompatTextView
77-
android:id="@+id/tvStatisticsGoalItemGoal"
78-
android:layout_width="wrap_content"
79-
android:layout_height="wrap_content"
80-
android:layout_marginEnd="10dp"
81-
android:gravity="center"
82-
android:textColor="?appLightTextColor"
83-
android:textSize="12sp"
84-
app:layout_constraintBottom_toBottomOf="parent"
85-
app:layout_constraintEnd_toStartOf="@id/dividerStatisticsGoalPercent"
86-
app:layout_constraintTop_toBottomOf="@id/tvStatisticsGoalItemCurrent"
87-
tools:text="goal 8h 30m" />
60+
<androidx.constraintlayout.widget.Barrier
61+
android:id="@+id/barrierStatisticsGoalItemGoal"
62+
android:layout_width="wrap_content"
63+
android:layout_height="wrap_content"
64+
app:barrierDirection="start"
65+
app:constraint_referenced_ids="tvStatisticsGoalItemCurrent, tvStatisticsGoalItemGoal" />
8866

89-
<androidx.appcompat.widget.AppCompatTextView
90-
android:id="@+id/tvStatisticsGoalItemPercent"
91-
android:layout_width="0dp"
92-
android:layout_height="wrap_content"
93-
android:gravity="center"
94-
android:textColor="?appLightTextColor"
95-
android:textStyle="bold"
96-
app:layout_constraintBottom_toBottomOf="parent"
97-
app:layout_constraintEnd_toEndOf="@id/tvStatisticsGoalItemPercentWidth"
98-
app:layout_constraintStart_toStartOf="@id/tvStatisticsGoalItemPercentWidth"
99-
app:layout_constraintTop_toTopOf="parent"
100-
tools:text="33%" />
67+
<androidx.appcompat.widget.AppCompatTextView
68+
android:id="@+id/tvStatisticsGoalItemCurrent"
69+
android:layout_width="wrap_content"
70+
android:layout_height="wrap_content"
71+
android:layout_marginEnd="10dp"
72+
android:gravity="center"
73+
android:textColor="?appLightTextColor"
74+
android:textSize="12sp"
75+
android:textStyle="bold"
76+
app:layout_constraintBottom_toTopOf="@id/barrierStatisticsGoalItemGoal"
77+
app:layout_constraintEnd_toStartOf="@id/dividerStatisticsGoalPercent"
78+
app:layout_constraintTop_toTopOf="parent"
79+
tools:text="1h 30m" />
10180

102-
<com.example.util.simpletimetracker.feature_views.GoalCheckmarkView
103-
android:id="@+id/ivStatisticsGoalItemCheck"
104-
android:layout_width="14dp"
105-
android:layout_height="14dp"
106-
app:layout_constraintBottom_toBottomOf="@id/tvStatisticsGoalItemPercent"
107-
app:layout_constraintEnd_toEndOf="@id/tvStatisticsGoalItemPercent"
108-
app:layout_constraintStart_toStartOf="@id/tvStatisticsGoalItemPercent"
109-
app:layout_constraintTop_toTopOf="@id/tvStatisticsGoalItemPercent"
110-
tools:itemCheckState="goalReached" />
81+
<androidx.appcompat.widget.AppCompatTextView
82+
android:id="@+id/tvStatisticsGoalItemGoal"
83+
android:layout_width="wrap_content"
84+
android:layout_height="wrap_content"
85+
android:layout_marginEnd="10dp"
86+
android:gravity="center"
87+
android:textColor="?appLightTextColor"
88+
android:textSize="12sp"
89+
app:layout_constraintBottom_toBottomOf="parent"
90+
app:layout_constraintEnd_toStartOf="@id/dividerStatisticsGoalPercent"
91+
app:layout_constraintTop_toBottomOf="@id/tvStatisticsGoalItemCurrent"
92+
tools:text="goal 8h 30m" />
11193

112-
<androidx.appcompat.widget.AppCompatTextView
113-
android:id="@+id/tvStatisticsGoalItemPercentWidth"
114-
android:layout_width="wrap_content"
115-
android:layout_height="wrap_content"
116-
android:layout_marginEnd="8dp"
117-
android:text="100%"
118-
android:textStyle="bold"
119-
android:visibility="invisible"
120-
app:layout_constraintBottom_toBottomOf="parent"
121-
app:layout_constraintEnd_toEndOf="parent"
122-
app:layout_constraintTop_toTopOf="parent"
123-
tools:ignore="HardcodedText" />
94+
<androidx.appcompat.widget.AppCompatTextView
95+
android:id="@+id/tvStatisticsGoalItemPercent"
96+
android:layout_width="0dp"
97+
android:layout_height="wrap_content"
98+
android:gravity="center"
99+
android:textColor="?appLightTextColor"
100+
android:textStyle="bold"
101+
app:layout_constraintBottom_toBottomOf="parent"
102+
app:layout_constraintEnd_toEndOf="@id/tvStatisticsGoalItemPercentWidth"
103+
app:layout_constraintStart_toStartOf="@id/tvStatisticsGoalItemPercentWidth"
104+
app:layout_constraintTop_toTopOf="parent"
105+
tools:text="33%" />
106+
107+
<androidx.appcompat.widget.AppCompatTextView
108+
android:id="@+id/tvStatisticsGoalItemPercentWidth"
109+
android:layout_width="wrap_content"
110+
android:layout_height="wrap_content"
111+
android:layout_marginEnd="8dp"
112+
android:text="100%"
113+
android:textStyle="bold"
114+
android:visibility="invisible"
115+
app:layout_constraintBottom_toBottomOf="parent"
116+
app:layout_constraintEnd_toEndOf="parent"
117+
app:layout_constraintTop_toTopOf="parent"
118+
tools:ignore="HardcodedText" />
119+
120+
</androidx.constraintlayout.widget.ConstraintLayout>
121+
122+
</androidx.cardview.widget.CardView>
124123

125-
</androidx.constraintlayout.widget.ConstraintLayout>
124+
<com.example.util.simpletimetracker.feature_views.GoalCheckmarkView
125+
android:id="@+id/ivStatisticsGoalItemCheck"
126+
android:layout_width="16dp"
127+
android:layout_height="16dp"
128+
android:layout_alignParentTop="true"
129+
android:layout_alignParentEnd="true"
130+
android:elevation="@dimen/record_type_card_elevation"
131+
android:translationZ="1dp"
132+
tools:itemCheckState="goalReached" />
126133

127-
</merge>
134+
</merge>

0 commit comments

Comments
 (0)