Преглед изворни кода

add footer when override percentage is used, and ...

move enums to reduce duplicated code,
shorten placeholders
Mike Plante пре 1 година
родитељ
комит
d702f668da

+ 32 - 25
FreeAPS/Sources/Modules/OverrideConfig/View/AddOverrideForm.swift

@@ -21,19 +21,6 @@ struct AddOverrideForm: View {
 
     @Environment(\.dismiss) var dismiss
 
-    enum IsfAndOrCrOptions: String, CaseIterable {
-        case isfAndCr = "ISF/CR"
-        case isf = "ISF"
-        case cr = "CR"
-        case nothing = "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: [
@@ -92,17 +79,7 @@ struct AddOverrideForm: View {
             .sheet(isPresented: $state.isHelpSheetPresented) {
                 NavigationStack {
                     List {
-                        Text(
-                            "Lorem Ipsum Dolor Sit Amet"
-                        )
-
-                        Text(
-                            "Lorem Ipsum Dolor Sit Amet"
-                        )
-
-                        Text(
-                            "Lorem Ipsum Dolor Sit Amet"
-                        )
+                        Text("Lorem Ipsum Dolor Sit Amet")
                     }
                     .padding(.trailing, 10)
                     .navigationBarTitle("Help", displayMode: .inline)
@@ -178,7 +155,7 @@ struct AddOverrideForm: View {
             }
             .listRowBackground(Color.chart)
 
-            Section {
+            Section(footer: percentageDescription(state.overridePercentage)) {
                 // Percentage Picker
                 HStack {
                     Text("Change Basal Rate by")
@@ -575,6 +552,36 @@ struct AddOverrideForm: View {
     }
 }
 
+enum IsfAndOrCrOptions: String, CaseIterable {
+    case isfAndCr = "ISF/CR"
+    case isf = "ISF"
+    case cr = "CR"
+    case nothing = "None"
+}
+
+enum DisableSmbOptions: String, CaseIterable {
+    case dontDisable = "Don't Disable"
+    case disable = "Disable"
+    case disableOnSchedule = "Disable on Schedule"
+}
+
+func percentageDescription(_ percent: Double) -> Text? {
+    if percent.isNaN || percent == 100 { return nil }
+
+    var description: String = "Insulin doses will be "
+
+    if percent < 100 {
+        description += "decreased by "
+    } else {
+        description += "increased by "
+    }
+
+    let deviationFrom100 = abs(percent - 100)
+    description += String(format: "%.0f% %.", deviationFrom100)
+
+    return Text(description)
+}
+
 // Function to check if the phone is using 24-hour format
 func is24HourFormat() -> Bool {
     let formatter = DateFormatter()

+ 2 - 25
FreeAPS/Sources/Modules/OverrideConfig/View/EditOverrideForm.swift

@@ -65,19 +65,6 @@ struct EditOverrideForm: View {
         _uamMinutes = State(initialValue: overrideToEdit.uamMinutes?.decimalValue)
     }
 
-    enum IsfAndOrCrOptions: String, CaseIterable {
-        case isfAndCr = "ISF/CR"
-        case isf = "ISF"
-        case cr = "CR"
-        case nothing = "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: [
@@ -155,17 +142,7 @@ struct EditOverrideForm: View {
             .sheet(isPresented: $state.isHelpSheetPresented) {
                 NavigationStack {
                     List {
-                        Text(
-                            "Lorem Ipsum Dolor Sit Amet"
-                        )
-
-                        Text(
-                            "Lorem Ipsum Dolor Sit Amet"
-                        )
-
-                        Text(
-                            "Lorem Ipsum Dolor Sit Amet"
-                        )
+                        Text("Lorem Ipsum Dolor Sit Amet")
                     }
                     .padding(.trailing, 10)
                     .navigationBarTitle("Help", displayMode: .inline)
@@ -264,7 +241,7 @@ struct EditOverrideForm: View {
             .listRowBackground(Color.chart)
 
             // Percentage Picker
-            Section {
+            Section(footer: percentageDescription(percentage)) {
                 HStack {
                     Text("Change Basal Rate by")
                     Spacer()