| 1 |
// |
|
| 2 |
// SettingsView.swift |
|
| 3 |
// USB Meter |
|
| 4 |
// |
|
| 5 |
// Created by Bogdan Timofte on 14/03/2020. |
|
| 6 |
// Copyright © 2020 Bogdan Timofte. All rights reserved. |
|
| 7 |
// |
|
| 8 | ||
| 9 |
import SwiftUI |
|
| 10 | ||
| 11 |
struct MeterSettingsView: View {
|
|
| 12 | ||
| 13 |
@EnvironmentObject private var meter: Meter |
|
| 14 | ||
| 15 |
@State private var editingName = false |
|
| 16 |
@State private var editingScreenTimeout = false |
|
| 17 |
@State private var editingScreenBrightness = false |
|
| 18 | ||
| 19 |
var body: some View {
|
|
| 20 |
ScrollView {
|
|
| 21 |
VStack (spacing: 10) {
|
|
| 22 |
// MARK: Name |
|
| 23 |
VStack {
|
|
| 24 |
HStack {
|
|
| 25 |
Text ("Name").fontWeight(.semibold)
|
|
| 26 |
Spacer() |
|
| 27 |
if !editingName {
|
|
| 28 |
Text(meter.name) |
|
| 29 |
} |
|
| 30 |
ChevronView( rotate: $editingName ) |
|
| 31 |
} |
|
| 32 |
if editingName {
|
|
| 33 |
EditNameView(editingName: $editingName, newName: meter.name) |
|
| 34 |
} |
|
| 35 |
} |
|
| 36 |
.padding() |
|
| 37 |
.background(RoundedRectangle(cornerRadius: 15).foregroundColor(.secondary).opacity(0.1)) |
|
| 38 |
if meter.operationalState == .dataIsAvailable && meter.supportsUMSettings {
|
|
| 39 |
// MARK: Screen Timeout |
|
| 40 |
// Ar trebui separat enabled/disabled de valorile in minute eventual stocata valoarea in iCloud la dezactivare pentru restaurare |
|
| 41 |
VStack{
|
|
| 42 |
HStack {
|
|
| 43 |
Text ("Screen Timeout").fontWeight(.semibold)
|
|
| 44 |
Spacer() |
|
| 45 |
if !editingScreenTimeout {
|
|
| 46 |
Text ( meter.screenTimeout != 0 ? "\(meter.screenTimeout) Minutes" : "Off" ) |
|
| 47 |
} |
|
| 48 |
ChevronView( rotate: $editingScreenTimeout ) |
|
| 49 |
} |
|
| 50 |
if editingScreenTimeout {
|
|
| 51 |
EditScreenTimeoutView() |
|
| 52 |
} |
|
| 53 |
} |
|
| 54 |
.padding() |
|
| 55 |
.background(RoundedRectangle(cornerRadius: 15).foregroundColor(.secondary).opacity(0.1)) |
|
| 56 |
// MARK: Screen Brightness |
|
| 57 |
VStack{
|
|
| 58 |
HStack {
|
|
| 59 |
Text ("Screen Brightness").fontWeight(.semibold)
|
|
| 60 |
Spacer() |
|
| 61 |
if !editingScreenBrightness {
|
|
| 62 |
Text ( "\(meter.screenBrightness)" ) |
|
| 63 |
} |
|
| 64 |
ChevronView( rotate: $editingScreenBrightness ) |
|
| 65 |
} |
|
| 66 |
if editingScreenBrightness {
|
|
| 67 |
EditScreenBrightnessView() |
|
| 68 |
} |
|
| 69 |
} |
|
| 70 |
.padding() |
|
| 71 |
.background(RoundedRectangle(cornerRadius: 15).foregroundColor(.secondary).opacity(0.1)) |
|
| 72 |
} |
|
| 73 |
} |
|
| 74 |
} |
|
| 75 |
.padding() |
|
| 76 |
.navigationBarTitle("Meter Settings")
|
|
| 77 |
.navigationBarItems( trailing: RSSIView( RSSI: meter.btSerial.RSSI ).frame( width: 24 ) ) |
|
| 78 |
} |
|
| 79 |
} |
|
| 80 | ||
| 81 |
struct EditNameView: View {
|
|
| 82 | ||
| 83 |
@EnvironmentObject private var meter: Meter |
|
| 84 | ||
| 85 |
@Binding var editingName: Bool |
|
| 86 |
@State var newName: String |
|
| 87 | ||
| 88 |
var body: some View {
|
|
| 89 |
TextField("Name", text: self.$newName, onCommit: {
|
|
| 90 |
self.meter.name = self.newName |
|
| 91 |
self.editingName = false |
|
| 92 |
}) |
|
| 93 |
.textFieldStyle(RoundedBorderTextFieldStyle()) |
|
| 94 |
.lineLimit(1) |
|
| 95 |
.disableAutocorrection(true) |
|
| 96 |
.multilineTextAlignment(.center) |
|
| 97 |
.padding(.horizontal) |
|
| 98 |
} |
|
| 99 |
} |
|
| 100 | ||
| 101 |
struct EditScreenTimeoutView: View {
|
|
| 102 | ||
| 103 |
@EnvironmentObject private var meter: Meter |
|
| 104 | ||
| 105 |
var body: some View {
|
|
| 106 |
Picker("", selection: self.$meter.screenTimeout ) {
|
|
| 107 |
Text("1").tag(1)
|
|
| 108 |
Text("2").tag(2)
|
|
| 109 |
Text("3").tag(3)
|
|
| 110 |
Text("4").tag(4)
|
|
| 111 |
Text("5").tag(5)
|
|
| 112 |
Text("6").tag(6)
|
|
| 113 |
Text("7").tag(7)
|
|
| 114 |
Text("8").tag(8)
|
|
| 115 |
Text("9").tag(9)
|
|
| 116 |
Text("Off").tag(0)
|
|
| 117 |
} |
|
| 118 |
.pickerStyle( SegmentedPickerStyle() ) |
|
| 119 |
.padding(.horizontal) |
|
| 120 |
} |
|
| 121 |
} |
|
| 122 | ||
| 123 |
struct EditScreenBrightnessView: View {
|
|
| 124 | ||
| 125 |
@EnvironmentObject private var meter: Meter |
|
| 126 | ||
| 127 |
var body: some View {
|
|
| 128 |
Picker("", selection: self.$meter.screenBrightness ) {
|
|
| 129 |
Text("0").tag(0)
|
|
| 130 |
Text("1").tag(1)
|
|
| 131 |
Text("2").tag(2)
|
|
| 132 |
Text("3").tag(3)
|
|
| 133 |
Text("4").tag(4)
|
|
| 134 |
Text("5").tag(5)
|
|
| 135 |
} |
|
| 136 |
.pickerStyle( SegmentedPickerStyle() ) |
|
| 137 |
.padding(.horizontal) |
|
| 138 |
} |
|
| 139 |
} |