Skip to content
Snippets Groups Projects
Commit 1016fd3c authored by I Putu Bakta Hari Sudewa's avatar I Putu Bakta Hari Sudewa
Browse files

fix: amount field on save transaction unhandled exception

parent 6e0daf85
2 merge requests!46Dev,!40fix: amount field on save transaction unhandled exception
...@@ -56,7 +56,7 @@ class TransactionViewModel( ...@@ -56,7 +56,7 @@ class TransactionViewModel(
Transaction( Transaction(
title = title, title = title,
owner = currentUserNim, owner = currentUserNim,
amount = Long.MAX_VALUE, amount = amount,
category = category, category = category,
location = location, location = location,
) )
......
...@@ -145,7 +145,8 @@ class ScanReceiptResultFragment : Fragment() { ...@@ -145,7 +145,8 @@ class ScanReceiptResultFragment : Fragment() {
val observer = val observer =
Observer<ScanReceiptResponseItemsWrapper> { response -> Observer<ScanReceiptResponseItemsWrapper> { response ->
if (response.error != null) { if (response.error != null) {
Toast.makeText(this.requireContext(), response.error, Toast.LENGTH_SHORT).show() Toast.makeText(this.requireContext(), response.error, Toast.LENGTH_SHORT)
.show()
Navigation.findNavController(view) Navigation.findNavController(view)
.navigate(R.id.action_scanReceiptResultFragment_to_scanReceiptFragment) .navigate(R.id.action_scanReceiptResultFragment_to_scanReceiptFragment)
} else { } else {
...@@ -211,24 +212,32 @@ class ScanReceiptResultFragment : Fragment() { ...@@ -211,24 +212,32 @@ class ScanReceiptResultFragment : Fragment() {
// Save button listener // Save button listener
viewBinding.scanReceiptFormButtonSave.setOnClickListener { viewBinding.scanReceiptFormButtonSave.setOnClickListener {
val title = viewBinding.scanReceiptFormTitle.getText().trim() try {
val amount = viewBinding.scanReceiptFormAmount.getText().trim().toLong() val title = viewBinding.scanReceiptFormTitle.getText().trim()
val location = viewBinding.scanReceiptFormLocationField.text.toString().trim() val amount = viewBinding.scanReceiptFormAmount.getText().trim().toLong()
val isDataValid = validateInput(title, amount, location) val location = viewBinding.scanReceiptFormLocationField.text.toString().trim()
val isDataValid = validateInput(title, amount, location)
if (isDataValid == null) {
// Create new transaction if (isDataValid == null) {
transactionViewModel.insertTransaction( // Create new transaction
title, transactionViewModel.insertTransaction(
TransactionCategory.EXPENSE, title,
amount, TransactionCategory.EXPENSE,
location, amount,
) { _, message -> location
Toast.makeText(this.requireContext(), message, Toast.LENGTH_SHORT).show() ) { _, message ->
findNavController().popBackStack(R.id.scanReceiptFragment, false) Toast.makeText(this.requireContext(), message, Toast.LENGTH_SHORT).show()
findNavController().popBackStack(R.id.scanReceiptFragment, false)
}
} else {
Toast.makeText(this.requireContext(), isDataValid, Toast.LENGTH_SHORT).show()
} }
} else { } catch (e: NumberFormatException) {
Toast.makeText(this.requireContext(), isDataValid, Toast.LENGTH_SHORT).show() Toast.makeText(
this.requireContext(),
"Amount must be a positive number",
Toast.LENGTH_SHORT
).show()
} }
} }
} }
...@@ -243,7 +252,7 @@ class ScanReceiptResultFragment : Fragment() { ...@@ -243,7 +252,7 @@ class ScanReceiptResultFragment : Fragment() {
} }
if (amount < 0) { if (amount < 0) {
return "Amount must be greater than zero" return "Amount must be a positive number"
} }
if (location == "") { if (location == "") {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment