// // MeterComunicationView.swift // USB Meter // // Created by Bogdan Timofte on 05/05/2020. // Copyright © 2020 Bogdan Timofte. All rights reserved. // import SwiftUI struct MeterRowView: View { @EnvironmentObject private var meter: Meter var body: some View { HStack(spacing: 14) { Image(systemName: "sensor.tag.radiowaves.forward.fill") .font(.system(size: 18, weight: .semibold)) .foregroundColor(Meter.operationalColor(for: meter.operationalState)) .frame(width: 42, height: 42) .background( Circle() .fill(Meter.operationalColor(for: meter.operationalState).opacity(0.18)) ) VStack(alignment: .leading, spacing: 4) { Text(meter.name) .font(.headline) Text(meter.deviceModelSummary) .font(.caption) .foregroundColor(.secondary) } Spacer() VStack(alignment: .trailing, spacing: 4) { Text(statusText) .font(.caption.weight(.semibold)) .foregroundColor(Meter.operationalColor(for: meter.operationalState)) Text(meter.btSerial.macAddress.description) .font(.caption2) .foregroundColor(.secondary) } } .padding(14) .meterCard( tint: Meter.operationalColor(for: meter.operationalState), fillOpacity: 0.16, strokeOpacity: 0.22, cornerRadius: 18 ) } private var statusText: String { switch meter.operationalState { case .notPresent: return "Missing" case .peripheralNotConnected: return "Available" case .peripheralConnectionPending: return "Connecting" case .peripheralConnected: return "Linked" case .peripheralReady: return "Ready" case .comunicating: return "Syncing" case .dataIsAvailable: return "Live" } } }