From 4f1845dd0e87227b30bce5c0c859e125cfde7428 Mon Sep 17 00:00:00 2001 From: leca Date: Sun, 20 Oct 2024 17:07:25 +0300 Subject: [PATCH] updated date input --- .../activities/AddAbstractProductActivity.kt | 2 +- .../activities/AddProductActivity.kt | 96 ++++++++++--------- .../main/res/layout/fragment_add_product.xml | 67 ++++++------- app/src/main/res/values/strings.xml | 2 +- 4 files changed, 82 insertions(+), 85 deletions(-) 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 369ea4f..961de15 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/AddAbstractProductActivity.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/AddAbstractProductActivity.kt @@ -106,7 +106,7 @@ class AddAbstractProductActivity : AppCompatActivity() { saveButton.setOnClickListener { val productName = productNameText.text.toString() val netWeight = netWeightText.text - if (abstractProduct == null && (!this::pictureFile.isInitialized || !pictureFile.exists())) { + if (action != "update" && (!this::pictureFile.isInitialized || !pictureFile.exists())) { Toast.makeText(this, getString(R.string.product_picture_request), Toast.LENGTH_SHORT).show() return@setOnClickListener } 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 adef2b2..09816e7 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/AddProductActivity.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/AddProductActivity.kt @@ -1,6 +1,5 @@ package org.foxarmy.barcodescannerforemployees.activities -import android.app.DatePickerDialog import android.content.Intent import android.os.Build import android.os.Bundle @@ -30,15 +29,13 @@ class AddProductActivity : AppCompatActivity() { private lateinit var expiryDateRadioButton: RadioButton private lateinit var shelfLifeRadioButton: RadioButton - private lateinit var expiryDateTextView: TextView - private lateinit var expiryDateSelectButton: Button + private lateinit var expiryDatePicker: DatePicker - private lateinit var shelfLifeTextView: TextView private lateinit var shelfLifeTextEdit: EditText private lateinit var amountTextEdit: EditText - private lateinit var dateOfProductionSelectButton: Button + private lateinit var dateOfProductionDatePicker: DatePicker private lateinit var saveProductButton: Button private var expiryDateOverShelfLife: Boolean? = null @@ -56,16 +53,14 @@ class AddProductActivity : AppCompatActivity() { expiryDateRadioButton = findViewById(R.id.expiryDateRadio) shelfLifeRadioButton = findViewById(R.id.shelfLifeRadio) - expiryDateTextView = findViewById(R.id.expiryDateTextView) - expiryDateSelectButton = findViewById(R.id.selectExpiryDateButton) + expiryDatePicker = findViewById(R.id.expiryDatePicker) - shelfLifeTextView = findViewById(R.id.shelfLife) shelfLifeTextEdit = findViewById(R.id.shelfLifeTextEdit) amountTextEdit = findViewById(R.id.amountTextEdit) amountTextEdit.setText("1") - dateOfProductionSelectButton = findViewById(R.id.selectDateOfProductionButton) + dateOfProductionDatePicker = findViewById(R.id.dateOfProductionDatePicker) saveProductButton = findViewById(R.id.saveProductButton) val extras = intent.extras @@ -99,34 +94,44 @@ class AddProductActivity : AppCompatActivity() { update() } - dateOfProductionSelectButton.setOnClickListener { - val c = Calendar.getInstance() - val year = c.get(Calendar.YEAR) - val month = c.get(Calendar.MONTH) - val day = c.get(Calendar.DAY_OF_MONTH) - - val dpd = DatePickerDialog(this, { _, y, m, d -> - product!!.dateOfProduction = SimpleDateFormat("dd.MM.yyyy").parse("$d.${m+1}.$y")!!.time / 1000 - update() - }, year, month, day) - - dpd.show() + dateOfProductionDatePicker.setOnDateChangedListener { _, year, monthOfYear, dayOfMonth -> + product!!.dateOfProduction = SimpleDateFormat("dd.MM.yyyy").parse("$dayOfMonth.$monthOfYear.$year")!!.time / 1000 + update() } - expiryDateSelectButton.setOnClickListener { - val c = Calendar.getInstance() - val year = c.get(Calendar.YEAR) - val month = c.get(Calendar.MONTH) - val day = c.get(Calendar.DAY_OF_MONTH) - - val dpd = DatePickerDialog(this, { _, y, m, d -> - product!!.dateOfExpiry = SimpleDateFormat("dd.MM.yyyy").parse("$d.${m+1}.$y")!!.time / 1000 - update() - }, year, month, day) - - dpd.show() + expiryDatePicker.setOnDateChangedListener { _, year, monthOfYear, dayOfMonth -> + product!!.dateOfExpiry = SimpleDateFormat("dd.MM.yyyy").parse("$dayOfMonth.$monthOfYear.$year")!!.time / 1000 + update() } +// dateOfProductionSelectButton.setOnClickListener { +// val c = Calendar.getInstance() +// val year = c.get(Calendar.YEAR) +// val month = c.get(Calendar.MONTH) +// val day = c.get(Calendar.DAY_OF_MONTH) +// +// val dpd = DatePickerDialog(this, { _, y, m, d -> +// product!!.dateOfProduction = SimpleDateFormat("dd.MM.yyyy").parse("$d.${m+1}.$y")!!.time / 1000 +// update() +// }, year, month, day) +// +// dpd.show() +// } + +// expiryDateSelectButton.setOnClickListener { +// val c = Calendar.getInstance() +// val year = c.get(Calendar.YEAR) +// val month = c.get(Calendar.MONTH) +// val day = c.get(Calendar.DAY_OF_MONTH) +// +// val dpd = DatePickerDialog(this, { _, y, m, d -> +// product!!.dateOfExpiry = SimpleDateFormat("dd.MM.yyyy").parse("$d.${m+1}.$y")!!.time / 1000 +// update() +// }, year, month, day) +// +// dpd.show() +// } + amountTextEdit.addTextChangedListener { val text = amountTextEdit.text.toString() if (text == "") return@addTextChangedListener @@ -167,27 +172,32 @@ class AddProductActivity : AppCompatActivity() { finish() } + update() } private fun update () { if (expiryDateOverShelfLife == true) { - expiryDateTextView.visibility = View.VISIBLE - expiryDateSelectButton.visibility = View.VISIBLE + expiryDatePicker.visibility = View.VISIBLE shelfLifeTextEdit.visibility = View.INVISIBLE - shelfLifeTextView.visibility = View.INVISIBLE } else if (expiryDateOverShelfLife == false){ - expiryDateTextView.visibility = View.INVISIBLE - expiryDateSelectButton.visibility = View.INVISIBLE + expiryDatePicker.visibility = View.INVISIBLE shelfLifeTextEdit.visibility = View.VISIBLE - shelfLifeTextView.visibility = View.VISIBLE } - val dateOfProductionParsed = SimpleDateFormat("dd.MM.yyyy").format(Date(product!!.dateOfProduction * 1000)) - findViewById(R.id.dateOfProductionTextView).text = "${getString(R.string.date_of_production)}: $dateOfProductionParsed" +// val dateOfProductionParsed = SimpleDateFormat("dd.MM.yyyy").format(Date(product!!.dateOfProduction * 1000)) +// findViewById(R.id.dateOfProductionTextView).text = "${getString(R.string.date_of_production)}: $dateOfProductionParsed" - val expiryDateParsed = SimpleDateFormat("dd.MM.yyyy").format(Date(product!!.dateOfExpiry * 1000)) - expiryDateTextView.text = "${getString(R.string.expiry_date)}: $expiryDateParsed" +// val expiryDateParsed = SimpleDateFormat("dd.MM.yyyy").format(Date(product!!.dateOfExpiry * 1000)) +// expiryDateTextView.text = "${getString(R.string.expiry_date)}: $expiryDateParsed" + + val dateOfProduction = SimpleDateFormat("dd.MM.yyyy").format(product!!.dateOfProduction * 1000).split(".") + + dateOfProductionDatePicker.updateDate(dateOfProduction[2].toInt(), dateOfProduction[1].toInt(), dateOfProduction[0].toInt()) + + val expiryDate = SimpleDateFormat("dd.MM.yyyy").format(product!!.dateOfExpiry * 1000).split(".") + + expiryDatePicker.updateDate(expiryDate[2].toInt(), expiryDate[1].toInt(), expiryDate[0].toInt()) if (amountTextEdit.text.toString() == "") { amountTextEdit.setText(product!!.amount.toString()) diff --git a/app/src/main/res/layout/fragment_add_product.xml b/app/src/main/res/layout/fragment_add_product.xml index 94cf4c2..25b4d81 100644 --- a/app/src/main/res/layout/fragment_add_product.xml +++ b/app/src/main/res/layout/fragment_add_product.xml @@ -28,76 +28,63 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/dateOfProductionTextView" app:layout_constraintTop_toBottomOf="@+id/scanButton" - android:layout_marginTop="16dp" app:layout_constraintStart_toStartOf="parent"/> -