Skip to content

Commit 4d82bb4

Browse files
committed
Battery: Regroup the battery hub details by subject
Promoting five readings into the tile grid left the detail sections named after what they used to hold ("Charging", "Health", "Electrical"), which no longer described their contents. The rows are now split by what the fact is about: "This battery" carries technology, battery health, charge cycles and charge remaining, "This charger" carries the power source and the charger's advertised maximum. "Charge counter" was the raw Android property name (BATTERY_PROPERTY_CHARGE_ COUNTER) surfacing in the UI and read as the cell's capacity. It is the charge currently in the cell, tracking the battery level, so it now reads "Charge remaining". "Health" becomes "Battery health", which also removes the title/row text collision the hub test had to work around. The battery section is deliberately first: unplugged, both charger rows read "Not reported", so a charger-first order would open the list with two empty rows in the most common state.
1 parent 5a8dabb commit 4d82bb4

3 files changed

Lines changed: 31 additions & 32 deletions

File tree

app/src/main/java/eu/darken/amply/main/ui/battery/BatteryHubScreen.kt

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,11 @@ fun BatteryHubScreen(
151151
onOpenMetric = onOpenMetric,
152152
)
153153
}
154-
item { ChargingSection(data) }
155-
item { HealthSection(data) }
156-
item { ElectricalSection(data) }
154+
// Battery before charger: unplugged, both charger rows read "Not reported", and a
155+
// charger-first order would open the section list with two empty rows in the most
156+
// common state. Keep this order.
157+
item { BatterySection(data) }
158+
item { ChargerSection(data) }
157159
}
158160
}
159161
}
@@ -267,25 +269,15 @@ private fun BatteryMetric.accentColor(): Color = when (this) {
267269
BatteryMetric.VOLTAGE, BatteryMetric.CURRENT -> MaterialTheme.colorScheme.secondary
268270
}
269271

272+
/** Facts about the cell itself. Voltage, current and charge power moved up into the tile grid. */
270273
@Composable
271-
private fun ChargingSection(readout: BatteryReadout) {
274+
private fun BatterySection(readout: BatteryReadout) {
272275
val notReported = stringResource(R.string.battery_value_not_reported)
273-
DetailSection(stringResource(R.string.battery_detail_section_charging)) {
274-
DetailRow(
275-
stringResource(R.string.battery_detail_power_source),
276-
batteryPlugLabel(readout.plugged)?.let { stringResource(it) } ?: notReported,
277-
)
276+
DetailSection(stringResource(R.string.battery_detail_section_battery)) {
278277
DetailRow(
279278
stringResource(R.string.battery_detail_technology),
280279
readout.technology ?: notReported,
281280
)
282-
}
283-
}
284-
285-
@Composable
286-
private fun HealthSection(readout: BatteryReadout) {
287-
val notReported = stringResource(R.string.battery_value_not_reported)
288-
DetailSection(stringResource(R.string.battery_detail_section_health)) {
289281
DetailRow(
290282
stringResource(R.string.battery_detail_health),
291283
stringResource(batteryHealthLabel(readout.health)),
@@ -294,15 +286,22 @@ private fun HealthSection(readout: BatteryReadout) {
294286
stringResource(R.string.battery_detail_cycle_count),
295287
readout.cycleCount?.toString() ?: notReported,
296288
)
289+
DetailRow(
290+
stringResource(R.string.battery_detail_charge_counter),
291+
formatChargeCounter(readout.chargeCounterMicroampHours) ?: notReported,
292+
)
297293
}
298294
}
299295

296+
/** Facts about whatever is currently plugged in. */
300297
@Composable
301-
private fun ElectricalSection(readout: BatteryReadout) {
298+
private fun ChargerSection(readout: BatteryReadout) {
302299
val notReported = stringResource(R.string.battery_value_not_reported)
303-
// Voltage, current and charge power moved up into the tile grid; what stays here is the pair
304-
// that has no live series to chart.
305-
DetailSection(stringResource(R.string.battery_detail_section_electrical)) {
300+
DetailSection(stringResource(R.string.battery_detail_section_charger)) {
301+
DetailRow(
302+
stringResource(R.string.battery_detail_power_source),
303+
batteryPlugLabel(readout.plugged)?.let { stringResource(it) } ?: notReported,
304+
)
306305
// Advertised, not measured: what the connected supply claims. Nothing connected means nothing
307306
// to claim, so the extras are only read through while on a charger.
308307
DetailRow(
@@ -311,10 +310,6 @@ private fun ElectricalSection(readout: BatteryReadout) {
311310
?.let { StatsFormat.power(StatsPowerCalculator.advertisedMaxMilliwatts(it)) }
312311
?: notReported,
313312
)
314-
DetailRow(
315-
stringResource(R.string.battery_detail_charge_counter),
316-
formatChargeCounter(readout.chargeCounterMicroampHours) ?: notReported,
317-
)
318313
}
319314
}
320315

app/src/main/res/values/strings.xml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -508,16 +508,15 @@
508508
<string name="battery_hub_teaser_loading">Loading…</string>
509509
<string name="battery_hub_teaser_unavailable">Statistics are unavailable right now</string>
510510
<string name="battery_hub_teaser_open_action">View charge session</string>
511-
<string name="battery_detail_section_charging">Charging</string>
512-
<string name="battery_detail_section_health">Health</string>
513-
<string name="battery_detail_section_electrical">Electrical</string>
511+
<string name="battery_detail_section_battery">This battery</string>
512+
<string name="battery_detail_section_charger">This charger</string>
514513
<string name="battery_detail_status">Status</string>
515514
<string name="battery_detail_power_source">Power source</string>
516515
<string name="battery_detail_technology">Technology</string>
517-
<string name="battery_detail_health">Health</string>
516+
<string name="battery_detail_health">Battery health</string>
518517
<string name="battery_detail_cycle_count">Charge cycles</string>
519518
<string name="battery_detail_charger_max">Charger max</string>
520-
<string name="battery_detail_charge_counter">Charge counter</string>
519+
<string name="battery_detail_charge_counter">Charge remaining</string>
521520

522521
<!-- Per-metric tiles and their detail screen -->
523522
<string name="battery_metric_open_action">Open metric details</string>

app/src/test/java/eu/darken/amply/main/ui/battery/BatteryHubScreenTest.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import androidx.compose.ui.test.assertCountEquals
99
import androidx.compose.ui.test.junit4.createComposeRule
1010
import androidx.compose.ui.test.onAllNodesWithTag
1111
import androidx.compose.ui.test.onAllNodesWithText
12-
import androidx.compose.ui.test.onFirst
1312
import androidx.compose.ui.test.onNodeWithContentDescription
1413
import androidx.compose.ui.test.onNodeWithText
1514
import androidx.compose.ui.test.performClick
@@ -149,8 +148,14 @@ class BatteryHubScreenTest {
149148
R.string.battery_detail_cycle_count,
150149
R.string.battery_detail_charger_max,
151150
R.string.battery_detail_charge_counter,
152-
// "Health" is both a section title and a row label, so match the first of either.
153-
).forEach { res -> compose.onAllNodesWithText(string(res)).onFirst().assertExists() }
151+
).forEach { res -> compose.onNodeWithText(string(res)).assertExists() }
152+
}
153+
154+
@Test
155+
fun `the detail rows are grouped into a battery and a charger section`() {
156+
render(charging)
157+
compose.onNodeWithText(string(R.string.battery_detail_section_battery)).assertExists()
158+
compose.onNodeWithText(string(R.string.battery_detail_section_charger)).assertExists()
154159
}
155160

156161
@Test

0 commit comments

Comments
 (0)