2 Commits

2 changed files with 145 additions and 10 deletions

View File

@@ -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,25 @@ 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
}
}
binding.etCaste.setOnItemClickListener { parent, view, position, id ->
if (parent.getItemAtPosition(position).toString().equals("OTHER", ignoreCase = true)) {
binding.tilOthercaste.visibility = View.VISIBLE
} else {
binding.tilOthercaste.visibility = View.GONE
}
}
}
private fun setupViewModel() {
@@ -59,20 +79,21 @@ class UserDetailsRegistrationFragment : Fragment() {
when (it) {
"Male" -> {
male.isChecked = true
binding.tilOthergender.visibility = View.GONE
}
"Female" -> {
female.isChecked = true
binding.tilOthergender.visibility = View.GONE
}
else -> {
other.isChecked = true
binding.tilOthergender.visibility = View.VISIBLE
}
}
}
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.subCaste.let { etSubCaste.setText(it) }
user.house.let { etHouse.setText(it) }
user.city.let { etCity.setText(it) }
@@ -94,6 +115,12 @@ class UserDetailsRegistrationFragment : Fragment() {
yes1history.isChecked = true
}
}
user.category.let {
etCategory.setText(it, false)
}
user.caste.let {
etCaste.setText(it, false)
}
if (yes1history.isChecked) {
if (binding.yes1history.isChecked) View.VISIBLE else View.GONE
@@ -112,6 +139,35 @@ class UserDetailsRegistrationFragment : Fragment() {
if (binding.no1history.isChecked) View.GONE else View.VISIBLE
}
if(other.isChecked){
user.gender.let { etOthergender.setText(it) }
}
binding.male.setOnClickListener {
binding.tilOthergender.visibility = View.GONE
}
binding.female.setOnClickListener {
binding.tilOthergender.visibility = View.GONE
}
binding.other.setOnClickListener {
binding.tilOthergender.visibility = 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
}
if (binding.etCaste.text.toString().equals("OTHER", ignoreCase = true)) {
binding.tilOthercaste.visibility = View.VISIBLE
binding.etOthercaste.visibility = View.VISIBLE
} else {
binding.tilOthercaste.visibility = View.GONE
}
}
}
@@ -145,11 +201,19 @@ class UserDetailsRegistrationFragment : Fragment() {
}
if (male.isChecked) {
binding.tilOthergender.visibility = View.GONE
userData.gender = "Male"
} else if (female.isChecked) {
binding.tilOthergender.visibility = View.GONE
userData.gender = "Female"
} else {
userData.gender = "Other"
} else if(other.isChecked) {
binding.tilOthergender.visibility = View.VISIBLE
val genderother= binding.etOthergender.text.toString()
userData.gender = genderother
if (genderother.isEmpty()) {
etOthergender.error = "Please fill the field"
return false
}
}
val mobile = etMobile.text.toString()
@@ -177,21 +241,28 @@ 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
}
val caste = etCaste.text.toString()
val othercaste = etOthercaste.text.toString()
if (caste.isEmpty()) {
etCaste.error = "Please enter your caste"
return false
} else if (caste == "OTHER" && tilOthercaste.isVisible) {
userData.caste = othercaste
} else {
userData.caste = caste
}
val subCaste = etSubCaste.text.toString()
if (subCaste.isNotEmpty()) {
userData.subCaste = subCaste
@@ -257,6 +328,8 @@ class UserDetailsRegistrationFragment : Fragment() {
return true
}
}

View File

@@ -63,7 +63,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:checked="true"
android:text="@string/male"
android:textSize="16sp" />
@@ -83,7 +82,8 @@
</RadioGroup>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/til_mobile"
android:visibility="gone"
android:id="@+id/til_othergender"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
@@ -93,6 +93,28 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/gender">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/et_othergender"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Other"
android:inputType="text"
android:maxLength="10" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/til_mobile"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="24dp"
android:layout_marginTop="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/til_othergender">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/et_mobile"
android:layout_width="match_parent"
@@ -160,12 +182,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" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:visibility="gone"
android:id="@+id/til_other"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="24dp"
android:layout_marginTop="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/til_category">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/et_other"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Other Category"
android:inputType="text"
android:maxLength="10" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/til_caste"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
@@ -175,19 +217,39 @@
android:layout_marginTop="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/til_category">
app:layout_constraintTop_toBottomOf="@id/til_other">
<AutoCompleteTextView
android:id="@+id/et_Caste"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/caste"
android:inputType="none"
android:inputType="text"
android:labelFor="@id/til_is_married"
app:simpleItems="@array/caste" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:visibility="gone"
android:id="@+id/til_othercaste"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="24dp"
android:layout_marginTop="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/til_caste">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/et_othercaste"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Other Caste"
android:inputType="text"
android:maxLength="10" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/til_subCaste"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
@@ -197,7 +259,7 @@
android:layout_marginTop="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/til_caste">
app:layout_constraintTop_toBottomOf="@id/til_othercaste">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/et_subCaste"