USB-Meter / USB Meter / Views / MeterRowView.swift
Newer Older
72 lines | 2.198kb
Bogdan Timofte authored 2 weeks ago
1
//
2
//  MeterComunicationView.swift
3
//  USB Meter
4
//
5
//  Created by Bogdan Timofte on 05/05/2020.
6
//  Copyright © 2020 Bogdan Timofte. All rights reserved.
7
//
8

            
9
import SwiftUI
10

            
11
struct MeterRowView: View {
12

            
13
    @EnvironmentObject private var meter: Meter
14

            
15
    var body: some View {
Bogdan Timofte authored 2 weeks ago
16
        HStack(spacing: 14) {
17
            Image(systemName: "sensor.tag.radiowaves.forward.fill")
18
                .font(.system(size: 18, weight: .semibold))
19
                .foregroundColor(Meter.operationalColor(for: meter.operationalState))
20
                .frame(width: 42, height: 42)
21
                .background(
22
                    Circle()
23
                        .fill(Meter.operationalColor(for: meter.operationalState).opacity(0.18))
24
                )
25

            
26
            VStack(alignment: .leading, spacing: 4) {
27
                Text(meter.name)
28
                    .font(.headline)
29
                Text(meter.deviceModelSummary)
30
                    .font(.caption)
31
                    .foregroundColor(.secondary)
32
            }
33

            
34
            Spacer()
35

            
36
            VStack(alignment: .trailing, spacing: 4) {
37
                Text(statusText)
38
                    .font(.caption.weight(.semibold))
39
                    .foregroundColor(Meter.operationalColor(for: meter.operationalState))
40
                Text(meter.btSerial.macAddress.description)
41
                    .font(.caption2)
42
                    .foregroundColor(.secondary)
43
            }
44
        }
45
        .padding(14)
46
        .meterCard(
47
            tint: Meter.operationalColor(for: meter.operationalState),
48
            fillOpacity: 0.16,
49
            strokeOpacity: 0.22,
50
            cornerRadius: 18
51
        )
52
    }
53

            
54
    private var statusText: String {
55
        switch meter.operationalState {
56
        case .notPresent:
57
            return "Missing"
58
        case .peripheralNotConnected:
59
            return "Available"
60
        case .peripheralConnectionPending:
61
            return "Connecting"
62
        case .peripheralConnected:
63
            return "Linked"
64
        case .peripheralReady:
65
            return "Ready"
66
        case .comunicating:
67
            return "Syncing"
68
        case .dataIsAvailable:
69
            return "Live"
Bogdan Timofte authored 2 weeks ago
70
        }
71
    }
72
}