From b1b987e5f64272a835b77efe5a1144ff525721bb Mon Sep 17 00:00:00 2001 From: leca Date: Thu, 17 Oct 2024 20:37:21 +0300 Subject: [PATCH] fixed adding months to product --- .../java/org/foxarmy/barcodescannerforemployees/Utils.kt | 2 -- .../activities/AddProductActivity.kt | 8 ++------ .../barcodescannerforemployees/views/ProductView.kt | 3 ++- app/src/main/res/layout/abstract_product_view.xml | 2 +- app/src/main/res/layout/product_view.xml | 2 +- 5 files changed, 6 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/Utils.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/Utils.kt index 0420b07..98e729e 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/Utils.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/Utils.kt @@ -79,7 +79,5 @@ fun calculateProductFreshness(dateOfProduction: Long, dateOfExpiry: Long): Doubl val productLifeSpan = dateOfExpiry - dateOfProduction; val lifeSpanLeft: Long = dateOfExpiry - Date().time / 1000 - Log.d("QWERTYUIOP", "ProductLifeSpan: ${productLifeSpan}, Lifespan left: ${lifeSpanLeft}, percent: ${lifeSpanLeft / productLifeSpan.toDouble()}") - return lifeSpanLeft / productLifeSpan.toDouble() } \ No newline at end of file diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/AddProductActivity.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/AddProductActivity.kt index bc8e174..b64d562 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/AddProductActivity.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/AddProductActivity.kt @@ -167,14 +167,10 @@ class AddProductActivity : AppCompatActivity() { } val c = Calendar.getInstance() - -// val dateOfProductionSplit = dateOfProduction.split(".") - c.set(Calendar.YEAR, Date(dateOfProduction).year) - c.set(Calendar.MONTH, Date(dateOfProduction).month) - c.set(Calendar.DAY_OF_MONTH, Date(dateOfProduction).day) + c.timeInMillis = dateOfProduction * 1000 c.add(Calendar.MONTH, shelfLifeMonths) - dateOfExpiry = SimpleDateFormat("dd.MM.yyyy").parse("${c.get(Calendar.YEAR)}.${c.get(Calendar.MONTH)}.${c.get(Calendar.DAY_OF_MONTH)}").time / 1000 + dateOfExpiry = c.timeInMillis / 1000 } fun findAndDisplayAbstractProductByBarcode(barcode: String) { 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 ee05d96..1e88960 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/views/ProductView.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/views/ProductView.kt @@ -26,6 +26,7 @@ import org.foxarmy.barcodescannerforemployees.dataclasses.AbstractProduct import org.foxarmy.barcodescannerforemployees.dataclasses.Product import java.io.File import java.text.DecimalFormat +import java.text.SimpleDateFormat import java.util.* import kotlin.concurrent.thread @@ -100,7 +101,7 @@ class ProductView: LinearLayout { productNetWeightTextView.text = linkedAbstractProduct.netWeight.toString() productAmountTextView.text = product.amount.toString() productCategoryView.text = DBStorageController(activity).getCategoryNameById(DBStorageController(activity).readableDatabase, linkedAbstractProduct.category) - productLifeSpan.text = "${Date(product.dateOfProduction*1000)}-${Date(product.dateOfExpiry*1000)}" + productLifeSpan.text = "${SimpleDateFormat("dd.MM.yyyy").format(Date(product.dateOfProduction*1000))}-${SimpleDateFormat("dd.MM.yyyy").format(Date(product.dateOfExpiry*1000))}" productFreshnessTextView.text = if (product.freshness == Double.NEGATIVE_INFINITY || product.freshness == Double.POSITIVE_INFINITY) { "Expired" diff --git a/app/src/main/res/layout/abstract_product_view.xml b/app/src/main/res/layout/abstract_product_view.xml index f676b75..484b77a 100644 --- a/app/src/main/res/layout/abstract_product_view.xml +++ b/app/src/main/res/layout/abstract_product_view.xml @@ -2,7 +2,7 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="190dp" - android:layout_height="wrap_content" app:barrierMargin="1dp" android:clickable="false" + android:layout_height="330dp" app:barrierMargin="1dp" android:clickable="false" android:outlineProvider="background" android:background="@drawable/outline"> + android:layout_height="345dp">