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

Merge branch 'dev' into Crowdin

Jon B.M пре 2 година
родитељ
комит
49da8eddb7

+ 11 - 0
Core_Data.xcdatamodeld/Core_Data.xcdatamodel/contents

@@ -1,5 +1,16 @@
 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 <model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="22225" systemVersion="22G120" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
+    <entity name="Autosens_" representedClassName="Autosens_" syncable="YES" codeGenerationType="class">
+        <attribute name="newisf" optional="YES" attributeType="Decimal" defaultValueString="0.0"/>
+        <attribute name="ratio" optional="YES" attributeType="Decimal" defaultValueString="0.0"/>
+        <attribute name="timestamp" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
+    </entity>
+    <entity name="Autotune_" representedClassName="Autotune_" syncable="YES" codeGenerationType="class">
+        <attribute name="basalProfile" optional="YES" attributeType="Transformable"/>
+        <attribute name="carbRatio" optional="YES" attributeType="Decimal" defaultValueString="0.0"/>
+        <attribute name="createdAt" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
+        <attribute name="sensitivity" optional="YES" attributeType="Decimal" defaultValueString="0.0"/>
+    </entity>
     <entity name="BGaverages" representedClassName="BGaverages" syncable="YES" codeGenerationType="class">
         <attribute name="average" optional="YES" attributeType="Decimal" defaultValueString="0.0"/>
         <attribute name="average_1" optional="YES" attributeType="Decimal" defaultValueString="0.0"/>

+ 2 - 2
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 {

+ 4 - 3
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)

+ 2 - 2
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) {

+ 22 - 23
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)
             }
         }
 

+ 28 - 28
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)
             }
         }
 

+ 1 - 1
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() {

+ 1 - 1
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")

+ 3 - 3
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):