@ -1,5 +1,7 @@
package com.nivesh.production.bajajfd.ui.fragment
package com.nivesh.production.bajajfd.ui.fragment
import android.annotation.SuppressLint
import android.app.DatePickerDialog
import android.os.Bundle
import android.os.Bundle
import android.text.Editable
import android.text.Editable
import android.text.InputFilter
import android.text.InputFilter
@ -7,22 +9,25 @@ import android.text.InputFilter.LengthFilter
import android.text.TextWatcher
import android.text.TextWatcher
import android.util.Log
import android.util.Log
import android.view.LayoutInflater
import android.view.LayoutInflater
import android.view.MotionEvent
import android.view.View
import android.view.View
import android.view.ViewGroup
import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.ArrayAdapter
import android.widget.RadioButton
import android.widget.RadioButton
import android.widget.Toast
import androidx.core.content.ContextCompat
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.Fragment
import com.google.android.material.textfield.TextInputEditText
import com.google.gson.Gson
import com.google.gson.Gson
import com.nivesh.production.bajajfd.R
import com.nivesh.production.bajajfd.R
import com.nivesh.production.bajajfd.databinding.FragmentBajajfdStepTwoBinding
import com.nivesh.production.bajajfd.databinding.FragmentBajajfdStepTwoBinding
import com.nivesh.production.bajajfd.interfaces.BajajFDInterface
import com.nivesh.production.bajajfd.interfaces.BajajFDInterface
import com.nivesh.production.bajajfd.model.PanCheckRequest
import com.nivesh.production.bajajfd.model.PanCheckResponse
import com.nivesh.production.bajajfd.model.*
import com.nivesh.production.bajajfd.ui.activity.BajajFdMainActivity
import com.nivesh.production.bajajfd.ui.activity.BajajFdMainActivity
import com.nivesh.production.bajajfd.util.Common
import com.nivesh.production.bajajfd.util.Common
import com.nivesh.production.bajajfd.util.Common.Companion.commonErrorMethod
import com.nivesh.production.bajajfd.util.Common.Companion.commonErrorMethod
import com.nivesh.production.bajajfd.util.Common.Companion.commonSpinnerErrorMethod
import com.nivesh.production.bajajfd.util.Common.Companion.commonSpinnerErrorMethod
import com.nivesh.production.bajajfd.util.Common.Companion.getDate
import com.nivesh.production.bajajfd.util.Common.Companion.isIndianMobileNo
import com.nivesh.production.bajajfd.util.Common.Companion.isIndianMobileNo
import com.nivesh.production.bajajfd.util.Common.Companion.isValidEmail
import com.nivesh.production.bajajfd.util.Common.Companion.isValidEmail
import com.nivesh.production.bajajfd.util.Common.Companion.isValidName
import com.nivesh.production.bajajfd.util.Common.Companion.isValidName
@ -31,14 +36,28 @@ import com.nivesh.production.bajajfd.util.Common.Companion.removeError
import com.nivesh.production.bajajfd.util.Constants.Companion.token
import com.nivesh.production.bajajfd.util.Constants.Companion.token
import com.nivesh.production.bajajfd.util.Resource
import com.nivesh.production.bajajfd.util.Resource
import com.nivesh.production.bajajfd.viewModel.StepTwoBajajFDViewModel
import com.nivesh.production.bajajfd.viewModel.StepTwoBajajFDViewModel
import java.util.*
class StepTwoBajajFDFragment : Fragment ( ) {
class StepTwoBajajFDFragment : Fragment ( ) {
private var _binding : FragmentBajajfdStepTwoBinding ? = null
private var _binding : FragmentBajajfdStepTwoBinding ? = null
private val binding get ( ) = _binding !!
private val binding get ( ) = _binding !!
private lateinit var bajajFDInterface : BajajFDInterface
private lateinit var bajajFDInterface : BajajFDInterface
private lateinit var rbBank : RadioButton
private lateinit var rbBank : RadioButton
private lateinit var rbPaymentMode : RadioButton
private lateinit var rbPaymentMode : RadioButton
private var cal = Calendar . getInstance ( )
private lateinit var listOfTitle : List < GetCodes >
private lateinit var listOfGender : List < GetCodes >
private lateinit var listOfAnnualIncome : List < GetCodes >
private lateinit var listOfRelationShip : List < GetCodes >
private lateinit var listOfMaritalStatus : List < GetCodes >
private lateinit var listOfOccupation : List < GetCodes >
private lateinit var listOfStates : List < DataObject >
private lateinit var listOfCities : List < DataObjectX >
private lateinit var stepTwoBajajFDViewModel : StepTwoBajajFDViewModel
private lateinit var stepTwoBajajFDViewModel : StepTwoBajajFDViewModel
companion object {
companion object {
@ -62,7 +81,13 @@ class StepTwoBajajFDFragment : Fragment() {
val root = binding . root
val root = binding . root
stepTwoBajajFDViewModel = ( activity as BajajFdMainActivity ) . stepTwoBajajFDViewModel
stepTwoBajajFDViewModel = ( activity as BajajFdMainActivity ) . stepTwoBajajFDViewModel
listOfTitle = ArrayList ( )
listOfGender = ArrayList ( )
listOfAnnualIncome = ArrayList ( )
listOfRelationShip = ArrayList ( )
listOfMaritalStatus = ArrayList ( )
listOfOccupation = ArrayList ( )
listOfStates = ArrayList ( )
// Personal Details
// Personal Details
binding . edtMobileNumber . filters = arrayOf < InputFilter > ( LengthFilter ( 10 ) )
binding . edtMobileNumber . filters = arrayOf < InputFilter > ( LengthFilter ( 10 ) )
binding . edtPANNumber . filters = arrayOf < InputFilter > ( LengthFilter ( 10 ) )
binding . edtPANNumber . filters = arrayOf < InputFilter > ( LengthFilter ( 10 ) )
@ -81,10 +106,17 @@ class StepTwoBajajFDFragment : Fragment() {
removeError ( binding . tlMobileNumber )
removeError ( binding . tlMobileNumber )
}
}
} )
} )
binding . edtMobileNumber . setText ( ( activity as BajajFdMainActivity ) . getClientDetailsResponse . ObjectResponse ?. clientDetails ?. mobile )
// create an OnDateSetListener
binding . edtDOB . setText ( ( activity as BajajFdMainActivity ) . getClientDetailsResponse . ObjectResponse ?. clientDetails ?. clientMasterMFD ?. CLIENT_DOB )
binding . edtDOB . setOnClickListener {
binding . edtDOB . setOnClickListener {
removeError ( binding . tlDOB )
removeError ( binding . tlDOB )
datePicker ( binding . edtDOB )
}
}
binding . edtPANNumber . setText ( ( activity as BajajFdMainActivity ) . getClientDetailsResponse . ObjectResponse ?. clientDetails ?. clientMasterMFD ?. CLIENT_PAN )
binding . edtPANNumber . addTextChangedListener ( object : TextWatcher {
binding . edtPANNumber . addTextChangedListener ( object : TextWatcher {
override fun afterTextChanged ( s : Editable ? ) {
override fun afterTextChanged ( s : Editable ? ) {
@ -101,18 +133,15 @@ class StepTwoBajajFDFragment : Fragment() {
}
}
} )
} )
val titleAdapter = ArrayAdapter (
activity as BajajFdMainActivity ,
R . layout . spinner_dropdown ,
resources . getStringArray (
R . array . title
)
)
binding . spTitle . setAdapter ( titleAdapter )
binding . spTitle . setOnItemClickListener { _ , _ , _ , _ - >
binding . spTitle . setOnItemClickListener { _ , _ , _ , _ - >
removeError ( binding . tlTitle )
removeError ( binding . tlTitle )
}
}
val splitStringName =
( activity as BajajFdMainActivity ) . getClientDetailsResponse . ObjectResponse ?. clientDetails ?. clientMasterMFD ?. CLIENT_APPNAME1 ?. split (
"\\s" . toRegex ( )
) ?. toTypedArray ( )
binding . edtFirstName . addTextChangedListener ( object : TextWatcher {
binding . edtFirstName . addTextChangedListener ( object : TextWatcher {
override fun afterTextChanged ( s : Editable ? ) {
override fun afterTextChanged ( s : Editable ? ) {
@ -125,6 +154,8 @@ class StepTwoBajajFDFragment : Fragment() {
removeError ( binding . tlFirstName )
removeError ( binding . tlFirstName )
}
}
} )
} )
binding . edtFirstName . setText ( splitStringName ?. get ( 0 ) . toString ( ) )
binding . edtMiddleName . addTextChangedListener ( object : TextWatcher {
binding . edtMiddleName . addTextChangedListener ( object : TextWatcher {
override fun afterTextChanged ( s : Editable ? ) {
override fun afterTextChanged ( s : Editable ? ) {
@ -137,6 +168,8 @@ class StepTwoBajajFDFragment : Fragment() {
removeError ( binding . tlMiddleName )
removeError ( binding . tlMiddleName )
}
}
} )
} )
binding . edtMiddleName . setText ( splitStringName ?. get ( 1 ) . toString ( ) )
binding . edtLastName . addTextChangedListener ( object : TextWatcher {
binding . edtLastName . addTextChangedListener ( object : TextWatcher {
override fun afterTextChanged ( s : Editable ? ) {
override fun afterTextChanged ( s : Editable ? ) {
@ -149,15 +182,8 @@ class StepTwoBajajFDFragment : Fragment() {
removeError ( binding . tlLastName )
removeError ( binding . tlLastName )
}
}
} )
} )
binding . edtLastName . setText ( splitStringName ?. get ( 2 ) . toString ( ) )
val genderAdapter = ArrayAdapter (
activity as BajajFdMainActivity ,
R . layout . spinner_dropdown ,
resources . getStringArray (
R . array . gender
)
)
binding . spGender . setAdapter ( genderAdapter )
binding . spGender . setOnItemClickListener { _ , _ , _ , _ - >
binding . spGender . setOnItemClickListener { _ , _ , _ , _ - >
removeError ( binding . tlGender )
removeError ( binding . tlGender )
}
}
@ -174,18 +200,12 @@ class StepTwoBajajFDFragment : Fragment() {
removeError ( binding . tlEmail )
removeError ( binding . tlEmail )
}
}
} )
} )
binding . edtOccupation . addTextChangedListener ( object : TextWatcher {
binding . edtEmail . setText ( ( activity as BajajFdMainActivity ) . getClientDetailsResponse . ObjectResponse ?. clientDetails ?. clientMasterMFD ?. CLIENT_EMAIL )
override fun afterTextChanged ( s : Editable ? ) {
}
override fun beforeTextChanged ( s : CharSequence ? , start : Int , count : Int , after : Int ) {
}
binding . spOccupation . setOnItemClickListener { _ , _ , _ , _ - >
removeError ( binding . tlOccupation )
}
override fun onTextChanged ( s : CharSequence ? , start : Int , before : Int , count : Int ) {
removeError ( binding . tlOccupation )
}
} )
binding . edtQualification . addTextChangedListener ( object : TextWatcher {
binding . edtQualification . addTextChangedListener ( object : TextWatcher {
override fun afterTextChanged ( s : Editable ? ) {
override fun afterTextChanged ( s : Editable ? ) {
@ -199,26 +219,10 @@ class StepTwoBajajFDFragment : Fragment() {
}
}
} )
} )
val maritalAdapter = ArrayAdapter (
activity as BajajFdMainActivity ,
R . layout . spinner_dropdown ,
resources . getStringArray (
R . array . maritalStatus
)
)
binding . spMarital . setAdapter ( maritalAdapter )
binding . spMarital . setOnItemClickListener { _ , _ , _ , _ - >
binding . spMarital . setOnItemClickListener { _ , _ , _ , _ - >
removeError ( binding . tlMarital )
removeError ( binding . tlMarital )
}
}
val relationShipAdapter = ArrayAdapter (
activity as BajajFdMainActivity ,
R . layout . spinner_dropdown ,
resources . getStringArray (
R . array . maritalStatus
)
)
binding . spRelation . setAdapter ( relationShipAdapter )
binding . spRelation . setOnItemClickListener { _ , _ , _ , _ - >
binding . spRelation . setOnItemClickListener { _ , _ , _ , _ - >
removeError ( binding . tlRelation )
removeError ( binding . tlRelation )
}
}
@ -235,6 +239,7 @@ class StepTwoBajajFDFragment : Fragment() {
removeError ( binding . tlRelationName )
removeError ( binding . tlRelationName )
}
}
} )
} )
binding . edtAddressLine1 . addTextChangedListener ( object : TextWatcher {
binding . edtAddressLine1 . addTextChangedListener ( object : TextWatcher {
override fun afterTextChanged ( s : Editable ? ) {
override fun afterTextChanged ( s : Editable ? ) {
@ -259,7 +264,7 @@ class StepTwoBajajFDFragment : Fragment() {
removeError ( binding . tlAddressLine2 )
removeError ( binding . tlAddressLine2 )
}
}
} )
} )
binding . edtState . addTextChangedListener ( object : TextWatcher {
binding . edtAddressLine3 . addTextChangedListener ( object : TextWatcher {
override fun afterTextChanged ( s : Editable ? ) {
override fun afterTextChanged ( s : Editable ? ) {
}
}
@ -268,21 +273,16 @@ class StepTwoBajajFDFragment : Fragment() {
}
}
override fun onTextChanged ( s : CharSequence ? , start : Int , before : Int , count : Int ) {
override fun onTextChanged ( s : CharSequence ? , start : Int , before : Int , count : Int ) {
removeError ( binding . tlState )
removeError ( binding . tlAddressLine3 )
}
}
} )
} )
binding . edtCity . addTextChangedListener ( object : TextWatcher {
override fun afterTextChanged ( s : Editable ? ) {
}
override fun beforeTextChanged ( s : CharSequence ? , start : Int , count : Int , after : Int ) {
}
override fun onTextChanged ( s : CharSequence ? , start : Int , before : Int , count : Int ) {
removeError ( binding . tlCity )
}
} )
binding . spState . setOnItemClickListener { _ , _ , _ , _ - >
removeError ( binding . tlState )
}
binding . spCity . setOnItemClickListener { _ , _ , _ , _ - >
removeError ( binding . tlCity )
}
binding . edtPinCode . addTextChangedListener ( object : TextWatcher {
binding . edtPinCode . addTextChangedListener ( object : TextWatcher {
override fun afterTextChanged ( s : Editable ? ) {
override fun afterTextChanged ( s : Editable ? ) {
@ -297,11 +297,9 @@ class StepTwoBajajFDFragment : Fragment() {
} )
} )
// Nominee Details
// Nominee Details
binding . spNomineeTitle . setAdapter ( titleAdapter )
binding . spNomineeTitle . setOnItemClickListener { _ , _ , _ , _ - >
binding . spNomineeTitle . setOnItemClickListener { _ , _ , _ , _ - >
binding . tlNomineeTitle . error = null
binding . tlNomineeTitle . error = null
}
}
binding . edtNomineeFirstName . addTextChangedListener ( object : TextWatcher {
binding . edtNomineeFirstName . addTextChangedListener ( object : TextWatcher {
override fun afterTextChanged ( s : Editable ? ) {
override fun afterTextChanged ( s : Editable ? ) {
@ -338,12 +336,10 @@ class StepTwoBajajFDFragment : Fragment() {
removeError ( binding . tlNomineeLastName )
removeError ( binding . tlNomineeLastName )
}
}
} )
} )
binding . edtNomineeDOB . setOnClickListener {
binding . edtNomineeDOB . setOnClickListener {
removeError ( binding . tlNomineeDOB )
removeError ( binding . tlNomineeDOB )
datePicker ( binding . edtNomineeDOB )
}
}
binding . spNomineeRelation . setAdapter ( relationShipAdapter )
binding . spNomineeRelation . setOnItemClickListener { _ , _ , _ , _ - >
binding . spNomineeRelation . setOnItemClickListener { _ , _ , _ , _ - >
removeError ( binding . tlNomineeRelation )
removeError ( binding . tlNomineeRelation )
}
}
@ -377,12 +373,9 @@ class StepTwoBajajFDFragment : Fragment() {
removeError ( binding . tlGuardianAge )
removeError ( binding . tlGuardianAge )
}
}
} )
} )
binding . spGuardianRelation . setAdapter ( relationShipAdapter )
binding . spGuardianRelation . setOnItemClickListener { _ , _ , _ , _ - >
binding . spGuardianRelation . setOnItemClickListener { _ , _ , _ , _ - >
removeError ( binding . tlGuardianRelation )
removeError ( binding . tlGuardianRelation )
}
}
binding . edtGuardianAddress . addTextChangedListener ( object : TextWatcher {
binding . edtGuardianAddress . addTextChangedListener ( object : TextWatcher {
override fun afterTextChanged ( s : Editable ? ) {
override fun afterTextChanged ( s : Editable ? ) {
@ -477,7 +470,6 @@ class StepTwoBajajFDFragment : Fragment() {
binding . llPersonalDetail . visibility = View . VISIBLE
binding . llPersonalDetail . visibility = View . VISIBLE
}
}
}
}
binding . tvNomineeDetails . setOnClickListener {
binding . tvNomineeDetails . setOnClickListener {
if ( binding . llNomineeDetail . visibility = = View . VISIBLE ) {
if ( binding . llNomineeDetail . visibility = = View . VISIBLE ) {
binding . llNomineeDetail . visibility = View . GONE
binding . llNomineeDetail . visibility = View . GONE
@ -485,7 +477,6 @@ class StepTwoBajajFDFragment : Fragment() {
binding . llNomineeDetail . visibility = View . VISIBLE
binding . llNomineeDetail . visibility = View . VISIBLE
}
}
}
}
binding . tvBankDetails . setOnClickListener {
binding . tvBankDetails . setOnClickListener {
if ( binding . llBankDetails . visibility = = View . VISIBLE ) {
if ( binding . llBankDetails . visibility = = View . VISIBLE ) {
binding . llBankDetails . visibility = View . GONE
binding . llBankDetails . visibility = View . GONE
@ -494,6 +485,7 @@ class StepTwoBajajFDFragment : Fragment() {
}
}
}
}
titleApi ( )
binding . btnNext . setOnClickListener {
binding . btnNext . setOnClickListener {
if ( validation ( ) ) {
if ( validation ( ) ) {
// Applicant Details
// Applicant Details
@ -514,7 +506,7 @@ class StepTwoBajajFDFragment : Fragment() {
( activity as BajajFdMainActivity ) . applicantDetails . ApplicantMobile =
( activity as BajajFdMainActivity ) . applicantDetails . ApplicantMobile =
binding . edtMobileNumber . text . toString ( )
binding . edtMobileNumber . text . toString ( )
( activity as BajajFdMainActivity ) . applicantDetails . ApplicantOccupation =
( activity as BajajFdMainActivity ) . applicantDetails . ApplicantOccupation =
binding . edt Occupation. text . toString ( )
binding . sp Occupation. text . toString ( )
( activity as BajajFdMainActivity ) . applicantDetails . ApplicantQualification =
( activity as BajajFdMainActivity ) . applicantDetails . ApplicantQualification =
binding . edtQualification . text . toString ( )
binding . edtQualification . text . toString ( )
( activity as BajajFdMainActivity ) . applicantDetails . ApplicantMaritalStatus =
( activity as BajajFdMainActivity ) . applicantDetails . ApplicantMaritalStatus =
@ -525,11 +517,12 @@ class StepTwoBajajFDFragment : Fragment() {
binding . edtAddressLine1 . text . toString ( )
binding . edtAddressLine1 . text . toString ( )
( activity as BajajFdMainActivity ) . applicantDetails . ApplicantAddress2 =
( activity as BajajFdMainActivity ) . applicantDetails . ApplicantAddress2 =
binding . edtAddressLine2 . text . toString ( )
binding . edtAddressLine2 . text . toString ( )
( activity as BajajFdMainActivity ) . applicantDetails . ApplicantAddress3 = ""
( activity as BajajFdMainActivity ) . applicantDetails . ApplicantAddress3 =
binding . edtAddressLine3 . text . toString ( )
( activity as BajajFdMainActivity ) . applicantDetails . ApplicantCity =
( activity as BajajFdMainActivity ) . applicantDetails . ApplicantCity =
binding . edt City. text . toString ( )
binding . sp City. text . toString ( )
( activity as BajajFdMainActivity ) . applicantDetails . ApplicantState =
( activity as BajajFdMainActivity ) . applicantDetails . ApplicantState =
binding . edt State. text . toString ( )
binding . sp State. text . toString ( )
( activity as BajajFdMainActivity ) . applicantDetails . ApplicantCountry = "India"
( activity as BajajFdMainActivity ) . applicantDetails . ApplicantCountry = "India"
( activity as BajajFdMainActivity ) . applicantDetails . ApplicantPincode =
( activity as BajajFdMainActivity ) . applicantDetails . ApplicantPincode =
binding . edtPinCode . text . toString ( ) . toInt ( )
binding . edtPinCode . text . toString ( ) . toInt ( )
@ -601,6 +594,16 @@ class StepTwoBajajFDFragment : Fragment() {
( activity as BajajFdMainActivity ) . fdBankDetails . PaymentMode =
( activity as BajajFdMainActivity ) . fdBankDetails . PaymentMode =
rbPaymentMode . text . toString ( )
rbPaymentMode . text . toString ( )
( activity as BajajFdMainActivity ) . createFDApplicantRequest . ApplicantDetails
( activity as BajajFdMainActivity ) . createFDApplicantRequest . ApplicantRelationDetails
( activity as BajajFdMainActivity ) . createFDApplicantRequest . FdBankDetails
( activity as BajajFdMainActivity ) . createFDApplicantRequest . NomineeDetails
( activity as BajajFdMainActivity ) . createFDApplicantRequest . NomineeGuardianDetails
Log . e (
"CreateFDRequest" ,
"-->" + Gson ( ) . toJson ( ( activity as BajajFdMainActivity ) . createFDApplicantRequest )
)
bajajFDInterface . stepTwoApi ( "stepTwoResponse" )
bajajFDInterface . stepTwoApi ( "stepTwoResponse" )
}
}
}
}
@ -608,9 +611,30 @@ class StepTwoBajajFDFragment : Fragment() {
binding . btnBack . setOnClickListener {
binding . btnBack . setOnClickListener {
( activity as BajajFdMainActivity ) . binding . viewPager . currentItem = 0
( activity as BajajFdMainActivity ) . binding . viewPager . currentItem = 0
}
}
return root
return root
}
}
private fun datePicker ( edtDOB : TextInputEditText ) {
val year = cal . get ( Calendar . YEAR )
val month = cal . get ( Calendar . MONTH )
val day = cal . get ( Calendar . DAY_OF_MONTH )
val datePickerDialog = DatePickerDialog (
activity as BajajFdMainActivity , { _ , year , monthOfYear , dayOfMonth - >
if ( monthOfYear . toString ( ) . length = = 1 ) {
"0" . plus ( monthOfYear )
}
edtDOB . setText ( getDate ( dayOfMonth . toString ( ) + "-" + ( monthOfYear + 1 ) + "-" + year ) )
} , year , month , day
)
datePickerDialog . datePicker . maxDate = cal . timeInMillis
val c = Calendar . getInstance ( )
c . add ( Calendar . YEAR , - 140 )
datePickerDialog . datePicker . minDate = c . timeInMillis
datePickerDialog . show ( )
}
private fun panCheckApi ( ) {
private fun panCheckApi ( ) {
if ( Common . isNetworkAvailable ( activity as BajajFdMainActivity ) ) {
if ( Common . isNetworkAvailable ( activity as BajajFdMainActivity ) ) {
val panCheck = PanCheckRequest ( )
val panCheck = PanCheckRequest ( )
@ -669,6 +693,486 @@ class StepTwoBajajFDFragment : Fragment() {
}
}
}
}
@SuppressLint ( "ClickableViewAccessibility" )
private fun titleApi ( ) {
if ( Common . isNetworkAvailable ( activity as BajajFdMainActivity ) ) {
val getCodeRequest = GetCodeRequest ( )
getCodeRequest . ProductName = getString ( R . string . bajajFD )
getCodeRequest . Category = getString ( R . string . salutationCategory )
getCodeRequest . Language = getString ( R . string . language )
getCodeRequest . InputValue = ""
stepTwoBajajFDViewModel . titleApi ( getCodeRequest , token )
stepTwoBajajFDViewModel . getTitleMutableData . observe ( viewLifecycleOwner ) { response - >
when ( response ) {
is Resource . Success - > {
Log . e ( "response" , "-->$response" )
val getCodeResponse : GetCodeResponse =
Gson ( ) . fromJson ( response . data ?. toString ( ) , GetCodeResponse :: class . java )
getCodeResponse . Response . StatusCode . let { code - >
when ( code ) {
200 - > {
//set data in spinner
listOfTitle = getCodeResponse . Response . GetCodesList
if ( listOfTitle . isNotEmpty ( ) ) {
val adapter = ArrayAdapter (
activity as BajajFdMainActivity ,
R . layout . spinner_dropdown ,
listOfTitle
)
binding . spTitle . setAdapter ( adapter )
val titleText = ( activity as BajajFdMainActivity ) . getClientDetailsResponse . ObjectResponse ?. clientDetails ?. clientMasterMFD ?. Client_Title
val newTitleText = "$titleText."
if ( titleText . isNullOrEmpty ( ) ) {
binding . spTitle . setText (
adapter . getItem ( 0 ) ?. Value ,
false
)
} else {
for ( title in listOfTitle ) {
if ( title . Value = = newTitleText )
{
binding . spTitle . setText ( title . Value , false )
break
}
binding . spTitle . setOnTouchListener { v , event - >
when ( event ?. action ) {
MotionEvent . ACTION_DOWN - > {
binding . spTitle . setText (
adapter . getItem ( 0 ) ?. Value ,
false
)
}
}
v ?. onTouchEvent ( event ) ?: true
}
}
}
binding . spNomineeTitle . setAdapter ( adapter )
binding . spNomineeTitle . setText (
adapter . getItem ( 0 ) ?. Value ,
false
)
}
genderApi ( )
relationShipApi ( )
maritalStatusApi ( )
occupationApi ( )
annualIncomeApi ( )
stateListApi ( )
}
// 650 -> refreshToken()
else - > { }
}
}
}
is Resource . Error - > {
response . message ?. let { message - >
Log . e ( " " , "An error occurred:$message" )
}
}
is Resource . Loading - > {
}
}
}
}
}
private fun genderApi ( ) {
if ( Common . isNetworkAvailable ( activity as BajajFdMainActivity ) ) {
val getCodeRequest = GetCodeRequest ( )
getCodeRequest . ProductName = getString ( R . string . bajajFD )
getCodeRequest . Category = getString ( R . string . genderCategory )
getCodeRequest . Language = getString ( R . string . language )
getCodeRequest . InputValue = ""
stepTwoBajajFDViewModel . genderApi ( getCodeRequest , token )
stepTwoBajajFDViewModel . getGenderMutableData . observe ( viewLifecycleOwner ) { response - >
when ( response ) {
is Resource . Success - > {
Log . e ( "response" , "-->$response" )
val getCodeResponse : GetCodeResponse =
Gson ( ) . fromJson ( response . data ?. toString ( ) , GetCodeResponse :: class . java )
getCodeResponse . Response . StatusCode . let { code - >
when ( code ) {
200 - > {
listOfGender = getCodeResponse . Response . GetCodesList
if ( listOfGender . isNotEmpty ( ) ) {
val adapter = ArrayAdapter (
activity as BajajFdMainActivity ,
R . layout . spinner_dropdown ,
listOfGender
)
binding . spGender . setAdapter ( adapter )
binding . spGender . setText (
adapter . getItem ( 0 ) ?. Value ,
false
)
}
}
// 650 -> refreshToken()
else - > { }
}
}
}
is Resource . Error - > {
response . message ?. let { message - >
Log . e ( " " , "An error occurred:$message" )
}
}
is Resource . Loading - > {
}
}
}
}
}
private fun relationShipApi ( ) {
if ( Common . isNetworkAvailable ( activity as BajajFdMainActivity ) ) {
val getCodeRequest = GetCodeRequest ( )
getCodeRequest . ProductName = getString ( R . string . bajajFD )
getCodeRequest . Category = getString ( R . string . relationshipCategory )
getCodeRequest . Language = getString ( R . string . language )
getCodeRequest . InputValue = ""
stepTwoBajajFDViewModel . relationShipApi ( getCodeRequest , token )
stepTwoBajajFDViewModel . getRelationShipMutableData . observe ( viewLifecycleOwner ) { response - >
when ( response ) {
is Resource . Success - > {
Log . e ( "response" , "-->$response" )
val getCodeResponse : GetCodeResponse =
Gson ( ) . fromJson ( response . data ?. toString ( ) , GetCodeResponse :: class . java )
getCodeResponse . Response . StatusCode . let { code - >
when ( code ) {
200 - > {
listOfRelationShip = getCodeResponse . Response . GetCodesList
if ( listOfGender . isNotEmpty ( ) ) {
val adapter = ArrayAdapter (
activity as BajajFdMainActivity ,
R . layout . spinner_dropdown ,
listOfRelationShip
)
binding . spRelation . setAdapter ( adapter )
binding . spRelation . setText (
adapter . getItem ( 0 ) ?. Value ,
false
)
binding . spNomineeRelation . setAdapter ( adapter )
binding . spNomineeRelation . setText (
adapter . getItem ( 0 ) ?. Value ,
false
)
binding . spGuardianRelation . setAdapter ( adapter )
binding . spGuardianRelation . setText (
adapter . getItem ( 0 ) ?. Value ,
false
)
}
}
// 650 -> refreshToken()
else - > { }
}
}
}
is Resource . Error - > {
response . message ?. let { message - >
Log . e ( " " , "An error occurred:$message" )
}
}
is Resource . Loading - > {
}
}
}
}
}
private fun maritalStatusApi ( ) {
if ( Common . isNetworkAvailable ( activity as BajajFdMainActivity ) ) {
val getCodeRequest = GetCodeRequest ( )
getCodeRequest . ProductName = getString ( R . string . bajajFD )
getCodeRequest . Category = getString ( R . string . maritalCategory )
getCodeRequest . Language = getString ( R . string . language )
getCodeRequest . InputValue = ""
stepTwoBajajFDViewModel . maritalStatusApi ( getCodeRequest , token )
stepTwoBajajFDViewModel . getMaritalStatusMutableData . observe ( viewLifecycleOwner ) { response - >
when ( response ) {
is Resource . Success - > {
Log . e ( "response" , "-->$response" )
val getCodeResponse : GetCodeResponse =
Gson ( ) . fromJson ( response . data ?. toString ( ) , GetCodeResponse :: class . java )
getCodeResponse . Response . StatusCode . let { code - >
when ( code ) {
200 - > {
listOfMaritalStatus = getCodeResponse . Response . GetCodesList
if ( listOfMaritalStatus . isNotEmpty ( ) ) {
val adapter = ArrayAdapter (
activity as BajajFdMainActivity ,
R . layout . spinner_dropdown ,
listOfMaritalStatus
)
binding . spMarital . setAdapter ( adapter )
binding . spMarital . setText (
adapter . getItem ( 0 ) ?. Value ,
false
)
}
}
// 650 -> refreshToken()
else - > { }
}
}
}
is Resource . Error - > {
response . message ?. let { message - >
Log . e ( " " , "An error occurred:$message" )
}
}
is Resource . Loading - > {
}
}
}
}
}
private fun occupationApi ( ) {
if ( Common . isNetworkAvailable ( activity as BajajFdMainActivity ) ) {
val getCodeRequest = GetCodeRequest ( )
getCodeRequest . ProductName = getString ( R . string . bajajFD )
getCodeRequest . Category = getString ( R . string . occupationCategory )
getCodeRequest . Language = getString ( R . string . language )
getCodeRequest . InputValue = ""
stepTwoBajajFDViewModel . occupationApi ( getCodeRequest , token )
stepTwoBajajFDViewModel . getOccupationMutableData . observe ( viewLifecycleOwner ) { response - >
when ( response ) {
is Resource . Success - > {
Log . e ( "response" , "-->$response" )
val getCodeResponse : GetCodeResponse =
Gson ( ) . fromJson ( response . data ?. toString ( ) , GetCodeResponse :: class . java )
getCodeResponse . Response . StatusCode . let { code - >
when ( code ) {
200 - > {
listOfOccupation = getCodeResponse . Response . GetCodesList
if ( listOfOccupation . isNotEmpty ( ) ) {
val adapter = ArrayAdapter (
activity as BajajFdMainActivity ,
R . layout . spinner_dropdown ,
listOfOccupation
)
binding . spOccupation . setAdapter ( adapter )
binding . spOccupation . setText (
adapter . getItem ( 0 ) ?. Value ,
false
)
}
}
// 650 -> refreshToken()
else - > { }
}
}
}
is Resource . Error - > {
response . message ?. let { message - >
Log . e ( " " , "An error occurred:$message" )
}
}
is Resource . Loading - > {
}
}
}
}
}
private fun annualIncomeApi ( ) {
if ( Common . isNetworkAvailable ( activity as BajajFdMainActivity ) ) {
val getCodeRequest = GetCodeRequest ( )
getCodeRequest . ProductName = getString ( R . string . bajajFD )
getCodeRequest . Category = getString ( R . string . annualIncome )
getCodeRequest . Language = getString ( R . string . language )
getCodeRequest . InputValue = ""
stepTwoBajajFDViewModel . annualIncomeApi ( getCodeRequest , token )
stepTwoBajajFDViewModel . getAnnualIncomeMutableData . observe ( viewLifecycleOwner ) { response - >
when ( response ) {
is Resource . Success - > {
Log . e ( "response" , "-->$response" )
val getCodeResponse : GetCodeResponse =
Gson ( ) . fromJson ( response . data ?. toString ( ) , GetCodeResponse :: class . java )
getCodeResponse . Response . StatusCode . let { code - >
when ( code ) {
200 - > {
listOfAnnualIncome = getCodeResponse . Response . GetCodesList
if ( listOfAnnualIncome . isNotEmpty ( ) ) {
val adapter = ArrayAdapter (
activity as BajajFdMainActivity ,
R . layout . spinner_dropdown ,
listOfAnnualIncome
)
binding . spIncome . setAdapter ( adapter )
binding . spIncome . setText (
adapter . getItem ( 0 ) ?. Value ,
false
)
}
}
// 650 -> refreshToken()
else - > { }
}
}
}
is Resource . Error - > {
response . message ?. let { message - >
Log . e ( " " , "An error occurred:$message" )
}
}
is Resource . Loading - > {
}
}
}
}
}
private fun stateListApi ( ) {
if ( Common . isNetworkAvailable ( activity as BajajFdMainActivity ) ) {
stepTwoBajajFDViewModel . stateApi ( token )
stepTwoBajajFDViewModel . getStateMasterMutableData . observe ( viewLifecycleOwner ) { response - >
when ( response ) {
is Resource . Success - > {
Log . e ( "response" , "-->$response" )
val stateListResponse : StateListResponse =
Gson ( ) . fromJson (
response . data ?. toString ( ) ,
StateListResponse :: class . java
)
stateListResponse . response . status_code . let { code - >
when ( code ) {
200 - > {
listOfStates = stateListResponse . DataObject
if ( listOfStates . isNotEmpty ( ) ) {
val adapter = ArrayAdapter (
activity as BajajFdMainActivity ,
R . layout . spinner_dropdown ,
listOfStates
)
binding . spState . setAdapter ( adapter )
binding . spState . setText (
adapter . getItem ( 0 ) ?. State_Name ,
false
)
cityListApi ( adapter . getItem ( 0 ) ?. State_Id )
}
}
// 650 -> refreshToken()
else - > { }
}
}
}
is Resource . Error - > {
response . message ?. let { message - >
Log . e ( " " , "An error occurred:$message" )
}
}
is Resource . Loading - > {
}
}
}
}
}
private fun cityListApi ( stateCode : Int ? ) {
val cityRequest = CityRequest ( )
cityRequest . StateCode = stateCode
cityRequest . Type = ""
cityRequest . ClientCode = "8872"
cityRequest . RoleID = 5
cityRequest . APIName = ""
cityRequest . UID = 19060
cityRequest . Subbroker_Code = "1014"
cityRequest . RMCode = ""
cityRequest . HOCode = ""
cityRequest . Source = "Nivesh"
cityRequest . APP_Web = "App"
stepTwoBajajFDViewModel . cityListApi ( cityRequest , token )
stepTwoBajajFDViewModel . getCityListMutableData . observe ( viewLifecycleOwner ) { response - >
when ( response ) {
is Resource . Success - > {
Log . e ( "response" , "-->$response" )
val cityListResponse : CityListResponse =
Gson ( ) . fromJson ( response . data ?. toString ( ) , CityListResponse :: class . java )
cityListResponse . response . status_code . let { code - >
when ( code ) {
200 - > {
listOfCities = cityListResponse . DataObject
if ( listOfCities . isNotEmpty ( ) ) {
val adapter = ArrayAdapter (
activity as BajajFdMainActivity ,
R . layout . spinner_dropdown ,
listOfCities
)
binding . spCity . setAdapter ( adapter )
binding . spCity . setText (
adapter . getItem ( 0 ) ?. city_name ,
false
)
}
}
// 650 -> refreshToken()
else - > { }
}
}
}
is Resource . Error - > {
response . message ?. let { message - >
Log . e ( " " , "An error occurred:$message" )
}
}
is Resource . Loading - > {
}
}
}
}
// validations
// validations
private fun validation ( ) : Boolean {
private fun validation ( ) : Boolean {
@ -678,17 +1182,17 @@ class StepTwoBajajFDFragment : Fragment() {
binding . tlMobileNumber ,
binding . tlMobileNumber ,
getString ( R . string . emptyMobileNumber )
getString ( R . string . emptyMobileNumber )
)
)
} else if ( binding . edtMobileNumber . text ?. length ! = 10 ) { // EditText
} else if ( ! isIndianMobileNo ( binding . edtMobileNumber . text . toString ( ) ) ) { // EditText
commonErrorMethod (
commonErrorMethod (
binding . edtMobileNumber ,
binding . edtMobileNumber ,
binding . tlMobileNumber ,
binding . tlMobileNumber ,
getString ( R . string . inValidMobileNumber )
getString ( R . string . inValidIndian MobileNumber )
)
)
} else if ( ! isIndianMobileNo ( binding . edtMobileNumber . text . toString ( ) ) ) { // EditText
} else if ( binding . edtMobileNumber . text ?. length ! = 10 ) { // EditText
commonErrorMethod (
commonErrorMethod (
binding . edtMobileNumber ,
binding . edtMobileNumber ,
binding . tlMobileNumber ,
binding . tlMobileNumber ,
getString ( R . string . inValidIndian MobileNumber )
getString ( R . string . inValidMobileNumber )
)
)
} else if ( binding . edtDOB . text . toString ( ) . isEmpty ( ) ) { // EditText
} else if ( binding . edtDOB . text . toString ( ) . isEmpty ( ) ) { // EditText
commonErrorMethod ( binding . edtDOB , binding . tlDOB , getString ( R . string . emptyDOB ) )
commonErrorMethod ( binding . edtDOB , binding . tlDOB , getString ( R . string . emptyDOB ) )
@ -698,7 +1202,7 @@ class StepTwoBajajFDFragment : Fragment() {
binding . tlPanNumber ,
binding . tlPanNumber ,
getString ( R . string . emptyPAN )
getString ( R . string . emptyPAN )
)
)
} else if ( isValidPan ( binding . edtPANNumber . text . toString ( ) ) ) { // EditText
} else if ( ! isValidPan ( binding . edtPANNumber . text . toString ( ) ) ) { // EditText
commonErrorMethod (
commonErrorMethod (
binding . edtPANNumber ,
binding . edtPANNumber ,
binding . tlPanNumber ,
binding . tlPanNumber ,
@ -716,7 +1220,7 @@ class StepTwoBajajFDFragment : Fragment() {
binding . tlFirstName ,
binding . tlFirstName ,
getString ( R . string . emptyFirstName )
getString ( R . string . emptyFirstName )
)
)
} else if ( isValidName ( binding . edtFirstName . text . toString ( ) ) ) { // EditText
} else if ( ! isValidName ( binding . edtFirstName . text . toString ( ) ) ) { // EditText
commonErrorMethod (
commonErrorMethod (
binding . edtFirstName ,
binding . edtFirstName ,
binding . tlFirstName ,
binding . tlFirstName ,
@ -728,7 +1232,7 @@ class StepTwoBajajFDFragment : Fragment() {
binding . tlMiddleName ,
binding . tlMiddleName ,
getString ( R . string . emptyMiddleName )
getString ( R . string . emptyMiddleName )
)
)
} else if ( isValidName ( binding . edtMiddleName . text . toString ( ) ) ) { // EditText
} else if ( ! isValidName ( binding . edtMiddleName . text . toString ( ) ) ) { // EditText
commonErrorMethod (
commonErrorMethod (
binding . edtMiddleName ,
binding . edtMiddleName ,
binding . tlMiddleName ,
binding . tlMiddleName ,
@ -740,7 +1244,7 @@ class StepTwoBajajFDFragment : Fragment() {
binding . tlLastName ,
binding . tlLastName ,
getString ( R . string . emptyLastName )
getString ( R . string . emptyLastName )
)
)
} else if ( isValidName ( binding . edtLastName . text . toString ( ) ) ) { // EditText
} else if ( ! isValidName ( binding . edtLastName . text . toString ( ) ) ) { // EditText
commonErrorMethod (
commonErrorMethod (
binding . edtLastName ,
binding . edtLastName ,
binding . tlLastName ,
binding . tlLastName ,
@ -756,9 +1260,9 @@ class StepTwoBajajFDFragment : Fragment() {
commonErrorMethod ( binding . edtEmail , binding . tlEmail , getString ( R . string . emptyEmail ) )
commonErrorMethod ( binding . edtEmail , binding . tlEmail , getString ( R . string . emptyEmail ) )
} else if ( isValidEmail ( binding . edtEmail . text . toString ( ) ) ) { // EditText
} else if ( isValidEmail ( binding . edtEmail . text . toString ( ) ) ) { // EditText
commonErrorMethod ( binding . edtEmail , binding . tlEmail , getString ( R . string . validEmail ) )
commonErrorMethod ( binding . edtEmail , binding . tlEmail , getString ( R . string . validEmail ) )
} else if ( binding . edt Occupation. text . toString ( ) . isEmpty ( ) ) { // EditText
commonErrorMethod (
binding . edt Occupation,
} else if ( binding . sp Occupation. text . toString ( ) . isEmpty ( ) ) { // EditText
commonSpinner ErrorMethod (
binding . sp Occupation,
binding . tlOccupation ,
binding . tlOccupation ,
getString ( R . string . emptyOccupation )
getString ( R . string . emptyOccupation )
)
)
@ -798,10 +1302,20 @@ class StepTwoBajajFDFragment : Fragment() {
binding . tlAddressLine2 ,
binding . tlAddressLine2 ,
getString ( R . string . emptyAddressLine2 )
getString ( R . string . emptyAddressLine2 )
)
)
} else if ( binding . edtState . text . toString ( ) . isEmpty ( ) ) { // EditText
commonErrorMethod ( binding . edtState , binding . tlState , getString ( R . string . emptyState ) )
} else if ( binding . edtCity . text . toString ( ) . isEmpty ( ) ) { // EditText
commonErrorMethod ( binding . edtCity , binding . tlCity , getString ( R . string . emptyCity ) )
} else if ( binding . edtAddressLine3 . text . toString ( ) . isEmpty ( ) ) { // EditText
commonErrorMethod (
binding . edtAddressLine3 ,
binding . tlAddressLine3 ,
getString ( R . string . emptyAddressLine3 )
)
} else if ( binding . spState . text . toString ( ) . isEmpty ( ) ) { // EditText
commonSpinnerErrorMethod (
binding . spState ,
binding . tlState ,
getString ( R . string . emptyState )
)
} else if ( binding . spCity . text . toString ( ) . isEmpty ( ) ) { // EditText
commonSpinnerErrorMethod ( binding . spCity , binding . tlCity , getString ( R . string . emptyCity ) )
} else if ( binding . edtPinCode . text . toString ( ) . isEmpty ( ) ) { // EditText
} else if ( binding . edtPinCode . text . toString ( ) . isEmpty ( ) ) { // EditText
commonErrorMethod (
commonErrorMethod (
binding . edtPinCode ,
binding . edtPinCode ,
@ -845,4 +1359,6 @@ class StepTwoBajajFDFragment : Fragment() {
super . onDestroyView ( )
super . onDestroyView ( )
_binding = null
_binding = null
}
}
}
}