@@ -31,9 +31,6 @@ class WooPosScanningSetupViewModel @Inject constructor(
31
31
)
32
32
val state: StateFlow <WooPosScanningSetupState > = _state .asStateFlow()
33
33
34
- private val _showBarcodeInfoDialogEvent = MutableSharedFlow <Unit >()
35
- val showBarcodeInfoDialogEvent: SharedFlow <Unit > = _showBarcodeInfoDialogEvent .asSharedFlow()
36
-
37
34
private val _openBluetoothSettingsEvent = MutableSharedFlow <Unit >()
38
35
val openBluetoothSettingsEvent: SharedFlow <Unit > = _openBluetoothSettingsEvent .asSharedFlow()
39
36
@@ -48,12 +45,12 @@ class WooPosScanningSetupViewModel @Inject constructor(
48
45
)
49
46
50
47
when (event.device) {
51
- BarcodeReaderDevice .OTHER -> viewModelScope.launch {
52
- _showBarcodeInfoDialogEvent .emit( Unit )
53
- }
48
+ BarcodeReaderDevice .OTHER -> _state .value = _state .value.copy(
49
+ currentStep = createScannerSetupInfoStep( _state .value.currentStep )
50
+ )
54
51
55
52
else -> _state .value = _state .value.copy(
56
- currentStep = createScannerHIDModeSetupStep()
53
+ currentStep = createScannerHIDModeSetupStep(_state .value.currentStep )
57
54
)
58
55
}
59
56
}
@@ -89,18 +86,19 @@ class WooPosScanningSetupViewModel @Inject constructor(
89
86
90
87
is ScanningSetupStep .ScannerHIDModeSetup -> {
91
88
_state .value = _state .value.copy(
92
- currentStep = createScannerPairModeSetupStep()
89
+ currentStep = createScannerPairModeSetupStep(_state .value.currentStep )
93
90
)
94
91
}
95
92
96
93
is ScanningSetupStep .ScannerPairModeSetup -> {
97
94
_state .value = _state .value.copy(
98
- currentStep = createPairYourScannerStep()
95
+ currentStep = createPairYourScannerStep(_state .value.currentStep )
99
96
)
100
97
}
98
+
101
99
is ScanningSetupStep .PairYourScanner -> {
102
100
_state .value = _state .value.copy(
103
- currentStep = createTestYourScannerStep()
101
+ currentStep = createTestYourScannerStep(_state .value.currentStep )
104
102
)
105
103
startAutoNavigationToSuccess()
106
104
}
@@ -110,7 +108,7 @@ class WooPosScanningSetupViewModel @Inject constructor(
110
108
}
111
109
112
110
is ScanningSetupStep .ScannerSetupSuccess -> {
113
- error(" Primary button should not be available on ScannerSetupSuccess step " )
111
+ error(" Not implemented yet " )
114
112
}
115
113
116
114
is ScanningSetupStep .ScannerSetupInfo -> {
@@ -122,46 +120,10 @@ class WooPosScanningSetupViewModel @Inject constructor(
122
120
}
123
121
124
122
private fun handleSecondaryButtonClick () {
125
- when (_state .value.currentStep) {
126
- is ScanningSetupStep .DeviceSelection -> error(
127
- " Secondary button should not be available on DeviceSelection step"
128
- )
129
-
130
- is ScanningSetupStep .ScannerHIDModeSetup -> {
131
- _state .value = _state .value.copy(
132
- currentStep = createDeviceSelectionStep()
133
- )
134
- }
135
-
136
- is ScanningSetupStep .ScannerPairModeSetup -> {
137
- _state .value = _state .value.copy(
138
- currentStep = createScannerHIDModeSetupStep()
139
- )
140
- }
141
- is ScanningSetupStep .PairYourScanner -> {
142
- _state .value = _state .value.copy(
143
- currentStep = createScannerPairModeSetupStep()
144
- )
145
- }
146
-
147
- is ScanningSetupStep .TestYourScanner -> {
148
- _state .value = _state .value.copy(
149
- currentStep = createPairYourScannerStep()
150
- )
151
- }
152
-
153
- is ScanningSetupStep .ScannerSetupSuccess -> {
154
- _state .value = _state .value.copy(
155
- currentStep = createScannerSetupInfoStep()
156
- )
157
- }
158
-
159
- is ScanningSetupStep .ScannerSetupInfo -> {
160
- _state .value = _state .value.copy(
161
- currentStep = createScannerSetupSuccessStep()
162
- )
163
- }
164
- }
123
+ val previousStep = requireNotNull(
124
+ _state .value.currentStep.previousStep
125
+ ) { " Previous step cannot be null if secondary button present" }
126
+ _state .value = _state .value.copy(currentStep = previousStep)
165
127
}
166
128
167
129
private fun createDeviceSelectionStep () = ScanningSetupStep .DeviceSelection (
@@ -171,25 +133,32 @@ class WooPosScanningSetupViewModel @Inject constructor(
171
133
BarcodeReaderDevice .STAR_BSH_20B ,
172
134
BarcodeReaderDevice .INATECK_BLUETOOTH ,
173
135
BarcodeReaderDevice .OTHER
174
- )
136
+ ),
137
+ previousStep = null
175
138
)
176
139
177
- private fun createScannerHIDModeSetupStep () = ScanningSetupStep .ScannerHIDModeSetup (
140
+ private fun createScannerHIDModeSetupStep (previousStep : ScanningSetupStep ) = ScanningSetupStep .ScannerHIDModeSetup (
178
141
title = resourceProvider.getString(R .string.woopos_scanning_setup_introduction_title),
179
142
message = resourceProvider.getString(R .string.woopos_scanning_setup_introduction_message),
180
143
qrCodeImageRes = R .drawable.ic_barcode,
181
144
primaryButtonText = resourceProvider.getString(R .string.woopos_scanning_setup_button_next),
182
- secondaryButtonText = resourceProvider.getString(R .string.woopos_scanning_setup_button_back)
145
+ secondaryButtonText = resourceProvider.getString(R .string.woopos_scanning_setup_button_back),
146
+ previousStep = previousStep
183
147
)
184
148
185
- private fun createScannerPairModeSetupStep () = ScanningSetupStep .ScannerPairModeSetup (
186
- title = resourceProvider.getString(R .string.woopos_scanning_setup_scanner_pair_mode_title),
187
- message = resourceProvider.getString(R .string.woopos_scanning_setup_scanner_pair_mode_message),
188
- qrCodeImageRes = R .drawable.ic_barcode,
189
- primaryButtonText = resourceProvider.getString(R .string.woopos_scanning_setup_button_next),
190
- secondaryButtonText = resourceProvider.getString(R .string.woopos_scanning_setup_button_back)
191
- )
192
- private fun createPairYourScannerStep () = ScanningSetupStep .PairYourScanner (
149
+ private fun createScannerPairModeSetupStep (previousStep : ScanningSetupStep ) =
150
+ ScanningSetupStep .ScannerPairModeSetup (
151
+ title = resourceProvider.getString(R .string.woopos_scanning_setup_scanner_pair_mode_title),
152
+ message = resourceProvider.getString(R .string.woopos_scanning_setup_scanner_pair_mode_message),
153
+ qrCodeImageRes = R .drawable.ic_barcode,
154
+ primaryButtonText = resourceProvider.getString(R .string.woopos_scanning_setup_button_next),
155
+ secondaryButtonText = resourceProvider.getString(R .string.woopos_scanning_setup_button_back),
156
+ previousStep = previousStep
157
+ )
158
+
159
+ private fun createPairYourScannerStep (
160
+ previousStep : ScanningSetupStep
161
+ ) = ScanningSetupStep .PairYourScanner (
193
162
title = resourceProvider.getString(R .string.woopos_scanning_setup_pair_your_scanner_title),
194
163
message = resourceProvider.getString(
195
164
R .string.woopos_scanning_setup_pair_your_scanner_message,
@@ -198,23 +167,28 @@ class WooPosScanningSetupViewModel @Inject constructor(
198
167
iconRes = R .drawable.ic_woopos_bluetooth_settings,
199
168
primaryButtonText = resourceProvider.getString(R .string.woopos_scanning_setup_button_next),
200
169
secondaryButtonText = resourceProvider.getString(R .string.woopos_scanning_setup_button_back),
201
- bluetoothSettingsButtonText = resourceProvider.getString(R .string.woopos_scanning_setup_go_to_settings)
170
+ bluetoothSettingsButtonText = resourceProvider.getString(R .string.woopos_scanning_setup_go_to_settings),
171
+ previousStep = previousStep
202
172
)
203
173
204
- private fun createTestYourScannerStep () = ScanningSetupStep .TestYourScanner (
174
+ private fun createTestYourScannerStep (
175
+ previousStep : ScanningSetupStep
176
+ ) = ScanningSetupStep .TestYourScanner (
205
177
title = resourceProvider.getString(R .string.woopos_scanning_setup_test_scanner_title),
206
178
message = resourceProvider.getString(R .string.woopos_scanning_setup_test_scanner_message),
207
179
barcodeImageRes = R .drawable.ic_barcode,
208
- secondaryButtonText = resourceProvider.getString(R .string.woopos_scanning_setup_button_back)
180
+ secondaryButtonText = resourceProvider.getString(R .string.woopos_scanning_setup_button_back),
181
+ previousStep = previousStep
209
182
)
210
183
211
184
private fun createScannerSetupSuccessStep () = ScanningSetupStep .ScannerSetupSuccess (
212
185
title = resourceProvider.getString(R .string.woopos_scanning_setup_success_title),
213
186
message = resourceProvider.getString(R .string.woopos_scanning_setup_success_message),
214
- moreInfoButtonText = resourceProvider.getString(R .string.woopos_scanning_setup_more_information)
187
+ moreInfoButtonText = resourceProvider.getString(R .string.woopos_scanning_setup_more_information),
188
+ previousStep = null
215
189
)
216
190
217
- private fun createScannerSetupInfoStep () = ScanningSetupStep .ScannerSetupInfo (
191
+ private fun createScannerSetupInfoStep (previousStep : ScanningSetupStep ) = ScanningSetupStep .ScannerSetupInfo (
218
192
title = resourceProvider.getString(R .string.woopos_scanning_setup_info_title),
219
193
message = resourceProvider.getString(R .string.woopos_scanning_setup_info_message),
220
194
bulletPoints = listOf (
@@ -224,7 +198,8 @@ class WooPosScanningSetupViewModel @Inject constructor(
224
198
),
225
199
infoText = resourceProvider.getString(R .string.woopos_scanning_setup_info_text),
226
200
backButtonText = resourceProvider.getString(R .string.woopos_scanning_setup_button_back),
227
- doneButtonText = resourceProvider.getString(R .string.woopos_scanning_setup_button_done)
201
+ doneButtonText = resourceProvider.getString(R .string.woopos_scanning_setup_button_done),
202
+ previousStep = previousStep
228
203
)
229
204
230
205
private fun startAutoNavigationToSuccess () {
@@ -242,10 +217,3 @@ class WooPosScanningSetupViewModel @Inject constructor(
242
217
private const val AUTO_NAVIGATION_DELAY_MS = 3000L
243
218
}
244
219
}
245
-
246
- sealed class WooPosScanningSetupUiEvent {
247
- data object OnPrimaryButtonClicked : WooPosScanningSetupUiEvent ()
248
- data object OnSecondaryButtonClicked : WooPosScanningSetupUiEvent ()
249
- data object OnOpenBluetoothSettings : WooPosScanningSetupUiEvent ()
250
- data class OnDeviceSelected (val device : BarcodeReaderDevice ) : WooPosScanningSetupUiEvent()
251
- }
0 commit comments