Browse Source

add custom progress view to add external insulin view

polscm32 2 năm trước cách đây
mục cha
commit
62830ecd88

+ 4 - 0
FreeAPS.xcodeproj/project.pbxproj

@@ -315,6 +315,7 @@
 		B9CAAEFC2AE70836000F68BC /* branch.txt in Resources */ = {isa = PBXBuildFile; fileRef = B9CAAEFB2AE70836000F68BC /* branch.txt */; };
 		BA00D96F7B2FF169A06FB530 /* CGMStateModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C018D1680307A31C9ED7120 /* CGMStateModel.swift */; };
 		BA90041DC8991147E5C8C3AA /* CalibrationsRootView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 500371C09F54F89A97D65FDB /* CalibrationsRootView.swift */; };
+		BD1661312B82ADAB00256551 /* CustomProgressView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD1661302B82ADAB00256551 /* CustomProgressView.swift */; };
 		BD188BEC2B1B805B00B183BF /* WidgetBobble.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD188BEB2B1B805A00B183BF /* WidgetBobble.swift */; };
 		BD188BED2B1B805B00B183BF /* WidgetBobble.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD188BEB2B1B805A00B183BF /* WidgetBobble.swift */; };
 		BD2B464E0745FBE7B79913F4 /* NightscoutConfigProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3BF768BD6264FF7D71D66767 /* NightscoutConfigProvider.swift */; };
@@ -881,6 +882,7 @@
 		B9CAAEFB2AE70836000F68BC /* branch.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = branch.txt; sourceTree = SOURCE_ROOT; };
 		BA49538D56989D8DA6FCF538 /* TargetsEditorDataFlow.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = TargetsEditorDataFlow.swift; sourceTree = "<group>"; };
 		BC210C0F3CB6D3C86E5DED4E /* LibreConfigRootView.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = LibreConfigRootView.swift; sourceTree = "<group>"; };
+		BD1661302B82ADAB00256551 /* CustomProgressView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomProgressView.swift; sourceTree = "<group>"; };
 		BD188BEB2B1B805A00B183BF /* WidgetBobble.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WidgetBobble.swift; sourceTree = "<group>"; };
 		BD2FF19F2AE29D43005D1C5D /* CheckboxToggleStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckboxToggleStyle.swift; sourceTree = "<group>"; };
 		BD3CC0712B0B89D50013189E /* MainChartView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainChartView.swift; sourceTree = "<group>"; };
@@ -1762,6 +1764,7 @@
 				CEA4F62229BE10F70011ADF7 /* SavitzkyGolayFilter.swift */,
 				587DA1F52B77F3DD00B28F8A /* SettingsRowView.swift */,
 				BD2FF19F2AE29D43005D1C5D /* CheckboxToggleStyle.swift */,
+				BD1661302B82ADAB00256551 /* CustomProgressView.swift */,
 			);
 			path = Helpers;
 			sourceTree = "<group>";
@@ -2990,6 +2993,7 @@
 				711C0CB42CAABE788916BC9D /* ManualTempBasalDataFlow.swift in Sources */,
 				BF1667ADE69E4B5B111CECAE /* ManualTempBasalProvider.swift in Sources */,
 				F90692D6274B9A450037068D /* HealthKitStateModel.swift in Sources */,
+				BD1661312B82ADAB00256551 /* CustomProgressView.swift in Sources */,
 				C967DACD3B1E638F8B43BE06 /* ManualTempBasalStateModel.swift in Sources */,
 				FE41E4D429463C660047FD55 /* NightscoutStatistics.swift in Sources */,
 				38E4453B274E411700EC9A94 /* Disk+VolumeInformation.swift in Sources */,

+ 1 - 1
FreeAPS/Sources/Helpers/CustomProgressView.swift

@@ -16,7 +16,7 @@ struct CustomProgressView: View {
                     radius: 3
                 )
                 .padding(.horizontal, 10)
-                .frame(maxHeight: UIScreen.main.bounds.height / 6)
+                .frame(maxHeight: UIScreen.main.bounds.height / 11)
 
             ProgressView {
                 Text(text)

+ 66 - 60
FreeAPS/Sources/Modules/DataTable/View/DataTableRootView.swift

@@ -394,78 +394,84 @@ extension DataTable {
 
         @ViewBuilder func addExternalInsulinView() -> some View {
             NavigationView {
-                VStack {
-                    Form {
-                        Section {
-                            HStack {
-                                Text("Amount")
-                                Spacer()
-                                DecimalTextField(
-                                    "0",
-                                    value: $state.externalInsulinAmount,
-                                    formatter: insulinFormatter,
-                                    autofocus: true,
-                                    cleanInput: true
-                                )
-                                Text("U").foregroundColor(.secondary)
-                            }
-                        }.listRowBackground(Color.chart)
+                ZStack(alignment: .center) {
+                    VStack {
+                        Form {
+                            Section {
+                                HStack {
+                                    Text("Amount")
+                                    Spacer()
+                                    DecimalTextField(
+                                        "0",
+                                        value: $state.externalInsulinAmount,
+                                        formatter: insulinFormatter,
+                                        autofocus: true,
+                                        cleanInput: true
+                                    )
+                                    Text("U").foregroundColor(.secondary)
+                                }
+                            }.listRowBackground(Color.chart)
 
-                        Section {
-                            DatePicker("Date", selection: $state.externalInsulinDate, in: ...Date())
-                        }.listRowBackground(Color.chart)
+                            Section {
+                                DatePicker("Date", selection: $state.externalInsulinDate, in: ...Date())
+                            }.listRowBackground(Color.chart)
 
-                        let amountWarningCondition = (state.externalInsulinAmount > state.maxBolus)
+                            let amountWarningCondition = (state.externalInsulinAmount > state.maxBolus)
 
-                        var listBackgroundColor: Color {
-                            if amountWarningCondition {
-                                return Color.red
-                            } else if state.externalInsulinAmount <= 0 || state.externalInsulinAmount > state.maxBolus * 3 {
-                                return Color(.systemGray4)
-                            } else {
-                                return Color(.systemBlue)
+                            var listBackgroundColor: Color {
+                                if amountWarningCondition {
+                                    return Color.red
+                                } else if state.externalInsulinAmount <= 0 || state.externalInsulinAmount > state.maxBolus * 3 {
+                                    return Color(.systemGray4)
+                                } else {
+                                    return Color(.systemBlue)
+                                }
                             }
-                        }
 
-                        var foregroundColor: Color {
-                            if amountWarningCondition {
-                                return Color.white
-                            } else if state.externalInsulinAmount <= 0 || state.externalInsulinAmount > state.maxBolus * 3 {
-                                return Color.secondary
-                            } else {
-                                return Color.white
+                            var foregroundColor: Color {
+                                if amountWarningCondition {
+                                    return Color.white
+                                } else if state.externalInsulinAmount <= 0 || state.externalInsulinAmount > state.maxBolus * 3 {
+                                    return Color.secondary
+                                } else {
+                                    return Color.white
+                                }
                             }
-                        }
 
-                        Section {
-                            HStack {
-                                Button {
-                                    Task {
-                                        do {
-                                            await state.addExternalInsulin()
-                                            state.waitForSuggestion = true
-                                            state.addButtonPressed = true
-                                            isAmountUnconfirmed = false
+                            Section {
+                                HStack {
+                                    Button {
+                                        Task {
+                                            do {
+                                                await state.addExternalInsulin()
+                                                state.waitForSuggestion = true
+                                                state.addButtonPressed = true
+                                                isAmountUnconfirmed = false
+                                            }
                                         }
+                                    } label: {
+                                        Text("Log external insulin")
                                     }
-                                } label: {
-                                    Text("Log external insulin")
+                                    .foregroundStyle(foregroundColor)
+                                    .frame(maxWidth: .infinity, alignment: .center)
+                                    .disabled(
+                                        state.externalInsulinAmount <= 0 || state.externalInsulinAmount > state.maxBolus * 3
+                                    )
                                 }
-                                .foregroundStyle(foregroundColor)
-                                .frame(maxWidth: .infinity, alignment: .center)
-                                .disabled(
-                                    state.externalInsulinAmount <= 0 || state.externalInsulinAmount > state.maxBolus * 3
-                                )
                             }
-                        }
-                        header: {
-                            if amountWarningCondition
-                            {
-                                Text("⚠️ Warning! The entered insulin amount is greater than your Max Bolus setting!")
+                            header: {
+                                if amountWarningCondition
+                                {
+                                    Text("⚠️ Warning! The entered insulin amount is greater than your Max Bolus setting!")
+                                }
                             }
-                        }
-                        .listRowBackground(listBackgroundColor).tint(.white)
-                    }.scrollContentBackground(.hidden).background(color)
+                            .listRowBackground(listBackgroundColor).tint(.white)
+                        }.scrollContentBackground(.hidden).background(color)
+                    }
+
+                    if state.waitForSuggestion {
+                        CustomProgressView(text: "Adding Insulin...")
+                    }
                 }
                 .onAppear(perform: configureView)
                 .onDisappear {