| 1 |
// |
|
| 2 |
// MeterSettingsTabView.swift |
|
| 3 |
// USB Meter |
|
| 4 |
// |
|
| 5 | ||
| 6 |
import SwiftUI |
|
| 7 | ||
| 8 |
struct MeterSettingsTabView: View {
|
|
| 9 |
@EnvironmentObject private var meter: Meter |
|
| 10 | ||
| 11 |
let isMacIPadApp: Bool |
|
| 12 |
let onBackToHome: () -> Void |
|
| 13 | ||
| 14 |
@State private var editingName = false |
|
| 15 |
@State private var editingScreenTimeout = false |
|
| 16 |
@State private var editingScreenBrightness = false |
|
| 17 | ||
| 18 |
var body: some View {
|
|
| 19 |
VStack(spacing: 0) {
|
|
| 20 |
if isMacIPadApp {
|
|
| 21 |
settingsMacHeader |
|
| 22 |
} |
|
| 23 |
ScrollView {
|
|
| 24 |
VStack(spacing: 14) {
|
|
| 25 |
settingsCard(title: "Name", tint: meter.color) {
|
|
| 26 |
HStack {
|
|
| 27 |
Spacer() |
|
| 28 |
if !editingName {
|
|
| 29 |
Text(meter.name) |
|
| 30 |
.foregroundColor(.secondary) |
|
| 31 |
} |
|
| 32 |
ChevronView(rotate: $editingName) |
|
| 33 |
} |
|
| 34 |
if editingName {
|
|
| 35 |
EditNameView(editingName: $editingName, newName: meter.name) |
|
| 36 |
} |
|
| 37 |
} |
|
| 38 | ||
| 39 |
if meter.operationalState == .dataIsAvailable && meter.supportsManualTemperatureUnitSelection {
|
|
| 40 |
settingsCard(title: "Meter Temperature Unit", tint: .orange) {
|
|
| 41 |
Text("TC66 temperature is shown as degrees without assuming Celsius or Fahrenheit. Keep this matched to the unit configured on the device so you can interpret the reading correctly.")
|
|
| 42 |
.font(.footnote) |
|
| 43 |
.foregroundColor(.secondary) |
|
| 44 |
Picker("", selection: $meter.tc66TemperatureUnitPreference) {
|
|
| 45 |
ForEach(TemperatureUnitPreference.allCases) { unit in
|
|
| 46 |
Text(unit.title).tag(unit) |
|
| 47 |
} |
|
| 48 |
} |
|
| 49 |
.pickerStyle(SegmentedPickerStyle()) |
|
| 50 |
} |
|
| 51 |
} |
|
| 52 | ||
| 53 |
if meter.operationalState == .dataIsAvailable && meter.model == .TC66C {
|
|
| 54 |
settingsCard(title: "Screen Reporting", tint: .orange) {
|
|
| 55 |
MeterInfoRow(label: "Current Screen", value: "Not Reported") |
|
| 56 |
Text("TC66 is the exception: it does not report the current screen in the payload, so the app keeps this note here instead of showing it on the home screen.")
|
|
| 57 |
.font(.footnote) |
|
| 58 |
.foregroundColor(.secondary) |
|
| 59 |
} |
|
| 60 |
} |
|
| 61 | ||
| 62 |
if meter.operationalState == .dataIsAvailable {
|
|
| 63 |
settingsCard( |
|
| 64 |
title: meter.reportsCurrentScreenIndex ? "Screen Controls" : "Page Controls", |
|
| 65 |
tint: .indigo |
|
| 66 |
) {
|
|
| 67 |
if meter.reportsCurrentScreenIndex {
|
|
| 68 |
Text("Use these controls when you want to change the screen shown on the device without crowding the main meter view.")
|
|
| 69 |
.font(.footnote) |
|
| 70 |
.foregroundColor(.secondary) |
|
| 71 |
} else {
|
|
| 72 |
Text("Use these controls when you want to switch device pages without crowding the main meter view.")
|
|
| 73 |
.font(.footnote) |
|
| 74 |
.foregroundColor(.secondary) |
|
| 75 |
} |
|
| 76 | ||
| 77 |
ControlView(showsHeader: false) |
|
| 78 |
} |
|
| 79 |
} |
|
| 80 | ||
| 81 |
if meter.operationalState == .dataIsAvailable && meter.supportsUMSettings {
|
|
| 82 |
settingsCard(title: "Screen Timeout", tint: .purple) {
|
|
| 83 |
HStack {
|
|
| 84 |
Spacer() |
|
| 85 |
if !editingScreenTimeout {
|
|
| 86 |
Text(meter.screenTimeout > 0 ? "\(meter.screenTimeout) Minutes" : "Off") |
|
| 87 |
.foregroundColor(.secondary) |
|
| 88 |
} |
|
| 89 |
ChevronView(rotate: $editingScreenTimeout) |
|
| 90 |
} |
|
| 91 |
if editingScreenTimeout {
|
|
| 92 |
EditScreenTimeoutView() |
|
| 93 |
} |
|
| 94 |
} |
|
| 95 | ||
| 96 |
settingsCard(title: "Screen Brightness", tint: .yellow) {
|
|
| 97 |
HStack {
|
|
| 98 |
Spacer() |
|
| 99 |
if !editingScreenBrightness {
|
|
| 100 |
Text("\(meter.screenBrightness)")
|
|
| 101 |
.foregroundColor(.secondary) |
|
| 102 |
} |
|
| 103 |
ChevronView(rotate: $editingScreenBrightness) |
|
| 104 |
} |
|
| 105 |
if editingScreenBrightness {
|
|
| 106 |
EditScreenBrightnessView() |
|
| 107 |
} |
|
| 108 |
} |
|
| 109 |
} |
|
| 110 |
} |
|
| 111 |
.padding() |
|
| 112 |
} |
|
| 113 |
.background( |
|
| 114 |
LinearGradient( |
|
| 115 |
colors: [meter.color.opacity(0.14), Color.clear], |
|
| 116 |
startPoint: .topLeading, |
|
| 117 |
endPoint: .bottomTrailing |
|
| 118 |
) |
|
| 119 |
.ignoresSafeArea() |
|
| 120 |
) |
|
| 121 |
} |
|
| 122 |
} |
|
| 123 | ||
| 124 |
private var settingsMacHeader: some View {
|
|
| 125 |
HStack(spacing: 12) {
|
|
| 126 |
Button(action: onBackToHome) {
|
|
| 127 |
HStack(spacing: 4) {
|
|
| 128 |
Image(systemName: "chevron.left") |
|
| 129 |
.font(.body.weight(.semibold)) |
|
| 130 |
Text("Back")
|
|
| 131 |
} |
|
| 132 |
.foregroundColor(.accentColor) |
|
| 133 |
} |
|
| 134 |
.buttonStyle(.plain) |
|
| 135 | ||
| 136 |
Text("Meter Settings")
|
|
| 137 |
.font(.headline) |
|
| 138 |
.lineLimit(1) |
|
| 139 | ||
| 140 |
Spacer() |
|
| 141 | ||
| 142 |
if meter.operationalState > .notPresent {
|
|
| 143 |
RSSIView(RSSI: meter.btSerial.averageRSSI) |
|
| 144 |
.frame(width: 18, height: 18) |
|
| 145 |
} |
|
| 146 |
} |
|
| 147 |
.padding(.horizontal, 16) |
|
| 148 |
.padding(.vertical, 10) |
|
| 149 |
.background( |
|
| 150 |
Rectangle() |
|
| 151 |
.fill(.ultraThinMaterial) |
|
| 152 |
.ignoresSafeArea(edges: .top) |
|
| 153 |
) |
|
| 154 |
.overlay(alignment: .bottom) {
|
|
| 155 |
Rectangle() |
|
| 156 |
.fill(Color.secondary.opacity(0.12)) |
|
| 157 |
.frame(height: 1) |
|
| 158 |
} |
|
| 159 |
} |
|
| 160 | ||
| 161 |
private func settingsCard<Content: View>( |
|
| 162 |
title: String, |
|
| 163 |
tint: Color, |
|
| 164 |
@ViewBuilder content: () -> Content |
|
| 165 |
) -> some View {
|
|
| 166 |
VStack(alignment: .leading, spacing: 12) {
|
|
| 167 |
Text(title) |
|
| 168 |
.font(.headline) |
|
| 169 |
content() |
|
| 170 |
} |
|
| 171 |
.padding(18) |
|
| 172 |
.meterCard(tint: tint, fillOpacity: 0.18, strokeOpacity: 0.24) |
|
| 173 |
} |
|
| 174 |
} |