From f8e20d48b10d3c7315acdf536d4ffd271b0269af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20B=20M=C3=A5rtensson?= <53905247+Jon-b-m@users.noreply.github.com> Date: Mon, 12 Aug 2024 12:55:17 +0200 Subject: [PATCH] Move max carbs (#811) (cherry picked from commit 0713f01830bb833aaa20660cbb22d5241bff4c5a) --- .../defaults/freeaps/freeaps_settings.json | 2 +- .../Main/en.lproj/Localizable.strings | 3 +++ .../PreferencesEditorStateModel.swift | 2 ++ .../View/PreferencesEditorRootView.swift | 27 +++++++++++++++++++ .../PumpSettingsEditorStateModel.swift | 4 --- .../View/PumpSettingsEditorRootView.swift | 4 --- 6 files changed, 33 insertions(+), 9 deletions(-) diff --git a/FreeAPS/Resources/json/defaults/freeaps/freeaps_settings.json b/FreeAPS/Resources/json/defaults/freeaps/freeaps_settings.json index b2b9e01ec9..d354f5df67 100644 --- a/FreeAPS/Resources/json/defaults/freeaps/freeaps_settings.json +++ b/FreeAPS/Resources/json/defaults/freeaps/freeaps_settings.json @@ -7,7 +7,7 @@ "units": "mmol/L", "timeCap": 8, "useCalc": true, - "maxCarbs": 350, + "maxCarbs": 200, "birthDate": "0001-01-01T23:00:00.000Z", "displayHR": true, "closedLoop": false, diff --git a/FreeAPS/Sources/Localizations/Main/en.lproj/Localizable.strings b/FreeAPS/Sources/Localizations/Main/en.lproj/Localizable.strings index 6cf67657ff..c33128523d 100644 --- a/FreeAPS/Sources/Localizations/Main/en.lproj/Localizable.strings +++ b/FreeAPS/Sources/Localizations/Main/en.lproj/Localizable.strings @@ -479,6 +479,9 @@ Enact a temp Basal or a temp target */ /* Max setting */ "Max Carbs" = "Max Carbs"; +/* Max carbs description */ +"Maximum amount of carbs (g) you can add each entry" = "Maximum amount of carbs (g) you can add each entry"; + /* */ "Pump Settings" = "Pump Settings"; diff --git a/FreeAPS/Sources/Modules/PreferencesEditor/PreferencesEditorStateModel.swift b/FreeAPS/Sources/Modules/PreferencesEditor/PreferencesEditorStateModel.swift index bf418665a9..7cdff99272 100644 --- a/FreeAPS/Sources/Modules/PreferencesEditor/PreferencesEditorStateModel.swift +++ b/FreeAPS/Sources/Modules/PreferencesEditor/PreferencesEditorStateModel.swift @@ -9,11 +9,13 @@ extension PreferencesEditor { @Published var sections: [FieldSection] = [] @Published var useAlternativeBolusCalc: Bool = false @Published var units: GlucoseUnits = .mmolL + @Published var maxCarbs: Decimal = 200 override func subscribe() { preferences = provider.preferences units = settingsManager.settings.units + subscribeSetting(\.maxCarbs, on: $maxCarbs) { maxCarbs = $0 } subscribeSetting(\.units, on: $unitsIndex.map { $0 == 0 ? GlucoseUnits.mgdL : .mmolL }) { unitsIndex = $0 == .mgdL ? 0 : 1 } didSet: { [weak self] _ in diff --git a/FreeAPS/Sources/Modules/PreferencesEditor/View/PreferencesEditorRootView.swift b/FreeAPS/Sources/Modules/PreferencesEditor/View/PreferencesEditorRootView.swift index 0b25db6fad..b97005b2b3 100644 --- a/FreeAPS/Sources/Modules/PreferencesEditor/View/PreferencesEditorRootView.swift +++ b/FreeAPS/Sources/Modules/PreferencesEditor/View/PreferencesEditorRootView.swift @@ -71,6 +71,11 @@ extension PreferencesEditor { } } } + + // Exceptions. Below a FreeAPS setting added. + if field.displayName == NSLocalizedString("Max COB", comment: "Max COB") { + maxCarbs + } } } } @@ -112,5 +117,27 @@ extension PreferencesEditor { ) } } + + var maxCarbs: some View { + HStack { + ZStack { + Button("", action: { + infoButtonPressed = InfoText( + description: NSLocalizedString( + "Maximum amount of carbs (g) you can add each entry", + comment: "Max carbs description" + ), + oref0Variable: NSLocalizedString("Max Carbs", comment: "Max setting") + ) + }) + Text("Max Carbs") + } + DecimalTextField( + "0", + value: self.$state.maxCarbs, + formatter: formatter + ) + } + } } } diff --git a/FreeAPS/Sources/Modules/PumpSettingsEditor/PumpSettingsEditorStateModel.swift b/FreeAPS/Sources/Modules/PumpSettingsEditor/PumpSettingsEditorStateModel.swift index 8368a36477..ecd77e0f42 100644 --- a/FreeAPS/Sources/Modules/PumpSettingsEditor/PumpSettingsEditorStateModel.swift +++ b/FreeAPS/Sources/Modules/PumpSettingsEditor/PumpSettingsEditorStateModel.swift @@ -5,8 +5,6 @@ extension PumpSettingsEditor { @Published var maxBasal: Decimal = 0.0 @Published var maxBolus: Decimal = 0.0 @Published var dia: Decimal = 0.0 - @Published var maxCarbs: Decimal = 1000 - @Published var syncInProgress = false override func subscribe() { @@ -14,8 +12,6 @@ extension PumpSettingsEditor { maxBasal = settings.maxBasal maxBolus = settings.maxBolus dia = settings.insulinActionCurve - maxCarbs = settingsManager.settings.maxCarbs - subscribeSetting(\.maxCarbs, on: $maxCarbs) { maxCarbs = $0 } } func save() { diff --git a/FreeAPS/Sources/Modules/PumpSettingsEditor/View/PumpSettingsEditorRootView.swift b/FreeAPS/Sources/Modules/PumpSettingsEditor/View/PumpSettingsEditorRootView.swift index 4611097c4c..5bf0884898 100644 --- a/FreeAPS/Sources/Modules/PumpSettingsEditor/View/PumpSettingsEditorRootView.swift +++ b/FreeAPS/Sources/Modules/PumpSettingsEditor/View/PumpSettingsEditorRootView.swift @@ -23,10 +23,6 @@ extension PumpSettingsEditor { Text("Max Bolus") DecimalTextField("U", value: $state.maxBolus, formatter: formatter) } - HStack { - Text("Max Carbs") - DecimalTextField("g", value: $state.maxCarbs, formatter: formatter) - } } Section(header: Text("Duration of Insulin Action")) {