Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,14 @@ private fun DetailGrid(state: BatteryUiState) {
Column(verticalArrangement = Arrangement.spacedBy(12.dp)) {
Row(horizontalArrangement = Arrangement.spacedBy(12.dp)) {
StatCard("Health", state.health, Modifier.weight(1f))
StatCard("Level", "${state.percentage}%", Modifier.weight(1f))
}
Row(horizontalArrangement = Arrangement.spacedBy(12.dp)) {
StatCard("Power Source", state.powerSource, Modifier.weight(1f))
StatCard("Status", state.status, Modifier.weight(1f))
}
Row(horizontalArrangement = Arrangement.spacedBy(12.dp)) {
StatCard("Technology", state.technology, Modifier.weight(1f))
StatCard("Temperature", state.temperature, Modifier.weight(1f))
}
Row(horizontalArrangement = Arrangement.spacedBy(12.dp)) {
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/dev/sayanthrock/batteryrock/BatteryViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ data class BatteryUiState(
val voltage: String = "Unknown",
val current: String = "Unknown",
val wattage: String = "Unknown",
val powerSource: String = "Unknown",
val isCharging: Boolean = false,
val timeToFullStr: String = "Calculating...",
val timeToEmptyStr: String = "Calculating..."
Expand All @@ -113,6 +114,7 @@ private fun Intent.toBatteryUiState(context: Context): BatteryUiState {
val healthCode = getIntExtra(BatteryManager.EXTRA_HEALTH, BatteryManager.BATTERY_HEALTH_UNKNOWN)
val tempRaw = getIntExtra(BatteryManager.EXTRA_TEMPERATURE, Int.MIN_VALUE)
val voltageMv = getIntExtra(BatteryManager.EXTRA_VOLTAGE, -1)
val pluggedCode = getIntExtra(BatteryManager.EXTRA_PLUGGED, -1)

val batteryManager = context.getSystemService(Context.BATTERY_SERVICE) as BatteryManager
val currentUa = batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CURRENT_NOW)
Expand Down Expand Up @@ -166,6 +168,7 @@ private fun Intent.toBatteryUiState(context: Context): BatteryUiState {
voltage = if (voltageMv > 0) "${voltageMv} mV" else "Unknown",
current = currentStr,
wattage = wattageStr,
powerSource = pluggedCode.toPowerSource(),
isCharging = isCharging,
timeToFullStr = timeToFull,
timeToEmptyStr = timeToEmpty
Expand All @@ -189,3 +192,11 @@ private fun Int.toBatteryHealth(): String = when (this) {
BatteryManager.BATTERY_HEALTH_COLD -> "Cold"
else -> "Unknown"
}

private fun Int.toPowerSource(): String = when (this) {
BatteryManager.BATTERY_PLUGGED_AC -> "AC Charger"
BatteryManager.BATTERY_PLUGGED_USB -> "USB"
BatteryManager.BATTERY_PLUGGED_WIRELESS -> "Wireless"
0 -> "Battery"
else -> "Unknown"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: The mapping omits the dock plugged value (8), which this repository already handles as Dock in DeviceStatusReader. Devices reporting dock-style charging will therefore display Unknown in the main battery UI instead of the actual power source. Add the dock mapping or share the existing power-source mapping. [api mismatch]

Severity Level: Major ⚠️
- ⚠️ Dock-connected devices show an unknown power source.
- ⚠️ Home battery details disagree with `DeviceStatusReader`.
- ⚠️ Users lose accurate dock charging information.

Fix in Cursor Fix in VSCode Claude

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** app/src/main/java/dev/sayanthrock/batteryrock/BatteryViewModel.kt
**Line:** 201:201
**Comment:**
	*Api Mismatch: The mapping omits the dock plugged value (`8`), which this repository already handles as `Dock` in `DeviceStatusReader`. Devices reporting dock-style charging will therefore display `Unknown` in the main battery UI instead of the actual power source. Add the dock mapping or share the existing power-source mapping.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

}
Loading