Skip to content

Commit e6ee6ba

Browse files
authored
Feature/fe 2055 support of new cell bounty boost rewards (#822)
* Support of the new boost Cell Bounties (WIP - pending finalization of API) * Fixes + hardcode "cell-bounty" for test purposes * Minor fix in chart of rewards breakdown legends * Use the correct cell bounty code * Change text of "Cell Bounties" to "Cell Bounty"
1 parent 0eb91a3 commit e6ee6ba

15 files changed

Lines changed: 143 additions & 19 deletions

File tree

app/src/main/java/com/weatherxm/data/models/ApiModels.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,13 +1054,15 @@ enum class RewardsCode {
10541054
base_reward,
10551055
beta_rewards,
10561056
correction,
1057-
trov2
1057+
trov2,
1058+
cell_bounty
10581059
}
10591060

10601061
@Suppress("EnumNaming")
10611062
enum class BoostCode {
10621063
beta_rewards,
10631064
correction,
1064-
trov2
1065+
trov2,
1066+
cell_bounty
10651067
}
10661068

app/src/main/java/com/weatherxm/ui/common/UIModels.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,8 @@ data class LineChartData(
493493
}
494494

495495
fun isDataValid(): Boolean {
496-
return timestamps.isNotEmpty() && entries.filterNot { it.y.isNaN() }.isNotEmpty()
496+
return timestamps.isNotEmpty() &&
497+
entries.filterNot { it.y.isNaN() || it.y < 0F }.isNotEmpty()
497498
}
498499

499500
/**
@@ -635,6 +636,7 @@ data class DeviceTotalRewardsDetails(
635636
val betaChartData: LineChartData,
636637
val correctionChartData: LineChartData,
637638
val rolloutsChartData: LineChartData,
639+
val cellBountyChartData: LineChartData,
638640
val otherChartData: LineChartData,
639641
var status: Status
640642
) : Parcelable {
@@ -650,6 +652,7 @@ data class DeviceTotalRewardsDetails(
650652
LineChartData.empty(),
651653
LineChartData.empty(),
652654
LineChartData.empty(),
655+
LineChartData.empty(),
653656
Status.LOADING
654657
)
655658
}

app/src/main/java/com/weatherxm/ui/components/TooltipMarkerView.kt

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class TooltipMarkerView(
2323
private val betaData: LineChartData = LineChartData.empty(),
2424
private val correctionData: LineChartData = LineChartData.empty(),
2525
private val rolloutsData: LineChartData = LineChartData.empty(),
26+
private val cellBountyData: LineChartData = LineChartData.empty(),
2627
private val othersData: LineChartData = LineChartData.empty(),
2728
) : MarkerView(context, R.layout.view_chart_tooltip) {
2829
private var dateView: TextView = findViewById(R.id.date)
@@ -35,12 +36,14 @@ class TooltipMarkerView(
3536
private var correctionView: TextView = findViewById(R.id.correctionValue)
3637
private var rolloutsTitleView: TextView = findViewById(R.id.rolloutsTitle)
3738
private var rolloutsView: TextView = findViewById(R.id.rolloutsValue)
39+
private var cellBountyTitleView: TextView = findViewById(R.id.cellBountyTitle)
40+
private var cellBountyView: TextView = findViewById(R.id.cellBountyValue)
3841
private var othersTitleView: TextView = findViewById(R.id.othersTitle)
3942
private var othersView: TextView = findViewById(R.id.othersValue)
4043

4144
// callbacks everytime the MarkerView is redrawn, can be used to update the
4245
// content (user-interface)
43-
@Suppress("CyclomaticComplexMethod")
46+
@Suppress("CyclomaticComplexMethod", "LongMethod")
4447
override fun refreshContent(e: Entry, highlight: Highlight?) {
4548
/**
4649
* We find the relevant timestamp by using the same index
@@ -59,6 +62,7 @@ class TooltipMarkerView(
5962
var betaValue = 0F
6063
var correctionValue = 0F
6164
var rolloutsValue = 0F
65+
var cellBountyValue = 0F
6266

6367
baseData.getEntryValueForTooltip(e.x).also {
6468
baseTitleView.visible(it != null)
@@ -106,11 +110,30 @@ class TooltipMarkerView(
106110
}
107111
}
108112

113+
cellBountyData.getEntryValueForTooltipWithPlaceholder(e.x).also {
114+
cellBountyTitleView.visible(it != null)
115+
cellBountyView.visible(it != null)
116+
if (it != null) {
117+
cellBountyValue = it
118+
cellBountyView.text = if (rolloutsValue > 0) {
119+
formatTokens((it - rolloutsValue).coerceAtLeast(0F))
120+
} else if (correctionValue > 0) {
121+
formatTokens((it - correctionValue).coerceAtLeast(0F))
122+
} else if (betaValue > 0) {
123+
formatTokens((it - betaValue).coerceAtLeast(0F))
124+
} else {
125+
formatTokens((it - baseValue).coerceAtLeast(0F))
126+
}
127+
}
128+
}
129+
109130
othersData.getEntryValueForTooltip(e.x).also {
110131
othersTitleView.visible(it != null)
111132
othersView.visible(it != null)
112133
if (it != null) {
113-
othersView.text = if (rolloutsValue > 0) {
134+
othersView.text = if (cellBountyValue > 0) {
135+
formatTokens((it - cellBountyValue).coerceAtLeast(0F))
136+
} else if (rolloutsValue > 0) {
114137
formatTokens((it - rolloutsValue).coerceAtLeast(0F))
115138
} else if (correctionValue > 0) {
116139
formatTokens((it - correctionValue).coerceAtLeast(0F))

app/src/main/java/com/weatherxm/ui/devicesrewards/DeviceRewardsAdapter.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ class DeviceRewardsAdapter(
129129
details.betaChartData,
130130
details.correctionChartData,
131131
details.rolloutsChartData,
132+
details.cellBountyChartData,
132133
details.otherChartData,
133134
details.totals,
134135
details.datesChartTooltip
@@ -138,6 +139,7 @@ class DeviceRewardsAdapter(
138139
binding.betaRewardsLegend.visible(details.betaChartData.isDataValid())
139140
binding.correctionRewardsLegend.visible(details.correctionChartData.isDataValid())
140141
binding.rolloutsRewardsLegend.visible(details.rolloutsChartData.isDataValid())
142+
binding.cellBountyLegend.visible(details.cellBountyChartData.isDataValid())
141143
binding.othersRewardsLegend.visible(details.otherChartData.isDataValid())
142144
binding.retryCard.visible(false)
143145
binding.detailsStatus.visible(false)

app/src/main/java/com/weatherxm/ui/devicesrewards/DeviceRewardsBoostAdapter.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ class DeviceRewardsBoostAdapter :
4949
} else {
5050
val isBetaRewards = boostCode == BoostCode.beta_rewards.name
5151
val isCorrectionRewards = boostCode.startsWith(BoostCode.correction.name, true)
52+
val isCellBountyReward =
53+
boostCode.startsWith(BoostCode.cell_bounty.name, true)
5254
val isRolloutRewards = boostCode == BoostCode.trov2.name
5355

5456
if (isBetaRewards) {
@@ -65,6 +67,13 @@ class DeviceRewardsBoostAdapter :
6567
itemView.context.getColorStateList(R.color.correction_rewards_color)
6668
binding.boostProgressSlider.trackInactiveTintList =
6769
itemView.context.getColorStateList(R.color.correction_rewards_fill)
70+
} else if (isCellBountyReward) {
71+
binding.title.text =
72+
itemView.context.getString(R.string.cell_bounty_reward_details)
73+
binding.boostProgressSlider.trackActiveTintList =
74+
itemView.context.getColorStateList(R.color.cell_bounty_reward)
75+
binding.boostProgressSlider.trackInactiveTintList =
76+
itemView.context.getColorStateList(R.color.cell_bounty_reward_fill)
6877
} else if (isRolloutRewards) {
6978
binding.title.text =
7079
itemView.context.getString(R.string.rollouts_reward_details)

app/src/main/java/com/weatherxm/ui/rewarddetails/RewardDetailsActivity.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,8 @@ class RewardDetailsActivity : BaseActivity(), RewardBoostListener {
418418
val isCodeSupported = try {
419419
if (boost.code?.startsWith(BoostCode.correction.name, true) == true) {
420420
true
421+
} else if (boost.code?.startsWith(BoostCode.cell_bounty.name, true) == true) {
422+
true
421423
} else {
422424
BoostCode.valueOf(boost.code ?: String.empty())
423425
true

app/src/main/java/com/weatherxm/usecases/RewardsUseCase.kt

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ class RewardsUseCaseImpl(
186186
val betaEntries = mutableListOf<Entry>()
187187
val correctionEntries = mutableListOf<Entry>()
188188
val rolloutsEntries = mutableListOf<Entry>()
189+
val cellBountyEntries = mutableListOf<Entry>()
189190
val otherEntries = mutableListOf<Entry>()
190191
val totals = mutableListOf<Float>()
191192
val datesChartTooltip = mutableListOf<String>()
@@ -198,6 +199,7 @@ class RewardsUseCaseImpl(
198199
val betaCode = RewardsCode.beta_rewards.name
199200
val correctionCode = RewardsCode.correction.name
200201
val rolloutsCode = RewardsCode.trov2.name
202+
val cellBountyCode = RewardsCode.cell_bounty.name
201203
var sum = 0F
202204
var baseSum = 0F
203205
var baseFound = false
@@ -209,6 +211,8 @@ class RewardsUseCaseImpl(
209211
var correctionFound = false
210212
var rolloutsSum = 0F
211213
var rolloutsFound = false
214+
var cellBountySum = 0F
215+
var cellBountyFound = false
212216

213217
/**
214218
* In order for the "chart with filled layers" to work properly, we need to add
@@ -224,6 +228,8 @@ class RewardsUseCaseImpl(
224228
val isBase = it.code == baseCode
225229
val isBeta = it.code == betaCode
226230
val isRollouts = it.code == rolloutsCode
231+
val isCellBounty = it.code.startsWith(cellBountyCode)
232+
val isCorrection = it.code.startsWith(correctionCode)
227233

228234
if (isBase) {
229235
baseSum += it.value
@@ -237,13 +243,16 @@ class RewardsUseCaseImpl(
237243
rolloutsSum += it.value
238244
rolloutsFound = true
239245
}
240-
val isCorrection = it.code.startsWith(correctionCode)
241246
if (isCorrection) {
242247
correctionSum += it.value
243248
correctionFound = true
244249
}
250+
if (isCellBounty) {
251+
cellBountySum += it.value
252+
cellBountyFound = true
253+
}
245254
@Suppress("ComplexCondition")
246-
if (!isBase && !isBeta && !isCorrection && !isRollouts) {
255+
if (!isBase && !isBeta && !isCorrection && !isRollouts && !isCellBounty) {
247256
othersSum += it.value
248257
othersFound = true
249258
}
@@ -279,10 +288,18 @@ class RewardsUseCaseImpl(
279288
isFound = rolloutsFound,
280289
sum = rolloutsSum
281290
)
291+
cellBountyEntries.createNewEntry(
292+
x = counter,
293+
yIfNotFound = -1F,
294+
yIfFound = cellBountySum + rolloutsSum + betaSum + baseSum + correctionSum,
295+
isFound = cellBountyFound,
296+
sum = cellBountySum
297+
)
282298
otherEntries.createNewEntry(
283299
x = counter,
284300
yIfNotFound = Float.NaN,
285-
yIfFound = othersSum + correctionSum + betaSum + baseSum + rolloutsSum,
301+
yIfFound = othersSum + cellBountySum + correctionSum + betaSum + baseSum +
302+
rolloutsSum,
286303
isFound = othersFound,
287304
sum = othersSum
288305
)
@@ -298,6 +315,7 @@ class RewardsUseCaseImpl(
298315
LineChartData(xLabels, betaEntries),
299316
LineChartData(xLabels, correctionEntries),
300317
LineChartData(xLabels, rolloutsEntries),
318+
LineChartData(xLabels, cellBountyEntries),
301319
LineChartData(xLabels, otherEntries),
302320
Status.SUCCESS
303321
)

app/src/main/java/com/weatherxm/util/Charts.kt

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,7 @@ fun LineChart.initRewardsBreakdownChart(
667667
betaData: LineChartData,
668668
correctionData: LineChartData,
669669
rolloutsData: LineChartData,
670+
cellBountyData: LineChartData,
670671
othersData: LineChartData,
671672
totals: List<Float>,
672673
datesChartTooltip: List<String>
@@ -687,18 +688,31 @@ fun LineChart.initRewardsBreakdownChart(
687688
val correctionDataEmptyLineDataSets = correctionData.getEmptyLineDataSets("")
688689
val rolloutsDataDataSetsWithValues = rolloutsData.getLineDataSetsWithValues("")
689690
val rolloutsDataEmptyLineDataSets = rolloutsData.getEmptyLineDataSets("")
690-
val otherDataDataSetsWithValues = othersData.getLineDataSetsWithValues("")
691-
val otherDataEmptyLineDataSets = othersData.getEmptyLineDataSets("")
692-
693-
if (otherDataDataSetsWithValues.isNotEmpty()) {
694-
dataSets.addAll(otherDataDataSetsWithValues.primaryLineInit(context, resources))
695-
otherDataDataSetsWithValues.initRewardBreakDown(
691+
val cellBountyDataSetsWithValues = cellBountyData.getLineDataSetsWithValues("")
692+
val cellBountyDataEmptyLineDataSets = cellBountyData.getEmptyLineDataSets("")
693+
val othersDataDataSetsWithValues = othersData.getLineDataSetsWithValues("")
694+
val othersDataEmptyLineDataSets = othersData.getEmptyLineDataSets("")
695+
696+
if (othersDataDataSetsWithValues.isNotEmpty()) {
697+
dataSets.addAll(othersDataDataSetsWithValues.primaryLineInit(context, resources))
698+
othersDataDataSetsWithValues.initRewardBreakDown(
696699
context.getColor(R.color.other_reward), context.getColor(R.color.darkGrey)
697700
)
698701
}
699702

700-
if (otherDataEmptyLineDataSets.isNotEmpty()) {
701-
dataSets.addAll(otherDataEmptyLineDataSets)
703+
if (othersDataEmptyLineDataSets.isNotEmpty()) {
704+
dataSets.addAll(othersDataEmptyLineDataSets)
705+
}
706+
707+
if (cellBountyDataSetsWithValues.isNotEmpty()) {
708+
dataSets.addAll(cellBountyDataSetsWithValues.primaryLineInit(context, resources))
709+
cellBountyDataSetsWithValues.initRewardBreakDown(
710+
context.getColor(R.color.cell_bounty_reward), context.getColor(R.color.darkGrey)
711+
)
712+
}
713+
714+
if (cellBountyDataEmptyLineDataSets.isNotEmpty()) {
715+
dataSets.addAll(cellBountyDataEmptyLineDataSets)
702716
}
703717

704718
if (rolloutsDataDataSetsWithValues.isNotEmpty()) {
@@ -788,6 +802,7 @@ fun LineChart.initRewardsBreakdownChart(
788802
betaData,
789803
correctionData,
790804
rolloutsData,
805+
cellBountyData,
791806
othersData
792807
)
793808
setDrawMarkers(true)

app/src/main/res/layout/list_item_device_rewards.xml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,21 @@
198198
app:layout_constraintTop_toBottomOf="@id/correctionRewardsLegend"
199199
tools:visibility="visible" />
200200

201+
<com.google.android.material.textview.MaterialTextView
202+
android:id="@+id/cellBountyLegend"
203+
android:layout_width="match_parent"
204+
android:layout_height="wrap_content"
205+
android:layout_marginTop="@dimen/margin_extra_small"
206+
android:drawableStart="@drawable/ic_rectangle"
207+
android:drawablePadding="@dimen/padding_extra_small"
208+
android:drawableTint="@color/cell_bounty_reward"
209+
android:text="@string/cell_bounty_rewards"
210+
android:textAppearance="@style/TextAppearance.WeatherXM.Default.BodySmall"
211+
android:textColor="@color/textColor"
212+
android:visibility="gone"
213+
app:layout_constraintTop_toBottomOf="@id/rolloutsRewardsLegend"
214+
tools:visibility="visible" />
215+
201216
<com.google.android.material.textview.MaterialTextView
202217
android:id="@+id/othersRewardsLegend"
203218
android:layout_width="match_parent"
@@ -210,7 +225,7 @@
210225
android:textAppearance="@style/TextAppearance.WeatherXM.Default.BodySmall"
211226
android:textColor="@color/textColor"
212227
android:visibility="gone"
213-
app:layout_constraintTop_toBottomOf="@id/rolloutsRewardsLegend"
228+
app:layout_constraintTop_toBottomOf="@id/cellBountyLegend"
214229
tools:visibility="visible" />
215230

216231
<androidx.recyclerview.widget.RecyclerView

app/src/main/res/layout/view_chart_tooltip.xml

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,27 @@
133133
app:layout_constraintTop_toBottomOf="@id/correctionValue"
134134
tools:text="73.24" />
135135

136+
<com.google.android.material.textview.MaterialTextView
137+
android:id="@+id/cellBountyTitle"
138+
android:layout_width="wrap_content"
139+
android:layout_height="wrap_content"
140+
android:layout_marginTop="@dimen/margin_extra_small"
141+
android:text="@string/cell_bounty"
142+
android:textAppearance="@style/TextAppearance.WeatherXM.Default.BodySmall"
143+
app:layout_constraintStart_toStartOf="parent"
144+
app:layout_constraintTop_toBottomOf="@id/rolloutsValue" />
145+
146+
<com.google.android.material.textview.MaterialTextView
147+
android:id="@+id/cellBountyValue"
148+
android:layout_width="wrap_content"
149+
android:layout_height="wrap_content"
150+
android:layout_marginStart="@dimen/margin_small_to_normal"
151+
android:layout_marginTop="@dimen/margin_extra_small"
152+
android:textAppearance="@style/TextAppearance.WeatherXM.Default.BodySmall"
153+
app:layout_constraintStart_toEndOf="@id/cellBountyTitle"
154+
app:layout_constraintTop_toBottomOf="@id/rolloutsValue"
155+
tools:text="73.24" />
156+
136157
<com.google.android.material.textview.MaterialTextView
137158
android:id="@+id/othersTitle"
138159
android:layout_width="wrap_content"
@@ -141,7 +162,7 @@
141162
android:text="@string/other"
142163
android:textAppearance="@style/TextAppearance.WeatherXM.Default.BodySmall"
143164
app:layout_constraintStart_toStartOf="parent"
144-
app:layout_constraintTop_toBottomOf="@id/rolloutsValue" />
165+
app:layout_constraintTop_toBottomOf="@id/cellBountyValue" />
145166

146167
<com.google.android.material.textview.MaterialTextView
147168
android:id="@+id/othersValue"
@@ -151,7 +172,7 @@
151172
android:layout_marginTop="@dimen/margin_extra_small"
152173
android:textAppearance="@style/TextAppearance.WeatherXM.Default.BodySmall"
153174
app:layout_constraintStart_toEndOf="@id/othersTitle"
154-
app:layout_constraintTop_toBottomOf="@id/rolloutsValue"
175+
app:layout_constraintTop_toBottomOf="@id/cellBountyValue"
155176
tools:text="73.24" />
156177

157178
</androidx.constraintlayout.widget.ConstraintLayout>

0 commit comments

Comments
 (0)