updated date input
This commit is contained in:
parent
79ab5c83c0
commit
4f1845dd0e
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
dateOfProductionDatePicker.setOnDateChangedListener { _, year, monthOfYear, dayOfMonth ->
|
||||
product!!.dateOfProduction = SimpleDateFormat("dd.MM.yyyy").parse("$dayOfMonth.$monthOfYear.$year")!!.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
|
||||
expiryDatePicker.setOnDateChangedListener { _, year, monthOfYear, dayOfMonth ->
|
||||
product!!.dateOfExpiry = SimpleDateFormat("dd.MM.yyyy").parse("$dayOfMonth.$monthOfYear.$year")!!.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 {
|
||||
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<TextView>(R.id.dateOfProductionTextView).text = "${getString(R.string.date_of_production)}: $dateOfProductionParsed"
|
||||
// val dateOfProductionParsed = SimpleDateFormat("dd.MM.yyyy").format(Date(product!!.dateOfProduction * 1000))
|
||||
// findViewById<TextView>(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())
|
||||
|
|
|
@ -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"/>
|
||||
<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"
|
||||
android:layout_marginTop="48dp" app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"/>
|
||||
<RadioGroup
|
||||
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_constraintEnd_toEndOf="parent" android:layout_marginTop="16dp"
|
||||
android:orientation="horizontal" android:id="@+id/radioGroup">
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
android:orientation="horizontal" android:id="@+id/radioGroup"
|
||||
app:layout_constraintTop_toBottomOf="@+id/dateOfProductionDatePicker" android:layout_marginTop="16dp">
|
||||
<RadioButton
|
||||
android:text="@string/expiry_date"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" android:id="@+id/expiryDateRadio"/>
|
||||
android:layout_height="match_parent" android:id="@+id/expiryDateRadio"/>
|
||||
<RadioButton
|
||||
android:text="@string/shelf_life"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" android:id="@+id/shelfLifeRadio"/>
|
||||
</RadioGroup>
|
||||
<TextView
|
||||
android:text="Expiry date: "
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" android:id="@+id/expiryDateTextView"
|
||||
app:layout_constraintTop_toBottomOf="@+id/radioGroup" app:layout_constraintStart_toStartOf="parent"
|
||||
android:layout_marginStart="16dp" android:layout_marginTop="16dp" android:visibility="invisible"/>
|
||||
<Button
|
||||
android:text="Select"
|
||||
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"/>
|
||||
<DatePicker
|
||||
android:layout_width="247dp"
|
||||
android:layout_height="78dp" android:id="@+id/expiryDatePicker"
|
||||
android:datePickerMode="spinner"
|
||||
android:calendarViewShown="false"
|
||||
app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.505" android:layout_marginTop="12dp"
|
||||
app:layout_constraintTop_toBottomOf="@+id/radioGroup" android:visibility="gone"/>
|
||||
<EditText
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="numberDecimal"
|
||||
android:ems="10"
|
||||
android:id="@+id/shelfLifeTextEdit" app:layout_constraintTop_toBottomOf="@+id/radioGroup"
|
||||
app:layout_constraintStart_toEndOf="@+id/expiryDateTextView" android:layout_marginStart="16dp"
|
||||
android:visibility="invisible"/>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" android:id="@+id/amountText"
|
||||
app:layout_constraintTop_toBottomOf="@+id/shelfLifeTextEdit"
|
||||
android:visibility="gone" app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent" android:layout_marginTop="16dp"
|
||||
android:text="@string/amount"/>
|
||||
android:hint="@string/shelf_life"/>
|
||||
<EditText
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="numberSigned"
|
||||
android:ems="10"
|
||||
android:id="@+id/amountTextEdit"
|
||||
app:layout_constraintTop_toBottomOf="@+id/selectExpiryDateButton"
|
||||
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@+id/amountText"/>
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
android:hint="@string/amount" app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/expiryDatePicker" android:layout_marginTop="12dp"/>
|
||||
<Button
|
||||
android:text="@string/saveButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" android:id="@+id/saveProductButton"
|
||||
app:layout_constraintTop_toBottomOf="@+id/amountTextEdit" app:layout_constraintStart_toStartOf="parent"
|
||||
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.core.widget.NestedScrollView>
|
|
@ -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="drop_filters">Drop filters</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="edit_existing">Edit existing</string>
|
||||
<string name="no_product_in_online_database">Product not found. Please, try again if you beleive barcode scanned
|
||||
|
|
Loading…
Reference in New Issue