@@ -18,6 +18,7 @@ struct MicrobolusView: View {
1818 @Published var withCOBValue : Double
1919 @Published var microbolusesWithoutCOB : Bool
2020 @Published var withoutCOBValue : Double
21+ @Published var partialApplication : Double
2122 @Published var safeMode : Microbolus . SafeMode
2223 @Published var microbolusesMinimumBolusSize : Double
2324 @Published var openBolusScreen : Bool
@@ -27,10 +28,12 @@ struct MicrobolusView: View {
2728 @Published fileprivate var pickerWithCOBIndex : Int
2829 @Published fileprivate var pickerWithoutCOBIndex : Int
2930 @Published fileprivate var pickerMinimumBolusSizeIndex : Int
31+ @Published fileprivate var partialApplicationIndex : Int
3032
3133 fileprivate let values = stride ( from: 30 , to: 301 , by: 5 ) . map { $0 }
3234 // @ToDo: Should be able to get the to limit from the settings but for now defult to a low value
3335 fileprivate let minimumBolusSizeValues = stride ( from: 0.0 , to: 0.51 , by: 0.05 ) . map { $0 }
36+ fileprivate let partialApplicationValues = stride ( from: 0.1 , to: 1.01 , by: 0.1 ) . map { $0 }
3437
3538 private var cancellable : AnyCancellable !
3639 fileprivate let formatter : NumberFormatter = {
@@ -47,6 +50,7 @@ struct MicrobolusView: View {
4750 self . withCOBValue = settings. size
4851 self . microbolusesWithoutCOB = settings. enabledWithoutCarbs
4952 self . withoutCOBValue = settings. sizeWithoutCarbs
53+ self . partialApplication = settings. partialApplication
5054 self . safeMode = settings. safeMode
5155 self . microbolusesMinimumBolusSize = settings. minimumBolusSize
5256 self . openBolusScreen = settings. shouldOpenBolusScreen
@@ -57,6 +61,7 @@ struct MicrobolusView: View {
5761 pickerWithCOBIndex = values. firstIndex ( of: Int ( settings. size) ) ?? 0
5862 pickerWithoutCOBIndex = values. firstIndex ( of: Int ( settings. sizeWithoutCarbs) ) ?? 0
5963 pickerMinimumBolusSizeIndex = minimumBolusSizeValues. firstIndex ( of: Double ( settings. minimumBolusSize) ) ?? 0
64+ partialApplicationIndex = partialApplicationValues. firstIndex ( of: Double ( settings. partialApplication) ) ?? 0
6065
6166 let withCOBCancellable = $pickerWithCOBIndex
6267 . map { Double ( self . values [ $0] ) }
@@ -71,30 +76,36 @@ struct MicrobolusView: View {
7176 . map { Double ( self . minimumBolusSizeValues [ $0] ) }
7277 . sink { self . microbolusesMinimumBolusSize = $0 }
7378
79+ let partialApplicationCancellable = $partialApplicationIndex
80+ . map { Double ( self . partialApplicationValues [ $0] ) }
81+ . sink { self . partialApplication = $0 }
82+
7483 cancellable = AnyCancellable {
7584 withCOBCancellable. cancel ( )
7685 withoutCOBCancellable. cancel ( )
7786 microbolusesMinimumBolusSizeCancellable. cancel ( )
87+ partialApplicationCancellable. cancel ( )
7888 }
7989 }
8090
8191 func changes( ) -> AnyPublisher < Microbolus . Settings , Never > {
8292 let lowerBoundPublisher = $lowerBound
8393 . map { value -> Double in self . formatter. number ( from: value) ? . doubleValue ?? 0 }
8494
85- return Publishers . CombineLatest3 (
95+ return Publishers . CombineLatest4 (
8696 Publishers . CombineLatest4 (
8797 $microbolusesWithCOB,
8898 $withCOBValue,
8999 $microbolusesWithoutCOB,
90100 $withoutCOBValue
91101 ) ,
92102 Publishers . CombineLatest4 (
103+ $partialApplication,
93104 $safeMode,
94105 $microbolusesMinimumBolusSize,
95- $openBolusScreen,
96- $disableByOverride
106+ $openBolusScreen
97107 ) ,
108+ $disableByOverride,
98109 lowerBoundPublisher
99110 )
100111 . map {
@@ -103,11 +114,12 @@ struct MicrobolusView: View {
103114 size: $0. 0 . 1 ,
104115 enabledWithoutCarbs: $0. 0 . 2 ,
105116 sizeWithoutCarb: $0. 0 . 3 ,
106- safeMode: $0. 1 . 0 ,
107- minimumBolusSize: $0. 1 . 1 ,
108- shouldOpenBolusScreen: $0. 1 . 2 ,
109- disableByOverride: $0. 1 . 3 ,
110- overrideLowerBound: $0. 2
117+ partialApplication: $0. 1 . 0 ,
118+ safeMode: $0. 1 . 1 ,
119+ minimumBolusSize: $0. 1 . 2 ,
120+ shouldOpenBolusScreen: $0. 1 . 3 ,
121+ disableByOverride: $0. 2 ,
122+ overrideLowerBound: $0. 3
111123 )
112124 }
113125 . eraseToAnyPublisher ( )
@@ -129,7 +141,7 @@ struct MicrobolusView: View {
129141 . foregroundColor ( . orange)
130142 . padding ( . trailing)
131143
132- Text ( " Caution! Microboluses have potential to reduce the safety effects of other mitigations like max temp basal rate. Please be careful! \n The actual size of a microbolus is always limited to half the recommended bolus. " )
144+ Text ( " Caution! Microboluses have potential to reduce the safety effects of other mitigations like max temp basal rate. Please be careful! \n The actual size of a microbolus is always limited to the partial application of recommended bolus. " )
133145 . font ( . caption)
134146 }
135147
@@ -161,6 +173,16 @@ struct MicrobolusView: View {
161173 }
162174 }
163175
176+ Section ( footer:
177+ Text ( " What part of the recommended bolus will be applied automatically. " )
178+ ) {
179+ Picker ( selection: $viewModel. partialApplicationIndex, label: Text ( " Partial Application " ) ) {
180+ ForEach ( 0 ..< viewModel. partialApplicationValues. count) { index in
181+ Text ( String ( format: " %.0f %% " , self . viewModel. partialApplicationValues [ index] * 100 ) ) . tag ( index)
182+ }
183+ }
184+ }
185+
164186 Section ( header: Text ( " Safe Mode " ) . font ( . headline) , footer:
165187 Text ( " • If Enabled and predicted glucose in 15 minutes is lower than current glucose, microboluses are not allowed. \n • If Limited and the predicted glucose in 15 minutes is lower than current glucose, the maximum microbolus size is limited to 30 basal minutes. \n • If Disabled, there are no restrictions. " )
166188 ) {
@@ -231,7 +253,7 @@ struct MicrobolusView_Previews: PreviewProvider {
231253 )
232254 )
233255 . environment ( \. colorScheme, . dark)
234- . previewLayout ( . sizeThatFits )
256+ . previewLayout ( . fixed ( width : 375 , height : 1000 ) )
235257 }
236258}
237259
0 commit comments