From bf9ac88f33a44537477535c2d5dd5ae51dd216d2 Mon Sep 17 00:00:00 2001 From: Alexander Junggeburth Date: Tue, 22 Feb 2022 11:31:19 +0100 Subject: [PATCH 1/2] Fix handling of edge cases (such as notForSale) when selecting products from a bundle --- .../snabble/sdk/ui/scanner/ProductResolver.kt | 65 ++++++++++--------- 1 file changed, 36 insertions(+), 29 deletions(-) diff --git a/ui/src/main/java/io/snabble/sdk/ui/scanner/ProductResolver.kt b/ui/src/main/java/io/snabble/sdk/ui/scanner/ProductResolver.kt index e8d6e9d1d5..55eda5829d 100644 --- a/ui/src/main/java/io/snabble/sdk/ui/scanner/ProductResolver.kt +++ b/ui/src/main/java/io/snabble/sdk/ui/scanner/ProductResolver.kt @@ -197,34 +197,6 @@ class ProductResolver private constructor(private val context: Context, private resolveBundles && product.bundleProducts.isNotEmpty() && !scannedCode.hasEmbeddedData() -> { showBundleDialog(product, scannedCode) } - product.saleStop -> { - onSaleStopListener?.onSaleStop() - progressDialog.dismiss() - onDismissListener?.onDismiss() - } - product.notForSale -> { - onNotForSaleListener?.onNotForSale(product) - progressDialog.dismiss() - onDismissListener?.onDismiss() - } - product.availability == Product.Availability.NOT_AVAILABLE -> { - handleProductNotFound(scannedCode) - } - product.type == Product.Type.PreWeighed - && (!scannedCode.hasEmbeddedData() || scannedCode.embeddedData == 0) -> { - onShelfCodeScannedListener?.onShelfCodeScanned() - progressDialog.dismiss() - onDismissListener?.onDismiss() - } - product.type == Product.Type.DepositReturnVoucher - && project.shoppingCart.containsScannedCode(scannedCode) -> { - onAlreadyScannedListener?.onAlreadyScanned() - progressDialog.dismiss() - onDismissListener?.onDismiss() - } - onProductFoundListener != null -> { - onProductFoundListener?.onProductFound(product, scannedCode) - } else -> { showProduct(product, scannedCode) val event = if (wasOnlineProduct) { @@ -279,7 +251,42 @@ class ProductResolver private constructor(private val context: Context, private private fun showProduct(product: Product?, scannedCode: ScannedCode?) { lastProduct = product - productConfirmationDialog.show(product, scannedCode) + + if (product != null && scannedCode != null) { + when { + product.saleStop -> { + onSaleStopListener?.onSaleStop() + progressDialog.dismiss() + onDismissListener?.onDismiss() + } + product.notForSale -> { + onNotForSaleListener?.onNotForSale(product) + progressDialog.dismiss() + onDismissListener?.onDismiss() + } + product.availability == Product.Availability.NOT_AVAILABLE -> { + handleProductNotFound(scannedCode) + } + product.type == Product.Type.PreWeighed + && (!scannedCode.hasEmbeddedData() || scannedCode.embeddedData == 0) -> { + onShelfCodeScannedListener?.onShelfCodeScanned() + progressDialog.dismiss() + onDismissListener?.onDismiss() + } + product.type == Product.Type.DepositReturnVoucher + && project.shoppingCart.containsScannedCode(scannedCode) -> { + onAlreadyScannedListener?.onAlreadyScanned() + progressDialog.dismiss() + onDismissListener?.onDismiss() + } + onProductFoundListener != null -> { + onProductFoundListener?.onProductFound(product, scannedCode) + } + else -> { + productConfirmationDialog.show(product, scannedCode) + } + } + } } @Deprecated("Use resolve() instead") From 1a045287507ad8cb0bad0f7dde41c4df2fc23649 Mon Sep 17 00:00:00 2001 From: Alexander Junggeburth Date: Tue, 22 Feb 2022 11:50:17 +0100 Subject: [PATCH 2/2] check for product flags earlier --- .../snabble/sdk/ui/scanner/ProductResolver.kt | 110 ++++++++++-------- 1 file changed, 59 insertions(+), 51 deletions(-) diff --git a/ui/src/main/java/io/snabble/sdk/ui/scanner/ProductResolver.kt b/ui/src/main/java/io/snabble/sdk/ui/scanner/ProductResolver.kt index 55eda5829d..e276c26645 100644 --- a/ui/src/main/java/io/snabble/sdk/ui/scanner/ProductResolver.kt +++ b/ui/src/main/java/io/snabble/sdk/ui/scanner/ProductResolver.kt @@ -210,30 +210,32 @@ class ProductResolver private constructor(private val context: Context, private } private fun showBundleDialog(product: Product, scannedCode: ScannedCode) { - SelectBundleDialog.show(context, product, object : SelectBundleDialog.Callback { - override fun onProductSelected(product: Product) { - Telemetry.event(Telemetry.Event.SelectedBundleProduct, product) - val codes = product.scannableCodes - if (codes.isNotEmpty() && codes[0].lookupCode != null) { - val newCodes = ScannedCode.parse(project, codes[0].lookupCode) - if (newCodes.size > 0) { - var defaultCode = newCodes[0] - for (newCode in newCodes) { - if (newCode.templateName == "default") { - defaultCode = newCode + if (handleProductFlags(product, scannedCode)) { + SelectBundleDialog.show(context, product, object : SelectBundleDialog.Callback { + override fun onProductSelected(product: Product) { + Telemetry.event(Telemetry.Event.SelectedBundleProduct, product) + val codes = product.scannableCodes + if (codes.isNotEmpty() && codes[0].lookupCode != null) { + val newCodes = ScannedCode.parse(project, codes[0].lookupCode) + if (newCodes.size > 0) { + var defaultCode = newCodes[0] + for (newCode in newCodes) { + if (newCode.templateName == "default") { + defaultCode = newCode + } } + showProduct(product, defaultCode) + } else { + showProduct(product, scannedCode) } - showProduct(product, defaultCode) - } else { - showProduct(product, scannedCode) } } - } - override fun onDismissed() { - onDismissListener?.onDismiss() - } - }) + override fun onDismissed() { + onDismissListener?.onDismiss() + } + }) + } } private fun handleProductNotFound(scannedCode: ScannedCode) { @@ -253,42 +255,48 @@ class ProductResolver private constructor(private val context: Context, private lastProduct = product if (product != null && scannedCode != null) { - when { - product.saleStop -> { - onSaleStopListener?.onSaleStop() - progressDialog.dismiss() - onDismissListener?.onDismiss() - } - product.notForSale -> { - onNotForSaleListener?.onNotForSale(product) - progressDialog.dismiss() - onDismissListener?.onDismiss() - } - product.availability == Product.Availability.NOT_AVAILABLE -> { - handleProductNotFound(scannedCode) - } - product.type == Product.Type.PreWeighed - && (!scannedCode.hasEmbeddedData() || scannedCode.embeddedData == 0) -> { - onShelfCodeScannedListener?.onShelfCodeScanned() - progressDialog.dismiss() - onDismissListener?.onDismiss() - } - product.type == Product.Type.DepositReturnVoucher - && project.shoppingCart.containsScannedCode(scannedCode) -> { - onAlreadyScannedListener?.onAlreadyScanned() - progressDialog.dismiss() - onDismissListener?.onDismiss() - } - onProductFoundListener != null -> { - onProductFoundListener?.onProductFound(product, scannedCode) - } - else -> { - productConfirmationDialog.show(product, scannedCode) - } + if (handleProductFlags(product, scannedCode)) { + productConfirmationDialog.show(product, scannedCode) } } } + private fun handleProductFlags(product: Product, scannedCode: ScannedCode) : Boolean { + when { + product.saleStop -> { + onSaleStopListener?.onSaleStop() + progressDialog.dismiss() + onDismissListener?.onDismiss() + } + product.notForSale -> { + onNotForSaleListener?.onNotForSale(product) + progressDialog.dismiss() + onDismissListener?.onDismiss() + } + product.availability == Product.Availability.NOT_AVAILABLE -> { + handleProductNotFound(scannedCode) + } + product.type == Product.Type.PreWeighed + && (!scannedCode.hasEmbeddedData() || scannedCode.embeddedData == 0) -> { + onShelfCodeScannedListener?.onShelfCodeScanned() + progressDialog.dismiss() + onDismissListener?.onDismiss() + } + product.type == Product.Type.DepositReturnVoucher + && project.shoppingCart.containsScannedCode(scannedCode) -> { + onAlreadyScannedListener?.onAlreadyScanned() + progressDialog.dismiss() + onDismissListener?.onDismiss() + } + onProductFoundListener != null -> { + onProductFoundListener?.onProductFound(product, scannedCode) + } + else -> return true + } + + return false + } + @Deprecated("Use resolve() instead") fun show() = resolve()