Explorar o código

use menu picker for Disable SMBs override & convert "More Options" to "Change Max SMB Minutes""

It's the only thing `advancedSettings` is used for in oref anyways
Also updates name of ISF/CR menu picker options
Mike Plante hai 1 ano
pai
achega
2a6b16e4af

+ 90 - 85
FreeAPS/Sources/Modules/OverrideConfig/View/AddOverrideForm.swift

@@ -4,7 +4,8 @@ import SwiftUI
 struct AddOverrideForm: View {
     @Environment(\.presentationMode) var presentationMode
     @StateObject var state: OverrideConfig.StateModel
-    @State private var selectedApplyToOption: ApplyToOption = .isfAndCr
+    @State private var selectedIsfCrOption: isfAndOrCrOptions = .isfAndCr
+    @State private var selectedDisableSmbOption: disableSmbOptions = .dontDisable
     @State private var displayPickerDuration: Bool = false
     @State private var displayPickerStart: Bool = false
     @State private var displayPickerEnd: Bool = false
@@ -19,13 +20,19 @@ struct AddOverrideForm: View {
 
     @Environment(\.dismiss) var dismiss
 
-    enum ApplyToOption: String, CaseIterable {
+    enum isfAndOrCrOptions: String, CaseIterable {
         case isfAndCr = "ISF/CR"
         case isf = "ISF"
         case cr = "CR"
         case none = "None"
     }
 
+    enum disableSmbOptions: String, CaseIterable {
+        case dontDisable = "Don't Disable"
+        case disable = "Disable"
+        case disableOnSchedule = "Disable on Schedule"
+    }
+
     var color: LinearGradient {
         colorScheme == .dark ? LinearGradient(
             gradient: Gradient(colors: [
@@ -136,13 +143,13 @@ struct AddOverrideForm: View {
                 )
 
                 // Picker for ISF/CR settings
-                Picker("Apply to", selection: $selectedApplyToOption) {
-                    ForEach(ApplyToOption.allCases, id: \.self) { option in
+                Picker("Apply to", selection: $selectedIsfCrOption) {
+                    ForEach(isfAndOrCrOptions.allCases, id: \.self) { option in
                         Text(option.rawValue).tag(option)
                     }
                 }
                 .pickerStyle(MenuPickerStyle())
-                .onChange(of: selectedApplyToOption) { newValue in
+                .onChange(of: selectedIsfCrOption) { newValue in
                     switch newValue {
                     case .isfAndCr:
                         state.isfAndCr = true
@@ -223,103 +230,101 @@ struct AddOverrideForm: View {
                 }
             }
 
-            Toggle(isOn: $state.advancedSettings) {
-                Text("More Options")
-            }
-            if state.advancedSettings {
-                Toggle(isOn: Binding(
-                    get: { state.smbIsOff },
-                    set: { newValue in
-                        state.smbIsOff = newValue
-                        if newValue {
-                            state.smbIsScheduledOff = false
-                        }
+            VStack {
+                // Picker for ISF/CR settings
+                Picker("Disable SMBs", selection: $selectedDisableSmbOption) {
+                    ForEach(disableSmbOptions.allCases, id: \.self) { option in
+                        Text(option.rawValue).tag(option)
                     }
-                )) {
-                    Text("Disable SMBs")
                 }
-
-                VStack {
-                    Toggle(isOn: Binding(
-                        get: { state.smbIsScheduledOff },
-                        set: { newValue in
-                            state.smbIsScheduledOff = newValue
-                            if newValue {
-                                state.smbIsOff = false
-                            }
-                        }
-                    )) {
-                        Text("Schedule When SMBs Are Disabled")
+                .pickerStyle(MenuPickerStyle())
+                .onChange(of: selectedDisableSmbOption) { newValue in
+                    switch newValue {
+                    case .dontDisable:
+                        state.smbIsOff = false
+                        state.smbIsScheduledOff = false
+                    case .disable:
+                        state.smbIsOff = true
+                        state.smbIsScheduledOff = false
+                    case .disableOnSchedule:
+                        state.smbIsOff = false
+                        state.smbIsScheduledOff = true
                     }
+                }
 
-                    if state.smbIsScheduledOff {
-                        // First Hour SMBs Are Disabled
-                        VStack {
-                            HStack {
-                                Text("From")
-                                Spacer()
+                if state.smbIsScheduledOff {
+                    // First Hour SMBs Are Disabled
+                    VStack {
+                        HStack {
+                            Text("From")
+                            Spacer()
 
-                                Text(
-                                    is24HourFormat() ? format24Hour(Int(truncating: state.start as NSNumber)) + ":00" :
-                                        convertTo12HourFormat(Int(truncating: state.start as NSNumber))
-                                )
-                                .foregroundColor(!displayPickerStart ? .primary : .accentColor)
-                            }
-                            .onTapGesture {
-                                displayPickerStart.toggle()
-                            }
+                            Text(
+                                is24HourFormat() ? format24Hour(Int(truncating: state.start as NSNumber)) + ":00" :
+                                    convertTo12HourFormat(Int(truncating: state.start as NSNumber))
+                            )
+                            .foregroundColor(!displayPickerStart ? .primary : .accentColor)
+                        }
+                        .onTapGesture {
+                            displayPickerStart.toggle()
+                        }
 
-                            if displayPickerStart {
-                                Picker(selection: Binding(
-                                    get: { Int(truncating: state.start as NSNumber) },
-                                    set: { state.start = Decimal($0) }
-                                ), label: Text("")) {
-                                    ForEach(0 ..< 24, id: \.self) { hour in
-                                        Text(is24HourFormat() ? format24Hour(hour) + ":00" : convertTo12HourFormat(hour))
-                                            .tag(hour)
-                                    }
+                        if displayPickerStart {
+                            Picker(selection: Binding(
+                                get: { Int(truncating: state.start as NSNumber) },
+                                set: { state.start = Decimal($0) }
+                            ), label: Text("")) {
+                                ForEach(0 ..< 24, id: \.self) { hour in
+                                    Text(is24HourFormat() ? format24Hour(hour) + ":00" : convertTo12HourFormat(hour))
+                                        .tag(hour)
                                 }
-                                .pickerStyle(WheelPickerStyle())
-                                .frame(maxWidth: .infinity)
                             }
+                            .pickerStyle(WheelPickerStyle())
+                            .frame(maxWidth: .infinity)
                         }
-                        .padding(.top, 10)
+                    }
+                    .padding(.top, 10)
 
-                        // First Hour SMBs Are Resumed
-                        VStack {
-                            HStack {
-                                Text("To")
-                                Spacer()
-                                Text(
-                                    is24HourFormat() ? format24Hour(Int(truncating: state.end as NSNumber)) + ":00" :
-                                        convertTo12HourFormat(Int(truncating: state.end as NSNumber))
-                                )
-                                .foregroundColor(!displayPickerEnd ? .primary : .accentColor)
-                            }
-                            .onTapGesture {
-                                displayPickerEnd.toggle()
-                            }
+                    // First Hour SMBs Are Resumed
+                    VStack {
+                        HStack {
+                            Text("To")
+                            Spacer()
+                            Text(
+                                is24HourFormat() ? format24Hour(Int(truncating: state.end as NSNumber)) + ":00" :
+                                    convertTo12HourFormat(Int(truncating: state.end as NSNumber))
+                            )
+                            .foregroundColor(!displayPickerEnd ? .primary : .accentColor)
+                        }
+                        .onTapGesture {
+                            displayPickerEnd.toggle()
+                        }
 
-                            if displayPickerEnd {
-                                Picker(selection: Binding(
-                                    get: { Int(truncating: state.end as NSNumber) },
-                                    set: { state.end = Decimal($0) }
-                                ), label: Text("")) {
-                                    ForEach(0 ..< 24, id: \.self) { hour in
-                                        Text(is24HourFormat() ? format24Hour(hour) + ":00" : convertTo12HourFormat(hour))
-                                            .tag(hour)
-                                    }
+                        if displayPickerEnd {
+                            Picker(selection: Binding(
+                                get: { Int(truncating: state.end as NSNumber) },
+                                set: { state.end = Decimal($0) }
+                            ), label: Text("")) {
+                                ForEach(0 ..< 24, id: \.self) { hour in
+                                    Text(is24HourFormat() ? format24Hour(hour) + ":00" : convertTo12HourFormat(hour))
+                                        .tag(hour)
                                 }
-                                .pickerStyle(WheelPickerStyle())
-                                .frame(maxWidth: .infinity)
                             }
+                            .pickerStyle(WheelPickerStyle())
+                            .frame(maxWidth: .infinity)
                         }
-                        .padding(.vertical, 10)
                     }
+                    .padding(.vertical, 10)
                 }
+            }
 
-                if !state.smbIsOff {
-                    VStack {
+            if !state.smbIsOff {
+                VStack {
+                    Toggle(isOn: $state.advancedSettings) {
+                        Text("Override Max SMB Minutes")
+                    }
+
+                    if state.advancedSettings {
                         // SMB Minutes Picker
                         VStack {
                             HStack {

+ 112 - 110
FreeAPS/Sources/Modules/OverrideConfig/View/EditOverrideForm.swift

@@ -22,7 +22,8 @@ struct EditOverrideForm: View {
     @State private var cr: Bool
     @State private var smbMinutes: Decimal?
     @State private var uamMinutes: Decimal?
-    @State private var selectedApplyToOption: ApplyToOption
+    @State private var selectedIsfCrOption: isfAndOrCrOptions
+    @State private var selectedDisableSmbOption: disableSmbOptions
 
     @State private var hasChanges = false
     @State private var isEditing = false
@@ -54,21 +55,31 @@ struct EditOverrideForm: View {
         _isfAndCr = State(initialValue: overrideToEdit.isfAndCr)
         _isf = State(initialValue: overrideToEdit.isf)
         _cr = State(initialValue: overrideToEdit.cr)
-        _selectedApplyToOption = State(
-            initialValue: overrideToEdit
-                .isfAndCr ? .isfAndCr : (overrideToEdit.isf ? .isf : (overrideToEdit.cr ? .cr : .none))
+        _selectedIsfCrOption = State(
+            initialValue: overrideToEdit.isfAndCr ? .isfAndCr
+                : (overrideToEdit.isf ? .isf : (overrideToEdit.cr ? .cr : .none))
+        )
+        _selectedDisableSmbOption = State(
+            initialValue: overrideToEdit.smbIsScheduledOff ? .disableOnSchedule
+                : (overrideToEdit.smbIsOff ? .disable : .dontDisable)
         )
         _smbMinutes = State(initialValue: overrideToEdit.smbMinutes?.decimalValue)
         _uamMinutes = State(initialValue: overrideToEdit.uamMinutes?.decimalValue)
     }
 
-    enum ApplyToOption: String, CaseIterable {
+    enum isfAndOrCrOptions: String, CaseIterable {
         case isfAndCr = "ISF/CR"
         case isf = "ISF"
         case cr = "CR"
         case none = "None"
     }
 
+    enum disableSmbOptions: String, CaseIterable {
+        case dontDisable = "Don't Disable"
+        case disable = "Disable"
+        case disableOnSchedule = "Disable on Schedule"
+    }
+
     var color: LinearGradient {
         colorScheme == .dark ? LinearGradient(
             gradient: Gradient(colors: [
@@ -192,13 +203,13 @@ struct EditOverrideForm: View {
                 ).onChange(of: percentage) { _ in hasChanges = true }
 
                 // Picker for ISF/CR settings
-                Picker("Apply to", selection: $selectedApplyToOption) {
-                    ForEach(ApplyToOption.allCases, id: \.self) { option in
+                Picker("Apply to", selection: $selectedIsfCrOption) {
+                    ForEach(isfAndOrCrOptions.allCases, id: \.self) { option in
                         Text(option.rawValue).tag(option)
                     }
                 }
                 .pickerStyle(MenuPickerStyle())
-                .onChange(of: selectedApplyToOption) { newValue in
+                .onChange(of: selectedIsfCrOption) { newValue in
                     switch newValue {
                     case .isfAndCr:
                         isfAndCr = true
@@ -308,129 +319,119 @@ struct EditOverrideForm: View {
                 }
             }
 
-            Toggle(isOn: $advancedSettings) {
-                Text("More Options")
-            }.onChange(of: advancedSettings) { _ in hasChanges = true }
-
-            if advancedSettings {
-                VStack {
-                    Toggle(
-                        isOn: Binding(
-                            get: { smbIsOff },
-                            set: { newValue in
-                                smbIsOff = newValue
-                                if newValue {
-                                    smbIsScheduledOff = false
-                                }
-                                hasChanges = true
-                            }
-                        )
-                    ) {
-                        Text("Disable SMBs")
+            VStack {
+                // Picker for Disable SMB settings
+                Picker("Disable SMBs", selection: $selectedDisableSmbOption) {
+                    ForEach(disableSmbOptions.allCases, id: \.self) { option in
+                        Text(option.rawValue).tag(option)
                     }
-
-                    Divider()
-
-                    Toggle(
-                        isOn: Binding(
-                            get: { smbIsScheduledOff },
-                            set: { newValue in
-                                smbIsScheduledOff = newValue
-                                if newValue {
-                                    smbIsOff = false
-                                }
-                                hasChanges = true
-                            }
-                        )
-                    ) {
-                        Text("Schedule When SMBs Are Disabled")
+                }
+                .pickerStyle(MenuPickerStyle())
+                .onChange(of: selectedDisableSmbOption) { newValue in
+                    switch newValue {
+                    case .dontDisable:
+                        smbIsOff = false
+                        smbIsScheduledOff = false
+                    case .disable:
+                        smbIsOff = true
+                        smbIsScheduledOff = false
+                    case .disableOnSchedule:
+                        smbIsOff = false
+                        smbIsScheduledOff = true
                     }
+                    hasChanges = true
+                }
 
-                    if smbIsScheduledOff {
-                        // First Hour SMBs Are Disabled
-                        VStack {
-                            HStack {
-                                Text("From")
-                                Spacer()
+                if smbIsScheduledOff {
+                    // First Hour SMBs Are Disabled
+                    VStack {
+                        HStack {
+                            Text("From")
+                            Spacer()
 
-                                Text(
-                                    is24HourFormat() ? format24Hour(Int(truncating: start! as NSNumber)) + ":00" :
-                                        convertTo12HourFormat(Int(truncating: start! as NSNumber))
-                                )
-                                .foregroundColor(!displayPickerStart ? .primary : .accentColor)
-                            }
-                            .onTapGesture {
-                                displayPickerStart.toggle()
-                            }
+                            Text(
+                                is24HourFormat() ? format24Hour(Int(truncating: start! as NSNumber)) + ":00" :
+                                    convertTo12HourFormat(Int(truncating: start! as NSNumber))
+                            )
+                            .foregroundColor(!displayPickerStart ? .primary : .accentColor)
+                        }
+                        .onTapGesture {
+                            displayPickerStart.toggle()
+                        }
 
-                            if displayPickerStart {
-                                Picker(selection: Binding(
-                                    get: { Int(truncating: start! as NSNumber) },
-                                    set: {
-                                        start = Decimal($0)
-                                        hasChanges = true
+                        if displayPickerStart {
+                            Picker(selection: Binding(
+                                get: { Int(truncating: start! as NSNumber) },
+                                set: {
+                                    start = Decimal($0)
+                                    hasChanges = true
+                                }
+                            ), label: Text("")) {
+                                if is24HourFormat() {
+                                    ForEach(0 ..< 24, id: \.self) { hour in
+                                        Text(format24Hour(hour) + ":00").tag(hour)
                                     }
-                                ), label: Text("")) {
-                                    if is24HourFormat() {
-                                        ForEach(0 ..< 24, id: \.self) { hour in
-                                            Text(format24Hour(hour) + ":00").tag(hour)
-                                        }
-                                    } else {
-                                        ForEach(0 ..< 24, id: \.self) { hour in
-                                            Text(convertTo12HourFormat(hour)).tag(hour)
-                                        }
+                                } else {
+                                    ForEach(0 ..< 24, id: \.self) { hour in
+                                        Text(convertTo12HourFormat(hour)).tag(hour)
                                     }
                                 }
-                                .pickerStyle(WheelPickerStyle())
-                                .frame(maxWidth: .infinity)
                             }
+                            .pickerStyle(WheelPickerStyle())
+                            .frame(maxWidth: .infinity)
                         }
-                        .padding(.top)
+                    }
+                    .padding(.top)
 
-                        // First Hour SMBs Are Resumed
-                        VStack {
-                            HStack {
-                                Text("To")
-                                Spacer()
+                    // First Hour SMBs Are Resumed
+                    VStack {
+                        HStack {
+                            Text("To")
+                            Spacer()
 
-                                Text(
-                                    is24HourFormat() ? format24Hour(Int(truncating: end! as NSNumber)) + ":00" :
-                                        convertTo12HourFormat(Int(truncating: end! as NSNumber))
-                                )
-                                .foregroundColor(!displayPickerEnd ? .primary : .accentColor)
-                            }
-                            .onTapGesture {
-                                displayPickerEnd.toggle()
-                            }
+                            Text(
+                                is24HourFormat() ? format24Hour(Int(truncating: end! as NSNumber)) + ":00" :
+                                    convertTo12HourFormat(Int(truncating: end! as NSNumber))
+                            )
+                            .foregroundColor(!displayPickerEnd ? .primary : .accentColor)
+                        }
+                        .onTapGesture {
+                            displayPickerEnd.toggle()
+                        }
 
-                            if displayPickerEnd {
-                                Picker(selection: Binding(
-                                    get: { Int(truncating: end! as NSNumber) },
-                                    set: {
-                                        end = Decimal($0)
-                                        hasChanges = true
+                        if displayPickerEnd {
+                            Picker(selection: Binding(
+                                get: { Int(truncating: end! as NSNumber) },
+                                set: {
+                                    end = Decimal($0)
+                                    hasChanges = true
+                                }
+                            ), label: Text("")) {
+                                if is24HourFormat() {
+                                    ForEach(0 ..< 24, id: \.self) { hour in
+                                        Text(format24Hour(hour) + ":00").tag(hour)
                                     }
-                                ), label: Text("")) {
-                                    if is24HourFormat() {
-                                        ForEach(0 ..< 24, id: \.self) { hour in
-                                            Text(format24Hour(hour) + ":00").tag(hour)
-                                        }
-                                    } else {
-                                        ForEach(0 ..< 24, id: \.self) { hour in
-                                            Text(convertTo12HourFormat(hour)).tag(hour)
-                                        }
+                                } else {
+                                    ForEach(0 ..< 24, id: \.self) { hour in
+                                        Text(convertTo12HourFormat(hour)).tag(hour)
                                     }
                                 }
-                                .pickerStyle(WheelPickerStyle())
-                                .frame(maxWidth: .infinity)
                             }
+                            .pickerStyle(WheelPickerStyle())
+                            .frame(maxWidth: .infinity)
                         }
-                        .padding(.top)
                     }
+                    .padding(.top)
                 }
+            }
 
-                if !smbIsOff {
-                    VStack {
+            if !smbIsOff {
+                VStack {
+                    Toggle(isOn: $advancedSettings) {
+                        Text("Change Max SMB Minutes")
+                    }.onChange(of: advancedSettings) { _ in hasChanges = true }
+
+                    if advancedSettings {
                         // SMB Minutes Picker
                         VStack {
                             HStack {
@@ -499,6 +500,7 @@ struct EditOverrideForm: View {
                     }
                 }
             }
+
         }.listRowBackground(Color.chart)
     }