Skip to content

Commit

Permalink
Created an if statement to check foodName is not empty
Browse files Browse the repository at this point in the history
  • Loading branch information
bhavesh100 committed May 19, 2023
1 parent 7af2e93 commit 02d24f2
Showing 1 changed file with 22 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,26 +220,30 @@ class InsertActivity : ComponentActivity() {
),
onClick = {
try {
if (datePickerState.selectedDateMillis != null) {
var id = 0
if (itemToEdit != null) {
id = itemId ?: 0
if(foodName.isNotEmpty()) {
if (datePickerState.selectedDateMillis != null) {
var id = 0
if (itemToEdit != null) {
id = itemId ?: 0
}
val entry = ExpirationDate(
id = id,
foodName = foodName,
expirationDate = datePickerState.selectedDateMillis!!
)
if (addExpirationDate != null) {
addExpirationDate(entry)
}
activity?.finish()
} else {
Toast.makeText(
activity,
R.string.please_select_a_date,
Toast.LENGTH_SHORT
).show()
}
val entry = ExpirationDate(
id = id,
foodName = foodName,
expirationDate = datePickerState.selectedDateMillis!!
)
if (addExpirationDate != null) {
addExpirationDate(entry)
}
activity?.finish()
} else {
Toast.makeText(
activity,
R.string.please_select_a_date,
Toast.LENGTH_SHORT
).show()
Toast.makeText(activity,R.string.please_enter_a_food_name,Toast.LENGTH_SHORT).show()
}
} catch (e: Exception) {
Toast.makeText(
Expand Down

0 comments on commit 02d24f2

Please sign in to comment.