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
|
barcode = abstractProduct!!.barcode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
picturesPath = File(filesDir, "pictures")
|
picturesPath = File(filesDir, "pictures")
|
||||||
val thumbnailsDir = File(cacheDir, "thumbnails")
|
val thumbnailsDir = File(cacheDir, "thumbnails")
|
||||||
thumbnailsDir.mkdirs()
|
thumbnailsDir.mkdirs()
|
||||||
|
@ -67,6 +69,10 @@ class AddAbstractProductActivity : AppCompatActivity() {
|
||||||
|
|
||||||
fillupCategorySpinner()
|
fillupCategorySpinner()
|
||||||
|
|
||||||
|
if (abstractProduct?.name == "" && abstractProduct?.barcode != "") {
|
||||||
|
performRequest(abstractProduct?.barcode!!)
|
||||||
|
}
|
||||||
|
|
||||||
if (abstractProduct != null) {
|
if (abstractProduct != null) {
|
||||||
val imageThumbnailUri = getImageUri(this, File(thumbnailsDir, "${abstractProduct!!.imageHash}.webp"))
|
val imageThumbnailUri = getImageUri(this, File(thumbnailsDir, "${abstractProduct!!.imageHash}.webp"))
|
||||||
pictureFile = File(picturesPath, "${abstractProduct!!.imageHash}.png]")
|
pictureFile = File(picturesPath, "${abstractProduct!!.imageHash}.png]")
|
||||||
|
@ -130,9 +136,23 @@ class AddAbstractProductActivity : AppCompatActivity() {
|
||||||
scanner.startScan()
|
scanner.startScan()
|
||||||
.addOnSuccessListener { barcode ->
|
.addOnSuccessListener { barcode ->
|
||||||
this.barcode = barcode.rawValue.toString()
|
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)
|
barcodeText.setText(this.barcode)
|
||||||
val requester = Requester("https://ean-online.ru", "match.php")
|
val requester = Requester("https://ean-online.ru", "match.php")
|
||||||
requester.request(this, barcode.rawValue!!.toString())
|
requester.request(this, barcode)
|
||||||
var abstractProduct: AbstractProduct
|
var abstractProduct: AbstractProduct
|
||||||
|
|
||||||
thread {
|
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() {
|
fun fillupCategorySpinner() {
|
||||||
val db = DBStorageController(this).readableDatabase
|
val db = DBStorageController(this).readableDatabase
|
||||||
|
|
|
@ -1,13 +1,18 @@
|
||||||
package org.foxarmy.barcodescannerforemployees.activities
|
package org.foxarmy.barcodescannerforemployees.activities
|
||||||
|
|
||||||
import android.app.DatePickerDialog
|
import android.app.DatePickerDialog
|
||||||
|
import android.content.DialogInterface
|
||||||
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.*
|
import android.widget.*
|
||||||
|
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.codescanner.GmsBarcodeScanning
|
import com.google.mlkit.vision.codescanner.GmsBarcodeScanning
|
||||||
import org.foxarmy.barcodescannerforemployees.DBStorageController
|
import org.foxarmy.barcodescannerforemployees.DBStorageController
|
||||||
import org.foxarmy.barcodescannerforemployees.R
|
import org.foxarmy.barcodescannerforemployees.R
|
||||||
|
import org.foxarmy.barcodescannerforemployees.dataclasses.AbstractProduct
|
||||||
import org.foxarmy.barcodescannerforemployees.dataclasses.Product
|
import org.foxarmy.barcodescannerforemployees.dataclasses.Product
|
||||||
import org.foxarmy.barcodescannerforemployees.views.AbstractProductView
|
import org.foxarmy.barcodescannerforemployees.views.AbstractProductView
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
@ -93,14 +98,6 @@ class AddProductActivity : AppCompatActivity() {
|
||||||
expiryDateOverShelfLife = false
|
expiryDateOverShelfLife = false
|
||||||
}
|
}
|
||||||
|
|
||||||
// shelfLifeTextEdit.addTextChangedListener {
|
|
||||||
// if (shelfLifeTextEdit.text.toString() == "") {
|
|
||||||
// return@addTextChangedListener
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// evaluateDateOfExpiry()
|
|
||||||
// }
|
|
||||||
|
|
||||||
dateOfProductionSelectButton.setOnClickListener {
|
dateOfProductionSelectButton.setOnClickListener {
|
||||||
val c = Calendar.getInstance()
|
val c = Calendar.getInstance()
|
||||||
val year = c.get(Calendar.YEAR)
|
val year = c.get(Calendar.YEAR)
|
||||||
|
@ -180,7 +177,17 @@ class AddProductActivity : AppCompatActivity() {
|
||||||
fun findAndDisplayAbstractProductByBarcode(barcode: String) {
|
fun findAndDisplayAbstractProductByBarcode(barcode: String) {
|
||||||
val abstractProduct = DBStorageController(this).findAbstractProductByBarcode(DBStorageController(this).readableDatabase, barcode)
|
val abstractProduct = DBStorageController(this).findAbstractProductByBarcode(DBStorageController(this).readableDatabase, barcode)
|
||||||
if (abstractProduct == null) {
|
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
|
return
|
||||||
}
|
}
|
||||||
abstractProductView.abstractProduct = abstractProduct
|
abstractProductView.abstractProduct = abstractProduct
|
||||||
|
|
Loading…
Reference in New Issue