Skip to content

Commit 6755f3c

Browse files
committed
Add option to define the project of the ProductResolver
1 parent 45d95f0 commit 6755f3c

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4+
## [0.35.8]
5+
6+
### Changes
7+
- Add option to set project of the ProductResolver
8+
- Changed builder method name from `setBarcodeOfProject(...)` to `setBarcode(...)` to simplify usage
9+
410
## [0.35.7]
511

612
### Changes

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ allprojects {
3030
}
3131

3232
project.ext {
33-
sdkVersion='0.35.7'
33+
sdkVersion='0.35.8'
3434
versionCode=1
3535

3636
compileSdkVersion=30

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ import io.snabble.sdk.ui.utils.DelayedProgressDialog
1919
import io.snabble.sdk.utils.Age
2020
import io.snabble.sdk.utils.Dispatch
2121

22-
class ProductResolver private constructor(private val context: Context) {
22+
class ProductResolver private constructor(private val context: Context, private val project: Project) {
2323
private var resolveBundles = true
24-
private val productConfirmationDialog = ProductConfirmationDialog(context, SnabbleUI.getProject())
24+
private val productConfirmationDialog = ProductConfirmationDialog(context, project)
2525
var scannedCodes: List<ScannedCode> = emptyList()
2626
private set
2727
private val progressDialog: DelayedProgressDialog
@@ -71,7 +71,6 @@ class ProductResolver private constructor(private val context: Context) {
7171
progressDialog.showAfterDelay(300)
7272
onShowListener?.onShow()
7373

74-
val project = SnabbleUI.getProject()
7574
val productDatabase = project.productDatabase
7675

7776
// check if its available local first
@@ -156,7 +155,6 @@ class ProductResolver private constructor(private val context: Context) {
156155
progressDialog.dismiss()
157156
val unit = product.getEncodingUnit(scannedCode.templateName, scannedCode.lookupCode)
158157
var gs1EmbeddedData: BigDecimal? = null
159-
val project = SnabbleUI.getProject()
160158

161159
if (gs1Code != null) {
162160
gs1EmbeddedData = gs1Code.getEmbeddedData(unit,
@@ -204,7 +202,7 @@ class ProductResolver private constructor(private val context: Context) {
204202
onDismissListener?.onDismiss()
205203
}
206204
product.type == Product.Type.DepositReturnVoucher
207-
&& SnabbleUI.getProject().shoppingCart.containsScannedCode(scannedCode) -> {
205+
&& project.shoppingCart.containsScannedCode(scannedCode) -> {
208206
onAlreadyScannedListener?.onAlreadyScanned()
209207
progressDialog.dismiss()
210208
onDismissListener?.onDismiss()
@@ -230,7 +228,7 @@ class ProductResolver private constructor(private val context: Context) {
230228
Telemetry.event(Telemetry.Event.SelectedBundleProduct, product)
231229
val codes = product.scannableCodes
232230
if (codes.isNotEmpty() && codes[0].lookupCode != null) {
233-
val newCodes = ScannedCode.parse(SnabbleUI.getProject(), codes[0].lookupCode)
231+
val newCodes = ScannedCode.parse(project, codes[0].lookupCode)
234232
if (newCodes.size > 0) {
235233
var defaultCode = newCodes[0]
236234
for (newCode in newCodes) {
@@ -324,8 +322,8 @@ class ProductResolver private constructor(private val context: Context) {
324322
fun onAlreadyScanned()
325323
}
326324

327-
class Builder(context: Context) {
328-
private val productResolver: ProductResolver = ProductResolver(context)
325+
class Builder @JvmOverloads constructor(context: Context, private val project: Project = SnabbleUI.getProject()) {
326+
private val productResolver: ProductResolver = ProductResolver(context, project)
329327

330328
fun setCodes(codes: List<ScannedCode>) = apply {
331329
productResolver.scannedCodes = codes
@@ -335,7 +333,7 @@ class ProductResolver private constructor(private val context: Context) {
335333
productResolver.scannedCodes = listOf(code)
336334
}
337335

338-
fun setBarcodeOfProject(barcode: Barcode, project: Project) = apply {
336+
fun setBarcode(barcode: Barcode) = apply {
339337
setCodes(ScannedCode.parse(project, barcode.text))
340338
}
341339

0 commit comments

Comments
 (0)