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 9999719..6eab79f 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/AddAbstractProductActivity.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/AddAbstractProductActivity.kt @@ -2,6 +2,8 @@ package org.foxarmy.barcodescannerforemployees.activities import android.Manifest import android.content.ContentValues +import android.content.DialogInterface +import android.content.Intent import android.os.Build import android.os.Bundle import android.provider.BaseColumns @@ -9,7 +11,9 @@ import android.util.Log import android.widget.* import androidx.activity.result.contract.ActivityResultContracts import androidx.annotation.RequiresApi +import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity +import androidx.core.content.ContextCompat import com.google.mlkit.vision.barcode.common.Barcode import com.google.mlkit.vision.codescanner.GmsBarcodeScannerOptions import com.google.mlkit.vision.codescanner.GmsBarcodeScanning @@ -78,6 +82,7 @@ class AddAbstractProductActivity : AppCompatActivity() { 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() categorySpinner.setSelection(abstractProduct!!.category) @@ -155,6 +160,23 @@ class AddAbstractProductActivity : AppCompatActivity() { requester.request(this, barcode) var abstractProduct: AbstractProduct + if (DBStorageController(this).findAbstractProductByBarcode(DBStorageController(this).readableDatabase, this.barcode) != null) { + AlertDialog.Builder(this) + .setMessage("You've got an abstract product with such barcode in your database") + .setPositiveButton("Quit") { _: DialogInterface, _: Int -> + finish() + } + .setNegativeButton("Edit existing") { _: DialogInterface, _: Int -> + val addProductIntent = Intent(this, AddAbstractProductActivity::class.java) + val extras = Bundle() + val existingAbstractProduct = DBStorageController(this).findAbstractProductByBarcode(DBStorageController(this).readableDatabase, this.barcode) + extras.putParcelable("abstractProduct", existingAbstractProduct) + addProductIntent.putExtras(extras) + ContextCompat.startActivity(this, addProductIntent, extras) + finish() + }.show() + } + thread { // Я сам в ахуях какой это костыль, пока хз как фиксить, потом придумаю :)) while (requester.response == "") { } @@ -164,6 +186,7 @@ class AddAbstractProductActivity : AppCompatActivity() { } return@thread } + abstractProduct = Parser().parse(requester.response) requester.response = "" runOnUiThread {