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

Fix example calculations and 'What This Means' sections WIP

Deniz Cengiz пре 1 година
родитељ
комит
4b03aed802

+ 9 - 28
Trio/Sources/Localizations/Main/Localizable.xcstrings

@@ -5953,16 +5953,6 @@
         }
       }
     },
-    "%@ ÷ %@ = %@ units of insulin" : {
-      "localizations" : {
-        "en" : {
-          "stringUnit" : {
-            "state" : "new",
-            "value" : "%1$@ ÷ %2$@ = %3$@ units of insulin"
-          }
-        }
-      }
-    },
     "%@ g" : {
       "localizations" : {
         "bg" : {
@@ -7511,11 +7501,15 @@
     "• A ratio of 10 g/U means 1 unit of insulin covers 10g of carbs" : {
 
     },
-    "• An ISF of 2.8 mmol/L means 1 unit of insulin lowers your BG by 2.8 mmol/L" : {
-
-    },
-    "• An ISF of 50 mg/dL means 1 unit of insulin lowers your BG by 50 mg/dL" : {
-
+    "• An ISF of %@ means 1 U lowers your glucose by %@" : {
+      "localizations" : {
+        "en" : {
+          "stringUnit" : {
+            "state" : "new",
+            "value" : "• An ISF of %1$@ means 1 U lowers your glucose by %2$@"
+          }
+        }
+      }
     },
     "• Basal Rate" : {
       "localizations" : {
@@ -11520,9 +11514,6 @@
         }
       }
     },
-    "• ISF may vary throughout the day" : {
-
-    },
     "• Last Loop Time: Time of the last algorithm run." : {
       "localizations" : {
         "bg" : {
@@ -16915,16 +16906,6 @@
         }
       }
     },
-    "45g ÷ %@ = %@ units of insulin" : {
-      "localizations" : {
-        "en" : {
-          "stringUnit" : {
-            "state" : "new",
-            "value" : "45g ÷ %1$@ = %2$@ units of insulin"
-          }
-        }
-      }
-    },
     "50% is half effect:" : {
       "localizations" : {
         "bg" : {

+ 10 - 11
Trio/Sources/Modules/Onboarding/View/OnboardingSteps/CarbRatioStepView.swift

@@ -55,15 +55,14 @@ struct CarbRatioStepView: View {
 
                 // Example calculation based on first carb ratio
                 if !state.carbRatioItems.isEmpty {
-                    Divider()
-                        .padding(.horizontal)
+                    Spacer(minLength: 20)
 
                     VStack(alignment: .leading, spacing: 8) {
                         Text("Example Calculation")
                             .font(.headline)
                             .padding(.horizontal)
 
-                        VStack(alignment: .leading, spacing: 4) {
+                        VStack(alignment: .leading, spacing: 8) {
                             Text("For 45g of carbs, you would need:")
                                 .font(.subheadline)
                                 .padding(.horizontal)
@@ -74,20 +73,20 @@ struct CarbRatioStepView: View {
                                         .carbRatioRateValues[state.carbRatioItems.first!.rateIndex] as NSNumber
                                 )
                             Text(
-                                "45g ÷ \(formatter.string(from: state.carbRatioRateValues[state.carbRatioItems.first!.rateIndex] as NSNumber) ?? "--") = \(String(format: "%.1f", insulinNeeded)) units of insulin"
+                                "45g ÷ \(formatter.string(from: state.carbRatioRateValues[state.carbRatioItems.first!.rateIndex] as NSNumber) ?? "--") = \(String(format: "%.1f", insulinNeeded))" +
+                                    " " + String(localized: "U")
                             )
                             .font(.system(.body, design: .monospaced))
                             .foregroundColor(.orange)
-                            .padding(.vertical, 8)
-                            .padding(.horizontal, 12)
-                            .frame(maxWidth: .infinity, alignment: .leading)
-                            .background(Color.orange.opacity(0.1))
-                            .cornerRadius(8)
-                            .padding(.horizontal)
+                            .padding()
+                            .frame(maxWidth: .infinity, alignment: .center)
+                            .background(Color.chart.opacity(0.45))
+                            .cornerRadius(10)
                         }
-                        .padding(.vertical, 4)
                     }
 
+                    Spacer(minLength: 20)
+
                     // Information about the carb ratio
                     VStack(alignment: .leading, spacing: 8) {
                         Text("What This Means")

+ 20 - 25
Trio/Sources/Modules/Onboarding/View/OnboardingSteps/InsulinSensitivityStepView.swift

@@ -55,17 +55,16 @@ struct InsulinSensitivityStepView: View {
 
                 // Example calculation based on first ISF
                 if !state.isfItems.isEmpty {
-                    Divider()
-                        .padding(.horizontal)
+                    Spacer(minLength: 20)
 
                     VStack(alignment: .leading, spacing: 8) {
                         Text("Example Calculation")
                             .font(.headline)
                             .padding(.horizontal)
 
-                        VStack(alignment: .leading, spacing: 4) {
+                        VStack(alignment: .leading, spacing: 8) {
                             // Current glucose is 40 mg/dL or 2.2 mmol/L above target
-                            let aboveTarget = state.units == .mgdL ? 40.0 : 2.2
+                            let aboveTarget = state.units == .mgdL ? Decimal(40) : 40.asMmolL
 
                             let isfValue = state.isfRateValues.isEmpty || state.isfItems.isEmpty ?
                                 Double(truncating: state.isf as NSNumber) :
@@ -74,29 +73,29 @@ struct InsulinSensitivityStepView: View {
                                         .isfRateValues[state.isfItems.first!.rateIndex] as NSNumber
                                 )
 
-                            let insulinNeeded = aboveTarget / isfValue
+                            let insulinNeeded = aboveTarget / Decimal(isfValue)
 
                             Text(
-                                "If you are \(numberFormatter.string(from: NSNumber(value: aboveTarget)) ?? "--") \(state.units == .mgdL ? "mg/dL" : "mmol/L") above target:"
+                                "If you are \(numberFormatter.string(from: aboveTarget as NSNumber) ?? "--") \(state.units.rawValue) above target:"
                             )
                             .font(.subheadline)
                             .padding(.horizontal)
 
                             Text(
-                                "\(numberFormatter.string(from: NSNumber(value: aboveTarget)) ?? "--") ÷ \(numberFormatter.string(from: isfValue as NSNumber) ?? "--") = \(String(format: "%.1f", insulinNeeded)) units of insulin"
+                                "\(numberFormatter.string(from: aboveTarget as NSNumber) ?? "--") ÷ \(numberFormatter.string(from: isfValue as NSNumber) ?? "--") = \(String(format: "%.1f", Double(insulinNeeded)))" +
+                                    " " + String(localized: "U")
                             )
                             .font(.system(.body, design: .monospaced))
                             .foregroundColor(.red)
-                            .padding(.vertical, 8)
-                            .padding(.horizontal, 12)
-                            .frame(maxWidth: .infinity, alignment: .leading)
-                            .background(Color.red.opacity(0.1))
-                            .cornerRadius(8)
-                            .padding(.horizontal)
+                            .padding()
+                            .frame(maxWidth: .infinity, alignment: .center)
+                            .background(Color.chart.opacity(0.45))
+                            .cornerRadius(10)
                         }
-                        .padding(.vertical, 4)
                     }
 
+                    Spacer(minLength: 20)
+
                     // Information about ISF
                     VStack(alignment: .leading, spacing: 8) {
                         Text("What This Means")
@@ -104,17 +103,13 @@ struct InsulinSensitivityStepView: View {
                             .padding(.horizontal)
 
                         VStack(alignment: .leading, spacing: 4) {
-                            if state.units == .mgdL {
-                                Text("• An ISF of 50 mg/dL means 1 unit of insulin lowers your BG by 50 mg/dL")
-                                Text("• A lower number means you're more sensitive to insulin")
-                                Text("• A higher number means you're less sensitive to insulin")
-                                Text("• ISF may vary throughout the day")
-                            } else {
-                                Text("• An ISF of 2.8 mmol/L means 1 unit of insulin lowers your BG by 2.8 mmol/L")
-                                Text("• A lower number means you're more sensitive to insulin")
-                                Text("• A higher number means you're less sensitive to insulin")
-                                Text("• ISF may vary throughout the day")
-                            }
+                            let isfValue = "\(state.units == .mgdL ? Decimal(50) : 50.asMmolL)" +
+                                "\(state.units.rawValue)"
+                            Text(
+                                "• An ISF of \(isfValue) means 1 U lowers your glucose by \(isfValue)"
+                            )
+                            Text("• A lower number means you're more sensitive to insulin")
+                            Text("• A higher number means you're less sensitive to insulin")
                         }
                         .font(.caption)
                         .foregroundColor(.secondary)