dialog on unknown barcode on adding product
This commit is contained in:
parent
224887422c
commit
fd7feb72eb
|
@ -49,6 +49,8 @@ class AddAbstractProductActivity : AppCompatActivity() {
|
|||
barcode = abstractProduct!!.barcode
|
||||
}
|
||||
|
||||
|
||||
|
||||
picturesPath = File(filesDir, "pictures")
|
||||
val thumbnailsDir = File(cacheDir, "thumbnails")
|
||||
thumbnailsDir.mkdirs()
|
||||
|
@ -67,6 +69,10 @@ class AddAbstractProductActivity : AppCompatActivity() {
|
|||
|
||||
fillupCategorySpinner()
|
||||
|
||||
if (abstractProduct?.name == "" && abstractProduct?.barcode != "") {
|
||||
performRequest(abstractProduct?.barcode!!)
|
||||
}
|
||||
|
||||
if (abstractProduct != null) {
|
||||
val imageThumbnailUri = getImageUri(this, File(thumbnailsDir, "${abstractProduct!!.imageHash}.webp"))
|
||||
pictureFile = File(picturesPath, "${abstractProduct!!.imageHash}.png]")
|
||||
|
@ -130,9 +136,23 @@ class AddAbstractProductActivity : AppCompatActivity() {
|
|||
scanner.startScan()
|
||||
.addOnSuccessListener { barcode ->
|
||||
this.barcode = barcode.rawValue.toString()
|
||||
|
||||
performRequest(this.barcode)
|
||||
}
|
||||
.addOnFailureListener { e ->
|
||||
Toast.makeText(
|
||||
this,
|
||||
"Failed to scan barcode. Please, try again or enter data manually",
|
||||
Toast.LENGTH_LONG
|
||||
).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun performRequest(barcode: String) {
|
||||
barcodeText.setText(this.barcode)
|
||||
val requester = Requester("https://ean-online.ru", "match.php")
|
||||
requester.request(this, barcode.rawValue!!.toString())
|
||||
requester.request(this, barcode)
|
||||
var abstractProduct: AbstractProduct
|
||||
|
||||
thread {
|
||||
|
@ -152,15 +172,6 @@ class AddAbstractProductActivity : AppCompatActivity() {
|
|||
}
|
||||
}
|
||||
}
|
||||
.addOnFailureListener { e ->
|
||||
Toast.makeText(
|
||||
this,
|
||||
"Failed to scan barcode. Please, try again or enter data manually",
|
||||
Toast.LENGTH_LONG
|
||||
).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun fillupCategorySpinner() {
|
||||
val db = DBStorageController(this).readableDatabase
|
||||
|
|
|
@ -1,13 +1,18 @@
|
|||
package org.foxarmy.barcodescannerforemployees.activities
|
||||
|
||||
import android.app.DatePickerDialog
|
||||
import android.content.DialogInterface
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.*
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.google.mlkit.vision.codescanner.GmsBarcodeScanning
|
||||
import org.foxarmy.barcodescannerforemployees.DBStorageController
|
||||
import org.foxarmy.barcodescannerforemployees.R
|
||||
import org.foxarmy.barcodescannerforemployees.dataclasses.AbstractProduct
|
||||
import org.foxarmy.barcodescannerforemployees.dataclasses.Product
|
||||
import org.foxarmy.barcodescannerforemployees.views.AbstractProductView
|
||||
import java.util.*
|
||||
|
@ -93,14 +98,6 @@ class AddProductActivity : AppCompatActivity() {
|
|||
expiryDateOverShelfLife = false
|
||||
}
|
||||
|
||||
// shelfLifeTextEdit.addTextChangedListener {
|
||||
// if (shelfLifeTextEdit.text.toString() == "") {
|
||||
// return@addTextChangedListener
|
||||
// }
|
||||
//
|
||||
// evaluateDateOfExpiry()
|
||||
// }
|
||||
|
||||
dateOfProductionSelectButton.setOnClickListener {
|
||||
val c = Calendar.getInstance()
|
||||
val year = c.get(Calendar.YEAR)
|
||||
|
@ -180,7 +177,17 @@ class AddProductActivity : AppCompatActivity() {
|
|||
fun findAndDisplayAbstractProductByBarcode(barcode: String) {
|
||||
val abstractProduct = DBStorageController(this).findAbstractProductByBarcode(DBStorageController(this).readableDatabase, barcode)
|
||||
if (abstractProduct == null) {
|
||||
Toast.makeText(this, "No product found", Toast.LENGTH_SHORT).show()
|
||||
AlertDialog.Builder(this).setMessage("Product with such barcode not found. Try scanning with better lightning or add new abstract product")
|
||||
.setPositiveButton("Add") { _: DialogInterface, _: Int ->
|
||||
val addAbstractProductIntent = Intent(this, AddAbstractProductActivity::class.java)
|
||||
val extras = Bundle()
|
||||
extras.putParcelable("abstractProduct", AbstractProduct(0, barcode, "", 0.0, "", 0))
|
||||
addAbstractProductIntent.putExtras(extras)
|
||||
ContextCompat.startActivity(this, addAbstractProductIntent, extras)
|
||||
}
|
||||
.setNegativeButton("Try again") {_: DialogInterface, _: Int ->
|
||||
|
||||
}.show()
|
||||
return
|
||||
}
|
||||
abstractProductView.abstractProduct = abstractProduct
|
||||
|
|
Loading…
Reference in New Issue