93 lines
3.6 KiB
Swift
93 lines
3.6 KiB
Swift
//
|
|
// CustomizeView.swift - The view to customize the data shown in forecast views.
|
|
//
|
|
// Created by Marcus Handte on 18.07.22.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct CustomizeView: View {
|
|
|
|
@ObservedObject var state: AppState
|
|
@State var unitSystem: UnitSystem
|
|
@State var temperatureUnit: TemperatureUnit
|
|
@State var precipitation: Bool
|
|
@State var windSpeed: Bool
|
|
@State var cloudCoverage: Bool
|
|
@State var humidity: Bool
|
|
@State var snowDepth: Bool
|
|
@State var pressure: Bool
|
|
|
|
init() {
|
|
self.state = AppState.shared
|
|
self.unitSystem = AppState.shared.unitSystem
|
|
self.temperatureUnit = AppState.shared.temperatureUnit
|
|
self.precipitation = AppState.shared.precipitation
|
|
self.windSpeed = AppState.shared.windSpeed
|
|
self.cloudCoverage = AppState.shared.cloudCoverage
|
|
self.humidity = AppState.shared.humidity
|
|
self.snowDepth = AppState.shared.snowDepth
|
|
self.pressure = AppState.shared.pressure
|
|
}
|
|
|
|
|
|
var body: some View {
|
|
Form {
|
|
Section(header: Text("customize_section_units")) {
|
|
Picker("customize_hint_system", selection: $unitSystem) {
|
|
ForEach([ UnitSystem.si, UnitSystem.imperial, UnitSystem.both], id: \.self) { s in
|
|
Text(TextBindings.getUnitSystem(s))
|
|
}
|
|
}
|
|
Picker("customize_hint_temperature", selection: $temperatureUnit) {
|
|
ForEach([ TemperatureUnit.celsius, TemperatureUnit.fahrenheit, TemperatureUnit.both], id: \.self) { t in
|
|
Text(TextBindings.getTemperatureUnit(t))
|
|
}
|
|
}
|
|
}
|
|
Section(header: Text("customize_section_data")) {
|
|
CustomizeToggleView(image: "icon_raindrops", label: "label_precipitation", enabled: $precipitation)
|
|
CustomizeToggleView(image: "icon_wind_direction", label: "label_wind_speed", enabled: $windSpeed)
|
|
CustomizeToggleView(image: "icon_cloud", label: "label_cloud_coverage", enabled: $cloudCoverage)
|
|
CustomizeToggleView(image: "icon_humidity", label: "label_humidity", enabled: $humidity)
|
|
CustomizeToggleView(image: "icon_snowflake_cold", label: "label_snow_depth", enabled: $snowDepth)
|
|
CustomizeToggleView(image: "icon_barometer", label: "label_pressure", enabled: $pressure)
|
|
}
|
|
}
|
|
.onChange(of: unitSystem, perform: { state.unitSystem = $0 })
|
|
.onChange(of: temperatureUnit, perform: { state.temperatureUnit = $0 })
|
|
.onChange(of: precipitation, perform: { state.precipitation = $0 })
|
|
.onChange(of: windSpeed, perform: { state.windSpeed = $0 })
|
|
.onChange(of: cloudCoverage, perform: { state.cloudCoverage = $0 })
|
|
.onChange(of: humidity, perform: { state.humidity = $0 })
|
|
.onChange(of: snowDepth, perform: { state.snowDepth = $0 })
|
|
.onChange(of: pressure, perform: { state.pressure = $0 })
|
|
.navigationTitle(Text("action_customize"))
|
|
}
|
|
|
|
}
|
|
|
|
struct CustomizeToggleView: View {
|
|
|
|
let image: String
|
|
let label: LocalizedStringKey
|
|
let enabled: Binding<Bool>
|
|
|
|
var body: some View {
|
|
Toggle(isOn: enabled) {
|
|
HStack {
|
|
Image(image)
|
|
Text(label)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct CustomizeView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
NavigationView {
|
|
CustomizeView()
|
|
}
|
|
}
|
|
}
|