Newer Older
85 lines | 2.629kb
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

            
Bogdan Timofte authored 2 months ago
14
    var body: some View {
Bogdan Timofte authored 2 months ago
15
        NavigationView {
Bogdan Timofte authored a month ago
16
            MeterChargeRecordContentView()
Bogdan Timofte authored a month ago
17
            .navigationTitle("Charge Record")
18
            .navigationBarTitleDisplayMode(.inline)
19
            .toolbar {
20
                ToolbarItem(placement: .cancellationAction) {
21
                    Button("Done") {
22
                        visibility = false
Bogdan Timofte authored 2 months ago
23
                    }
Bogdan Timofte authored 2 months ago
24
                }
Bogdan Timofte authored a month ago
25
            }
Bogdan Timofte authored 2 months ago
26
        }
Bogdan Timofte authored 2 months ago
27
        .navigationViewStyle(StackNavigationViewStyle())
Bogdan Timofte authored 2 months ago
28
    }
29
}
Bogdan Timofte authored a month ago
30

            
Bogdan Timofte authored a month ago
31
struct BatteryTargetNotificationEditorSheetView: View {
Bogdan Timofte authored a month ago
32
    @Environment(\.dismiss) private var dismiss
33
    @EnvironmentObject private var appData: AppData
34

            
35
    let sessionID: UUID
36
    let initialTargetPercent: Double?
37

            
38
    @State private var targetPercent: Double
39

            
40
    init(sessionID: UUID, initialTargetPercent: Double?) {
41
        self.sessionID = sessionID
42
        self.initialTargetPercent = initialTargetPercent
43
        _targetPercent = State(initialValue: initialTargetPercent ?? 80)
44
    }
45

            
46
    var body: some View {
47
        NavigationView {
48
            Form {
Bogdan Timofte authored a month ago
49
                Section(
50
                    header: ContextInfoHeader(
51
                        title: "Target Level",
52
                        message: "A local notification will be generated on synced devices when the estimated battery level reaches this target."
53
                    )
54
                ) {
Bogdan Timofte authored a month ago
55
                    VStack(alignment: .leading, spacing: 12) {
56
                        Text("\(targetPercent.format(decimalDigits: 0))%")
57
                            .font(.title3.weight(.bold))
58
                        Slider(value: $targetPercent, in: 20...100, step: 1)
59
                    }
60
                }
61
            }
62
            .navigationTitle("Battery Target")
63
            .navigationBarTitleDisplayMode(.inline)
64
            .toolbar {
65
                ToolbarItem(placement: .cancellationAction) {
66
                    Button("Cancel") {
67
                        dismiss()
68
                    }
69
                }
70

            
71
                ToolbarItem(placement: .confirmationAction) {
72
                    Button("Save") {
73
                        if appData.setTargetBatteryPercent(targetPercent, for: sessionID) {
74
                            dismiss()
75
                        }
76
                    }
77
                }
78
            }
79
        }
80
    }
81
}
Bogdan Timofte authored a month ago
82

            
83
#Preview {
84
    ChargeRecordSheetView(visibility: .constant(true))
85
}