|
Bogdan Timofte
authored
a week ago
|
1
|
import SwiftUI
|
|
|
2
|
|
|
|
3
|
struct MeterDetailView: View {
|
|
Bogdan Timofte
authored
a week ago
|
4
|
let meterSummary: AppData.MeterSummary
|
|
Bogdan Timofte
authored
a week ago
|
5
|
|
|
|
6
|
var body: some View {
|
|
|
7
|
ScrollView {
|
|
|
8
|
VStack(spacing: 18) {
|
|
|
9
|
headerCard
|
|
|
10
|
statusCard
|
|
Bogdan Timofte
authored
a week ago
|
11
|
identifiersCard
|
|
Bogdan Timofte
authored
a week ago
|
12
|
}
|
|
|
13
|
.padding()
|
|
|
14
|
}
|
|
|
15
|
.background(
|
|
|
16
|
LinearGradient(
|
|
Bogdan Timofte
authored
a week ago
|
17
|
colors: [meterSummary.tint.opacity(0.18), Color.clear],
|
|
Bogdan Timofte
authored
a week ago
|
18
|
startPoint: .topLeading,
|
|
|
19
|
endPoint: .bottomTrailing
|
|
|
20
|
)
|
|
|
21
|
.ignoresSafeArea()
|
|
|
22
|
)
|
|
Bogdan Timofte
authored
a week ago
|
23
|
.navigationTitle(meterSummary.displayName)
|
|
Bogdan Timofte
authored
a week ago
|
24
|
}
|
|
|
25
|
|
|
|
26
|
private var headerCard: some View {
|
|
|
27
|
VStack(alignment: .leading, spacing: 8) {
|
|
Bogdan Timofte
authored
a week ago
|
28
|
Text(meterSummary.displayName)
|
|
Bogdan Timofte
authored
a week ago
|
29
|
.font(.title2.weight(.semibold))
|
|
Bogdan Timofte
authored
a week ago
|
30
|
Text(meterSummary.modelSummary)
|
|
Bogdan Timofte
authored
a week ago
|
31
|
.font(.subheadline)
|
|
|
32
|
.foregroundColor(.secondary)
|
|
Bogdan Timofte
authored
a week ago
|
33
|
if let advertisedName = meterSummary.advertisedName {
|
|
Bogdan Timofte
authored
a week ago
|
34
|
Text("Advertised as " + advertisedName)
|
|
|
35
|
.font(.caption2)
|
|
|
36
|
.foregroundColor(.secondary)
|
|
|
37
|
}
|
|
|
38
|
}
|
|
|
39
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
|
40
|
.padding(18)
|
|
Bogdan Timofte
authored
a week ago
|
41
|
.meterCard(tint: meterSummary.tint, fillOpacity: 0.22, strokeOpacity: 0.28, cornerRadius: 20)
|
|
Bogdan Timofte
authored
a week ago
|
42
|
}
|
|
|
43
|
|
|
|
44
|
private var statusCard: some View {
|
|
|
45
|
VStack(alignment: .leading, spacing: 10) {
|
|
|
46
|
Text("Status")
|
|
|
47
|
.font(.headline)
|
|
|
48
|
HStack(spacing: 8) {
|
|
|
49
|
Circle()
|
|
Bogdan Timofte
authored
a week ago
|
50
|
.fill(meterSummary.tint)
|
|
Bogdan Timofte
authored
a week ago
|
51
|
.frame(width: 10, height: 10)
|
|
|
52
|
Text("Offline")
|
|
|
53
|
.font(.caption.weight(.semibold))
|
|
|
54
|
.foregroundColor(.secondary)
|
|
|
55
|
}
|
|
|
56
|
Text("The meter is not currently connected. Bring it within Bluetooth range or wake it up to open live diagnostics.")
|
|
|
57
|
.font(.caption)
|
|
|
58
|
.foregroundColor(.secondary)
|
|
|
59
|
}
|
|
|
60
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
|
61
|
.padding(18)
|
|
Bogdan Timofte
authored
a week ago
|
62
|
.meterCard(tint: meterSummary.tint, fillOpacity: 0.16, strokeOpacity: 0.22, cornerRadius: 18)
|
|
Bogdan Timofte
authored
a week ago
|
63
|
}
|
|
|
64
|
|
|
Bogdan Timofte
authored
a week ago
|
65
|
private var identifiersCard: some View {
|
|
Bogdan Timofte
authored
a week ago
|
66
|
VStack(alignment: .leading, spacing: 10) {
|
|
Bogdan Timofte
authored
a week ago
|
67
|
Text("Identifiers")
|
|
Bogdan Timofte
authored
a week ago
|
68
|
.font(.headline)
|
|
Bogdan Timofte
authored
a week ago
|
69
|
infoRow(label: "MAC Address", value: meterSummary.macAddress)
|
|
|
70
|
if let advertisedName = meterSummary.advertisedName {
|
|
|
71
|
infoRow(label: "Advertised as", value: advertisedName)
|
|
|
72
|
}
|
|
Bogdan Timofte
authored
a week ago
|
73
|
}
|
|
|
74
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
|
75
|
.padding(18)
|
|
|
76
|
.meterCard(tint: .secondary, fillOpacity: 0.12, strokeOpacity: 0.18, cornerRadius: 18)
|
|
|
77
|
}
|
|
|
78
|
|
|
|
79
|
private func infoRow(label: String, value: String) -> some View {
|
|
|
80
|
HStack {
|
|
|
81
|
Text(label)
|
|
|
82
|
Spacer()
|
|
|
83
|
Text(value)
|
|
|
84
|
.foregroundColor(.secondary)
|
|
|
85
|
.font(.caption)
|
|
|
86
|
}
|
|
|
87
|
}
|
|
|
88
|
}
|
|
|
89
|
|
|
|
90
|
struct MeterDetailView_Previews: PreviewProvider {
|
|
|
91
|
static var previews: some View {
|
|
|
92
|
MeterDetailView(
|
|
Bogdan Timofte
authored
a week ago
|
93
|
meterSummary: AppData.MeterSummary(
|
|
Bogdan Timofte
authored
a week ago
|
94
|
macAddress: "AA:BB:CC:DD:EE:FF",
|
|
|
95
|
displayName: "Desk Meter",
|
|
|
96
|
modelSummary: "UM25C",
|
|
|
97
|
advertisedName: "UM25C-123",
|
|
|
98
|
lastSeen: Date(),
|
|
|
99
|
lastConnected: Date().addingTimeInterval(-3600),
|
|
|
100
|
meter: nil
|
|
|
101
|
)
|
|
|
102
|
)
|
|
|
103
|
}
|
|
|
104
|
}
|