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 fb89c16..d3914ac 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/AddAbstractProductActivity.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/AddAbstractProductActivity.kt @@ -45,7 +45,7 @@ class AddAbstractProductActivity : AppCompatActivity() { private lateinit var pictureFile: File private lateinit var picturesPath: File private var barcode: String = "" - private var updatingExisting = false + private var action: String = "new" private var scanningBarcode = false @@ -54,8 +54,6 @@ class AddAbstractProductActivity : AppCompatActivity() { setContentView(R.layout.fragment_add_abstract_product) - val extras = intent.extras - abstractProduct = extras!!.get("abstractProduct") as AbstractProduct? picturesPath = File(filesDir, "pictures") val thumbnailsDir = File(cacheDir, "thumbnails") @@ -81,21 +79,23 @@ class AddAbstractProductActivity : AppCompatActivity() { this.barcode = barcodeText.text.toString() } - if (abstractProduct != null && abstractProduct!!.barcode != "" && abstractProduct!!.name == "") { - barcode = abstractProduct!!.barcode - updatingExisting = false - performRequest(abstractProduct!!.barcode) - } else if (abstractProduct != null && abstractProduct!!.barcode == ""){ - updatingExisting = true - } else if (abstractProduct == null) { - updatingExisting = false + val extras = intent.extras + action = extras!!.get("action") as String + when (action) { + "update" -> { + abstractProduct = extras.get("abstractProduct") as AbstractProduct? + } + "new_from_barcode" -> { + abstractProduct = extras.get("abstractProduct") as AbstractProduct? + barcode = abstractProduct!!.barcode + performRequest(abstractProduct!!.barcode) + } } if (abstractProduct != null) { val imageThumbnailUri = getImageUri(this, File(thumbnailsDir, "${abstractProduct!!.imageHash}.webp")) pictureFile = File(picturesPath, "${abstractProduct!!.imageHash}.png]") imageView.setImageURI(imageThumbnailUri) -// imageView.rotation = 90f barcodeText.setText(abstractProduct!!.barcode) productNameText.text = abstractProduct!!.name netWeightText.text = abstractProduct!!.netWeight.toString() @@ -134,14 +134,14 @@ class AddAbstractProductActivity : AppCompatActivity() { put(AbstractProductContract.AbstractProductEntry.UNIT, unitTypeSpinner.selectedItemPosition) } - if (updatingExisting) { + if (action == "update") { db.update( AbstractProductContract.AbstractProductEntry.TABLE_NAME, values, "${BaseColumns._ID} = ?", arrayOf(abstractProduct!!.id.toString()) ) - } else { + } else if (action == "new" || action == "new_from_barcode"){ db.insert(AbstractProductContract.AbstractProductEntry.TABLE_NAME, null, values) } diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/AddCategoryActivity.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/AddCategoryActivity.kt index 9c178d8..c2d4c01 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/AddCategoryActivity.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/AddCategoryActivity.kt @@ -6,10 +6,11 @@ import android.os.Bundle import android.provider.BaseColumns import android.widget.Button import android.widget.EditText +import android.widget.Toast import org.foxarmy.barcodescannerforemployees.CategoriesContract -import org.foxarmy.barcodescannerforemployees.dataclasses.Category import org.foxarmy.barcodescannerforemployees.DBStorageController import org.foxarmy.barcodescannerforemployees.R +import org.foxarmy.barcodescannerforemployees.dataclasses.Category class AddCategoryActivity : Activity() { override fun onCreate(savedInstanceState: Bundle?) { @@ -27,6 +28,11 @@ class AddCategoryActivity : Activity() { findViewById