| 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 {
|
|
| 39 |
VStack(alignment: .leading, spacing: 8) {
|
|
| 40 |
Text("Device Info").fontWeight(.semibold)
|
|
| 41 |
DeviceInfoRow(label: "Advertised Model", value: meter.modelString) |
|
| 42 |
DeviceInfoRow(label: "Displayed Model", value: meter.deviceModelSummary) |
|
| 43 |
DeviceInfoRow(label: "Temperature Unit", value: meter.temperatureUnitDescription) |
|
| 44 |
if meter.modelNumber != 0 {
|
|
| 45 |
DeviceInfoRow(label: "Model Code", value: "\(meter.modelNumber)") |
|
| 46 |
} |
|
| 47 |
if !meter.firmwareVersion.isEmpty {
|
|
| 48 |
DeviceInfoRow(label: "Firmware", value: meter.firmwareVersion) |
|
| 49 |
} |
|
| 50 |
if meter.serialNumber != 0 {
|
|
| 51 |
DeviceInfoRow(label: "Serial", value: "\(meter.serialNumber)") |
|
| 52 |
} |
|
| 53 |
if meter.bootCount != 0 {
|
|
| 54 |
DeviceInfoRow(label: "Boot Count", value: "\(meter.bootCount)") |
|
| 55 |
} |
|
| 56 |
} |
|
| 57 |
.padding() |
|
| 58 |
.background(RoundedRectangle(cornerRadius: 15).foregroundColor(.secondary).opacity(0.1)) |
|
| 59 |
} |
|
| 60 |
if meter.operationalState == .dataIsAvailable && meter.supportsManualTemperatureUnitSelection {
|
|
| 61 |
VStack(alignment: .leading, spacing: 8) {
|
|
| 62 |
Text("Temperature Unit").fontWeight(.semibold)
|
|
| 63 |
Text("TC66 reports temperature using the unit selected on the device. Keep this setting matched to the meter.")
|
|
| 64 |
.font(.footnote) |
|
| 65 |
.foregroundColor(.secondary) |
|
| 66 |
Picker("", selection: $meter.tc66TemperatureUnitPreference) {
|
|
| 67 |
ForEach(TemperatureUnitPreference.allCases) { unit in
|
|
| 68 |
Text(unit.title).tag(unit) |
|
| 69 |
} |
|
| 70 |
} |
|
| 71 |
.pickerStyle(SegmentedPickerStyle()) |
|
| 72 |
} |
|
| 73 |
.padding() |
|
| 74 |
.background(RoundedRectangle(cornerRadius: 15).foregroundColor(.secondary).opacity(0.1)) |
|
| 75 |
} |
|
| 76 |
if meter.operationalState == .dataIsAvailable && meter.supportsUMSettings {
|
|
| 77 |
// MARK: Screen Timeout |
|
| 78 |
// Ar trebui separat enabled/disabled de valorile in minute eventual stocata valoarea in iCloud la dezactivare pentru restaurare |
|
| 79 |
VStack{
|
|
| 80 |
HStack {
|
|
| 81 |
Text ("Screen Timeout").fontWeight(.semibold)
|
|
| 82 |
Spacer() |
|
| 83 |
if !editingScreenTimeout {
|
|
| 84 |
Text ( meter.screenTimeout != 0 ? "\(meter.screenTimeout) Minutes" : "Off" ) |
|
| 85 |
} |
|
| 86 |
ChevronView( rotate: $editingScreenTimeout ) |
|
| 87 |
} |
|
| 88 |
if editingScreenTimeout {
|
|
| 89 |
EditScreenTimeoutView() |
|
| 90 |
} |
|
| 91 |
} |
|
| 92 |
.padding() |
|
| 93 |
.background(RoundedRectangle(cornerRadius: 15).foregroundColor(.secondary).opacity(0.1)) |
|
| 94 |
// MARK: Screen Brightness |
|
| 95 |
VStack{
|
|
| 96 |
HStack {
|
|
| 97 |
Text ("Screen Brightness").fontWeight(.semibold)
|
|
| 98 |
Spacer() |
|
| 99 |
if !editingScreenBrightness {
|
|
| 100 |
Text ( "\(meter.screenBrightness)" ) |
|
| 101 |
} |
|
| 102 |
ChevronView( rotate: $editingScreenBrightness ) |
|
| 103 |
} |
|
| 104 |
if editingScreenBrightness {
|
|
| 105 |
EditScreenBrightnessView() |
|
| 106 |
} |
|
| 107 |
} |
|
| 108 |
.padding() |
|
| 109 |
.background(RoundedRectangle(cornerRadius: 15).foregroundColor(.secondary).opacity(0.1)) |
|
| 110 |
} |
|
| 111 |
} |
|
| 112 |
} |
|
| 113 |
.padding() |
|
| 114 |
.navigationBarTitle("Meter Settings")
|
|
| 115 |
.navigationBarItems( trailing: RSSIView( RSSI: meter.btSerial.RSSI ).frame( width: 24 ) ) |
|
| 116 |
} |
|
| 117 |
} |
|
| 118 | ||
| 119 |
private struct DeviceInfoRow: View {
|
|
| 120 |
let label: String |
|
| 121 |
let value: String |
|
| 122 | ||
| 123 |
var body: some View {
|
|
| 124 |
HStack {
|
|
| 125 |
Text(label) |
|
| 126 |
Spacer() |
|
| 127 |
Text(value) |
|
| 128 |
.foregroundColor(.secondary) |
|
| 129 |
.multilineTextAlignment(.trailing) |
|
| 130 |
} |
|
| 131 |
.font(.footnote) |
|
| 132 |
} |
|
| 133 |
} |
|
| 134 | ||
| 135 |
struct EditNameView: View {
|
|
| 136 | ||
| 137 |
@EnvironmentObject private var meter: Meter |
|
| 138 | ||
| 139 |
@Binding var editingName: Bool |
|
| 140 |
@State var newName: String |
|
| 141 | ||
| 142 |
var body: some View {
|
|
| 143 |
TextField("Name", text: self.$newName, onCommit: {
|
|
| 144 |
self.meter.name = self.newName |
|
| 145 |
self.editingName = false |
|
| 146 |
}) |
|
| 147 |
.textFieldStyle(RoundedBorderTextFieldStyle()) |
|
| 148 |
.lineLimit(1) |
|
| 149 |
.disableAutocorrection(true) |
|
| 150 |
.multilineTextAlignment(.center) |
|
| 151 |
.padding(.horizontal) |
|
| 152 |
} |
|
| 153 |
} |
|
| 154 | ||
| 155 |
struct EditScreenTimeoutView: View {
|
|
| 156 | ||
| 157 |
@EnvironmentObject private var meter: Meter |
|
| 158 | ||
| 159 |
var body: some View {
|
|
| 160 |
Picker("", selection: self.$meter.screenTimeout ) {
|
|
| 161 |
Text("1").tag(1)
|
|
| 162 |
Text("2").tag(2)
|
|
| 163 |
Text("3").tag(3)
|
|
| 164 |
Text("4").tag(4)
|
|
| 165 |
Text("5").tag(5)
|
|
| 166 |
Text("6").tag(6)
|
|
| 167 |
Text("7").tag(7)
|
|
| 168 |
Text("8").tag(8)
|
|
| 169 |
Text("9").tag(9)
|
|
| 170 |
Text("Off").tag(0)
|
|
| 171 |
} |
|
| 172 |
.pickerStyle( SegmentedPickerStyle() ) |
|
| 173 |
.padding(.horizontal) |
|
| 174 |
} |
|
| 175 |
} |
|
| 176 | ||
| 177 |
struct EditScreenBrightnessView: View {
|
|
| 178 | ||
| 179 |
@EnvironmentObject private var meter: Meter |
|
| 180 | ||
| 181 |
var body: some View {
|
|
| 182 |
Picker("", selection: self.$meter.screenBrightness ) {
|
|
| 183 |
Text("0").tag(0)
|
|
| 184 |
Text("1").tag(1)
|
|
| 185 |
Text("2").tag(2)
|
|
| 186 |
Text("3").tag(3)
|
|
| 187 |
Text("4").tag(4)
|
|
| 188 |
Text("5").tag(5)
|
|
| 189 |
} |
|
| 190 |
.pickerStyle( SegmentedPickerStyle() ) |
|
| 191 |
.padding(.horizontal) |
|
| 192 |
} |
|
| 193 |
} |