2635 | Reyaz | Add form validation for creating profile
This commit is contained in:
@@ -13,8 +13,6 @@ import com.navi.permission.fragments.PermissionConsentFragment
|
||||
import com.navi.permission.fragments.PermissionDescriptionFragment
|
||||
import com.navi.permission.listeners.PermissionScreenListener
|
||||
import com.navi.registration.RegistrationActivity
|
||||
import com.navi.welcomejourney.common.fragments.BaseBottomSheet
|
||||
import com.navi.welcomejourney.profile.fragments.CreateYourProfileFragment
|
||||
|
||||
class PermissionActivity : BaseActivity(), PermissionScreenListener {
|
||||
private lateinit var binding: ActivityPermissionBinding
|
||||
@@ -25,7 +23,6 @@ class PermissionActivity : BaseActivity(), PermissionScreenListener {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
binding = DataBindingUtil.setContentView(this, R.layout.activity_permission)
|
||||
initUi()
|
||||
onPermissionScreen()
|
||||
}
|
||||
|
||||
@@ -39,15 +36,6 @@ class PermissionActivity : BaseActivity(), PermissionScreenListener {
|
||||
fragmentTransaction.commit()
|
||||
}
|
||||
|
||||
private fun initUi() {
|
||||
binding.permissionHeader.setOnClickListener {
|
||||
BaseBottomSheet(CreateYourProfileFragment.TAG).show(
|
||||
supportFragmentManager,
|
||||
BaseBottomSheet.TAG
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun addTransitionAnimation(fragmentTransaction: FragmentTransaction, tag: String) {
|
||||
when (tag) {
|
||||
PermissionDescriptionFragment.TAG -> fragmentTransaction.setCustomAnimations(
|
||||
|
||||
@@ -40,4 +40,5 @@ object Constants {
|
||||
const val API_POLL_REPEAT_PERIOD_SECONDS = 10L
|
||||
const val API_POLL_RETRY_COUNT_SECONDS = 2
|
||||
const val FCM_UPDATE_PERIOD = 24 * 60 * 60 * 1000 // 24 hrs in milli seconds
|
||||
const val ZIP_CODE_LENGTH = 6
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.navi.welcomejourney.custom
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.ColorStateList
|
||||
import android.util.AttributeSet
|
||||
import android.widget.EditText
|
||||
import androidx.core.widget.addTextChangedListener
|
||||
import com.navi.R
|
||||
import com.navi.utils.Constants
|
||||
|
||||
class FormEditText(context: Context, attrs: AttributeSet) : EditText(context, attrs) {
|
||||
private var formTextView: FormTextView? = null
|
||||
|
||||
init {
|
||||
addTextChangedListener {
|
||||
if (text.isNotBlank()) {
|
||||
backgroundTintList =
|
||||
ColorStateList.valueOf(context.resources.getColor(R.color.black))
|
||||
formTextView?.setDefault()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun setError() {
|
||||
error = Constants.EMPTY
|
||||
backgroundTintList = ColorStateList.valueOf(context.resources.getColor(R.color.red))
|
||||
formTextView?.setError()
|
||||
}
|
||||
|
||||
fun setDependentFormTextView(formTextView: FormTextView) {
|
||||
this.formTextView = formTextView
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.navi.welcomejourney.custom
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.widget.RadioGroup
|
||||
|
||||
class FormRadioGroup(context: Context, attrs: AttributeSet) : RadioGroup(context, attrs) {
|
||||
private var formTextView: FormTextView? = null
|
||||
|
||||
init {
|
||||
setOnCheckedChangeListener { _, _ ->
|
||||
if (checkedRadioButtonId != -1) {
|
||||
formTextView?.setDefault()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun setDependentFormTextView(formTextView: FormTextView) {
|
||||
this.formTextView = formTextView
|
||||
}
|
||||
|
||||
fun setError() {
|
||||
formTextView?.setError()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.navi.welcomejourney.custom
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.widget.TextView
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.navi.R
|
||||
|
||||
class FormTextView(context: Context, attrs: AttributeSet) : TextView(context, attrs) {
|
||||
fun setError() {
|
||||
setTextColor(ContextCompat.getColor(context, R.color.red))
|
||||
}
|
||||
|
||||
fun setDefault() {
|
||||
setTextColor(ContextCompat.getColor(context, R.color.title_color_one))
|
||||
}
|
||||
}
|
||||
@@ -7,8 +7,10 @@ import android.view.ViewGroup
|
||||
import com.navi.R
|
||||
import com.navi.common.BaseFragment
|
||||
import com.navi.databinding.CreateYourProfileLayoutBinding
|
||||
import com.navi.utils.Constants.ZIP_CODE_LENGTH
|
||||
import com.navi.utils.toast
|
||||
|
||||
class CreateYourProfileFragment : BaseFragment() {
|
||||
class CreateYourProfileFragment : BaseFragment(), View.OnClickListener {
|
||||
private lateinit var binding: CreateYourProfileLayoutBinding
|
||||
|
||||
override fun onCreateView(
|
||||
@@ -18,13 +20,64 @@ class CreateYourProfileFragment : BaseFragment() {
|
||||
): View? {
|
||||
binding = CreateYourProfileLayoutBinding.inflate(inflater, container, false)
|
||||
initUi()
|
||||
initListeners()
|
||||
return binding.root
|
||||
}
|
||||
|
||||
private fun initListeners() {
|
||||
binding.doneBtn.setOnClickListener(this)
|
||||
binding.fullNameLayout.firstNameEt.setDependentFormTextView(binding.fullNameLayout.fullNameTag)
|
||||
binding.fullNameLayout.lastNameEt.setDependentFormTextView(binding.fullNameLayout.fullNameTag)
|
||||
binding.emailLayout.personalEmailIdEt.setDependentFormTextView(binding.emailLayout.personalEmailIdTag)
|
||||
binding.dobLayout.dobEt.setDependentFormTextView(binding.dobLayout.dobTag)
|
||||
binding.genderLayout.genderRadio.setDependentFormTextView(binding.genderLayout.genderTag)
|
||||
binding.pincodeLayout.pincodeEt.setDependentFormTextView(binding.pincodeLayout.pincodeTag)
|
||||
}
|
||||
|
||||
private fun initUi() {
|
||||
binding.doneBtn.setProperties(getString(R.string.done))
|
||||
}
|
||||
|
||||
private fun submitProfileDetails() {
|
||||
if (validateProfileDetails()) {
|
||||
context?.toast("Done")
|
||||
}
|
||||
}
|
||||
|
||||
private fun validateProfileDetails(): Boolean {
|
||||
var validated = true
|
||||
if (binding.emailLayout.personalEmailIdEt.text.toString().isBlank()) {
|
||||
binding.emailLayout.personalEmailIdEt.setError()
|
||||
validated = false
|
||||
}
|
||||
if (binding.fullNameLayout.firstNameEt.text.toString().isBlank()) {
|
||||
binding.fullNameLayout.firstNameEt.setError()
|
||||
validated = false
|
||||
}
|
||||
if (binding.fullNameLayout.lastNameEt.text.toString().isBlank()) {
|
||||
binding.fullNameLayout.lastNameEt.setError()
|
||||
validated = false
|
||||
}
|
||||
if (binding.dobLayout.dobEt.text.toString().isBlank()) {
|
||||
binding.dobLayout.dobEt.setError()
|
||||
validated = false
|
||||
}
|
||||
if (binding.genderLayout.genderRadio.checkedRadioButtonId == -1) {
|
||||
binding.genderLayout.genderRadio.setError()
|
||||
}
|
||||
if (binding.pincodeLayout.pincodeEt.text.toString().length != ZIP_CODE_LENGTH) {
|
||||
binding.pincodeLayout.pincodeEt.setError()
|
||||
validated = false
|
||||
}
|
||||
return validated
|
||||
}
|
||||
|
||||
override fun onClick(view: View?) {
|
||||
when (view?.id) {
|
||||
R.id.done_btn -> submitProfileDetails()
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val TAG = "CREATE_YOUR_PROFILE_FRAGMENT"
|
||||
}
|
||||
|
||||
@@ -6,9 +6,7 @@
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<include
|
||||
android:id="@+id/permission_header"
|
||||
layout="@layout/permission_header" />
|
||||
<include layout="@layout/permission_header" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/permission_container"
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
<com.navi.welcomejourney.custom.FormTextView
|
||||
android:id="@+id/dob_tag"
|
||||
style="@style/FormSubHeadingFontStyle"
|
||||
android:layout_width="wrap_content"
|
||||
@@ -28,7 +28,7 @@
|
||||
app:layout_constraintStart_toEndOf="@id/dob_iv"
|
||||
app:layout_constraintTop_toTopOf="@id/dob_iv" />
|
||||
|
||||
<EditText
|
||||
<com.navi.welcomejourney.custom.FormEditText
|
||||
android:id="@+id/dob_et"
|
||||
style="@style/TitleFontStyle"
|
||||
android:layout_width="0dp"
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
<com.navi.welcomejourney.custom.FormTextView
|
||||
android:id="@+id/personal_email_id_tag"
|
||||
style="@style/FormSubHeadingFontStyle"
|
||||
android:layout_width="wrap_content"
|
||||
@@ -28,7 +28,7 @@
|
||||
app:layout_constraintTop_toBottomOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@id/personal_email_id_iv" />
|
||||
|
||||
<EditText
|
||||
<com.navi.welcomejourney.custom.FormEditText
|
||||
android:id="@+id/personal_email_id_et"
|
||||
style="@style/TitleFontStyle"
|
||||
android:layout_width="0dp"
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
<com.navi.welcomejourney.custom.FormTextView
|
||||
android:id="@+id/full_name_tag"
|
||||
style="@style/FormSubHeadingFontStyle"
|
||||
android:layout_width="wrap_content"
|
||||
@@ -28,7 +28,7 @@
|
||||
app:layout_constraintStart_toEndOf="@id/full_name_iv"
|
||||
app:layout_constraintTop_toTopOf="@id/full_name_iv" />
|
||||
|
||||
<EditText
|
||||
<com.navi.welcomejourney.custom.FormEditText
|
||||
android:id="@+id/first_name_et"
|
||||
style="@style/TitleFontStyle"
|
||||
android:layout_width="0dp"
|
||||
@@ -42,7 +42,7 @@
|
||||
app:layout_constraintStart_toStartOf="@id/full_name_tag"
|
||||
app:layout_constraintTop_toBottomOf="@id/full_name_tag" />
|
||||
|
||||
<EditText
|
||||
<com.navi.welcomejourney.custom.FormEditText
|
||||
android:id="@+id/last_name_et"
|
||||
style="@style/TitleFontStyle"
|
||||
android:layout_width="0dp"
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
<com.navi.welcomejourney.custom.FormTextView
|
||||
android:id="@+id/gender_tag"
|
||||
style="@style/FormSubHeadingFontStyle"
|
||||
android:layout_width="wrap_content"
|
||||
@@ -28,7 +28,7 @@
|
||||
app:layout_constraintStart_toEndOf="@id/gender_iv"
|
||||
app:layout_constraintTop_toTopOf="@id/gender_iv" />
|
||||
|
||||
<RadioGroup
|
||||
<com.navi.welcomejourney.custom.FormRadioGroup
|
||||
android:id="@+id/gender_radio"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
@@ -64,7 +64,7 @@
|
||||
android:layout_weight="1"
|
||||
android:buttonTint="@color/red"
|
||||
android:text="@string/other" />
|
||||
</RadioGroup>
|
||||
</com.navi.welcomejourney.custom.FormRadioGroup>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</layout>
|
||||
@@ -16,7 +16,7 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
<com.navi.welcomejourney.custom.FormTextView
|
||||
android:id="@+id/pincode_tag"
|
||||
style="@style/FormSubHeadingFontStyle"
|
||||
android:layout_width="wrap_content"
|
||||
@@ -28,7 +28,7 @@
|
||||
app:layout_constraintStart_toEndOf="@id/pincode_iv"
|
||||
app:layout_constraintTop_toTopOf="@id/pincode_iv" />
|
||||
|
||||
<EditText
|
||||
<com.navi.welcomejourney.custom.FormEditText
|
||||
android:id="@+id/pincode_et"
|
||||
style="@style/TitleFontStyle"
|
||||
android:layout_width="0dp"
|
||||
|
||||
Reference in New Issue
Block a user