| 1 |
// |
|
| 2 |
// MeasurementView.swift |
|
| 3 |
// USB Meter |
|
| 4 |
// |
|
| 5 |
// Created by Bogdan Timofte on 13/04/2020. |
|
| 6 |
// Copyright © 2020 Bogdan Timofte. All rights reserved. |
|
| 7 |
// |
|
| 8 | ||
| 9 |
import SwiftUI |
|
| 10 | ||
| 11 |
struct MeasurementsView: View {
|
|
| 12 | ||
| 13 |
@EnvironmentObject private var measurements: Measurements |
|
| 14 | ||
| 15 |
@Binding var visibility: Bool |
|
| 16 | ||
| 17 |
var body: some View {
|
|
| 18 |
NavigationView {
|
|
| 19 |
ScrollView {
|
|
| 20 |
VStack(alignment: .leading, spacing: 14) {
|
|
| 21 |
VStack(alignment: .leading, spacing: 8) {
|
|
| 22 |
Text("App History")
|
|
| 23 |
.font(.system(.title3, design: .rounded).weight(.bold)) |
|
| 24 |
Text("Local timeline captured by the app while connected to the meter.")
|
|
| 25 |
.font(.footnote) |
|
| 26 |
.foregroundColor(.secondary) |
|
| 27 |
} |
|
| 28 |
.padding(18) |
|
| 29 |
.meterCard(tint: .blue, fillOpacity: 0.18, strokeOpacity: 0.24) |
|
| 30 | ||
| 31 |
if measurements.power.points.isEmpty {
|
|
| 32 |
Text("No history samples have been captured yet.")
|
|
| 33 |
.font(.footnote) |
|
| 34 |
.foregroundColor(.secondary) |
|
| 35 |
.padding(18) |
|
| 36 |
.meterCard(tint: .secondary, fillOpacity: 0.14, strokeOpacity: 0.20) |
|
| 37 |
} else {
|
|
| 38 |
LazyVStack(spacing: 12) {
|
|
| 39 |
ForEach(measurements.power.points) { point in
|
|
| 40 |
MeasurementPointView( |
|
| 41 |
power: point, |
|
| 42 |
voltage: measurements.voltage.points[point.id], |
|
| 43 |
current: measurements.current.points[point.id] |
|
| 44 |
) |
|
| 45 |
} |
|
| 46 |
} |
|
| 47 |
} |
|
| 48 |
} |
|
| 49 |
.padding() |
|
| 50 |
} |
|
| 51 |
.background( |
|
| 52 |
LinearGradient( |
|
| 53 |
colors: [.blue.opacity(0.14), Color.clear], |
|
| 54 |
startPoint: .topLeading, |
|
| 55 |
endPoint: .bottomTrailing |
|
| 56 |
) |
|
| 57 |
.ignoresSafeArea() |
|
| 58 |
) |
|
| 59 |
.navigationBarItems( |
|
| 60 |
leading: Button("Done") { visibility.toggle() },
|
|
| 61 |
trailing: Button("Clear") {
|
|
| 62 |
measurements.reset() |
|
| 63 |
} |
|
| 64 |
.foregroundColor(.red) |
|
| 65 |
) |
|
| 66 |
.navigationBarTitle("App History", displayMode: .inline)
|
|
| 67 |
} |
|
| 68 |
.navigationViewStyle(StackNavigationViewStyle()) |
|
| 69 |
} |
|
| 70 |
} |