diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/Parser.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/Parser.kt index 461629c..1a09cb7 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/Parser.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/Parser.kt @@ -1,5 +1,6 @@ package org.foxarmy.barcodescannerforemployees +import android.util.Log import org.foxarmy.barcodescannerforemployees.dataclasses.AbstractProduct class Parser constructor() { @@ -34,7 +35,19 @@ class Parser constructor() { Regex("[0-9]+,?[0-9*]\\s*((шт)|(Шт))") ) ) + var unitNumber = -1 + val strippedUnit = unit.lowercase().replace(Regex("\\d"), "").strip() + unitNumber = when (strippedUnit) { + "кг" -> { 0 } + "г" -> { 1 } + "л" -> { 2 } + "мл" -> { 3 } + "шт" -> { 4 } - return AbstractProduct(0, "", name, netWeight, "", 0, unit) + else -> { -1 } + } + Log.d("QWERTYUIOP", "Unit: ${strippedUnit}, number: ${unitNumber}") + + return AbstractProduct(0, "", name, netWeight, "", 0, unitNumber) } } \ No newline at end of file diff --git a/app/src/main/res/values/units.xml b/app/src/main/res/values/units.xml index 62aa378..ba4d897 100644 --- a/app/src/main/res/values/units.xml +++ b/app/src/main/res/values/units.xml @@ -1,7 +1,7 @@ - g kg + g l ml pc