| 1 |
// |
|
| 2 |
// ChargedDeviceLibraryRowView.swift |
|
| 3 |
// USB Meter |
|
| 4 |
// |
|
| 5 |
// Created by Codex on 22/04/2026. |
|
| 6 |
// |
|
| 7 | ||
| 8 |
import SwiftUI |
|
| 9 | ||
| 10 |
struct ChargedDeviceLibraryRowView: View {
|
|
| 11 |
let chargedDevice: ChargedDeviceSummary |
|
| 12 |
let isSelected: Bool |
|
| 13 | ||
| 14 |
var body: some View {
|
|
| 15 |
HStack(alignment: .top, spacing: 14) {
|
|
| 16 |
ChargedDeviceQRCodeView(qrIdentifier: chargedDevice.qrIdentifier, side: 58) |
|
| 17 | ||
| 18 |
VStack(alignment: .leading, spacing: 6) {
|
|
| 19 |
header |
|
| 20 |
summaryText |
|
| 21 |
} |
|
| 22 |
} |
|
| 23 |
.padding(.vertical, 4) |
|
| 24 |
} |
|
| 25 | ||
| 26 |
private var header: some View {
|
|
| 27 |
HStack {
|
|
| 28 |
ChargedDeviceIdentityLabelView( |
|
| 29 |
chargedDevice: chargedDevice, |
|
| 30 |
iconPointSize: 17 |
|
| 31 |
) |
|
| 32 |
.font(.headline) |
|
| 33 |
.foregroundColor(.primary) |
|
| 34 | ||
| 35 |
Spacer() |
|
| 36 | ||
| 37 |
if isSelected {
|
|
| 38 |
Image(systemName: "checkmark.circle.fill") |
|
| 39 |
.foregroundColor(.green) |
|
| 40 |
} |
|
| 41 |
} |
|
| 42 |
} |
|
| 43 | ||
| 44 |
@ViewBuilder |
|
| 45 |
private var summaryText: some View {
|
|
| 46 |
Text(chargedDevice.identityTitle) |
|
| 47 |
.font(.caption.weight(.semibold)) |
|
| 48 |
.foregroundColor(.secondary) |
|
| 49 | ||
| 50 |
if chargedDevice.isCharger {
|
|
| 51 |
chargerSummaryText |
|
| 52 |
} else {
|
|
| 53 |
deviceSummaryText |
|
| 54 |
} |
|
| 55 |
} |
|
| 56 | ||
| 57 |
@ViewBuilder |
|
| 58 |
private var chargerSummaryText: some View {
|
|
| 59 |
if !chargedDevice.chargerObservedVoltageSelections.isEmpty {
|
|
| 60 |
Text(chargedDevice.chargerObservedVoltageSelections.map { "\($0.format(decimalDigits: 1)) V" }.joined(separator: ", "))
|
|
| 61 |
.font(.caption2) |
|
| 62 |
.foregroundColor(.secondary) |
|
| 63 |
} else if let chargerMaximumPowerWatts = chargedDevice.chargerMaximumPowerWatts {
|
|
| 64 |
Text("Max power: \(chargerMaximumPowerWatts.format(decimalDigits: 2)) W")
|
|
| 65 |
.font(.caption2) |
|
| 66 |
.foregroundColor(.secondary) |
|
| 67 |
} else {
|
|
| 68 |
Text("Wireless charger")
|
|
| 69 |
.font(.caption2) |
|
| 70 |
.foregroundColor(.secondary) |
|
| 71 |
} |
|
| 72 |
} |
|
| 73 | ||
| 74 |
@ViewBuilder |
|
| 75 |
private var deviceSummaryText: some View {
|
|
| 76 |
Text(chargedDevice.supportedChargingModes.map(\.title).joined(separator: " + ")) |
|
| 77 |
.font(.caption2) |
|
| 78 |
.foregroundColor(.secondary) |
|
| 79 | ||
| 80 |
if let capacity = chargedDevice.estimatedBatteryCapacityWh {
|
|
| 81 |
Text("Estimated capacity: \(capacity.format(decimalDigits: 2)) Wh")
|
|
| 82 |
.font(.caption) |
|
| 83 |
.foregroundColor(.secondary) |
|
| 84 |
} |
|
| 85 | ||
| 86 |
if let minimumCurrent = chargedDevice.minimumCurrentAmps {
|
|
| 87 |
Text("Completion current: \(minimumCurrent.format(decimalDigits: 2)) A")
|
|
| 88 |
.font(.caption2) |
|
| 89 |
.foregroundColor(.secondary) |
|
| 90 |
} |
|
| 91 |
} |
|
| 92 |
} |