From a3d67a7a8815ac27896d36c6a16c5761f24f358b Mon Sep 17 00:00:00 2001 From: Mariya Date: Fri, 6 Oct 2023 15:31:25 +0530 Subject: [PATCH] Added search for caste and category dropdown, and Added textbox for Under Category if the "OTHER" option is selected from dropdown --- .../UserDetailsRegistrationFragment.kt | 34 +++++++++++++++++-- .../fragment_user_details_registration.xml | 26 ++++++++++++-- 2 files changed, 54 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/example/hposregistration/ui/fragments/registration/UserDetailsRegistrationFragment.kt b/app/src/main/java/com/example/hposregistration/ui/fragments/registration/UserDetailsRegistrationFragment.kt index 037abd6..e58cf16 100644 --- a/app/src/main/java/com/example/hposregistration/ui/fragments/registration/UserDetailsRegistrationFragment.kt +++ b/app/src/main/java/com/example/hposregistration/ui/fragments/registration/UserDetailsRegistrationFragment.kt @@ -5,6 +5,7 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.Toast +import androidx.core.view.isVisible import androidx.fragment.app.Fragment import androidx.fragment.app.viewModels import androidx.navigation.fragment.findNavController @@ -42,6 +43,17 @@ class UserDetailsRegistrationFragment : Fragment() { private fun init() { setupViewModel() setupSubmitButton() + + + binding.etCategory.setOnItemClickListener { parent, view, position, id -> + if (parent.getItemAtPosition(position).toString().equals("OTHER", ignoreCase = true)) { + binding.tilOther.visibility = View.VISIBLE + } else { + binding.tilOther.visibility = View.GONE + } + } + + } private fun setupViewModel() { @@ -71,8 +83,9 @@ class UserDetailsRegistrationFragment : Fragment() { user.phoneNumber.let { etMobile.setText(it) } user.careOf.let { etCareof.setText(it) } user.maritalStatus.let { etIsMarried.setText(it, false) } - user.caste.let { etCaste.setText(it, false) } - user.category.let { etCategory.setText(it, false) } + user.caste.let { + etCaste.setText(it, false) + } user.subCaste.let { etSubCaste.setText(it) } user.house.let { etHouse.setText(it) } user.city.let { etCity.setText(it) } @@ -94,6 +107,11 @@ class UserDetailsRegistrationFragment : Fragment() { yes1history.isChecked = true } } + user.category.let { + etCategory.setText(it, false) + } + + if (yes1history.isChecked) { if (binding.yes1history.isChecked) View.VISIBLE else View.GONE @@ -112,6 +130,12 @@ class UserDetailsRegistrationFragment : Fragment() { if (binding.no1history.isChecked) View.GONE else View.VISIBLE } + if (binding.etCategory.text.toString().equals("OTHER", ignoreCase = true)) { + binding.tilOther.visibility = View.VISIBLE + binding.etOther.visibility = View.VISIBLE + } else { + binding.tilOther.visibility = View.GONE + } } } @@ -177,9 +201,12 @@ class UserDetailsRegistrationFragment : Fragment() { } val category = etCategory.text.toString() + val other = etOther.text.toString() if (category.isEmpty()) { etCategory.error = "Please enter your category" return false + } else if (category == "OTHER" && tilOther.isVisible) { + userData.category = other } else { userData.category = category } @@ -188,10 +215,11 @@ class UserDetailsRegistrationFragment : Fragment() { if (caste.isEmpty()) { etCaste.error = "Please enter your caste" return false - } else { + }else{ userData.caste = caste } + val subCaste = etSubCaste.text.toString() if (subCaste.isNotEmpty()) { userData.subCaste = subCaste diff --git a/app/src/main/res/layout/fragment_user_details_registration.xml b/app/src/main/res/layout/fragment_user_details_registration.xml index 84a8eef..1c3b502 100644 --- a/app/src/main/res/layout/fragment_user_details_registration.xml +++ b/app/src/main/res/layout/fragment_user_details_registration.xml @@ -160,12 +160,32 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/category" - android:inputType="none" + android:inputType="text" android:labelFor="@id/til_is_married" app:simpleItems="@array/category" /> + + + + + app:layout_constraintTop_toBottomOf="@id/til_other">