From 54693ff15d55fe211692b17e9ec6757a833169e0 Mon Sep 17 00:00:00 2001 From: leca Date: Sat, 19 Oct 2024 23:50:01 +0300 Subject: [PATCH] remade scaling, fixed updating --- .../foxarmy/barcodescannerforemployees/Utils.kt | 10 +++++++--- .../activities/AddAbstractProductActivity.kt | 14 +++++--------- .../views/AbstractProductView.kt | 2 +- .../views/ProductView.kt | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/Utils.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/Utils.kt index 9311250..1f896b3 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/Utils.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/Utils.kt @@ -5,11 +5,11 @@ import android.content.Context import android.content.ContextWrapper import android.graphics.Bitmap import android.graphics.BitmapFactory +import android.graphics.Matrix import android.net.Uri import android.os.Build import androidx.annotation.RequiresApi import androidx.core.content.FileProvider -import androidx.core.graphics.scale import com.google.firebase.components.BuildConfig import java.io.File import java.io.FileOutputStream @@ -33,8 +33,12 @@ fun generateThumbnailForImage(context: Context, imageHash: String) { val imageFile = File(picturesDir, "$imageHash.png") val imageContent = imageFile.inputStream().readBytes() var img = BitmapFactory.decodeByteArray(imageContent, 0, imageContent.size) - img = img.scale(img.width/4,img.height/4) - img.compress(Bitmap.CompressFormat.WEBP_LOSSY, 25, FileOutputStream(thumbnailFile)) + + val matrix = Matrix(); + matrix.postRotate(90f) + val scaled = Bitmap.createScaledBitmap(img, img.width/4, img.height/4, true) + val rotated = Bitmap.createBitmap(scaled, 0, 0, scaled.width, scaled.height, matrix, true) + rotated.compress(Bitmap.CompressFormat.WEBP_LOSSY, 25, FileOutputStream(thumbnailFile)) } @OptIn(ExperimentalStdlibApi::class) 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 1d0a553..fb89c16 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/AddAbstractProductActivity.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/AddAbstractProductActivity.kt @@ -81,25 +81,21 @@ class AddAbstractProductActivity : AppCompatActivity() { this.barcode = barcodeText.text.toString() } - if (abstractProduct != null) { + if (abstractProduct != null && abstractProduct!!.barcode != "" && abstractProduct!!.name == "") { barcode = abstractProduct!!.barcode updatingExisting = false performRequest(abstractProduct!!.barcode) - } else { + } else if (abstractProduct != null && abstractProduct!!.barcode == ""){ updatingExisting = true + } else if (abstractProduct == null) { + updatingExisting = false } - -// if (abstractProduct?.name == "" && abstractProduct?.barcode != "") { -// updatingExisting = true -// 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 +// imageView.rotation = 90f barcodeText.setText(abstractProduct!!.barcode) productNameText.text = abstractProduct!!.name netWeightText.text = abstractProduct!!.netWeight.toString() diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/views/AbstractProductView.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/views/AbstractProductView.kt index 29bd48b..4b481bc 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/views/AbstractProductView.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/views/AbstractProductView.kt @@ -80,7 +80,7 @@ class AbstractProductView: LinearLayout { thumbnailsDir.mkdirs() val imageUri = getImageUri(activity, File(thumbnailsDir, "${abstractProduct.imageHash}.webp")) productPicture!!.setImageURI(imageUri) - productPicture!!.rotation = 90f +// productPicture!!.rotation = 90f productNameField!!.text = abstractProduct.name netWeightField!!.text = abstractProduct.netWeight.toString() diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/views/ProductView.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/views/ProductView.kt index 612208b..fb1e9f2 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/views/ProductView.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/views/ProductView.kt @@ -95,7 +95,7 @@ class ProductView: LinearLayout { val pictureFile = File(thumbnailsDir, "${linkedAbstractProduct.imageHash}.webp") val imageUri = getImageUri(activity, pictureFile) productImageView.setImageURI(imageUri) - productImageView.rotation = 90f +// productImageView.rotation = 90f productNameTextView.text = linkedAbstractProduct.name productNetWeightTextView.text = linkedAbstractProduct.netWeight.toString()