Explorar o código

Phrasing fixes and variable naming cleanup

- Miscellaneous changes
- Variable naming cleanup like "bolusQ" --> bolusQuantity and "noAllowed" --> "notAllowed"
- Phrasing cleanup per recommendations from @MikePlante1 in https://github.com/nightscout/Trio/pull/177
Auggie Fisher hai 1 ano
pai
achega
3558eb8ac4

+ 5 - 5
FreeAPS/Sources/Models/FreeAPSSettings.swift

@@ -2,18 +2,18 @@ import Foundation
 
 enum BolusShortcutLimit: String, JSON, CaseIterable, Identifiable {
     var id: String { rawValue }
-    case noAllowed
+    case notAllowed
     case limitBolusMax
     case limitInsulinSuggestion
 
     var displayName: String {
         switch self {
-        case .noAllowed:
+        case .notAllowed:
             return String(localized: "Not allowed", table: "ShortcutsDetail")
         case .limitBolusMax:
-            return String(localized: "Limit by max bolus", table: "ShortcutsDetail")
+            return String(localized: "Max bolus", table: "ShortcutsDetail")
         case .limitInsulinSuggestion:
-            return String(localized: "Limit by insulin suggestion estimation", table: "ShortcutsDetail")
+            return String(localized: "Insulin recommended", table: "ShortcutsDetail")
         }
     }
 }
@@ -78,7 +78,7 @@ struct FreeAPSSettings: JSON, Equatable {
     var useLiveActivity: Bool = false
     var historyLayout: HistoryLayout = .twoTabs
     var lockScreenView: LockScreenView = .simple
-    var bolusShortcut: BolusShortcutLimit = .noAllowed
+    var bolusShortcut: BolusShortcutLimit = .notAllowed
 }
 
 extension FreeAPSSettings: Decodable {

+ 5 - 5
FreeAPS/Sources/Modules/ShortcutsConfig/ShortcutsConfigStateModel.swift

@@ -9,21 +9,21 @@ import SwiftUI
 extension ShortcutsConfig {
     final class StateModel: BaseStateModel<Provider> {
         @Published var allowBolusByShortcuts: Bool = false
-        @Published var maxBolusByShortcuts: BolusShortcutLimit = .noAllowed
+        @Published var maxBolusByShortcuts: BolusShortcutLimit = .notAllowed
 
         override func subscribe() {
-            // allowBolusByShortcuts = (maxBolusByShortcuts != .noAllowed)
+            // allowBolusByShortcuts = (maxBolusByShortcuts != .notAllowed)
 
             subscribeSetting(\.bolusShortcut, on: $maxBolusByShortcuts) {
-                maxBolusByShortcuts = ($0 == .noAllowed) ? .limitBolusMax : $0
-                allowBolusByShortcuts = ($0 != .noAllowed)
+                maxBolusByShortcuts = ($0 == .notAllowed) ? .limitBolusMax : $0
+                allowBolusByShortcuts = ($0 != .notAllowed)
             }
 
             $allowBolusByShortcuts.receive(on: DispatchQueue.main)
                 .sink { [weak self] value in
                     if !value {
                         // the bolus is not allowed
-                        self?.settingsManager.settings.bolusShortcut = .noAllowed
+                        self?.settingsManager.settings.bolusShortcut = .notAllowed
                     } else {
                         //
                         if let bs = self?.maxBolusByShortcuts {

+ 3 - 3
FreeAPS/Sources/Modules/ShortcutsConfig/View/ShortcutsConfigView.swift

@@ -22,16 +22,16 @@ extension ShortcutsConfig {
 
                 Section(header: Text("Options", tableName: "ShorcutsDetail")) {
                     Toggle(
-                        String(localized: "Allows to bolus with shortcuts", table: "ShortcutsDetail"),
+                        String(localized: "Allow bolusing with shortcuts", table: "ShortcutsDetail"),
                         isOn: $state.allowBolusByShortcuts
                     )
 
                     Picker(
                         selection: $state.maxBolusByShortcuts,
-                        label: Text("Method to limit the bolus amount", tableName: "ShortcutsDetail")
+                        label: Text("Limit bolus from shortcuts to", tableName: "ShortcutsDetail")
                     ) {
                         ForEach(BolusShortcutLimit.allCases) { v in
-                            v != .noAllowed ? Text(v.displayName).tag(v) : nil
+                            v != .notAllowed ? Text(v.displayName).tag(v) : nil
                             // Text(v.displayName).tag(v)
                         }
                     }

+ 28 - 13
FreeAPS/Sources/Shortcuts/Bolus/BolusIntentRequest.swift

@@ -8,29 +8,44 @@ import Foundation
     }
 
     func bolus(_ bolusAmount: Double) async throws -> LocalizedStringResource {
-        var bolusQ: Decimal = 0
+        var bolusQuantity: Decimal = 0
         switch settingsManager.settings.bolusShortcut {
-        case .noAllowed:
+        
+        //Block boluses if they are disabled
+        case .notAllowed:
             return LocalizedStringResource(
-                "Bolusing is not allowed with Shortcuts",
+                "Bolusing is not allowed with shortcuts.",
                 table: "ShortcutsDetail"
             )
+        
+        //Block any bolus attempted if it is larger than the max bolus in settings
         case .limitBolusMax:
-            bolusQ = apsManager
-                .roundBolus(amount: min(settingsManager.pumpSettings.maxBolus, Decimal(bolusAmount)))
+            if Decimal(bolusAmount) > settingsManager.pumpSettings.maxBolus {
+                return LocalizedStringResource(
+                    "The bolus cannot be larger than the pump setting max bolus.",
+                    table: "ShortcutsDetail"
+                )
+            } else {
+                bolusQuantity = apsManager.roundBolus(amount: Decimal(bolusAmount))
+            }
+        
+        //Block any bolus attempted if it is larger than the max bolus in settings
         case .limitInsulinSuggestion:
             let insulinSuggestion = suggestion?.insulinForManualBolus ?? 0
-
-            bolusQ = apsManager
-                .roundBolus(amount: min(
-                    insulinSuggestion * (settingsManager.settings.insulinReqPercentage / 100),
-                    Decimal(bolusAmount)
-                ))
+            if Decimal(bolusAmount) > insulinSuggestion {
+                return LocalizedStringResource(
+                    "The bolus cannot be larger than the suggested insulin.",
+                    table: "ShortcutsDetail"
+                )
+            } else {
+                bolusQuantity = apsManager
+                    .roundBolus(amount: Decimal(bolusAmount))
+            }
         }
 
-        await apsManager.enactBolus(amount: Double(bolusQ), isSMB: false)
+        await apsManager.enactBolus(amount: Double(bolusQuantity), isSMB: false)
         return LocalizedStringResource(
-            "A bolus command of \(bolusQ.formatted()) U of insulin was sent",
+            "A bolus command of \(bolusQuantity.formatted()) U of insulin was sent",
             table: "ShortcutsDetail"
         )
     }