fix(power): 完善电池卡片的共同供电判定、功率图标与预估续航
按适配器和电池的实际贡献判定共同供电,以双图标和双色柱展示两路功率。同步三语预估续航文案,在仅外接供电时隐藏估时行。
This commit is contained in:
@@ -27,17 +27,18 @@ struct PowerResourceCard: View {
|
||||
}
|
||||
|
||||
private func details(_ flow: BatteryPowerFlow) -> String {
|
||||
var rows: [(String, String)] = [
|
||||
("battery.power", formatted(flow.battery, signed: true)),
|
||||
("power.load", formatted(flow.load))
|
||||
]
|
||||
if flow.connected != false {
|
||||
rows.append(("power.input", formatted(flow.input)))
|
||||
rows.append(("power.capacity", MetricFormat.watts(flow.adapterCapacity)))
|
||||
}
|
||||
if flow.battery?.source == .average {
|
||||
rows[0].0 = "power.averageBattery"
|
||||
var rows: [(String, String)]
|
||||
if let joint = flow.jointSupply {
|
||||
let load = flow.load ?? PowerReading(watts: joint.adapter.watts + joint.discharge.watts, source: .balance)
|
||||
rows = [("power.adapterContribution", formatted(joint.adapter)),
|
||||
("power.batteryContribution", formatted(joint.discharge)),
|
||||
("power.load", formatted(load))]
|
||||
} else {
|
||||
let batteryLabel = flow.battery?.source == .average ? "power.averageBattery" : "battery.power"
|
||||
rows = [(batteryLabel, formatted(flow.battery, signed: true)), ("power.load", formatted(flow.load))]
|
||||
if flow.connected != false { rows.append(("power.input", formatted(flow.input))) }
|
||||
}
|
||||
if flow.connected != false { rows.append(("power.capacity", MetricFormat.watts(flow.adapterCapacity))) }
|
||||
return rows.map { AppLocalization.string($0.0, locale: locale) + " " + $0.1 }.joined(separator: "\n")
|
||||
}
|
||||
|
||||
@@ -66,9 +67,12 @@ struct PowerResourceCard: View {
|
||||
}
|
||||
|
||||
private var batteryPowerCard: some View {
|
||||
ResourceCard(
|
||||
title: "metric.battery", symbol: "battery.100percent", color: Color("MetricBattery"),
|
||||
let joint = snapshot.battery?.flow.jointSupply
|
||||
return ResourceCard(
|
||||
title: "metric.battery", symbol: joint == nil ? "battery.100percent" : "powerplug.fill",
|
||||
color: Color(joint == nil ? "MetricBattery" : "BatteryExternal"),
|
||||
value: MetricFormat.percent(snapshot.battery?.charge),
|
||||
companionIcon: joint == nil ? nil : ("battery.50percent", Color("MetricBattery")),
|
||||
status: snapshot.battery.map { label($0.flow.state) },
|
||||
warningText: snapshot.battery.map { Text(verbatim: details($0.flow)) },
|
||||
chart: {
|
||||
@@ -81,8 +85,17 @@ struct PowerResourceCard: View {
|
||||
}
|
||||
}
|
||||
) {
|
||||
InlineMetric("battery.powerShort", formatted(snapshot.battery?.flow.battery, signed: true))
|
||||
if let joint {
|
||||
HStack(spacing: 8) {
|
||||
powerLabel(joint.adapter, symbol: "powerplug.fill", color: "BatteryExternal", title: "power.adapterContribution")
|
||||
powerLabel(joint.discharge, symbol: "battery.50percent", color: "MetricBattery", title: "power.batteryContribution")
|
||||
}
|
||||
.frame(height: 16)
|
||||
} else {
|
||||
powerLabel(snapshot.battery?.flow.battery, signed: true, symbol: "battery.50percent",
|
||||
color: "MetricBattery", title: "battery.power")
|
||||
.frame(height: 16)
|
||||
}
|
||||
if let battery = snapshot.battery {
|
||||
batteryDetails(battery)
|
||||
} else {
|
||||
@@ -91,20 +104,33 @@ struct PowerResourceCard: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
private func powerLabel(_ reading: PowerReading?, signed: Bool = false, symbol: String,
|
||||
color: String, title: LocalizedStringKey) -> some View {
|
||||
let value = formatted(reading, signed: signed)
|
||||
return Label {
|
||||
Text(verbatim: value).monospacedDigit()
|
||||
} icon: {
|
||||
Image(systemName: symbol).foregroundStyle(Color(color))
|
||||
}
|
||||
.accessibilityLabel(Text(title)).accessibilityValue(Text(verbatim: value))
|
||||
.help(Text(title))
|
||||
}
|
||||
|
||||
private func batteryDetails(_ battery: BatteryMetrics) -> some View {
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
HStack(spacing: 8) {
|
||||
InlineMetric("battery.healthShort", MetricFormat.percent(battery.health))
|
||||
InlineMetric("battery.cyclesShort", battery.cycles.map(String.init) ?? "--")
|
||||
}
|
||||
HStack(spacing: 4) {
|
||||
Text(battery.flow.charging == true ? "battery.timeToFull" : "battery.timeShort").foregroundStyle(.secondary)
|
||||
if let minutes = battery.minutesRemaining {
|
||||
Text("duration.minutes \(minutes)").monospacedDigit()
|
||||
} else if battery.flow.state == .external && battery.flow.charging != true {
|
||||
Text("battery.notApplicableShort").help(Text("battery.timeNotApplicable"))
|
||||
} else {
|
||||
Text("battery.timeUnknown")
|
||||
if battery.flow.state != .external {
|
||||
HStack(spacing: 4) {
|
||||
Text(battery.flow.state == .charging ? "battery.timeToFull" : "battery.timeEstimate")
|
||||
.foregroundStyle(.secondary)
|
||||
if let minutes = battery.minutesRemaining {
|
||||
Text("duration.minutes \(minutes)").monospacedDigit()
|
||||
} else {
|
||||
Text("battery.timeUnknown")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user