Meshtastic-Apple/Meshtastic/Views/Settings/UpdateIntervalPicker.swift
2025-10-31 09:08:46 -07:00

57 lines
1.5 KiB
Swift
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
//  UpdateIntervalPicker.swift
//  Meshtastic
//
//  Copyright(c) Garth Vander Houwen 10/4/25.
//
import SwiftUI
struct UpdateIntervalPicker: View {
let config: IntervalConfiguration
let pickerLabel: String
let formatter: DateComponentsFormatter // Make it a stored property
@Binding var selectedInterval: UpdateInterval
private var fixedOptions: [UpdateInterval] {
config.allowedCases
.map { UpdateInterval(from: $0.rawValue) }
}
init(config: IntervalConfiguration, pickerLabel: String, selectedInterval: Binding<UpdateInterval>) {
self.config = config
self.pickerLabel = pickerLabel
self._selectedInterval = selectedInterval
let f = DateComponentsFormatter()
f.unitsStyle = .full
self.formatter = f
}
var body: some View {
VStack(alignment: .leading, spacing: 4) {
Picker(pickerLabel, selection: $selectedInterval) {
ForEach(fixedOptions, id: \.self) { interval in
Text(interval.description)
.tag(interval)
}
}
if isOutOfRange {
let interval: TimeInterval = Double(selectedInterval.intValue)
if let formattedString = formatter.string(from: interval) {
Text("⚠️ The configured value: (\(formattedString)) is not one of the optimized options.")
.font(.caption)
.foregroundColor(.orange)
}
}
}
}
private var isOutOfRange: Bool {
switch selectedInterval.type {
case .manual:
return true
case .fixed(let fixedCase):
return !config.allowedCases.contains(fixedCase)
}
}
}