| 1 |
// |
|
| 2 |
// PowerbankSidebarCardView.swift |
|
| 3 |
// USB Meter |
|
| 4 |
// |
|
| 5 | ||
| 6 |
import SwiftUI |
|
| 7 | ||
| 8 |
struct PowerbankSidebarCardView: View {
|
|
| 9 |
let powerbank: PowerbankSummary |
|
| 10 | ||
| 11 |
var body: some View {
|
|
| 12 |
HStack(alignment: .top, spacing: 12) {
|
|
| 13 |
ChargedDeviceQRCodeView(qrIdentifier: powerbank.qrIdentifier, side: 54) |
|
| 14 | ||
| 15 |
VStack(alignment: .leading, spacing: 6) {
|
|
| 16 |
header |
|
| 17 |
Text(powerbank.identityTitle) |
|
| 18 |
.font(.caption.weight(.semibold)) |
|
| 19 |
.foregroundColor(.secondary) |
|
| 20 |
details |
|
| 21 |
} |
|
| 22 |
} |
|
| 23 |
.padding(.vertical, 4) |
|
| 24 |
} |
|
| 25 | ||
| 26 |
private var header: some View {
|
|
| 27 |
HStack {
|
|
| 28 |
Label(powerbank.name, systemImage: powerbank.identitySymbolName) |
|
| 29 |
.font(.headline) |
|
| 30 | ||
| 31 |
if powerbank.openSession != nil {
|
|
| 32 |
Spacer() |
|
| 33 |
Text("Live")
|
|
| 34 |
.font(.caption.weight(.bold)) |
|
| 35 |
.foregroundColor(.green) |
|
| 36 |
} |
|
| 37 |
} |
|
| 38 |
} |
|
| 39 | ||
| 40 |
@ViewBuilder |
|
| 41 |
private var details: some View {
|
|
| 42 |
Text(reportingSummary) |
|
| 43 |
.font(.caption2) |
|
| 44 |
.foregroundColor(.secondary) |
|
| 45 | ||
| 46 |
if let capacityWh = powerbank.apparentCapacityWh ?? powerbank.estimatedBatteryCapacityWh {
|
|
| 47 |
Text("Capacity: \(capacityWh.format(decimalDigits: 2)) Wh")
|
|
| 48 |
.font(.caption2) |
|
| 49 |
.foregroundColor(.secondary) |
|
| 50 |
} else {
|
|
| 51 |
Text("Capacity: learning")
|
|
| 52 |
.font(.caption2) |
|
| 53 |
.foregroundColor(.secondary) |
|
| 54 |
} |
|
| 55 |
} |
|
| 56 | ||
| 57 |
private var reportingSummary: String {
|
|
| 58 |
switch powerbank.batteryLevelReporting {
|
|
| 59 |
case .percent: |
|
| 60 |
return "Battery: 0–100%" |
|
| 61 |
case .bars: |
|
| 62 |
return "Battery: \(powerbank.batteryBarsCount) bars" |
|
| 63 |
case .fullOnly: |
|
| 64 |
return "Battery: full-only LED" |
|
| 65 |
case .none: |
|
| 66 |
return "Battery: not reported" |
|
| 67 |
} |
|
| 68 |
} |
|
| 69 |
} |