|
Bogdan Timofte
authored
2 months ago
|
1
|
//
|
|
Bogdan Timofte
authored
2 months ago
|
2
|
// ChargeRecordSheetView.swift
|
|
Bogdan Timofte
authored
2 months ago
|
3
|
// USB Meter
|
|
|
4
|
//
|
|
|
5
|
// Created by Bogdan Timofte on 09/03/2020.
|
|
|
6
|
// Copyright © 2020 Bogdan Timofte. All rights reserved.
|
|
|
7
|
//
|
|
|
8
|
|
|
|
9
|
import SwiftUI
|
|
|
10
|
|
|
Bogdan Timofte
authored
2 months ago
|
11
|
struct ChargeRecordSheetView: View {
|
|
Bogdan Timofte
authored
2 months ago
|
12
|
@Binding var visibility: Bool
|
|
Bogdan Timofte
authored
a month ago
|
13
|
@EnvironmentObject private var appData: AppData
|
|
|
14
|
|
|
|
15
|
@State private var chargedDeviceLibraryVisibility = false
|
|
|
16
|
@State private var chargerLibraryVisibility = false
|
|
|
17
|
@State private var deviceLibraryMACAddress = ""
|
|
|
18
|
@State private var chargerLibraryMACAddress = ""
|
|
|
19
|
@State private var chargedDeviceLibraryTint: Color = .orange
|
|
|
20
|
@State private var chargerLibraryTint: Color = .pink
|
|
Bogdan Timofte
authored
a month ago
|
21
|
|
|
Bogdan Timofte
authored
2 months ago
|
22
|
var body: some View {
|
|
Bogdan Timofte
authored
2 months ago
|
23
|
NavigationView {
|
|
Bogdan Timofte
authored
a month ago
|
24
|
MeterChargeRecordContentView(
|
|
|
25
|
onSelectDevice: { mac, tint in
|
|
|
26
|
deviceLibraryMACAddress = mac
|
|
|
27
|
chargedDeviceLibraryTint = tint
|
|
|
28
|
chargedDeviceLibraryVisibility = true
|
|
|
29
|
},
|
|
|
30
|
onSelectCharger: { mac, tint in
|
|
|
31
|
chargerLibraryMACAddress = mac
|
|
|
32
|
chargerLibraryTint = tint
|
|
|
33
|
chargerLibraryVisibility = true
|
|
|
34
|
}
|
|
|
35
|
)
|
|
|
36
|
.navigationTitle("Charge Record")
|
|
|
37
|
.navigationBarTitleDisplayMode(.inline)
|
|
|
38
|
.toolbar {
|
|
|
39
|
ToolbarItem(placement: .cancellationAction) {
|
|
|
40
|
Button("Done") {
|
|
|
41
|
visibility = false
|
|
Bogdan Timofte
authored
2 months ago
|
42
|
}
|
|
Bogdan Timofte
authored
2 months ago
|
43
|
}
|
|
Bogdan Timofte
authored
a month ago
|
44
|
}
|
|
|
45
|
.background(
|
|
|
46
|
Group {
|
|
|
47
|
NavigationLink(isActive: $chargedDeviceLibraryVisibility) {
|
|
|
48
|
ChargedDeviceLibrarySheetView(
|
|
|
49
|
meterMACAddress: deviceLibraryMACAddress,
|
|
|
50
|
meterTint: chargedDeviceLibraryTint,
|
|
|
51
|
mode: .device,
|
|
|
52
|
standalone: false
|
|
|
53
|
)
|
|
|
54
|
.environmentObject(appData)
|
|
|
55
|
} label: { EmptyView() }
|
|
|
56
|
|
|
|
57
|
NavigationLink(isActive: $chargerLibraryVisibility) {
|
|
|
58
|
ChargedDeviceLibrarySheetView(
|
|
|
59
|
meterMACAddress: chargerLibraryMACAddress,
|
|
|
60
|
meterTint: chargerLibraryTint,
|
|
|
61
|
mode: .charger,
|
|
|
62
|
standalone: false
|
|
|
63
|
)
|
|
|
64
|
.environmentObject(appData)
|
|
|
65
|
} label: { EmptyView() }
|
|
|
66
|
}
|
|
|
67
|
)
|
|
Bogdan Timofte
authored
2 months ago
|
68
|
}
|
|
Bogdan Timofte
authored
2 months ago
|
69
|
.navigationViewStyle(StackNavigationViewStyle())
|
|
Bogdan Timofte
authored
2 months ago
|
70
|
}
|
|
|
71
|
}
|
|
Bogdan Timofte
authored
a month ago
|
72
|
|
|
Bogdan Timofte
authored
a month ago
|
73
|
struct BatteryTargetNotificationEditorSheetView: View {
|
|
Bogdan Timofte
authored
a month ago
|
74
|
@Environment(\.dismiss) private var dismiss
|
|
|
75
|
@EnvironmentObject private var appData: AppData
|
|
|
76
|
|
|
|
77
|
let sessionID: UUID
|
|
|
78
|
let initialTargetPercent: Double?
|
|
|
79
|
|
|
|
80
|
@State private var targetPercent: Double
|
|
|
81
|
|
|
|
82
|
init(sessionID: UUID, initialTargetPercent: Double?) {
|
|
|
83
|
self.sessionID = sessionID
|
|
|
84
|
self.initialTargetPercent = initialTargetPercent
|
|
|
85
|
_targetPercent = State(initialValue: initialTargetPercent ?? 80)
|
|
|
86
|
}
|
|
|
87
|
|
|
|
88
|
var body: some View {
|
|
|
89
|
NavigationView {
|
|
|
90
|
Form {
|
|
Bogdan Timofte
authored
a month ago
|
91
|
Section(
|
|
|
92
|
header: ContextInfoHeader(
|
|
|
93
|
title: "Target Level",
|
|
|
94
|
message: "A local notification will be generated on synced devices when the estimated battery level reaches this target."
|
|
|
95
|
)
|
|
|
96
|
) {
|
|
Bogdan Timofte
authored
a month ago
|
97
|
VStack(alignment: .leading, spacing: 12) {
|
|
|
98
|
Text("\(targetPercent.format(decimalDigits: 0))%")
|
|
|
99
|
.font(.title3.weight(.bold))
|
|
|
100
|
Slider(value: $targetPercent, in: 20...100, step: 1)
|
|
|
101
|
}
|
|
|
102
|
}
|
|
|
103
|
}
|
|
|
104
|
.navigationTitle("Battery Target")
|
|
|
105
|
.navigationBarTitleDisplayMode(.inline)
|
|
|
106
|
.toolbar {
|
|
|
107
|
ToolbarItem(placement: .cancellationAction) {
|
|
|
108
|
Button("Cancel") {
|
|
|
109
|
dismiss()
|
|
|
110
|
}
|
|
|
111
|
}
|
|
|
112
|
|
|
|
113
|
ToolbarItem(placement: .confirmationAction) {
|
|
|
114
|
Button("Save") {
|
|
|
115
|
if appData.setTargetBatteryPercent(targetPercent, for: sessionID) {
|
|
|
116
|
dismiss()
|
|
|
117
|
}
|
|
|
118
|
}
|
|
|
119
|
}
|
|
|
120
|
}
|
|
|
121
|
}
|
|
|
122
|
}
|
|
|
123
|
}
|
|
Bogdan Timofte
authored
a month ago
|
124
|
|
|
|
125
|
#Preview {
|
|
|
126
|
ChargeRecordSheetView(visibility: .constant(true))
|
|
|
127
|
}
|