Skip to content

Commit ceaa1f1

Browse files
authored
Merge pull request #20 from snabble/fixBundleProductEdgeCases
APPS-177 Fix notForSale handling
2 parents 74f20e0 + 1a04528 commit ceaa1f1

File tree

1 file changed

+63
-48
lines changed

1 file changed

+63
-48
lines changed

ui/src/main/java/io/snabble/sdk/ui/scanner/ProductResolver.kt

Lines changed: 63 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -197,34 +197,6 @@ class ProductResolver private constructor(private val context: Context, private
197197
resolveBundles && product.bundleProducts.isNotEmpty() && !scannedCode.hasEmbeddedData() -> {
198198
showBundleDialog(product, scannedCode)
199199
}
200-
product.saleStop -> {
201-
onSaleStopListener?.onSaleStop()
202-
progressDialog.dismiss()
203-
onDismissListener?.onDismiss()
204-
}
205-
product.notForSale -> {
206-
onNotForSaleListener?.onNotForSale(product)
207-
progressDialog.dismiss()
208-
onDismissListener?.onDismiss()
209-
}
210-
product.availability == Product.Availability.NOT_AVAILABLE -> {
211-
handleProductNotFound(scannedCode)
212-
}
213-
product.type == Product.Type.PreWeighed
214-
&& (!scannedCode.hasEmbeddedData() || scannedCode.embeddedData == 0) -> {
215-
onShelfCodeScannedListener?.onShelfCodeScanned()
216-
progressDialog.dismiss()
217-
onDismissListener?.onDismiss()
218-
}
219-
product.type == Product.Type.DepositReturnVoucher
220-
&& project.shoppingCart.containsScannedCode(scannedCode) -> {
221-
onAlreadyScannedListener?.onAlreadyScanned()
222-
progressDialog.dismiss()
223-
onDismissListener?.onDismiss()
224-
}
225-
onProductFoundListener != null -> {
226-
onProductFoundListener?.onProductFound(product, scannedCode)
227-
}
228200
else -> {
229201
showProduct(product, scannedCode)
230202
val event = if (wasOnlineProduct) {
@@ -238,30 +210,32 @@ class ProductResolver private constructor(private val context: Context, private
238210
}
239211

240212
private fun showBundleDialog(product: Product, scannedCode: ScannedCode) {
241-
SelectBundleDialog.show(context, product, object : SelectBundleDialog.Callback {
242-
override fun onProductSelected(product: Product) {
243-
Telemetry.event(Telemetry.Event.SelectedBundleProduct, product)
244-
val codes = product.scannableCodes
245-
if (codes.isNotEmpty() && codes[0].lookupCode != null) {
246-
val newCodes = ScannedCode.parse(project, codes[0].lookupCode)
247-
if (newCodes.size > 0) {
248-
var defaultCode = newCodes[0]
249-
for (newCode in newCodes) {
250-
if (newCode.templateName == "default") {
251-
defaultCode = newCode
213+
if (handleProductFlags(product, scannedCode)) {
214+
SelectBundleDialog.show(context, product, object : SelectBundleDialog.Callback {
215+
override fun onProductSelected(product: Product) {
216+
Telemetry.event(Telemetry.Event.SelectedBundleProduct, product)
217+
val codes = product.scannableCodes
218+
if (codes.isNotEmpty() && codes[0].lookupCode != null) {
219+
val newCodes = ScannedCode.parse(project, codes[0].lookupCode)
220+
if (newCodes.size > 0) {
221+
var defaultCode = newCodes[0]
222+
for (newCode in newCodes) {
223+
if (newCode.templateName == "default") {
224+
defaultCode = newCode
225+
}
252226
}
227+
showProduct(product, defaultCode)
228+
} else {
229+
showProduct(product, scannedCode)
253230
}
254-
showProduct(product, defaultCode)
255-
} else {
256-
showProduct(product, scannedCode)
257231
}
258232
}
259-
}
260233

261-
override fun onDismissed() {
262-
onDismissListener?.onDismiss()
263-
}
264-
})
234+
override fun onDismissed() {
235+
onDismissListener?.onDismiss()
236+
}
237+
})
238+
}
265239
}
266240

267241
private fun handleProductNotFound(scannedCode: ScannedCode) {
@@ -279,7 +253,48 @@ class ProductResolver private constructor(private val context: Context, private
279253

280254
private fun showProduct(product: Product?, scannedCode: ScannedCode?) {
281255
lastProduct = product
282-
productConfirmationDialog.show(product, scannedCode)
256+
257+
if (product != null && scannedCode != null) {
258+
if (handleProductFlags(product, scannedCode)) {
259+
productConfirmationDialog.show(product, scannedCode)
260+
}
261+
}
262+
}
263+
264+
private fun handleProductFlags(product: Product, scannedCode: ScannedCode) : Boolean {
265+
when {
266+
product.saleStop -> {
267+
onSaleStopListener?.onSaleStop()
268+
progressDialog.dismiss()
269+
onDismissListener?.onDismiss()
270+
}
271+
product.notForSale -> {
272+
onNotForSaleListener?.onNotForSale(product)
273+
progressDialog.dismiss()
274+
onDismissListener?.onDismiss()
275+
}
276+
product.availability == Product.Availability.NOT_AVAILABLE -> {
277+
handleProductNotFound(scannedCode)
278+
}
279+
product.type == Product.Type.PreWeighed
280+
&& (!scannedCode.hasEmbeddedData() || scannedCode.embeddedData == 0) -> {
281+
onShelfCodeScannedListener?.onShelfCodeScanned()
282+
progressDialog.dismiss()
283+
onDismissListener?.onDismiss()
284+
}
285+
product.type == Product.Type.DepositReturnVoucher
286+
&& project.shoppingCart.containsScannedCode(scannedCode) -> {
287+
onAlreadyScannedListener?.onAlreadyScanned()
288+
progressDialog.dismiss()
289+
onDismissListener?.onDismiss()
290+
}
291+
onProductFoundListener != null -> {
292+
onProductFoundListener?.onProductFound(product, scannedCode)
293+
}
294+
else -> return true
295+
}
296+
297+
return false
283298
}
284299

285300
@Deprecated("Use resolve() instead")

0 commit comments

Comments
 (0)