Skip to content

Commit

Permalink
Price validation
Browse files Browse the repository at this point in the history
  • Loading branch information
joemacd committed Dec 6, 2024
1 parent f1b71f4 commit 7d5391c
Showing 1 changed file with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ class SubletteeFragment : Fragment() {
return@setOnClickListener
}

if (!validatePrices()) {
Toast.makeText(context, "Please enter a valid price range", Toast.LENGTH_SHORT).show()
return@setOnClickListener
}


// Load new fragment, which will hold the subletting marketplace in whole
mActivity.supportFragmentManager.beginTransaction()
Expand All @@ -137,6 +142,28 @@ class SubletteeFragment : Fragment() {
}
}

private fun validatePrices(): Boolean {
val minPriceString = binding.subletteeMinPriceText.text.toString().trim()
val maxPriceString = binding.subletteeMaxPriceText.text.toString().trim()

if (minPriceString.isEmpty() || maxPriceString.isEmpty()) {
return false
}

val minPrice = minPriceString.toDoubleOrNull()
val maxPrice = maxPriceString.toDoubleOrNull()

if (minPrice == null || maxPrice == null || minPrice < 0 || maxPrice < 0) {
return false
}

if (minPrice > maxPrice) {
return false
}

return true
}


private fun setupDatePickers() {
// Start Date
Expand Down

0 comments on commit 7d5391c

Please sign in to comment.