Kaynağa Gözat

Merge branch 'dev' into Crowdin

Jon B.M 2 yıl önce
ebeveyn
işleme
17f335bff2

+ 1 - 1
FreeAPS/Sources/APS/CGM/LibreTransmitterSource.swift

@@ -72,7 +72,7 @@ extension BaseLibreTransmitterSource: LibreTransmitterManagerDelegate {
         case let .success(newGlucose):
         case let .success(newGlucose):
             let glucose = newGlucose.map { value -> BloodGlucose in
             let glucose = newGlucose.map { value -> BloodGlucose in
                 BloodGlucose(
                 BloodGlucose(
-                    _id: value.syncId,
+                    _id: UUID().uuidString,
                     sgv: Int(value.glucose),
                     sgv: Int(value.glucose),
                     direction: manager.glucoseDisplay?.trendType
                     direction: manager.glucoseDisplay?.trendType
                         .map { .init(trendType: $0) },
                         .map { .init(trendType: $0) },

+ 5 - 3
FreeAPS/Sources/Modules/AddCarbs/AddCarbsStateModel.swift

@@ -12,7 +12,7 @@ extension AddCarbs {
         @Published var protein: Decimal = 0
         @Published var protein: Decimal = 0
         @Published var fat: Decimal = 0
         @Published var fat: Decimal = 0
         @Published var carbsRequired: Decimal?
         @Published var carbsRequired: Decimal?
-        @Published var useFPUconversion: Bool = true
+        @Published var useFPUconversion: Bool = false
         @Published var dish: String = ""
         @Published var dish: String = ""
         @Published var selection: Presets?
         @Published var selection: Presets?
         @Published var summation: [String] = []
         @Published var summation: [String] = []
@@ -20,13 +20,15 @@ extension AddCarbs {
         @Published var note: String = ""
         @Published var note: String = ""
         @Published var id_: String = ""
         @Published var id_: String = ""
         @Published var summary: String = ""
         @Published var summary: String = ""
+        @Published var skipBolus: Bool = false
 
 
         let coredataContext = CoreDataStack.shared.persistentContainer.viewContext
         let coredataContext = CoreDataStack.shared.persistentContainer.viewContext
 
 
         override func subscribe() {
         override func subscribe() {
-            subscribeSetting(\.useFPUconversion, on: $useFPUconversion) { useFPUconversion = $0 }
             carbsRequired = provider.suggestion?.carbsReq
             carbsRequired = provider.suggestion?.carbsReq
             maxCarbs = settings.settings.maxCarbs
             maxCarbs = settings.settings.maxCarbs
+            skipBolus = settingsManager.settings.skipBolusScreenAfterCarbs
+            useFPUconversion = settingsManager.settings.useFPUconversion
         }
         }
 
 
         func add() {
         func add() {
@@ -49,7 +51,7 @@ extension AddCarbs {
             )]
             )]
             carbsStorage.storeCarbs(carbsToStore)
             carbsStorage.storeCarbs(carbsToStore)
 
 
-            if settingsManager.settings.skipBolusScreenAfterCarbs {
+            if skipBolus {
                 apsManager.determineBasalSync()
                 apsManager.determineBasalSync()
                 showModal(for: nil)
                 showModal(for: nil)
             } else if carbs > 0 {
             } else if carbs > 0 {

+ 96 - 119
FreeAPS/Sources/Modules/AddCarbs/View/AddCarbsRootView.swift

@@ -63,71 +63,24 @@ extension AddCarbs {
                                 .controlSize(.mini)
                                 .controlSize(.mini)
                         }
                         }
                     }.focused($isFocused)
                     }.focused($isFocused)
-                    HStack {
-                        Button {
-                            state.useFPUconversion.toggle()
+                        .popover(isPresented: $isPromptPresented) {
+                            presetPopover
                         }
                         }
-                        label: {
-                            Text(
-                                state
-                                    .useFPUconversion ? NSLocalizedString("Hide Fat & Protein", comment: "") :
-                                    NSLocalizedString("Fat & Protein", comment: "")
-                            ) }
-                            .controlSize(.mini)
-                            .buttonStyle(BorderlessButtonStyle())
-                        Button {
-                            isPromptPresented = true
-                        }
-                        label: { Text("Save as Preset") }
-                            .frame(maxWidth: .infinity, alignment: .trailing)
-                            .controlSize(.mini)
-                            .buttonStyle(BorderlessButtonStyle())
-                            .foregroundColor(
-                                (state.carbs <= 0 && state.fat <= 0 && state.protein <= 0) ||
-                                    (
-                                        (((state.selection?.carbs ?? 0) as NSDecimalNumber) as Decimal) == state
-                                            .carbs && (((state.selection?.fat ?? 0) as NSDecimalNumber) as Decimal) == state
-                                            .fat && (((state.selection?.protein ?? 0) as NSDecimalNumber) as Decimal) ==
-                                            state
-                                            .protein
-                                    ) ? .secondary : .orange
-                            )
-                            .disabled(
-                                (state.carbs <= 0 && state.fat <= 0 && state.protein <= 0) ||
-                                    (
-                                        (((state.selection?.carbs ?? 0) as NSDecimalNumber) as Decimal) == state
-                                            .carbs && (((state.selection?.fat ?? 0) as NSDecimalNumber) as Decimal) == state
-                                            .fat && (((state.selection?.protein ?? 0) as NSDecimalNumber) as Decimal) == state
-                                            .protein
-                                    )
-                            )
-                    }
-                    .popover(isPresented: $isPromptPresented) {
-                        presetPopover
-                    }
-                }
-
-                if state.useFPUconversion {
-                    Section {
-                        mealPresets
-                    }
                 }
                 }
 
 
                 Section {
                 Section {
-                    DatePicker("Date", selection: $state.date)
+                    mealPresets
                 }
                 }
 
 
                 Section {
                 Section {
                     Button { state.add() }
                     Button { state.add() }
-                    label: { Text(state.carbs > 0 ? "Continue" : "Save") }
+                    label: { Text(state.skipBolus ? "Save" : "Continue") }
                         .disabled(state.carbs <= 0 && state.fat <= 0 && state.protein <= 0)
                         .disabled(state.carbs <= 0 && state.fat <= 0 && state.protein <= 0)
                         .frame(maxWidth: .infinity, alignment: .center)
                         .frame(maxWidth: .infinity, alignment: .center)
                 } footer: { Text(state.waitersNotepad().description) }
                 } footer: { Text(state.waitersNotepad().description) }
 
 
-                if !state.useFPUconversion {
-                    Section {
-                        mealPresets
-                    }
+                Section {
+                    DatePicker("Date", selection: $state.date)
                 }
                 }
             }
             }
             .onAppear {
             .onAppear {
@@ -135,7 +88,7 @@ extension AddCarbs {
                     state.loadEntries(editMode)
                     state.loadEntries(editMode)
                 }
                 }
             }
             }
-            .navigationTitle("Add Meals")
+            .navigationTitle("Add Meal")
             .navigationBarTitleDisplayMode(.inline)
             .navigationBarTitleDisplayMode(.inline)
             .navigationBarItems(leading: Button("Close", action: state.hideModal))
             .navigationBarItems(leading: Button("Close", action: state.hideModal))
         }
         }
@@ -168,16 +121,36 @@ extension AddCarbs {
             }
             }
         }
         }
 
 
+        var notEmpty: Bool {
+            state.carbs > 0 || state.protein > 0 || state.fat > 0
+        }
+
         var mealPresets: some View {
         var mealPresets: some View {
             Section {
             Section {
-                VStack {
-                    Picker("Meal Presets", selection: $state.selection) {
-                        Text("Empty").tag(nil as Presets?)
+                HStack {
+                    Button {
+                        isPromptPresented = true
+                    }
+                    label: { Text("Save as Preset") }
+                        .buttonStyle(BorderlessButtonStyle())
+                        .disabled(
+                            !notEmpty ||
+                                (
+                                    (((state.selection?.carbs ?? 0) as NSDecimalNumber) as Decimal) == state
+                                        .carbs && (((state.selection?.fat ?? 0) as NSDecimalNumber) as Decimal) == state
+                                        .fat && (((state.selection?.protein ?? 0) as NSDecimalNumber) as Decimal) == state
+                                        .protein
+                                )
+                        )
+
+                    Picker("Select a Preset", selection: $state.selection) {
+                        Text("Presets").tag(nil as Presets?)
                         ForEach(carbPresets, id: \.self) { (preset: Presets) in
                         ForEach(carbPresets, id: \.self) { (preset: Presets) in
                             Text(preset.dish ?? "").tag(preset as Presets?)
                             Text(preset.dish ?? "").tag(preset as Presets?)
                         }
                         }
                     }
                     }
-                    .pickerStyle(.automatic)
+                    .labelsHidden()
+                    .frame(maxWidth: .infinity, alignment: .trailing)
                     ._onBindingChange($state.selection) { _ in
                     ._onBindingChange($state.selection) { _ in
                         state.carbs += ((state.selection?.carbs ?? 0) as NSDecimalNumber) as Decimal
                         state.carbs += ((state.selection?.carbs ?? 0) as NSDecimalNumber) as Decimal
                         state.fat += ((state.selection?.fat ?? 0) as NSDecimalNumber) as Decimal
                         state.fat += ((state.selection?.fat ?? 0) as NSDecimalNumber) as Decimal
@@ -185,80 +158,84 @@ extension AddCarbs {
                         state.addToSummation()
                         state.addToSummation()
                     }
                     }
                 }
                 }
-                HStack {
-                    Button("Delete Preset") {
-                        showAlert.toggle()
-                    }
-                    .disabled(state.selection == nil)
-                    .accentColor(.orange)
-                    .buttonStyle(BorderlessButtonStyle())
-                    .alert(
-                        "Delete preset '\(state.selection?.dish ?? "")'?",
-                        isPresented: $showAlert,
-                        actions: {
-                            Button("No", role: .cancel) {}
-                            Button("Yes", role: .destructive) {
-                                state.deletePreset()
 
 
-                                state.carbs += ((state.selection?.carbs ?? 0) as NSDecimalNumber) as Decimal
-                                state.fat += ((state.selection?.fat ?? 0) as NSDecimalNumber) as Decimal
-                                state.protein += ((state.selection?.protein ?? 0) as NSDecimalNumber) as Decimal
+                if state.selection != nil {
+                    HStack {
+                        Button("Delete Preset") {
+                            showAlert.toggle()
+                        }
+                        .disabled(state.selection == nil)
+                        .tint(.orange)
+                        .buttonStyle(BorderlessButtonStyle())
+                        .alert(
+                            "Delete preset '\(state.selection?.dish ?? "")'?",
+                            isPresented: $showAlert,
+                            actions: {
+                                Button("No", role: .cancel) {}
+                                Button("Yes", role: .destructive) {
+                                    state.deletePreset()
 
 
-                                state.addPresetToNewMeal()
+                                    state.carbs += ((state.selection?.carbs ?? 0) as NSDecimalNumber) as Decimal
+                                    state.fat += ((state.selection?.fat ?? 0) as NSDecimalNumber) as Decimal
+                                    state.protein += ((state.selection?.protein ?? 0) as NSDecimalNumber) as Decimal
+
+                                    state.addPresetToNewMeal()
+                                }
                             }
                             }
-                        }
-                    )
-                    Button {
-                        if state.carbs != 0,
-                           (state.carbs - (((state.selection?.carbs ?? 0) as NSDecimalNumber) as Decimal) as Decimal) >= 0
-                        {
-                            state.carbs -= (((state.selection?.carbs ?? 0) as NSDecimalNumber) as Decimal)
-                        } else { state.carbs = 0 }
+                        )
+                        Button {
+                            if state.carbs != 0,
+                               (state.carbs - (((state.selection?.carbs ?? 0) as NSDecimalNumber) as Decimal) as Decimal) >= 0
+                            {
+                                state.carbs -= (((state.selection?.carbs ?? 0) as NSDecimalNumber) as Decimal)
+                            } else { state.carbs = 0 }
 
 
-                        if state.fat != 0,
-                           (state.fat - (((state.selection?.fat ?? 0) as NSDecimalNumber) as Decimal) as Decimal) >= 0
-                        {
-                            state.fat -= (((state.selection?.fat ?? 0) as NSDecimalNumber) as Decimal)
-                        } else { state.fat = 0 }
+                            if state.fat != 0,
+                               (state.fat - (((state.selection?.fat ?? 0) as NSDecimalNumber) as Decimal) as Decimal) >= 0
+                            {
+                                state.fat -= (((state.selection?.fat ?? 0) as NSDecimalNumber) as Decimal)
+                            } else { state.fat = 0 }
 
 
-                        if state.protein != 0,
-                           (state.protein - (((state.selection?.protein ?? 0) as NSDecimalNumber) as Decimal) as Decimal) >= 0
-                        {
-                            state.protein -= (((state.selection?.protein ?? 0) as NSDecimalNumber) as Decimal)
-                        } else { state.protein = 0 }
+                            if state.protein != 0,
+                               (state.protein - (((state.selection?.protein ?? 0) as NSDecimalNumber) as Decimal) as Decimal) >= 0
+                            {
+                                state.protein -= (((state.selection?.protein ?? 0) as NSDecimalNumber) as Decimal)
+                            } else { state.protein = 0 }
 
 
-                        state.removePresetFromNewMeal()
-                        if state.carbs == 0, state.fat == 0, state.protein == 0 { state.summation = [] }
-                    }
-                    label: { Text("[ -1 ]") }
-                        .disabled(
-                            state
-                                .selection == nil ||
-                                (
-                                    !state.summation.contains(state.selection?.dish ?? "") && (state.selection?.dish ?? "") != ""
-                                )
-                        )
-                        .buttonStyle(BorderlessButtonStyle())
-                        .frame(maxWidth: .infinity, alignment: .trailing)
-                        .accentColor(.minus)
-                    Button {
-                        state.carbs += ((state.selection?.carbs ?? 0) as NSDecimalNumber) as Decimal
-                        state.fat += ((state.selection?.fat ?? 0) as NSDecimalNumber) as Decimal
-                        state.protein += ((state.selection?.protein ?? 0) as NSDecimalNumber) as Decimal
+                            state.removePresetFromNewMeal()
+                            if state.carbs == 0, state.fat == 0, state.protein == 0 { state.summation = [] }
+                        }
+                        label: { Text("[ -1 ]") }
+                            .disabled(
+                                state
+                                    .selection == nil ||
+                                    (
+                                        !state.summation
+                                            .contains(state.selection?.dish ?? "") && (state.selection?.dish ?? "") != ""
+                                    )
+                            )
+                            .buttonStyle(BorderlessButtonStyle())
+                            .frame(maxWidth: .infinity, alignment: .trailing)
+                            .tint(.minus)
+                        Button {
+                            state.carbs += ((state.selection?.carbs ?? 0) as NSDecimalNumber) as Decimal
+                            state.fat += ((state.selection?.fat ?? 0) as NSDecimalNumber) as Decimal
+                            state.protein += ((state.selection?.protein ?? 0) as NSDecimalNumber) as Decimal
 
 
-                        state.addPresetToNewMeal()
+                            state.addPresetToNewMeal()
+                        }
+                        label: { Text("[ +1 ]") }
+                            .disabled(state.selection == nil)
+                            .buttonStyle(BorderlessButtonStyle())
+                            .tint(.blue)
                     }
                     }
-                    label: { Text("[ +1 ]") }
-                        .disabled(state.selection == nil)
-                        .buttonStyle(BorderlessButtonStyle())
-                        .accentColor(.blue)
                 }
                 }
             }
             }
         }
         }
 
 
         @ViewBuilder private func proteinAndFat() -> some View {
         @ViewBuilder private func proteinAndFat() -> some View {
             HStack {
             HStack {
-                Text("Fat").foregroundColor(.orange) // .fontWeight(.thin)
+                Text("Fat").foregroundColor(.orange)
                 Spacer()
                 Spacer()
                 DecimalTextField(
                 DecimalTextField(
                     "0",
                     "0",
@@ -270,7 +247,7 @@ extension AddCarbs {
                 Text("grams").foregroundColor(.secondary)
                 Text("grams").foregroundColor(.secondary)
             }
             }
             HStack {
             HStack {
-                Text("Protein").foregroundColor(.red) // .fontWeight(.thin)
+                Text("Protein").foregroundColor(.red)
                 Spacer()
                 Spacer()
                 DecimalTextField(
                 DecimalTextField(
                     "0",
                     "0",

+ 1 - 0
FreeAPS/Sources/Modules/Bolus/BolusDataFlow.swift

@@ -5,4 +5,5 @@ enum Bolus {
 protocol BolusProvider: Provider {
 protocol BolusProvider: Provider {
     var suggestion: Suggestion? { get }
     var suggestion: Suggestion? { get }
     func pumpSettings() -> PumpSettings
     func pumpSettings() -> PumpSettings
+    func fetchGlucose() -> [Readings]
 }
 }

+ 19 - 0
FreeAPS/Sources/Modules/Bolus/BolusProvider.swift

@@ -1,5 +1,9 @@
+import CoreData
+
 extension Bolus {
 extension Bolus {
     final class Provider: BaseProvider, BolusProvider {
     final class Provider: BaseProvider, BolusProvider {
+        let coredataContext = CoreDataStack.shared.persistentContainer.viewContext
+
         var suggestion: Suggestion? {
         var suggestion: Suggestion? {
             storage.retrieve(OpenAPS.Enact.suggested, as: Suggestion.self)
             storage.retrieve(OpenAPS.Enact.suggested, as: Suggestion.self)
         }
         }
@@ -9,5 +13,20 @@ extension Bolus {
                 ?? PumpSettings(from: OpenAPS.defaults(for: OpenAPS.Settings.settings))
                 ?? PumpSettings(from: OpenAPS.defaults(for: OpenAPS.Settings.settings))
                 ?? PumpSettings(insulinActionCurve: 6, maxBolus: 10, maxBasal: 2)
                 ?? PumpSettings(insulinActionCurve: 6, maxBolus: 10, maxBasal: 2)
         }
         }
+
+        func fetchGlucose() -> [Readings] {
+            var fetchGlucose = [Readings]()
+            coredataContext.performAndWait {
+                let requestReadings = Readings.fetchRequest() as NSFetchRequest<Readings>
+                let sort = NSSortDescriptor(key: "date", ascending: true)
+                requestReadings.sortDescriptors = [sort]
+                requestReadings.predicate = NSPredicate(
+                    format: "glucose > 0 AND date > %@",
+                    Date().addingTimeInterval(-1.hours.timeInterval) as NSDate
+                )
+                try? fetchGlucose = self.coredataContext.fetch(requestReadings)
+            }
+            return fetchGlucose
+        }
     }
     }
 }
 }

+ 6 - 4
FreeAPS/Sources/Modules/Bolus/BolusStateModel.swift

@@ -1,4 +1,5 @@
 
 
+import CoreData
 import LoopKit
 import LoopKit
 import SwiftUI
 import SwiftUI
 import Swinject
 import Swinject
@@ -10,10 +11,11 @@ extension Bolus {
         @Injected() var broadcaster: Broadcaster!
         @Injected() var broadcaster: Broadcaster!
         @Injected() var pumpHistoryStorage: PumpHistoryStorage!
         @Injected() var pumpHistoryStorage: PumpHistoryStorage!
         // added for bolus calculator
         // added for bolus calculator
-        @Injected() var glucoseStorage: GlucoseStorage!
         @Injected() var settings: SettingsManager!
         @Injected() var settings: SettingsManager!
         @Injected() var nsManager: NightscoutManager!
         @Injected() var nsManager: NightscoutManager!
 
 
+        let coredataContext = CoreDataStack.shared.persistentContainer.viewContext
+
         @Published var suggestion: Suggestion?
         @Published var suggestion: Suggestion?
         @Published var amount: Decimal = 0
         @Published var amount: Decimal = 0
         @Published var insulinRecommended: Decimal = 0
         @Published var insulinRecommended: Decimal = 0
@@ -94,11 +96,11 @@ extension Bolus {
         }
         }
 
 
         func getDeltaBG() {
         func getDeltaBG() {
-            let glucose = glucoseStorage.recent()
+            let glucose = provider.fetchGlucose()
             guard glucose.count >= 3 else { return }
             guard glucose.count >= 3 else { return }
-            let lastGlucose = glucose.last!
+            let lastGlucose = glucose.last?.glucose ?? 0
             let thirdLastGlucose = glucose[glucose.count - 3]
             let thirdLastGlucose = glucose[glucose.count - 3]
-            let delta = Decimal(lastGlucose.glucose!) - Decimal(thirdLastGlucose.glucose!)
+            let delta = Decimal(lastGlucose) - Decimal(thirdLastGlucose.glucose)
             deltaBG = delta
             deltaBG = delta
         }
         }
 
 

+ 7 - 6
FreeAPS/Sources/Modules/Bolus/View/AlternativeBolusCalcRootView.swift

@@ -1,4 +1,3 @@
-import Charts
 import CoreData
 import CoreData
 import SwiftUI
 import SwiftUI
 import Swinject
 import Swinject
@@ -159,12 +158,14 @@ extension Bolus {
                             )
                             )
                     }
                     }
                 }
                 }
-                Section {
-                    Button {
-                        keepForNextWiew = true
-                        state.showModal(for: nil)
+                if state.amount <= 0 {
+                    Section {
+                        Button {
+                            keepForNextWiew = true
+                            state.showModal(for: nil)
+                        }
+                        label: { Text("Continue without bolus") }.frame(maxWidth: .infinity, alignment: .center)
                     }
                     }
-                    label: { Text("Continue without bolus") }.frame(maxWidth: .infinity, alignment: .center)
                 }
                 }
             }
             }
             .blur(radius: showInfo ? 3 : 0)
             .blur(radius: showInfo ? 3 : 0)

+ 1 - 1
FreeAPS/Sources/Modules/Bolus/View/DefaultBolusCalcRootView.swift

@@ -146,7 +146,7 @@ extension Bolus {
                                 )
                                 )
                         }
                         }
                     }
                     }
-                    if waitForSuggestion {
+                    if state.amount <= 0 {
                         Section {
                         Section {
                             Button {
                             Button {
                                 keepForNextWiew = true
                                 keepForNextWiew = true

+ 2 - 1
FreeAPS/Sources/Modules/BolusCalculatorConfig/BolusCalculatorStateModel.swift

@@ -6,7 +6,7 @@ extension BolusCalculatorConfig {
         @Published var useCalc: Bool = false
         @Published var useCalc: Bool = false
         @Published var fattyMeals: Bool = false
         @Published var fattyMeals: Bool = false
         @Published var fattyMealFactor: Decimal = 0
         @Published var fattyMealFactor: Decimal = 0
-
+        @Published var insulinReqPercentage: Decimal = 70
         override func subscribe() {
         override func subscribe() {
             subscribeSetting(\.overrideFactor, on: $overrideFactor, initial: {
             subscribeSetting(\.overrideFactor, on: $overrideFactor, initial: {
                 let value = max(min($0, 1.2), 0.1)
                 let value = max(min($0, 1.2), 0.1)
@@ -22,6 +22,7 @@ extension BolusCalculatorConfig {
             }, map: {
             }, map: {
                 $0
                 $0
             })
             })
+            subscribeSetting(\.insulinReqPercentage, on: $insulinReqPercentage) { insulinReqPercentage = $0 }
         }
         }
     }
     }
 }
 }

Dosya farkı çok büyük olduğundan ihmal edildi
+ 39 - 21
FreeAPS/Sources/Modules/BolusCalculatorConfig/View/BolusCalculatorConfigRootView.swift


+ 2 - 3
FreeAPS/Sources/Modules/PreferencesEditor/PreferencesEditorStateModel.swift

@@ -5,17 +5,16 @@ extension PreferencesEditor {
     final class StateModel: BaseStateModel<Provider>, PreferencesSettable { private(set) var preferences = Preferences()
     final class StateModel: BaseStateModel<Provider>, PreferencesSettable { private(set) var preferences = Preferences()
         @Published var unitsIndex = 1
         @Published var unitsIndex = 1
         @Published var allowAnnouncements = false
         @Published var allowAnnouncements = false
-        @Published var insulinReqPercentage: Decimal = 70
         @Published var skipBolusScreenAfterCarbs = false
         @Published var skipBolusScreenAfterCarbs = false
         @Published var sections: [FieldSection] = []
         @Published var sections: [FieldSection] = []
         @Published var useAlternativeBolusCalc: Bool = false
         @Published var useAlternativeBolusCalc: Bool = false
+        @Published var units: GlucoseUnits = .mmolL
 
 
         override func subscribe() {
         override func subscribe() {
             preferences = provider.preferences
             preferences = provider.preferences
             useAlternativeBolusCalc = settingsManager.settings.useCalc
             useAlternativeBolusCalc = settingsManager.settings.useCalc
+            units = settingsManager.settings.units
             subscribeSetting(\.allowAnnouncements, on: $allowAnnouncements) { allowAnnouncements = $0 }
             subscribeSetting(\.allowAnnouncements, on: $allowAnnouncements) { allowAnnouncements = $0 }
-            subscribeSetting(\.insulinReqPercentage, on: $insulinReqPercentage) { insulinReqPercentage = $0 }
-            subscribeSetting(\.skipBolusScreenAfterCarbs, on: $skipBolusScreenAfterCarbs) { skipBolusScreenAfterCarbs = $0 }
 
 
             subscribeSetting(\.units, on: $unitsIndex.map { $0 == 0 ? GlucoseUnits.mgdL : .mmolL }) {
             subscribeSetting(\.units, on: $unitsIndex.map { $0 == 0 ? GlucoseUnits.mgdL : .mmolL }) {
                 unitsIndex = $0 == .mgdL ? 0 : 1
                 unitsIndex = $0 == .mgdL ? 0 : 1

+ 0 - 9
FreeAPS/Sources/Modules/PreferencesEditor/View/PreferencesEditorRootView.swift

@@ -29,15 +29,6 @@ extension PreferencesEditor {
                     }
                     }
 
 
                     Toggle("Remote control", isOn: $state.allowAnnouncements)
                     Toggle("Remote control", isOn: $state.allowAnnouncements)
-
-                    if !state.useAlternativeBolusCalc {
-                        HStack {
-                            Text("Recommended Bolus Percentage")
-                            DecimalTextField("", value: $state.insulinReqPercentage, formatter: formatter)
-                        }
-                    }
-
-                    Toggle("Skip Bolus screen after carbs", isOn: $state.skipBolusScreenAfterCarbs)
                 }
                 }
 
 
                 ForEach(state.sections.indexed(), id: \.1.id) { sectionIndex, section in
                 ForEach(state.sections.indexed(), id: \.1.id) { sectionIndex, section in

+ 22 - 16
FreeAPS/Sources/Modules/Settings/View/SettingsRootView.swift

@@ -10,43 +10,49 @@ extension Settings {
 
 
         var body: some View {
         var body: some View {
             Form {
             Form {
-                Section(
-                    header: Text(
+                Section {
+                    Toggle("Closed loop", isOn: $state.closedLoop)
+                } header: {
+                    Text(
                         "iAPS v\(state.versionNumber) (\(state.buildNumber))\nBranch: \(state.branch) \(state.copyrightNotice) "
                         "iAPS v\(state.versionNumber) (\(state.buildNumber))\nBranch: \(state.branch) \(state.copyrightNotice) "
                     ).textCase(nil)
                     ).textCase(nil)
-                ) {
-                    Toggle("Closed loop", isOn: $state.closedLoop)
                 }
                 }
 
 
-                Section(header: Text("Devices")) {
+                Section {
                     Text("Pump").navigationLink(to: .pumpConfig, from: self)
                     Text("Pump").navigationLink(to: .pumpConfig, from: self)
                     Text("CGM").navigationLink(to: .cgm, from: self)
                     Text("CGM").navigationLink(to: .cgm, from: self)
                     Text("Watch").navigationLink(to: .watch, from: self)
                     Text("Watch").navigationLink(to: .watch, from: self)
-                }
+                } header: { Text("Devices") }
 
 
-                Section(header: Text("Services")) {
+                Section {
                     Text("Nightscout").navigationLink(to: .nighscoutConfig, from: self)
                     Text("Nightscout").navigationLink(to: .nighscoutConfig, from: self)
                     if HKHealthStore.isHealthDataAvailable() {
                     if HKHealthStore.isHealthDataAvailable() {
                         Text("Apple Health").navigationLink(to: .healthkit, from: self)
                         Text("Apple Health").navigationLink(to: .healthkit, from: self)
                     }
                     }
                     Text("Notifications").navigationLink(to: .notificationsConfig, from: self)
                     Text("Notifications").navigationLink(to: .notificationsConfig, from: self)
-                    Text("Fat And Protein Conversion").navigationLink(to: .fpuConfig, from: self)
-                    Text("App Icons").navigationLink(to: .iconConfig, from: self)
-                    Text("Statistics and Home View").navigationLink(to: .statisticsConfig, from: self)
-                }
+                } header: { Text("Services") }
 
 
-                Section(header: Text("Configuration")) {
-                    Text("Preferences").navigationLink(to: .preferencesEditor, from: self)
+                Section {
                     Text("Pump Settings").navigationLink(to: .pumpSettingsEditor, from: self)
                     Text("Pump Settings").navigationLink(to: .pumpSettingsEditor, from: self)
                     Text("Basal Profile").navigationLink(to: .basalProfileEditor, from: self)
                     Text("Basal Profile").navigationLink(to: .basalProfileEditor, from: self)
                     Text("Insulin Sensitivities").navigationLink(to: .isfEditor, from: self)
                     Text("Insulin Sensitivities").navigationLink(to: .isfEditor, from: self)
                     Text("Carb Ratios").navigationLink(to: .crEditor, from: self)
                     Text("Carb Ratios").navigationLink(to: .crEditor, from: self)
                     Text("Target Glucose").navigationLink(to: .targetsEditor, from: self)
                     Text("Target Glucose").navigationLink(to: .targetsEditor, from: self)
+                } header: { Text("Configuration") }
+
+                Section {
+                    Text("OpenAPS").navigationLink(to: .preferencesEditor, from: self)
                     Text("Autotune").navigationLink(to: .autotuneConfig, from: self)
                     Text("Autotune").navigationLink(to: .autotuneConfig, from: self)
+                } header: { Text("OpenAPS") }
+
+                Section {
+                    Text("UI/UX").navigationLink(to: .statisticsConfig, from: self)
+                    Text("App Icons").navigationLink(to: .iconConfig, from: self)
                     Text("Bolus Calculator").navigationLink(to: .bolusCalculatorConfig, from: self)
                     Text("Bolus Calculator").navigationLink(to: .bolusCalculatorConfig, from: self)
-                }
+                    Text("Fat And Protein Conversion").navigationLink(to: .fpuConfig, from: self)
+                } header: { Text("Extra Features") }
 
 
-                Section(header: Text("Developer")) {
+                Section {
                     Toggle("Debug options", isOn: $state.debugOptions)
                     Toggle("Debug options", isOn: $state.debugOptions)
                     if state.debugOptions {
                     if state.debugOptions {
                         Group {
                         Group {
@@ -108,7 +114,7 @@ extension Settings {
                                 .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.settings), from: self)
                                 .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.settings), from: self)
                         }
                         }
                     }
                     }
-                }
+                } header: { Text("Developer") }
 
 
                 Section {
                 Section {
                     Toggle("Animated Background", isOn: $state.animatedBackground)
                     Toggle("Animated Background", isOn: $state.animatedBackground)

+ 4 - 2
FreeAPS/Sources/Modules/StatConfig/StatConfigStateModel.swift

@@ -10,7 +10,8 @@ extension StatConfig {
         @Published var yGridLines: Bool = false
         @Published var yGridLines: Bool = false
         @Published var oneDimensionalGraph = false
         @Published var oneDimensionalGraph = false
         @Published var rulerMarks: Bool = false
         @Published var rulerMarks: Bool = false
-
+        @Published var skipBolusScreenAfterCarbs: Bool = false
+        @Published var useFPUconversion: Bool = true
         var units: GlucoseUnits = .mmolL
         var units: GlucoseUnits = .mmolL
 
 
         override func subscribe() {
         override func subscribe() {
@@ -21,7 +22,8 @@ extension StatConfig {
             subscribeSetting(\.xGridLines, on: $xGridLines) { xGridLines = $0 }
             subscribeSetting(\.xGridLines, on: $xGridLines) { xGridLines = $0 }
             subscribeSetting(\.yGridLines, on: $yGridLines) { yGridLines = $0 }
             subscribeSetting(\.yGridLines, on: $yGridLines) { yGridLines = $0 }
             subscribeSetting(\.rulerMarks, on: $rulerMarks) { rulerMarks = $0 }
             subscribeSetting(\.rulerMarks, on: $rulerMarks) { rulerMarks = $0 }
-            subscribeSetting(\.oneDimensionalGraph, on: $oneDimensionalGraph) { oneDimensionalGraph = $0 }
+            subscribeSetting(\.useFPUconversion, on: $useFPUconversion) { useFPUconversion = $0 }
+            subscribeSetting(\.skipBolusScreenAfterCarbs, on: $skipBolusScreenAfterCarbs) { skipBolusScreenAfterCarbs = $0 }
 
 
             subscribeSetting(\.low, on: $low, initial: {
             subscribeSetting(\.low, on: $low, initial: {
                 let value = max(min($0, 90), 40)
                 let value = max(min($0, 90), 40)

+ 12 - 6
FreeAPS/Sources/Modules/StatConfig/View/StatConfigRootView.swift

@@ -26,37 +26,43 @@ extension StatConfig {
 
 
         var body: some View {
         var body: some View {
             Form {
             Form {
-                Section(header: Text("Settings")) {
-                    Toggle("Change HbA1c Unit", isOn: $state.overrideHbA1cUnit)
+                Section {
                     Toggle("Display Chart X - Grid lines", isOn: $state.xGridLines)
                     Toggle("Display Chart X - Grid lines", isOn: $state.xGridLines)
                     Toggle("Display Chart Y - Grid lines", isOn: $state.yGridLines)
                     Toggle("Display Chart Y - Grid lines", isOn: $state.yGridLines)
                     Toggle("Display Chart Threshold lines for Low and High", isOn: $state.rulerMarks)
                     Toggle("Display Chart Threshold lines for Low and High", isOn: $state.rulerMarks)
                     Toggle("Standing / Laying TIR Chart", isOn: $state.oneDimensionalGraph)
                     Toggle("Standing / Laying TIR Chart", isOn: $state.oneDimensionalGraph)
-
                     HStack {
                     HStack {
                         Text("Hours X-Axis (6 default)")
                         Text("Hours X-Axis (6 default)")
                         Spacer()
                         Spacer()
                         DecimalTextField("6", value: $state.hours, formatter: carbsFormatter)
                         DecimalTextField("6", value: $state.hours, formatter: carbsFormatter)
                         Text("hours").foregroundColor(.secondary)
                         Text("hours").foregroundColor(.secondary)
                     }
                     }
+                } header: { Text("Home Chart settings ") }
 
 
+                Section {
                     HStack {
                     HStack {
                         Text("Low")
                         Text("Low")
                         Spacer()
                         Spacer()
                         DecimalTextField("0", value: $state.low, formatter: glucoseFormatter)
                         DecimalTextField("0", value: $state.low, formatter: glucoseFormatter)
                         Text(state.units.rawValue).foregroundColor(.secondary)
                         Text(state.units.rawValue).foregroundColor(.secondary)
                     }
                     }
-
                     HStack {
                     HStack {
                         Text("High")
                         Text("High")
                         Spacer()
                         Spacer()
                         DecimalTextField("0", value: $state.high, formatter: glucoseFormatter)
                         DecimalTextField("0", value: $state.high, formatter: glucoseFormatter)
                         Text(state.units.rawValue).foregroundColor(.secondary)
                         Text(state.units.rawValue).foregroundColor(.secondary)
                     }
                     }
-                }
+                    Toggle("Override HbA1c Unit", isOn: $state.overrideHbA1cUnit)
+
+                } header: { Text("Statistics settings ") }
+
+                Section {
+                    Toggle("Skip Bolus screen after carbs", isOn: $state.skipBolusScreenAfterCarbs)
+                    Toggle("Display and allow Fat and Protein entries", isOn: $state.useFPUconversion)
+                } header: { Text("Add Meal View settings ") }
             }
             }
             .onAppear(perform: configureView)
             .onAppear(perform: configureView)
-            .navigationBarTitle("Statistics")
+            .navigationBarTitle("UI/UX Settings")
             .navigationBarTitleDisplayMode(.automatic)
             .navigationBarTitleDisplayMode(.automatic)
         }
         }
     }
     }

+ 3 - 3
FreeAPS/Sources/Services/HealthKit/HealthKitManager.swift

@@ -186,7 +186,7 @@ final class BaseHealthKitManager: HealthKitManager, Injectable, CarbsObserver, P
         else { return }
         else { return }
 
 
         let carbsWithId = carbs.filter { c in
         let carbsWithId = carbs.filter { c in
-            guard c.id != nil else { return false }
+            guard c.collectionID != nil else { return false }
             return true
             return true
         }
         }
 
 
@@ -203,8 +203,8 @@ final class BaseHealthKitManager: HealthKitManager, Injectable, CarbsObserver, P
                         start: $0.createdAt,
                         start: $0.createdAt,
                         end: $0.createdAt,
                         end: $0.createdAt,
                         metadata: [
                         metadata: [
-                            HKMetadataKeyExternalUUID: $0.id ?? "_id",
-                            HKMetadataKeySyncIdentifier: $0.id ?? "_id",
+                            HKMetadataKeyExternalUUID: $0.collectionID ?? "_id",
+                            HKMetadataKeySyncIdentifier: $0.collectionID ?? "_id",
                             HKMetadataKeySyncVersion: 1,
                             HKMetadataKeySyncVersion: 1,
                             Config.freeAPSMetaKey: true
                             Config.freeAPSMetaKey: true
                         ]
                         ]