diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/Subletting/SubletteeFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/Subletting/SubletteeFragment.kt index b6c6eb6b..38c87421 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/Subletting/SubletteeFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/Subletting/SubletteeFragment.kt @@ -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() @@ -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