diff --git a/Core_Data.xcdatamodeld/Core_Data.xcdatamodel/contents b/Core_Data.xcdatamodeld/Core_Data.xcdatamodel/contents index fefaa04c7..3a617a7a3 100644 --- a/Core_Data.xcdatamodeld/Core_Data.xcdatamodel/contents +++ b/Core_Data.xcdatamodeld/Core_Data.xcdatamodel/contents @@ -1,5 +1,16 @@ + + + + + + + + + + + diff --git a/FreeAPS/Sources/Modules/AddCarbs/AddCarbsStateModel.swift b/FreeAPS/Sources/Modules/AddCarbs/AddCarbsStateModel.swift index 7decc6441..c10114e6f 100644 --- a/FreeAPS/Sources/Modules/AddCarbs/AddCarbsStateModel.swift +++ b/FreeAPS/Sources/Modules/AddCarbs/AddCarbsStateModel.swift @@ -31,7 +31,7 @@ extension AddCarbs { useFPUconversion = settingsManager.settings.useFPUconversion } - func add() { + func add(_ continue_: Bool, fetch: Bool) { guard carbs > 0 || fat > 0 || protein > 0 else { showModal(for: nil) return @@ -51,7 +51,7 @@ extension AddCarbs { )] carbsStorage.storeCarbs(carbsToStore) - if skipBolus { + if skipBolus, !continue_, !fetch { apsManager.determineBasalSync() showModal(for: nil) } else if carbs > 0 { diff --git a/FreeAPS/Sources/Modules/AddCarbs/View/AddCarbsRootView.swift b/FreeAPS/Sources/Modules/AddCarbs/View/AddCarbsRootView.swift index f432fd6cb..c0b9a028b 100644 --- a/FreeAPS/Sources/Modules/AddCarbs/View/AddCarbsRootView.swift +++ b/FreeAPS/Sources/Modules/AddCarbs/View/AddCarbsRootView.swift @@ -6,6 +6,7 @@ extension AddCarbs { struct RootView: BaseView { let resolver: Resolver let editMode: Bool + let override: Bool @StateObject var state = StateModel() @State var dish: String = "" @State var isPromptPresented = false @@ -115,9 +116,9 @@ extension AddCarbs { } Section { - Button { state.add() } - label: { Text(state.skipBolus ? "Save" : "Continue") } - .disabled(state.carbs <= 0 && state.fat <= 0 && state.protein <= 0) + Button { state.add(override, fetch: editMode) } + label: { Text((state.skipBolus && !override && !editMode) ? "Save" : "Continue") } + .disabled(empty) .frame(maxWidth: .infinity, alignment: .center) }.listRowBackground(!empty ? Color(.systemBlue) : Color(.systemGray4)) .tint(.white) diff --git a/FreeAPS/Sources/Modules/Bolus/BolusStateModel.swift b/FreeAPS/Sources/Modules/Bolus/BolusStateModel.swift index 46c47c72a..cc64987ee 100644 --- a/FreeAPS/Sources/Modules/Bolus/BolusStateModel.swift +++ b/FreeAPS/Sources/Modules/Bolus/BolusStateModel.swift @@ -222,9 +222,9 @@ extension Bolus { } } - func backToCarbsView(complexEntry: Bool, _ id: String) { + func backToCarbsView(complexEntry: Bool, _ id: String, override: Bool) { delete(deleteTwice: complexEntry, id: id) - showModal(for: .addCarbs(editMode: complexEntry)) + showModal(for: .addCarbs(editMode: complexEntry, override: override)) } func delete(deleteTwice: Bool, id: String) { diff --git a/FreeAPS/Sources/Modules/Bolus/View/AlternativeBolusCalcRootView.swift b/FreeAPS/Sources/Modules/Bolus/View/AlternativeBolusCalcRootView.swift index b60a9fc35..7427593dc 100644 --- a/FreeAPS/Sources/Modules/Bolus/View/AlternativeBolusCalcRootView.swift +++ b/FreeAPS/Sources/Modules/Bolus/View/AlternativeBolusCalcRootView.swift @@ -118,27 +118,26 @@ extension Bolus { .onTapGesture { state.amount = state.insulinCalculated } } - if !state.waitForSuggestion { - HStack { - Text("Bolus") - Spacer() - DecimalTextField( - "0", - value: $state.amount, - formatter: formatter, - autofocus: false, - cleanInput: true - ) - Text(exceededMaxBolus ? "😵" : " U").foregroundColor(.secondary) - } - .onChange(of: state.amount) { newValue in - if newValue > state.maxBolus { - exceededMaxBolus = true - } else { - exceededMaxBolus = false - } + HStack { + Text("Bolus") + Spacer() + DecimalTextField( + "0", + value: $state.amount, + formatter: formatter, + autofocus: false, + cleanInput: true + ) + Text(exceededMaxBolus ? "😵" : " U").foregroundColor(.secondary) + } + .onChange(of: state.amount) { newValue in + if newValue > state.maxBolus { + exceededMaxBolus = true + } else { + exceededMaxBolus = false } } + } header: { Text("Bolus") } if state.amount > 0 { @@ -169,7 +168,7 @@ extension Bolus { .navigationBarTitleDisplayMode(.inline) .navigationBarItems( leading: Button { - carbssView() + carbsView() } label: { Text(fetch ? "Back" : "Meal") }, @@ -278,13 +277,13 @@ extension Bolus { ((meal.first?.fat ?? 0) > 0) || ((meal.first?.protein ?? 0) > 0) } - func carbssView() { + func carbsView() { let id_ = meal.first?.id ?? "" if fetch { keepForNextWiew = true - state.backToCarbsView(complexEntry: fetch, id_) + state.backToCarbsView(complexEntry: fetch, id_, override: false) } else { - state.showModal(for: .addCarbs(editMode: false)) + state.backToCarbsView(complexEntry: false, id_, override: true) } } diff --git a/FreeAPS/Sources/Modules/Bolus/View/DefaultBolusCalcRootView.swift b/FreeAPS/Sources/Modules/Bolus/View/DefaultBolusCalcRootView.swift index 166755aaa..3ad2b7b23 100644 --- a/FreeAPS/Sources/Modules/Bolus/View/DefaultBolusCalcRootView.swift +++ b/FreeAPS/Sources/Modules/Bolus/View/DefaultBolusCalcRootView.swift @@ -80,37 +80,37 @@ extension Bolus { else { state.amount = state.insulinRecommended } } }.contentShape(Rectangle()) + } - HStack { - Text("Amount") - Spacer() - DecimalTextField( - "0", - value: $state.amount, - formatter: formatter, - autofocus: true, - cleanInput: true - ) - Text(!(state.amount > state.maxBolus) ? "U" : "😵").foregroundColor(.secondary) - } + HStack { + Text("Amount") + Spacer() + DecimalTextField( + "0", + value: $state.amount, + formatter: formatter, + autofocus: true, + cleanInput: true + ) + Text(!(state.amount > state.maxBolus) ? "U" : "😵").foregroundColor(.secondary) } + } header: { Text("Bolus") } - if !state.waitForSuggestion { - if state.amount > 0 { - Section { - Button { - keepForNextWiew = true - state.add() - } - label: { Text(!(state.amount > state.maxBolus) ? "Enact bolus" : "Max Bolus exceeded!") } - .frame(maxWidth: .infinity, alignment: .center) - .disabled(disabled) - .listRowBackground(!disabled ? Color(.systemBlue) : Color(.systemGray4)) - .tint(.white) + if state.amount > 0 { + Section { + Button { + keepForNextWiew = true + state.add() } + label: { Text(!(state.amount > state.maxBolus) ? "Enact bolus" : "Max Bolus exceeded!") } + .frame(maxWidth: .infinity, alignment: .center) + .disabled(disabled) + .listRowBackground(!disabled ? Color(.systemBlue) : Color(.systemGray4)) + .tint(.white) } } + if state.amount <= 0 { Section { Button { @@ -153,7 +153,7 @@ extension Bolus { .navigationBarTitleDisplayMode(.inline) .navigationBarItems( leading: Button { - carbssView() + carbsView() } label: { Text(fetch ? "Back" : "Meal") }, @@ -185,13 +185,13 @@ extension Bolus { ((meal.first?.fat ?? 0) > 0) || ((meal.first?.protein ?? 0) > 0) } - func carbssView() { + func carbsView() { let id_ = meal.first?.id ?? "" if fetch { keepForNextWiew = true - state.backToCarbsView(complexEntry: fetch, id_) + state.backToCarbsView(complexEntry: fetch, id_, override: false) } else { - state.showModal(for: .addCarbs(editMode: false)) + state.backToCarbsView(complexEntry: false, id_, override: true) } } diff --git a/FreeAPS/Sources/Modules/Home/HomeStateModel.swift b/FreeAPS/Sources/Modules/Home/HomeStateModel.swift index 2075d544b..50d737ead 100644 --- a/FreeAPS/Sources/Modules/Home/HomeStateModel.swift +++ b/FreeAPS/Sources/Modules/Home/HomeStateModel.swift @@ -196,7 +196,7 @@ extension Home { } func addCarbs() { - showModal(for: .addCarbs(editMode: false)) + showModal(for: .addCarbs(editMode: false, override: false)) } func runLoop() { diff --git a/FreeAPS/Sources/Modules/Home/View/HomeRootView.swift b/FreeAPS/Sources/Modules/Home/View/HomeRootView.swift index acc79ac51..ed4c3645f 100644 --- a/FreeAPS/Sources/Modules/Home/View/HomeRootView.swift +++ b/FreeAPS/Sources/Modules/Home/View/HomeRootView.swift @@ -481,7 +481,7 @@ extension Home { Rectangle().fill(Color.gray.opacity(0.3)).frame(height: 50 + geo.safeAreaInsets.bottom) HStack { - Button { state.showModal(for: .addCarbs(editMode: false)) } + Button { state.showModal(for: .addCarbs(editMode: false, override: false)) } label: { ZStack(alignment: Alignment(horizontal: .trailing, vertical: .bottom)) { Image("carbs") diff --git a/FreeAPS/Sources/Router/Screen.swift b/FreeAPS/Sources/Router/Screen.swift index 23f83f4a9..55a634de8 100644 --- a/FreeAPS/Sources/Router/Screen.swift +++ b/FreeAPS/Sources/Router/Screen.swift @@ -14,7 +14,7 @@ enum Screen: Identifiable, Hashable { case crEditor case targetsEditor case preferencesEditor - case addCarbs(editMode: Bool) + case addCarbs(editMode: Bool, override: Bool) case addTempTarget case bolus(waitForSuggestion: Bool, fetch: Bool) case manualTempBasal @@ -65,8 +65,8 @@ extension Screen { TargetsEditor.RootView(resolver: resolver) case .preferencesEditor: PreferencesEditor.RootView(resolver: resolver) - case let .addCarbs(editMode): - AddCarbs.RootView(resolver: resolver, editMode: editMode) + case let .addCarbs(editMode, override): + AddCarbs.RootView(resolver: resolver, editMode: editMode, override: override) case .addTempTarget: AddTempTarget.RootView(resolver: resolver) case let .bolus(waitForSuggestion, fetch):