@@ -11,7 +11,7 @@ import Combine
1111import LoopCore
1212
1313struct MicrobolusView : View {
14- typealias Result = ( microbolusesWithCOB: Bool , withCOBValue: Double , microbolusesWithoutCOB: Bool , withoutCOBValue: Double , safeMode: Microbolus . SafeMode , microbolusesMinimumBolusSize: Double )
14+ typealias Result = ( microbolusesWithCOB: Bool , withCOBValue: Double , microbolusesWithoutCOB: Bool , withoutCOBValue: Double , safeMode: Microbolus . SafeMode , microbolusesMinimumBolusSize: Double , openBolusScreen : Bool )
1515
1616 final class ViewModel : ObservableObject {
1717 @Published var microbolusesWithCOB : Bool
@@ -20,6 +20,7 @@ struct MicrobolusView: View {
2020 @Published var withoutCOBValue : Double
2121 @Published var safeMode : Microbolus . SafeMode
2222 @Published var microbolusesMinimumBolusSize : Double
23+ @Published var openBolusScreen : Bool
2324
2425 @Published fileprivate var pickerWithCOBIndex : Int
2526 @Published fileprivate var pickerWithoutCOBIndex : Int
@@ -31,13 +32,14 @@ struct MicrobolusView: View {
3132
3233 private var cancellable : AnyCancellable !
3334
34- init ( microbolusesWithCOB: Bool , withCOBValue: Double , microbolusesWithoutCOB: Bool , withoutCOBValue: Double , safeMode: Microbolus . SafeMode , microbolusesMinimumBolusSize: Double ) {
35+ init ( microbolusesWithCOB: Bool , withCOBValue: Double , microbolusesWithoutCOB: Bool , withoutCOBValue: Double , safeMode: Microbolus . SafeMode , microbolusesMinimumBolusSize: Double , openBolusScreen : Bool ) {
3536 self . microbolusesWithCOB = microbolusesWithCOB
3637 self . withCOBValue = withCOBValue
3738 self . microbolusesWithoutCOB = microbolusesWithoutCOB
3839 self . withoutCOBValue = withoutCOBValue
3940 self . safeMode = safeMode
4041 self . microbolusesMinimumBolusSize = microbolusesMinimumBolusSize
42+ self . openBolusScreen = openBolusScreen
4143
4244 pickerWithCOBIndex = values. firstIndex ( of: Int ( withCOBValue) ) ?? 0
4345 pickerWithoutCOBIndex = values. firstIndex ( of: Int ( withoutCOBValue) ) ?? 0
@@ -63,19 +65,19 @@ struct MicrobolusView: View {
6365 }
6466
6567 func changes( ) -> AnyPublisher < Result , Never > {
66- // Publishers.CombineLatest5
67- Publishers . CombineLatest3 (
68+ Publishers . CombineLatest4 (
6869 Publishers . CombineLatest4 (
6970 $microbolusesWithCOB,
7071 $withCOBValue,
7172 $microbolusesWithoutCOB,
7273 $withoutCOBValue
7374 ) ,
7475 $safeMode,
75- $microbolusesMinimumBolusSize
76+ $microbolusesMinimumBolusSize,
77+ $openBolusScreen
7678 )
77- . map { ( $0. 0 . 0 , $0. 0 . 1 , $0. 0 . 2 , $0. 0 . 3 , $0. 1 , $0. 2 ) }
78- . eraseToAnyPublisher ( )
79+ . map { ( $0. 0 . 0 , $0. 0 . 1 , $0. 0 . 2 , $0. 0 . 3 , $0. 1 , $0. 2 , $0 . 3 ) }
80+ . eraseToAnyPublisher ( )
7981 }
8082 }
8183
@@ -112,38 +114,39 @@ struct MicrobolusView: View {
112114 }
113115 }
114116
115- if viewModel. microbolusesWithCOB {
116- Section ( footer:
117- Text ( " This is the minimum Microbolus size in units that will be delivered. Only if the Microbolus calculated is equal to or greater than this number of units will a bolus be delivered. " )
118- ) {
119- Picker ( selection: $viewModel. pickerMinimumBolusSizeIndex, label: Text ( " Minimum Bolus Size " ) ) {
120- ForEach ( 0 ..< viewModel. minimumBolusSizeValues. count) { index in Text ( String ( format: " %.2f U " , self . viewModel. minimumBolusSizeValues [ index] ) ) . tag ( index)
121- }
117+ Section ( footer:
118+ Text ( " This is the maximum minutes of basal that can be delivered as a single microbolus without COB. " )
119+ ) {
120+ Toggle ( isOn: $viewModel. microbolusesWithoutCOB) {
121+ Text ( " Enable Without Carbs " )
122+ }
123+ Picker ( selection: $viewModel. pickerWithoutCOBIndex, label: Text ( " Maximum Size " ) ) {
124+ ForEach ( 0 ..< viewModel. values. count) { index in
125+ Text ( " \( self . viewModel. values [ index] ) " ) . tag ( index)
122126 }
123127 }
128+ }
124129
125- Section ( footer:
126- Text ( " This is the maximum minutes of basal that can be delivered as a single microbolus without COB. " )
127- ) {
128- Toggle ( isOn: $viewModel. microbolusesWithoutCOB) {
129- Text ( " Enable Without Carbs " )
130- }
131- Picker ( selection: $viewModel. pickerWithoutCOBIndex, label: Text ( " Maximum Size " ) ) {
132- ForEach ( 0 ..< viewModel. values. count) { index in
133- Text ( " \( self . viewModel. values [ index] ) " ) . tag ( index)
134- }
130+ Section ( header: Text ( " Safe Mode " ) . font ( . headline) , footer:
131+ 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. " )
132+ ) {
133+ Picker ( selection: $viewModel. safeMode, label: Text ( " Safe Mode " ) ) {
134+ ForEach ( Microbolus . SafeMode. allCases, id: \. self) { value in
135+ Text ( " \( value. displayName) " ) . tag ( value)
135136 }
136137 }
138+ . pickerStyle ( SegmentedPickerStyle ( ) )
139+ }
137140
138- Section ( header: Text ( " Safe Mode " ) . font ( . headline) , footer:
139- 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. " )
140- ) {
141- Picker ( selection: $viewModel. safeMode, label: Text ( " Safe Mode " ) ) {
142- ForEach ( Microbolus . SafeMode. allCases, id: \. self) { value in
143- Text ( " \( value. displayName) " ) . tag ( value)
144- }
141+ Section ( header: Text ( " Other Options " ) . font ( . headline) , footer:
142+ Text ( " This is the minimum microbolus size in units that will be delivered. Only if the microbolus calculated is equal to or greater than this number of units will a bolus be delivered. " )
143+ ) {
144+ Toggle ( isOn: $viewModel. openBolusScreen) {
145+ Text ( " Open Bolus screen after Carbs " )
146+ }
147+ Picker ( selection: $viewModel. pickerMinimumBolusSizeIndex, label: Text ( " Minimum Bolus Size " ) ) {
148+ ForEach ( 0 ..< viewModel. minimumBolusSizeValues. count) { index in Text ( String ( format: " %.2f U " , self . viewModel. minimumBolusSizeValues [ index] ) ) . tag ( index)
145149 }
146- . pickerStyle ( SegmentedPickerStyle ( ) )
147150 }
148151 }
149152
@@ -173,9 +176,11 @@ struct MicrobolusView_Previews: PreviewProvider {
173176 microbolusesWithoutCOB: false ,
174177 withoutCOBValue: 30 ,
175178 safeMode: . enabled,
176- microbolusesMinimumBolusSize: 0.0
179+ microbolusesMinimumBolusSize: 0.0 ,
180+ openBolusScreen: false
177181 )
178182 )
179183 . environment ( \. colorScheme, . dark)
184+ . previewLayout ( . sizeThatFits)
180185 }
181186}
0 commit comments