From 7d5391c30df39a393f3601fa32d912c5bcedf4ee Mon Sep 17 00:00:00 2001 From: joemacd Date: Fri, 6 Dec 2024 18:14:56 -0500 Subject: [PATCH] Price validation --- .../Subletting/SubletteeFragment.kt | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) 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