| 1 |
// |
|
| 2 |
// ChargedDeviceSidebarCardView.swift |
|
| 3 |
// USB Meter |
|
| 4 |
// |
|
| 5 |
// Created by Codex on 22/04/2026. |
|
| 6 |
// |
|
| 7 | ||
| 8 |
import SwiftUI |
|
| 9 | ||
| 10 |
struct ChargedDeviceSidebarCardView: View {
|
|
| 11 |
let chargedDevice: ChargedDeviceSummary |
|
| 12 | ||
| 13 |
var body: some View {
|
|
| 14 |
HStack(alignment: .top, spacing: 12) {
|
|
| 15 |
ChargedDeviceQRCodeView(qrIdentifier: chargedDevice.qrIdentifier, side: 54) |
|
| 16 | ||
| 17 |
VStack(alignment: .leading, spacing: 6) {
|
|
| 18 |
header |
|
| 19 |
Text(chargedDevice.identityTitle) |
|
| 20 |
.font(.caption.weight(.semibold)) |
|
| 21 |
.foregroundColor(.secondary) |
|
| 22 |
details |
|
| 23 |
} |
|
| 24 |
} |
|
| 25 |
.padding(.vertical, 4) |
|
| 26 |
} |
|
| 27 | ||
| 28 |
private var header: some View {
|
|
| 29 |
HStack {
|
|
| 30 |
ChargedDeviceIdentityLabelView( |
|
| 31 |
chargedDevice: chargedDevice, |
|
| 32 |
iconPointSize: 17 |
|
| 33 |
) |
|
| 34 |
.font(.headline) |
|
| 35 | ||
| 36 |
if chargedDevice.activeSession != nil {
|
|
| 37 |
Spacer() |
|
| 38 |
Text("Live")
|
|
| 39 |
.font(.caption.weight(.bold)) |
|
| 40 |
.foregroundColor(.green) |
|
| 41 |
} |
|
| 42 |
} |
|
| 43 |
} |
|
| 44 | ||
| 45 |
@ViewBuilder |
|
| 46 |
private var details: some View {
|
|
| 47 |
if chargedDevice.isCharger {
|
|
| 48 |
if let chargerMaximumPowerWatts = chargedDevice.chargerMaximumPowerWatts {
|
|
| 49 |
Text("Max power: \(chargerMaximumPowerWatts.format(decimalDigits: 2)) W")
|
|
| 50 |
.font(.caption2) |
|
| 51 |
.foregroundColor(.secondary) |
|
| 52 |
} else {
|
|
| 53 |
Text("Wireless charger")
|
|
| 54 |
.font(.caption2) |
|
| 55 |
.foregroundColor(.secondary) |
|
| 56 |
} |
|
| 57 |
} else {
|
|
| 58 |
Text(chargedDevice.supportedChargingModes.map(\.title).joined(separator: " + ")) |
|
| 59 |
.font(.caption2) |
|
| 60 |
.foregroundColor(.secondary) |
|
| 61 | ||
| 62 |
if let estimatedCapacityWh = chargedDevice.estimatedBatteryCapacityWh {
|
|
| 63 |
Text("Capacity: \(estimatedCapacityWh.format(decimalDigits: 2)) Wh")
|
|
| 64 |
.font(.caption2) |
|
| 65 |
.foregroundColor(.secondary) |
|
| 66 |
} else {
|
|
| 67 |
Text("Capacity: learning")
|
|
| 68 |
.font(.caption2) |
|
| 69 |
.foregroundColor(.secondary) |
|
| 70 |
} |
|
| 71 |
} |
|
| 72 |
} |
|
| 73 |
} |