handling existing abstract products
This commit is contained in:
parent
6a49b573ca
commit
a2662bf55b
|
@ -2,6 +2,8 @@ package org.foxarmy.barcodescannerforemployees.activities
|
||||||
|
|
||||||
import android.Manifest
|
import android.Manifest
|
||||||
import android.content.ContentValues
|
import android.content.ContentValues
|
||||||
|
import android.content.DialogInterface
|
||||||
|
import android.content.Intent
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.provider.BaseColumns
|
import android.provider.BaseColumns
|
||||||
|
@ -9,7 +11,9 @@ import android.util.Log
|
||||||
import android.widget.*
|
import android.widget.*
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.annotation.RequiresApi
|
import androidx.annotation.RequiresApi
|
||||||
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
import com.google.mlkit.vision.barcode.common.Barcode
|
import com.google.mlkit.vision.barcode.common.Barcode
|
||||||
import com.google.mlkit.vision.codescanner.GmsBarcodeScannerOptions
|
import com.google.mlkit.vision.codescanner.GmsBarcodeScannerOptions
|
||||||
import com.google.mlkit.vision.codescanner.GmsBarcodeScanning
|
import com.google.mlkit.vision.codescanner.GmsBarcodeScanning
|
||||||
|
@ -78,6 +82,7 @@ class AddAbstractProductActivity : AppCompatActivity() {
|
||||||
pictureFile = File(picturesPath, "${abstractProduct!!.imageHash}.png]")
|
pictureFile = File(picturesPath, "${abstractProduct!!.imageHash}.png]")
|
||||||
imageView.setImageURI(imageThumbnailUri)
|
imageView.setImageURI(imageThumbnailUri)
|
||||||
imageView.rotation = 90f
|
imageView.rotation = 90f
|
||||||
|
barcodeText.setText(abstractProduct!!.barcode)
|
||||||
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)
|
||||||
|
@ -155,6 +160,23 @@ class AddAbstractProductActivity : AppCompatActivity() {
|
||||||
requester.request(this, barcode)
|
requester.request(this, barcode)
|
||||||
var abstractProduct: AbstractProduct
|
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 {
|
thread {
|
||||||
// Я сам в ахуях какой это костыль, пока хз как фиксить, потом придумаю :))
|
// Я сам в ахуях какой это костыль, пока хз как фиксить, потом придумаю :))
|
||||||
while (requester.response == "") { }
|
while (requester.response == "") { }
|
||||||
|
@ -164,6 +186,7 @@ class AddAbstractProductActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
return@thread
|
return@thread
|
||||||
}
|
}
|
||||||
|
|
||||||
abstractProduct = Parser().parse(requester.response)
|
abstractProduct = Parser().parse(requester.response)
|
||||||
requester.response = ""
|
requester.response = ""
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
|
|
Loading…
Reference in New Issue