diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/Utils.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/Utils.kt
index 98e729e..9311250 100644
--- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/Utils.kt
+++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/Utils.kt
@@ -7,7 +7,6 @@ import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.net.Uri
import android.os.Build
-import android.util.Log
import androidx.annotation.RequiresApi
import androidx.core.content.FileProvider
import androidx.core.graphics.scale
@@ -80,4 +79,15 @@ fun calculateProductFreshness(dateOfProduction: Long, dateOfExpiry: Long): Doubl
val lifeSpanLeft: Long = dateOfExpiry - Date().time / 1000
return lifeSpanLeft / productLifeSpan.toDouble()
-}
\ No newline at end of file
+}
+
+fun getUnitNameById (context: Context, id: Int): String {
+ return when(id) {
+ 0 -> { context.getString(R.string.kilogram) }
+ 1 -> { context.getString(R.string.gram) }
+ 2 -> { context.getString(R.string.liter) }
+ 3 -> { context.getString(R.string.milliliter) }
+ 4 -> { context.getString(R.string.pieces) }
+ else -> { "" }
+ }
+}
diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/AddAbstractProductActivity.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/AddAbstractProductActivity.kt
index 6eab79f..7875466 100644
--- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/AddAbstractProductActivity.kt
+++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/AddAbstractProductActivity.kt
@@ -34,6 +34,7 @@ class AddAbstractProductActivity : AppCompatActivity() {
private lateinit var barcodeText: EditText
private lateinit var productNameText: TextView
private lateinit var netWeightText: TextView
+ private lateinit var unitTypeSpinner: Spinner
private lateinit var categorySpinner: Spinner
@@ -68,10 +69,12 @@ class AddAbstractProductActivity : AppCompatActivity() {
barcodeText = findViewById(R.id.barcodeTextEdit)
productNameText = findViewById(R.id.productName)
netWeightText = findViewById(R.id.netWeight)
+ unitTypeSpinner = findViewById(R.id.unitTypeSpinner)
categorySpinner = findViewById(R.id.categorySpinner)
fillupCategorySpinner()
+ fillupUnitsSpinner()
if (abstractProduct?.name == "" && abstractProduct?.barcode != "") {
performRequest(abstractProduct?.barcode!!)
@@ -86,6 +89,7 @@ class AddAbstractProductActivity : AppCompatActivity() {
productNameText.text = abstractProduct!!.name
netWeightText.text = abstractProduct!!.netWeight.toString()
categorySpinner.setSelection(abstractProduct!!.category)
+ unitTypeSpinner.setSelection(abstractProduct!!.unit)
}
saveButton.setOnClickListener {
@@ -116,6 +120,7 @@ class AddAbstractProductActivity : AppCompatActivity() {
put(AbstractProductContract.AbstractProductEntry.PRODUCT_NET_WEIGHT, netWeight.toString())
put(AbstractProductContract.AbstractProductEntry.IMAGE_FILENAME, pictureFile.nameWithoutExtension)
put(AbstractProductContract.AbstractProductEntry.CATEGORY, categorySpinner.selectedItemPosition)
+ put(AbstractProductContract.AbstractProductEntry.UNIT, unitTypeSpinner.selectedItemPosition)
}
if (abstractProduct == null) {
@@ -192,10 +197,26 @@ class AddAbstractProductActivity : AppCompatActivity() {
runOnUiThread {
productNameText.text = abstractProduct.name
netWeightText.text = abstractProduct.netWeight.toString()
+ unitTypeSpinner.setSelection(abstractProduct.unit)
}
}
}
+ private fun fillupUnitsSpinner() {
+ val units = listOf(
+ getString(R.string.kilogram),
+ getString(R.string.gram),
+ getString(R.string.liter),
+ getString(R.string.milliliter),
+ getString(R.string.pieces)
+ )
+
+
+ val arrayAdapter = ArrayAdapter(this, androidx.appcompat.R.layout.support_simple_spinner_dropdown_item, units)
+ arrayAdapter.setDropDownViewResource(androidx.appcompat.R.layout.support_simple_spinner_dropdown_item)
+ unitTypeSpinner.adapter = arrayAdapter
+ }
+
fun fillupCategorySpinner() {
val db = DBStorageController(this).readableDatabase
diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/views/AbstractProductView.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/views/AbstractProductView.kt
index 814c5ec..29bd48b 100644
--- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/views/AbstractProductView.kt
+++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/views/AbstractProductView.kt
@@ -12,12 +12,9 @@ import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.ContextCompat
import androidx.core.content.ContextCompat.startActivity
-import org.foxarmy.barcodescannerforemployees.DBStorageController
-import org.foxarmy.barcodescannerforemployees.R
+import org.foxarmy.barcodescannerforemployees.*
import org.foxarmy.barcodescannerforemployees.activities.FullscreenActivity
import org.foxarmy.barcodescannerforemployees.dataclasses.AbstractProduct
-import org.foxarmy.barcodescannerforemployees.getActivity
-import org.foxarmy.barcodescannerforemployees.getImageUri
import java.io.File
class AbstractProductView: LinearLayout {
@@ -67,7 +64,7 @@ class AbstractProductView: LinearLayout {
}
- //TODO: units
+ unitField?.text = getUnitNameById(context, abstractProduct.unit)
productLayout!!.setOnLongClickListener {
isProductSelected = !isProductSelected
diff --git a/app/src/main/res/layout/fragment_add_abstract_product.xml b/app/src/main/res/layout/fragment_add_abstract_product.xml
index fe3eae5..940e50c 100644
--- a/app/src/main/res/layout/fragment_add_abstract_product.xml
+++ b/app/src/main/res/layout/fragment_add_abstract_product.xml
@@ -40,17 +40,21 @@
android:visibility="visible" android:hint="@string/product_name_label" android:textColorHint="#737373"
android:layout_marginTop="8dp" app:layout_constraintTop_toBottomOf="@+id/barcodeTextEdit"/>
+ app:layout_constraintTop_toBottomOf="@+id/productName"
+ />
+
delete
Category
Date of production
+
+
+ kg
+ g
+ l
+ ml
+ pc
\ No newline at end of file
diff --git a/app/src/main/res/values/units.xml b/app/src/main/res/values/units.xml
deleted file mode 100644
index ba4d897..0000000
--- a/app/src/main/res/values/units.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
- kg
- g
- l
- ml
- pc
-
\ No newline at end of file