adding units to abstract product
This commit is contained in:
parent
a2662bf55b
commit
c112eec868
|
@ -18,6 +18,7 @@ object AbstractProductContract {
|
||||||
const val PRODUCT_NET_WEIGHT = "net_weight"
|
const val PRODUCT_NET_WEIGHT = "net_weight"
|
||||||
const val IMAGE_FILENAME = "image_filename"
|
const val IMAGE_FILENAME = "image_filename"
|
||||||
const val CATEGORY = "category"
|
const val CATEGORY = "category"
|
||||||
|
const val UNIT = "unit"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +46,8 @@ const val SQL_CREATE_ABSTRACT_PRODUCTS_TABLE =
|
||||||
"${AbstractProductContract.AbstractProductEntry.PRODUCT_NAME} TEXT," +
|
"${AbstractProductContract.AbstractProductEntry.PRODUCT_NAME} TEXT," +
|
||||||
"${AbstractProductContract.AbstractProductEntry.PRODUCT_NET_WEIGHT} REAL," +
|
"${AbstractProductContract.AbstractProductEntry.PRODUCT_NET_WEIGHT} REAL," +
|
||||||
"${AbstractProductContract.AbstractProductEntry.IMAGE_FILENAME} TEXT," +
|
"${AbstractProductContract.AbstractProductEntry.IMAGE_FILENAME} TEXT," +
|
||||||
"${AbstractProductContract.AbstractProductEntry.CATEGORY} INTEGER)"
|
"${AbstractProductContract.AbstractProductEntry.CATEGORY} INTEGER," +
|
||||||
|
"${AbstractProductContract.AbstractProductEntry.UNIT} INTEGER)"
|
||||||
|
|
||||||
const val SQL_CREATE_PRODUCTS_TABLE =
|
const val SQL_CREATE_PRODUCTS_TABLE =
|
||||||
"CREATE TABLE ${ProductContract.ProductEntry.TABLE_NAME} (" +
|
"CREATE TABLE ${ProductContract.ProductEntry.TABLE_NAME} (" +
|
||||||
|
@ -109,6 +111,7 @@ class DBStorageController(context: Context) : SQLiteOpenHelper(context, DATABASE
|
||||||
AbstractProductContract.AbstractProductEntry.PRODUCT_NAME,
|
AbstractProductContract.AbstractProductEntry.PRODUCT_NAME,
|
||||||
AbstractProductContract.AbstractProductEntry.IMAGE_FILENAME,
|
AbstractProductContract.AbstractProductEntry.IMAGE_FILENAME,
|
||||||
AbstractProductContract.AbstractProductEntry.PRODUCT_NET_WEIGHT,
|
AbstractProductContract.AbstractProductEntry.PRODUCT_NET_WEIGHT,
|
||||||
|
AbstractProductContract.AbstractProductEntry.UNIT
|
||||||
)
|
)
|
||||||
|
|
||||||
val selection = "${AbstractProductContract.AbstractProductEntry.CATEGORY} = ?"
|
val selection = "${AbstractProductContract.AbstractProductEntry.CATEGORY} = ?"
|
||||||
|
@ -123,8 +126,9 @@ class DBStorageController(context: Context) : SQLiteOpenHelper(context, DATABASE
|
||||||
val abstractProductName = getString(getColumnIndexOrThrow(AbstractProductContract.AbstractProductEntry.PRODUCT_NAME))
|
val abstractProductName = getString(getColumnIndexOrThrow(AbstractProductContract.AbstractProductEntry.PRODUCT_NAME))
|
||||||
val abstractProductNetWeight = getDouble(getColumnIndexOrThrow(AbstractProductContract.AbstractProductEntry.PRODUCT_NET_WEIGHT))
|
val abstractProductNetWeight = getDouble(getColumnIndexOrThrow(AbstractProductContract.AbstractProductEntry.PRODUCT_NET_WEIGHT))
|
||||||
val abstractProductImageHash = getString(getColumnIndexOrThrow(AbstractProductContract.AbstractProductEntry.IMAGE_FILENAME))
|
val abstractProductImageHash = getString(getColumnIndexOrThrow(AbstractProductContract.AbstractProductEntry.IMAGE_FILENAME))
|
||||||
|
val abstractProductUnit = getInt(getColumnIndexOrThrow(AbstractProductContract.AbstractProductEntry.UNIT))
|
||||||
|
|
||||||
val abstractProduct = AbstractProduct(abstractProductId, abstractProductBarcode, abstractProductName, abstractProductNetWeight, abstractProductImageHash, category = id)
|
val abstractProduct = AbstractProduct(abstractProductId, abstractProductBarcode, abstractProductName, abstractProductNetWeight, abstractProductImageHash, category = id, abstractProductUnit)
|
||||||
|
|
||||||
result.add(abstractProduct)
|
result.add(abstractProduct)
|
||||||
}
|
}
|
||||||
|
@ -203,7 +207,8 @@ class DBStorageController(context: Context) : SQLiteOpenHelper(context, DATABASE
|
||||||
AbstractProductContract.AbstractProductEntry.PRODUCT_NAME,
|
AbstractProductContract.AbstractProductEntry.PRODUCT_NAME,
|
||||||
AbstractProductContract.AbstractProductEntry.IMAGE_FILENAME,
|
AbstractProductContract.AbstractProductEntry.IMAGE_FILENAME,
|
||||||
AbstractProductContract.AbstractProductEntry.PRODUCT_NET_WEIGHT,
|
AbstractProductContract.AbstractProductEntry.PRODUCT_NET_WEIGHT,
|
||||||
AbstractProductContract.AbstractProductEntry.CATEGORY
|
AbstractProductContract.AbstractProductEntry.CATEGORY,
|
||||||
|
AbstractProductContract.AbstractProductEntry.UNIT
|
||||||
)
|
)
|
||||||
|
|
||||||
val selection = "${AbstractProductContract.AbstractProductEntry.BARCODE} = ?"
|
val selection = "${AbstractProductContract.AbstractProductEntry.BARCODE} = ?"
|
||||||
|
@ -218,8 +223,9 @@ class DBStorageController(context: Context) : SQLiteOpenHelper(context, DATABASE
|
||||||
val imageFilename = getString(getColumnIndexOrThrow(AbstractProductContract.AbstractProductEntry.IMAGE_FILENAME))
|
val imageFilename = getString(getColumnIndexOrThrow(AbstractProductContract.AbstractProductEntry.IMAGE_FILENAME))
|
||||||
val netWeight = getDouble(getColumnIndexOrThrow(AbstractProductContract.AbstractProductEntry.PRODUCT_NET_WEIGHT))
|
val netWeight = getDouble(getColumnIndexOrThrow(AbstractProductContract.AbstractProductEntry.PRODUCT_NET_WEIGHT))
|
||||||
val category = getInt(getColumnIndexOrThrow(AbstractProductContract.AbstractProductEntry.CATEGORY))
|
val category = getInt(getColumnIndexOrThrow(AbstractProductContract.AbstractProductEntry.CATEGORY))
|
||||||
|
val unit = getInt(getColumnIndexOrThrow(AbstractProductContract.AbstractProductEntry.UNIT))
|
||||||
|
|
||||||
abstractProduct = AbstractProduct(id, barcode, productName, netWeight, imageFilename, category)
|
abstractProduct = AbstractProduct(id, barcode, productName, netWeight, imageFilename, category, unit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,7 +240,8 @@ class DBStorageController(context: Context) : SQLiteOpenHelper(context, DATABASE
|
||||||
AbstractProductContract.AbstractProductEntry.PRODUCT_NET_WEIGHT,
|
AbstractProductContract.AbstractProductEntry.PRODUCT_NET_WEIGHT,
|
||||||
AbstractProductContract.AbstractProductEntry.IMAGE_FILENAME,
|
AbstractProductContract.AbstractProductEntry.IMAGE_FILENAME,
|
||||||
AbstractProductContract.AbstractProductEntry.CATEGORY,
|
AbstractProductContract.AbstractProductEntry.CATEGORY,
|
||||||
AbstractProductContract.AbstractProductEntry.BARCODE
|
AbstractProductContract.AbstractProductEntry.BARCODE,
|
||||||
|
AbstractProductContract.AbstractProductEntry.UNIT
|
||||||
)
|
)
|
||||||
|
|
||||||
val selection = "${BaseColumns._ID} = ?"
|
val selection = "${BaseColumns._ID} = ?"
|
||||||
|
@ -250,8 +257,9 @@ class DBStorageController(context: Context) : SQLiteOpenHelper(context, DATABASE
|
||||||
val netWeight = getDouble(getColumnIndexOrThrow(AbstractProductContract.AbstractProductEntry.PRODUCT_NET_WEIGHT))
|
val netWeight = getDouble(getColumnIndexOrThrow(AbstractProductContract.AbstractProductEntry.PRODUCT_NET_WEIGHT))
|
||||||
val imageHash = getString((getColumnIndexOrThrow(AbstractProductContract.AbstractProductEntry.IMAGE_FILENAME)))
|
val imageHash = getString((getColumnIndexOrThrow(AbstractProductContract.AbstractProductEntry.IMAGE_FILENAME)))
|
||||||
val category = getInt(getColumnIndexOrThrow(AbstractProductContract.AbstractProductEntry.CATEGORY))
|
val category = getInt(getColumnIndexOrThrow(AbstractProductContract.AbstractProductEntry.CATEGORY))
|
||||||
|
val unit = getInt(getColumnIndexOrThrow(AbstractProductContract.AbstractProductEntry.UNIT))
|
||||||
|
|
||||||
abstractProduct = AbstractProduct(productId, barcode, name, netWeight, imageHash, category)
|
abstractProduct = AbstractProduct(productId, barcode, name, netWeight, imageHash, category, unit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import org.foxarmy.barcodescannerforemployees.dataclasses.AbstractProduct
|
||||||
|
|
||||||
class Parser constructor() {
|
class Parser constructor() {
|
||||||
|
|
||||||
fun findNetWeightInText(text: String, regexes: List<Regex>): Pair<String, Double> {
|
fun findNetWeightInText(text: String, regexes: List<Regex>): Triple<String, Double, String> {
|
||||||
var text = text
|
var text = text
|
||||||
var netWeight = 0.0
|
var netWeight = 0.0
|
||||||
for (regex in regexes.iterator()) {
|
for (regex in regexes.iterator()) {
|
||||||
|
@ -13,18 +13,18 @@ class Parser constructor() {
|
||||||
val found = foundByRegex.groupValues[0]
|
val found = foundByRegex.groupValues[0]
|
||||||
text = text.replace(found, "")
|
text = text.replace(found, "")
|
||||||
netWeight = stripNetWeight(found)
|
netWeight = stripNetWeight(found)
|
||||||
when (found.lowercase().strip()) {
|
// when (found.lowercase().strip()) {
|
||||||
"кг" -> netWeight *= 1000
|
// "кг" -> netWeight *= 1000
|
||||||
"мл" -> netWeight /= 1000
|
// "мл" -> netWeight /= 1000
|
||||||
}
|
// }
|
||||||
return Pair(text, netWeight)
|
return Triple(text, netWeight, found)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Pair("", 0.0)
|
return Triple("", 0.0, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun parse(text: String): AbstractProduct {
|
fun parse(text: String): AbstractProduct {
|
||||||
val (name, netWeight) = findNetWeightInText(
|
val (name, netWeight, unit) = findNetWeightInText(
|
||||||
text,
|
text,
|
||||||
listOf(
|
listOf(
|
||||||
Regex("[0-9]+,?[0-9]*\\s*[лЛ]"),
|
Regex("[0-9]+,?[0-9]*\\s*[лЛ]"),
|
||||||
|
@ -35,6 +35,6 @@ class Parser constructor() {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
return AbstractProduct(0, "", name, netWeight, "", 0)
|
return AbstractProduct(0, "", name, netWeight, "", 0, unit)
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -73,7 +73,7 @@ class AddProductActivity : AppCompatActivity() {
|
||||||
update()
|
update()
|
||||||
} else {
|
} else {
|
||||||
product = Product(0, 0, 0, 0, 0)
|
product = Product(0, 0, 0, 0, 0)
|
||||||
abstractProduct = AbstractProduct(0, "", "", 0.0, "", 0)
|
abstractProduct = AbstractProduct(0, "", "", 0.0, "", 0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
scanButton.setOnClickListener {
|
scanButton.setOnClickListener {
|
||||||
|
|
|
@ -10,14 +10,16 @@ class AbstractProduct() : Parcelable {
|
||||||
var netWeight: Double = 0.0
|
var netWeight: Double = 0.0
|
||||||
var imageHash: String = ""
|
var imageHash: String = ""
|
||||||
var category: Int = 0
|
var category: Int = 0
|
||||||
|
var unit: Int = 0
|
||||||
|
|
||||||
constructor(id: Int, barcode: String, name: String ,netWeight: Double, imageHash: String, category: Int) : this() {
|
constructor(id: Int, barcode: String, name: String, netWeight: Double, imageHash: String, category: Int, unit: Int) : this() {
|
||||||
this.id = id
|
this.id = id
|
||||||
this.barcode = barcode
|
this.barcode = barcode
|
||||||
this.name = name
|
this.name = name
|
||||||
this.netWeight = netWeight
|
this.netWeight = netWeight
|
||||||
this.imageHash = imageHash
|
this.imageHash = imageHash
|
||||||
this.category = category
|
this.category = category
|
||||||
|
this.unit = unit
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(parcel: Parcel) : this() {
|
constructor(parcel: Parcel) : this() {
|
||||||
|
@ -27,6 +29,7 @@ class AbstractProduct() : Parcelable {
|
||||||
netWeight = parcel.readDouble()
|
netWeight = parcel.readDouble()
|
||||||
imageHash = parcel.readString()!!
|
imageHash = parcel.readString()!!
|
||||||
category = parcel.readInt()
|
category = parcel.readInt()
|
||||||
|
unit = parcel.readInt()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun writeToParcel(parcel: Parcel, flags: Int) {
|
override fun writeToParcel(parcel: Parcel, flags: Int) {
|
||||||
|
@ -36,6 +39,7 @@ class AbstractProduct() : Parcelable {
|
||||||
parcel.writeDouble(netWeight)
|
parcel.writeDouble(netWeight)
|
||||||
parcel.writeString(imageHash)
|
parcel.writeString(imageHash)
|
||||||
parcel.writeInt(category)
|
parcel.writeInt(category)
|
||||||
|
parcel.writeInt(unit)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun describeContents(): Int {
|
override fun describeContents(): Int {
|
||||||
|
|
|
@ -116,7 +116,8 @@ class StorageFragment : Fragment() {
|
||||||
AbstractProductContract.AbstractProductEntry.PRODUCT_NAME,
|
AbstractProductContract.AbstractProductEntry.PRODUCT_NAME,
|
||||||
AbstractProductContract.AbstractProductEntry.PRODUCT_NET_WEIGHT,
|
AbstractProductContract.AbstractProductEntry.PRODUCT_NET_WEIGHT,
|
||||||
AbstractProductContract.AbstractProductEntry.IMAGE_FILENAME,
|
AbstractProductContract.AbstractProductEntry.IMAGE_FILENAME,
|
||||||
AbstractProductContract.AbstractProductEntry.CATEGORY
|
AbstractProductContract.AbstractProductEntry.CATEGORY,
|
||||||
|
AbstractProductContract.AbstractProductEntry.UNIT
|
||||||
)
|
)
|
||||||
|
|
||||||
var orderBy: String = ""
|
var orderBy: String = ""
|
||||||
|
@ -140,8 +141,9 @@ class StorageFragment : Fragment() {
|
||||||
val netWeight = getDouble(getColumnIndexOrThrow(AbstractProductContract.AbstractProductEntry.PRODUCT_NET_WEIGHT))
|
val netWeight = getDouble(getColumnIndexOrThrow(AbstractProductContract.AbstractProductEntry.PRODUCT_NET_WEIGHT))
|
||||||
val productImageHash = getString(getColumnIndexOrThrow(AbstractProductContract.AbstractProductEntry.IMAGE_FILENAME))
|
val productImageHash = getString(getColumnIndexOrThrow(AbstractProductContract.AbstractProductEntry.IMAGE_FILENAME))
|
||||||
val category = getInt(getColumnIndexOrThrow(AbstractProductContract.AbstractProductEntry.CATEGORY))
|
val category = getInt(getColumnIndexOrThrow(AbstractProductContract.AbstractProductEntry.CATEGORY))
|
||||||
|
val unit = getInt(getColumnIndexOrThrow(AbstractProductContract.AbstractProductEntry.UNIT))
|
||||||
|
|
||||||
val product = AbstractProduct(productId, barcode, productName, netWeight, productImageHash, category)
|
val product = AbstractProduct(productId, barcode, productName, netWeight, productImageHash, category, unit)
|
||||||
|
|
||||||
generateThumbnailForImage(context!!, productImageHash)
|
generateThumbnailForImage(context!!, productImageHash)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<string name="gram">g</string>
|
||||||
|
<string name="kilogram">kg</string>
|
||||||
|
<string name="liter">l</string>
|
||||||
|
<string name="milliliter">ml</string>
|
||||||
|
<string name="pieces">pc</string>
|
||||||
|
</resources>
|
Loading…
Reference in New Issue