| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- import SwiftUI
- import Swinject
- struct InfoText: Identifiable {
- var id: String { description }
- let description: String
- let oref0Variable: String
- }
- extension PreferencesEditor {
- struct RootView: BaseView {
- let resolver: Resolver
- @StateObject var state = StateModel()
- @Environment(\.colorScheme) var colorScheme
- var color: LinearGradient {
- colorScheme == .dark ? LinearGradient(
- gradient: Gradient(colors: [
- Color("Background_1"),
- Color("Background_1"),
- Color("Background_2")
- // Color("Background_1")
- ]),
- startPoint: .top,
- endPoint: .bottom
- )
- :
- LinearGradient(
- gradient: Gradient(colors: [Color.gray.opacity(0.1)]),
- startPoint: .top,
- endPoint: .bottom
- )
- }
- private var formatter: NumberFormatter {
- let formatter = NumberFormatter()
- formatter.numberStyle = .decimal
- return formatter
- }
- @State private var infoButtonPressed: InfoText?
- var body: some View {
- Form {
- Section(header: Text("iAPS").textCase(nil)) {
- Picker("Glucose units", selection: $state.unitsIndex) {
- Text("mg/dL").tag(0)
- Text("mmol/L").tag(1)
- }
- }
- ForEach(state.sections.indexed(), id: \.1.id) { sectionIndex, section in
- Section(header: Text(section.displayName)) {
- ForEach(section.fields.indexed(), id: \.1.id) { fieldIndex, field in
- HStack {
- switch field.type {
- case .boolean:
- ZStack {
- Button("", action: {
- infoButtonPressed = InfoText(
- description: field.infoText,
- oref0Variable: field.displayName
- )
- })
- Toggle(isOn: self.$state.sections[sectionIndex].fields[fieldIndex].boolValue) {
- Text(field.displayName)
- }
- }
- case .decimal:
- ZStack {
- Button("", action: {
- infoButtonPressed = InfoText(
- description: field.infoText,
- oref0Variable: field.displayName
- )
- })
- Text(field.displayName)
- }
- DecimalTextField(
- "0",
- value: self.$state.sections[sectionIndex].fields[fieldIndex].decimalValue,
- formatter: formatter
- )
- case .insulinCurve:
- Picker(
- selection: $state.sections[sectionIndex].fields[fieldIndex].insulinCurveValue,
- label: Text(field.displayName)
- ) {
- ForEach(InsulinCurve.allCases) { v in
- Text(v.rawValue).tag(v)
- }
- }
- }
- }
- }
- }
- }
- }
- .scrollContentBackground(.hidden).background(color)
- .onAppear(perform: configureView)
- .navigationTitle("Preferences")
- .navigationBarTitleDisplayMode(.automatic)
- .navigationBarItems(
- trailing:
- Button {
- let lang = Locale.current.languageCode ?? "en"
- if lang == "en" {
- UIApplication.shared.open(
- URL(
- string: "https://openaps.readthedocs.io/en/latest/docs/While%20You%20Wait%20For%20Gear/preferences-and-safety-settings.html"
- )!,
- options: [:],
- completionHandler: nil
- )
- } else {
- UIApplication.shared.open(
- URL(
- string: "https://openaps-readthedocs-io.translate.goog/en/latest/docs/While%20You%20Wait%20For%20Gear/preferences-and-safety-settings.html?_x_tr_sl=en&_x_tr_tl=\(lang)&_x_tr_hl=\(lang)"
- )!,
- options: [:],
- completionHandler: nil
- )
- }
- }
- label: { Image(systemName: "questionmark.circle") }
- )
- .alert(item: $infoButtonPressed) { infoButton in
- Alert(
- title: Text("\(infoButton.oref0Variable)"),
- message: Text("\(infoButton.description)"),
- dismissButton: .default(Text("OK"))
- )
- }
- }
- }
- }
|