updated date input

This commit is contained in:
leca 2024-10-20 17:07:25 +03:00
parent 79ab5c83c0
commit 4f1845dd0e
4 changed files with 82 additions and 85 deletions

View File

@ -106,7 +106,7 @@ class AddAbstractProductActivity : AppCompatActivity() {
saveButton.setOnClickListener { saveButton.setOnClickListener {
val productName = productNameText.text.toString() val productName = productNameText.text.toString()
val netWeight = netWeightText.text 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() Toast.makeText(this, getString(R.string.product_picture_request), Toast.LENGTH_SHORT).show()
return@setOnClickListener return@setOnClickListener
} }

View File

@ -1,6 +1,5 @@
package org.foxarmy.barcodescannerforemployees.activities package org.foxarmy.barcodescannerforemployees.activities
import android.app.DatePickerDialog
import android.content.Intent import android.content.Intent
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
@ -30,15 +29,13 @@ class AddProductActivity : AppCompatActivity() {
private lateinit var expiryDateRadioButton: RadioButton private lateinit var expiryDateRadioButton: RadioButton
private lateinit var shelfLifeRadioButton: RadioButton private lateinit var shelfLifeRadioButton: RadioButton
private lateinit var expiryDateTextView: TextView private lateinit var expiryDatePicker: DatePicker
private lateinit var expiryDateSelectButton: Button
private lateinit var shelfLifeTextView: TextView
private lateinit var shelfLifeTextEdit: EditText private lateinit var shelfLifeTextEdit: EditText
private lateinit var amountTextEdit: EditText private lateinit var amountTextEdit: EditText
private lateinit var dateOfProductionSelectButton: Button private lateinit var dateOfProductionDatePicker: DatePicker
private lateinit var saveProductButton: Button private lateinit var saveProductButton: Button
private var expiryDateOverShelfLife: Boolean? = null private var expiryDateOverShelfLife: Boolean? = null
@ -56,16 +53,14 @@ class AddProductActivity : AppCompatActivity() {
expiryDateRadioButton = findViewById(R.id.expiryDateRadio) expiryDateRadioButton = findViewById(R.id.expiryDateRadio)
shelfLifeRadioButton = findViewById(R.id.shelfLifeRadio) shelfLifeRadioButton = findViewById(R.id.shelfLifeRadio)
expiryDateTextView = findViewById(R.id.expiryDateTextView) expiryDatePicker = findViewById(R.id.expiryDatePicker)
expiryDateSelectButton = findViewById(R.id.selectExpiryDateButton)
shelfLifeTextView = findViewById(R.id.shelfLife)
shelfLifeTextEdit = findViewById(R.id.shelfLifeTextEdit) shelfLifeTextEdit = findViewById(R.id.shelfLifeTextEdit)
amountTextEdit = findViewById(R.id.amountTextEdit) amountTextEdit = findViewById(R.id.amountTextEdit)
amountTextEdit.setText("1") amountTextEdit.setText("1")
dateOfProductionSelectButton = findViewById(R.id.selectDateOfProductionButton) dateOfProductionDatePicker = findViewById(R.id.dateOfProductionDatePicker)
saveProductButton = findViewById(R.id.saveProductButton) saveProductButton = findViewById(R.id.saveProductButton)
val extras = intent.extras val extras = intent.extras
@ -99,34 +94,44 @@ class AddProductActivity : AppCompatActivity() {
update() update()
} }
dateOfProductionSelectButton.setOnClickListener { dateOfProductionDatePicker.setOnDateChangedListener { _, year, monthOfYear, dayOfMonth ->
val c = Calendar.getInstance() product!!.dateOfProduction = SimpleDateFormat("dd.MM.yyyy").parse("$dayOfMonth.$monthOfYear.$year")!!.time / 1000
val year = c.get(Calendar.YEAR) update()
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 { expiryDatePicker.setOnDateChangedListener { _, year, monthOfYear, dayOfMonth ->
val c = Calendar.getInstance() product!!.dateOfExpiry = SimpleDateFormat("dd.MM.yyyy").parse("$dayOfMonth.$monthOfYear.$year")!!.time / 1000
val year = c.get(Calendar.YEAR) update()
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()
} }
// 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 { amountTextEdit.addTextChangedListener {
val text = amountTextEdit.text.toString() val text = amountTextEdit.text.toString()
if (text == "") return@addTextChangedListener if (text == "") return@addTextChangedListener
@ -167,27 +172,32 @@ class AddProductActivity : AppCompatActivity() {
finish() finish()
} }
update()
} }
private fun update () { private fun update () {
if (expiryDateOverShelfLife == true) { if (expiryDateOverShelfLife == true) {
expiryDateTextView.visibility = View.VISIBLE expiryDatePicker.visibility = View.VISIBLE
expiryDateSelectButton.visibility = View.VISIBLE
shelfLifeTextEdit.visibility = View.INVISIBLE shelfLifeTextEdit.visibility = View.INVISIBLE
shelfLifeTextView.visibility = View.INVISIBLE
} else if (expiryDateOverShelfLife == false){ } else if (expiryDateOverShelfLife == false){
expiryDateTextView.visibility = View.INVISIBLE expiryDatePicker.visibility = View.INVISIBLE
expiryDateSelectButton.visibility = View.INVISIBLE
shelfLifeTextEdit.visibility = View.VISIBLE shelfLifeTextEdit.visibility = View.VISIBLE
shelfLifeTextView.visibility = View.VISIBLE
} }
val dateOfProductionParsed = SimpleDateFormat("dd.MM.yyyy").format(Date(product!!.dateOfProduction * 1000)) // val dateOfProductionParsed = SimpleDateFormat("dd.MM.yyyy").format(Date(product!!.dateOfProduction * 1000))
findViewById<TextView>(R.id.dateOfProductionTextView).text = "${getString(R.string.date_of_production)}: $dateOfProductionParsed" // findViewById<TextView>(R.id.dateOfProductionTextView).text = "${getString(R.string.date_of_production)}: $dateOfProductionParsed"
val expiryDateParsed = SimpleDateFormat("dd.MM.yyyy").format(Date(product!!.dateOfExpiry * 1000)) // val expiryDateParsed = SimpleDateFormat("dd.MM.yyyy").format(Date(product!!.dateOfExpiry * 1000))
expiryDateTextView.text = "${getString(R.string.expiry_date)}: $expiryDateParsed" // 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() == "") { if (amountTextEdit.text.toString() == "") {
amountTextEdit.setText(product!!.amount.toString()) amountTextEdit.setText(product!!.amount.toString())

View File

@ -28,76 +28,63 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/dateOfProductionTextView" android:layout_height="wrap_content" android:id="@+id/dateOfProductionTextView"
app:layout_constraintTop_toBottomOf="@+id/scanButton" app:layout_constraintTop_toBottomOf="@+id/scanButton"
android:layout_marginTop="16dp" app:layout_constraintStart_toStartOf="parent"/> android:layout_marginTop="48dp" app:layout_constraintStart_toStartOf="parent"
<Button
android:text="@string/select"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/selectDateOfProductionButton"
app:layout_constraintTop_toBottomOf="@+id/scanButton"
app:layout_constraintStart_toEndOf="@+id/dateOfProductionTextView"
app:layout_constraintEnd_toEndOf="parent"/> app:layout_constraintEnd_toEndOf="parent"/>
<RadioGroup <RadioGroup
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" app:layout_constraintTop_toBottomOf="@+id/selectDateOfProductionButton" android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" android:layout_marginTop="16dp" app:layout_constraintEnd_toEndOf="parent"
android:orientation="horizontal" android:id="@+id/radioGroup"> android:orientation="horizontal" android:id="@+id/radioGroup"
app:layout_constraintTop_toBottomOf="@+id/dateOfProductionDatePicker" android:layout_marginTop="16dp">
<RadioButton <RadioButton
android:text="@string/expiry_date" android:text="@string/expiry_date"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="@+id/expiryDateRadio"/> android:layout_height="match_parent" android:id="@+id/expiryDateRadio"/>
<RadioButton <RadioButton
android:text="@string/shelf_life" android:text="@string/shelf_life"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="@+id/shelfLifeRadio"/> android:layout_height="wrap_content" android:id="@+id/shelfLifeRadio"/>
</RadioGroup> </RadioGroup>
<TextView <DatePicker
android:text="Expiry date: " android:layout_width="247dp"
android:layout_width="wrap_content" android:layout_height="78dp" android:id="@+id/expiryDatePicker"
android:layout_height="wrap_content" android:id="@+id/expiryDateTextView" android:datePickerMode="spinner"
app:layout_constraintTop_toBottomOf="@+id/radioGroup" app:layout_constraintStart_toStartOf="parent" android:calendarViewShown="false"
android:layout_marginStart="16dp" android:layout_marginTop="16dp" android:visibility="invisible"/> app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent"
<Button app:layout_constraintHorizontal_bias="0.505" android:layout_marginTop="12dp"
android:text="Select" app:layout_constraintTop_toBottomOf="@+id/radioGroup" android:visibility="gone"/>
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/selectExpiryDateButton"
app:layout_constraintTop_toBottomOf="@+id/radioGroup"
app:layout_constraintStart_toEndOf="@+id/expiryDateTextView" android:layout_marginStart="16dp"
android:visibility="invisible"/>
<TextView
android:text="Shelf life:"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/shelfLife"
app:layout_constraintTop_toBottomOf="@+id/radioGroup"
android:layout_marginTop="16dp" app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="16dp" android:visibility="invisible"/>
<EditText <EditText
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:inputType="numberDecimal" android:inputType="numberDecimal"
android:ems="10" android:ems="10"
android:id="@+id/shelfLifeTextEdit" app:layout_constraintTop_toBottomOf="@+id/radioGroup" android:id="@+id/shelfLifeTextEdit" app:layout_constraintTop_toBottomOf="@+id/radioGroup"
app:layout_constraintStart_toEndOf="@+id/expiryDateTextView" android:layout_marginStart="16dp" android:visibility="gone" app:layout_constraintEnd_toEndOf="parent"
android:visibility="invisible"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/amountText"
app:layout_constraintTop_toBottomOf="@+id/shelfLifeTextEdit"
app:layout_constraintStart_toStartOf="parent" android:layout_marginTop="16dp" app:layout_constraintStart_toStartOf="parent" android:layout_marginTop="16dp"
android:text="@string/amount"/> android:hint="@string/shelf_life"/>
<EditText <EditText
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:inputType="numberSigned" android:inputType="numberSigned"
android:ems="10" android:ems="10"
android:id="@+id/amountTextEdit" android:id="@+id/amountTextEdit"
app:layout_constraintTop_toBottomOf="@+id/selectExpiryDateButton" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@+id/amountText"/> android:hint="@string/amount" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/expiryDatePicker" android:layout_marginTop="12dp"/>
<Button <Button
android:text="@string/saveButton" android:text="@string/saveButton"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/saveProductButton" android:layout_height="wrap_content" android:id="@+id/saveProductButton"
app:layout_constraintTop_toBottomOf="@+id/amountTextEdit" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/amountTextEdit" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" android:layout_marginTop="16dp"/> app:layout_constraintEnd_toEndOf="parent" android:layout_marginTop="16dp"/>
<DatePicker
android:layout_width="247dp"
android:layout_height="78dp" android:id="@+id/dateOfProductionDatePicker"
android:datePickerMode="spinner"
android:calendarViewShown="false"
app:layout_constraintTop_toBottomOf="@+id/dateOfProductionTextView"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="16dp" app:layout_constraintHorizontal_bias="0.505"/>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView> </androidx.core.widget.NestedScrollView>

View File

@ -78,7 +78,7 @@
<string name="abstract_product_does_not_exist">Abstract product with such barcode does not exist. Do you want to add one?</string> <string name="abstract_product_does_not_exist">Abstract product with such barcode does not exist. Do you want to add one?</string>
<string name="drop_filters">Drop filters</string> <string name="drop_filters">Drop filters</string>
<string name="category_name_required">Category name required</string> <string name="category_name_required">Category name required</string>
<string name="abstract_product_already_exists">You've got an abstract product with such barcode in your database.</string> <string name="abstract_product_already_exists">You\'ve got an abstract product with such barcode in your database.</string>
<string name="quit">Quit</string> <string name="quit">Quit</string>
<string name="edit_existing">Edit existing</string> <string name="edit_existing">Edit existing</string>
<string name="no_product_in_online_database">Product not found. Please, try again if you beleive barcode scanned <string name="no_product_in_online_database">Product not found. Please, try again if you beleive barcode scanned