implemented units
This commit is contained in:
parent
e9ef4c44f9
commit
0fdcabca48
|
@ -7,7 +7,6 @@ import android.graphics.Bitmap
|
||||||
import android.graphics.BitmapFactory
|
import android.graphics.BitmapFactory
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.util.Log
|
|
||||||
import androidx.annotation.RequiresApi
|
import androidx.annotation.RequiresApi
|
||||||
import androidx.core.content.FileProvider
|
import androidx.core.content.FileProvider
|
||||||
import androidx.core.graphics.scale
|
import androidx.core.graphics.scale
|
||||||
|
@ -81,3 +80,14 @@ fun calculateProductFreshness(dateOfProduction: Long, dateOfExpiry: Long): Doubl
|
||||||
|
|
||||||
return lifeSpanLeft / productLifeSpan.toDouble()
|
return lifeSpanLeft / productLifeSpan.toDouble()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 -> { "" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ class AddAbstractProductActivity : AppCompatActivity() {
|
||||||
private lateinit var barcodeText: EditText
|
private lateinit var barcodeText: EditText
|
||||||
private lateinit var productNameText: TextView
|
private lateinit var productNameText: TextView
|
||||||
private lateinit var netWeightText: TextView
|
private lateinit var netWeightText: TextView
|
||||||
|
private lateinit var unitTypeSpinner: Spinner
|
||||||
|
|
||||||
private lateinit var categorySpinner: Spinner
|
private lateinit var categorySpinner: Spinner
|
||||||
|
|
||||||
|
@ -68,10 +69,12 @@ class AddAbstractProductActivity : AppCompatActivity() {
|
||||||
barcodeText = findViewById(R.id.barcodeTextEdit)
|
barcodeText = findViewById(R.id.barcodeTextEdit)
|
||||||
productNameText = findViewById(R.id.productName)
|
productNameText = findViewById(R.id.productName)
|
||||||
netWeightText = findViewById(R.id.netWeight)
|
netWeightText = findViewById(R.id.netWeight)
|
||||||
|
unitTypeSpinner = findViewById(R.id.unitTypeSpinner)
|
||||||
|
|
||||||
categorySpinner = findViewById(R.id.categorySpinner)
|
categorySpinner = findViewById(R.id.categorySpinner)
|
||||||
|
|
||||||
fillupCategorySpinner()
|
fillupCategorySpinner()
|
||||||
|
fillupUnitsSpinner()
|
||||||
|
|
||||||
if (abstractProduct?.name == "" && abstractProduct?.barcode != "") {
|
if (abstractProduct?.name == "" && abstractProduct?.barcode != "") {
|
||||||
performRequest(abstractProduct?.barcode!!)
|
performRequest(abstractProduct?.barcode!!)
|
||||||
|
@ -86,6 +89,7 @@ class AddAbstractProductActivity : AppCompatActivity() {
|
||||||
productNameText.text = abstractProduct!!.name
|
productNameText.text = abstractProduct!!.name
|
||||||
netWeightText.text = abstractProduct!!.netWeight.toString()
|
netWeightText.text = abstractProduct!!.netWeight.toString()
|
||||||
categorySpinner.setSelection(abstractProduct!!.category)
|
categorySpinner.setSelection(abstractProduct!!.category)
|
||||||
|
unitTypeSpinner.setSelection(abstractProduct!!.unit)
|
||||||
}
|
}
|
||||||
|
|
||||||
saveButton.setOnClickListener {
|
saveButton.setOnClickListener {
|
||||||
|
@ -116,6 +120,7 @@ class AddAbstractProductActivity : AppCompatActivity() {
|
||||||
put(AbstractProductContract.AbstractProductEntry.PRODUCT_NET_WEIGHT, netWeight.toString())
|
put(AbstractProductContract.AbstractProductEntry.PRODUCT_NET_WEIGHT, netWeight.toString())
|
||||||
put(AbstractProductContract.AbstractProductEntry.IMAGE_FILENAME, pictureFile.nameWithoutExtension)
|
put(AbstractProductContract.AbstractProductEntry.IMAGE_FILENAME, pictureFile.nameWithoutExtension)
|
||||||
put(AbstractProductContract.AbstractProductEntry.CATEGORY, categorySpinner.selectedItemPosition)
|
put(AbstractProductContract.AbstractProductEntry.CATEGORY, categorySpinner.selectedItemPosition)
|
||||||
|
put(AbstractProductContract.AbstractProductEntry.UNIT, unitTypeSpinner.selectedItemPosition)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (abstractProduct == null) {
|
if (abstractProduct == null) {
|
||||||
|
@ -192,10 +197,26 @@ class AddAbstractProductActivity : AppCompatActivity() {
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
productNameText.text = abstractProduct.name
|
productNameText.text = abstractProduct.name
|
||||||
netWeightText.text = abstractProduct.netWeight.toString()
|
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<String>(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() {
|
fun fillupCategorySpinner() {
|
||||||
val db = DBStorageController(this).readableDatabase
|
val db = DBStorageController(this).readableDatabase
|
||||||
|
|
||||||
|
|
|
@ -12,12 +12,9 @@ import android.widget.TextView
|
||||||
import androidx.constraintlayout.widget.ConstraintLayout
|
import androidx.constraintlayout.widget.ConstraintLayout
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.content.ContextCompat.startActivity
|
import androidx.core.content.ContextCompat.startActivity
|
||||||
import org.foxarmy.barcodescannerforemployees.DBStorageController
|
import org.foxarmy.barcodescannerforemployees.*
|
||||||
import org.foxarmy.barcodescannerforemployees.R
|
|
||||||
import org.foxarmy.barcodescannerforemployees.activities.FullscreenActivity
|
import org.foxarmy.barcodescannerforemployees.activities.FullscreenActivity
|
||||||
import org.foxarmy.barcodescannerforemployees.dataclasses.AbstractProduct
|
import org.foxarmy.barcodescannerforemployees.dataclasses.AbstractProduct
|
||||||
import org.foxarmy.barcodescannerforemployees.getActivity
|
|
||||||
import org.foxarmy.barcodescannerforemployees.getImageUri
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
class AbstractProductView: LinearLayout {
|
class AbstractProductView: LinearLayout {
|
||||||
|
@ -67,7 +64,7 @@ class AbstractProductView: LinearLayout {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: units
|
unitField?.text = getUnitNameById(context, abstractProduct.unit)
|
||||||
|
|
||||||
productLayout!!.setOnLongClickListener {
|
productLayout!!.setOnLongClickListener {
|
||||||
isProductSelected = !isProductSelected
|
isProductSelected = !isProductSelected
|
||||||
|
|
|
@ -40,17 +40,21 @@
|
||||||
android:visibility="visible" android:hint="@string/product_name_label" android:textColorHint="#737373"
|
android:visibility="visible" android:hint="@string/product_name_label" android:textColorHint="#737373"
|
||||||
android:layout_marginTop="8dp" app:layout_constraintTop_toBottomOf="@+id/barcodeTextEdit"/>
|
android:layout_marginTop="8dp" app:layout_constraintTop_toBottomOf="@+id/barcodeTextEdit"/>
|
||||||
<EditText
|
<EditText
|
||||||
android:layout_width="350dp"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="50dp"
|
android:layout_height="50dp"
|
||||||
android:inputType="text"
|
android:inputType="text"
|
||||||
android:ems="10"
|
android:ems="10"
|
||||||
android:id="@+id/netWeight"
|
android:id="@+id/netWeight"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
android:layout_marginStart="8dp"
|
android:layout_marginStart="8dp"
|
||||||
android:layout_marginEnd="8dp"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
android:visibility="visible" android:hint="@string/netWeight" android:textColorHint="#737373"
|
android:visibility="visible" android:hint="@string/netWeight" android:textColorHint="#737373"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/productName"/>
|
app:layout_constraintTop_toBottomOf="@+id/productName"
|
||||||
|
/>
|
||||||
|
<Spinner
|
||||||
|
android:layout_width="130dp"
|
||||||
|
android:layout_height="50dp" android:id="@+id/unitTypeSpinner"
|
||||||
|
app:layout_constraintStart_toEndOf="@+id/netWeight"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/productName" app:layout_constraintEnd_toEndOf="parent"/>
|
||||||
<EditText
|
<EditText
|
||||||
android:layout_width="350dp"
|
android:layout_width="350dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
|
|
@ -27,4 +27,11 @@
|
||||||
<string name="delete">delete</string>
|
<string name="delete">delete</string>
|
||||||
<string name="category">Category</string>
|
<string name="category">Category</string>
|
||||||
<string name="date_of_production">Date of production</string>
|
<string name="date_of_production">Date of production</string>
|
||||||
|
|
||||||
|
<!-- Unit names -->
|
||||||
|
<string name="kilogram">kg</string>
|
||||||
|
<string name="gram">g</string>
|
||||||
|
<string name="liter">l</string>
|
||||||
|
<string name="milliliter">ml</string>
|
||||||
|
<string name="pieces">pc</string>
|
||||||
</resources>
|
</resources>
|
|
@ -1,8 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<resources>
|
|
||||||
<string name="kilogram">kg</string>
|
|
||||||
<string name="gram">g</string>
|
|
||||||
<string name="liter">l</string>
|
|
||||||
<string name="milliliter">ml</string>
|
|
||||||
<string name="pieces">pc</string>
|
|
||||||
</resources>
|
|
Loading…
Reference in New Issue