Jelajahi Sumber

prevent entering more than Max Carbs

Also update color and language of Max Bolus exceeded
Mike Plante 2 tahun lalu
induk
melakukan
9e787618bf

+ 18 - 2
FreeAPS/Sources/Modules/AddCarbs/View/AddCarbsRootView.swift

@@ -118,8 +118,24 @@ extension AddCarbs {
 
                 Section {
                     Button { state.add() }
-                    label: { Text("Save and continue").font(.title3) }
-                        .disabled(state.carbs <= 0 && state.fat <= 0 && state.protein <= 0)
+                    label: {
+                        Text(
+                            state.carbs <= state.maxCarbs ? NSLocalizedString("Save and continue", comment: "") :
+                                NSLocalizedString("Max Carbs of", comment: "")
+                                + " "
+                                + formatter.string(from: state.maxCarbs as NSNumber)!
+                                + NSLocalizedString("g", comment: "The short unit display string for grams")
+                                + " "
+                                + NSLocalizedString("exceeded", comment: "")
+                        ).font(.title3) }
+                        .disabled(
+                            state.carbs > state.maxCarbs
+                                || (state.carbs <= 0 && state.fat <= 0 && state.protein <= 0)
+                        )
+                        .foregroundStyle(
+                            (state.carbs <= 0 && state.fat <= 0 && state.protein <= 0) ? .gray :
+                                state.carbs > state.maxCarbs ? .red : .blue
+                        )
                         .frame(maxWidth: .infinity, alignment: .center)
                 } footer: { Text(state.waitersNotepad().description) }
 

+ 8 - 3
FreeAPS/Sources/Modules/Bolus/View/BolusRootView.swift

@@ -81,15 +81,20 @@ extension Bolus {
                         label: {
                             Text(
                                 state.amount <= state.maxBolus ? NSLocalizedString("Enact bolus", comment: "") :
-                                    NSLocalizedString("Max Bolus exceeded!", comment: "")
-                                    + " (>"
+                                    NSLocalizedString("Max Bolus of", comment: "")
+                                    + " "
                                     + formatter.string(from: state.maxBolus as NSNumber)!
                                     + NSLocalizedString("U", comment: "Insulin unit")
-                                    + ")"
+                                    + " "
+                                    + NSLocalizedString("exceeded", comment: "")
                             ) }
                             .disabled(
                                 state.amount <= 0 || state.amount > state.maxBolus
                             )
+                            .foregroundStyle(
+                                state.amount <= 0 ? .gray :
+                                    state.amount > state.maxBolus ? .red : .blue
+                            )
                     }
                     if waitForSuggestion {
                         Section {