Newer Older
93 lines | 2.885kb
Bogdan Timofte authored 2 months ago
1
//
Bogdan Timofte authored a month ago
2
//  SidebarMeterCardView.swift
Bogdan Timofte authored 2 months ago
3
//  USB Meter
4
//
5

            
6
import SwiftUI
7

            
Bogdan Timofte authored a month ago
8
struct SidebarMeterCardView: View {
Bogdan Timofte authored 2 months ago
9
    @EnvironmentObject private var meter: Meter
Bogdan Timofte authored a month ago
10

            
Bogdan Timofte authored 2 months ago
11
    var body: some View {
Bogdan Timofte authored 2 months ago
12
        HStack(spacing: 14) {
13
            Image(systemName: "sensor.tag.radiowaves.forward.fill")
14
                .font(.system(size: 18, weight: .semibold))
Bogdan Timofte authored 2 months ago
15
                .foregroundColor(meter.color)
Bogdan Timofte authored 2 months ago
16
                .frame(width: 42, height: 42)
17
                .background(
18
                    Circle()
Bogdan Timofte authored 2 months ago
19
                        .fill(meter.color.opacity(0.18))
Bogdan Timofte authored 2 months ago
20
                )
Bogdan Timofte authored 2 months ago
21
                .overlay(alignment: .bottomTrailing) {
22
                    Circle()
23
                        .fill(connectivityTint)
24
                        .frame(width: 12, height: 12)
25
                        .overlay(
26
                            Circle()
27
                                .stroke(Color(uiColor: .systemBackground), lineWidth: 2)
28
                        )
29
                }
Bogdan Timofte authored 2 months ago
30

            
31
            VStack(alignment: .leading, spacing: 4) {
32
                Text(meter.name)
33
                    .font(.headline)
34
                Text(meter.deviceModelSummary)
35
                    .font(.caption)
36
                    .foregroundColor(.secondary)
37
            }
38

            
39
            Spacer()
40

            
41
            VStack(alignment: .trailing, spacing: 4) {
Bogdan Timofte authored 2 months ago
42
                HStack(spacing: 6) {
43
                    Circle()
44
                        .fill(connectivityTint)
45
                        .frame(width: 8, height: 8)
46
                    Text(statusText)
47
                        .font(.caption.weight(.semibold))
48
                        .foregroundColor(.secondary)
49
                }
50
                .padding(.horizontal, 10)
51
                .padding(.vertical, 6)
52
                .background(
53
                    Capsule(style: .continuous)
54
                        .fill(connectivityTint.opacity(0.12))
55
                )
56
                .overlay(
57
                    Capsule(style: .continuous)
58
                        .stroke(connectivityTint.opacity(0.22), lineWidth: 1)
59
                )
Bogdan Timofte authored 2 months ago
60
            }
61
        }
62
        .padding(14)
63
        .meterCard(
Bogdan Timofte authored 2 months ago
64
            tint: meter.color,
Bogdan Timofte authored 2 months ago
65
            fillOpacity: 0.16,
66
            strokeOpacity: 0.22,
67
            cornerRadius: 18
68
        )
69
    }
70

            
Bogdan Timofte authored 2 months ago
71
    private var connectivityTint: Color {
72
        Meter.operationalColor(for: meter.operationalState)
73
    }
74

            
Bogdan Timofte authored 2 months ago
75
    private var statusText: String {
76
        switch meter.operationalState {
77
        case .notPresent:
78
            return "Missing"
79
        case .peripheralNotConnected:
80
            return "Available"
81
        case .peripheralConnectionPending:
82
            return "Connecting"
83
        case .peripheralConnected:
84
            return "Linked"
85
        case .peripheralReady:
86
            return "Ready"
87
        case .comunicating:
88
            return "Syncing"
89
        case .dataIsAvailable:
90
            return "Live"
Bogdan Timofte authored 2 months ago
91
        }
92
    }
93
}