@ -12,17 +12,19 @@ import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.RadioButton
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView.LayoutManager
import com.google.gson.Gson
import com.nivesh.production.bajajfd.R
import com.nivesh.production.bajajfd.adapter.HorizontalRecyclerViewAdapter
import com.nivesh.production.bajajfd.api.ApiClient
import com.nivesh.production.bajajfd.databinding.FragmentBajajfdStepOneBinding
import com.nivesh.production.bajajfd.interfaces.BajajFDInterface
import com.nivesh.production.bajajfd.model.*
import com.nivesh.production.bajajfd.repositories.MainRepository
import com.nivesh.production.bajajfd.ui.activity.BajajFdMainActivity
import com.nivesh.production.bajajfd.ui.providerfactory.StepOneModelProviderFactory
import com.nivesh.production.bajajfd.util.Common
import com.nivesh.production.bajajfd.util.Common.Companion.commonErrorMethod
import com.nivesh.production.bajajfd.util.Common.Companion.removeError
@ -35,7 +37,6 @@ class StepOneBajajFDFragment : BaseFragment() {
private var _binding : FragmentBajajfdStepOneBinding ? = null
private val binding get ( ) = _binding !!
private lateinit var bajajFDInterface : BajajFDInterface
private lateinit var stepOneBajajFDViewModel : StepOneBajajFDViewModel
private lateinit var rgMaturity : RadioButton
private lateinit var listOfTenure : MutableList < ROIDataList >
@ -47,25 +48,19 @@ class StepOneBajajFDFragment : BaseFragment() {
private var tenure : Int = 0
private var interest : Double = 0.0
companion object {
fun getInstance ( fdInterface : BajajFDInterface ) : StepOneBajajFDFragment {
val stepStartFragment = StepOneBajajFDFragment ( )
stepStartFragment . setApi ( fdInterface )
return stepStartFragment
}
}
private fun setApi ( bajajFDInterfaces : BajajFDInterface ) {
bajajFDInterface = bajajFDInterfaces
}
override fun onCreateView (
inflater : LayoutInflater , container : ViewGroup ? , savedInstanceState : Bundle ?
) : View {
_binding = FragmentBajajfdStepOneBinding . inflate ( inflater , container , false )
val root = binding . root
return binding . root
}
stepOneBajajFDViewModel = ( activity as BajajFdMainActivity ) . stepOneBajajFDViewModel
override fun onViewCreated ( view : View , savedInstanceState : Bundle ? ) {
super . onViewCreated ( view , savedInstanceState )
stepOneBajajFDViewModel = ViewModelProvider (
this ,
StepOneModelProviderFactory ( MainRepository ( ApiClient . getApiClient ) )
) [ StepOneBajajFDViewModel :: class . java ]
listOfTenure = ArrayList ( )
binding . edtAmount . filters = arrayOf < InputFilter > ( InputFilter . LengthFilter ( 8 ) ) // upto 1 Cr
@ -142,7 +137,7 @@ class StepOneBajajFDFragment : BaseFragment() {
binding . spInterestPayout . text . toString ( )
( activity as BajajFdMainActivity ) . fdInvestmentDetails . Tenure = tenure
( activity as BajajFdMainActivity ) . fdInvestmentDetails . Interest = interest
( activity as BajajFdMainActivity ) . fdInvestmentDetails . NiveshClientCode = "8872"
( activity as BajajFdMainActivity ) . fdInvestmentDetails . NiveshClientCode = ( activity as BajajFdMainActivity ) . getClientDetailsResponse . ObjectResponse ?. clientDetails ?. clientMasterMFD ?. CLIENT_CODE
( activity as BajajFdMainActivity ) . fdInvestmentDetails . Provider =
getString ( R . string . bajaj )
( activity as BajajFdMainActivity ) . fdInvestmentDetails . IPAddress = "192.168.1.23"
@ -160,16 +155,19 @@ class StepOneBajajFDFragment : BaseFragment() {
( activity as BajajFdMainActivity ) . fdInvestmentDetails . CustomerType = ""
( activity as BajajFdMainActivity ) . fdInvestmentDetails . CKYCNumber = ""
( activity as BajajFdMainActivity ) . createFDApplicantRequest . FDInvestmentDetails = ( activity as BajajFdMainActivity ) . fdInvestmentDetails
Log . e ( "Maturity" , "-->" + rgMaturity . text )
bajajFDInterface . stepOneApi ( "stepOneResponse" )
( activity as BajajFdMainActivity ) . createFDApplicantRequest . FDInvestmentDetails =
( activity as BajajFdMainActivity ) . fdInvestmentDetails
Log . e (
"StepOneData" ,
"-->" + Gson ( ) . toJson ( ( activity as BajajFdMainActivity ) . fdInvestmentDetails )
)
( activity as BajajFdMainActivity ) . stepOneApi ( "stepOneResponse" )
}
}
minAmountApi ( )
interestPayoutApi ( )
return root
}
private fun interestPayoutApi ( ) {
@ -178,7 +176,7 @@ class StepOneBajajFDFragment : BaseFragment() {
getCodeRequest . Category = getString ( R . string . category )
getCodeRequest . Language = getString ( R . string . language )
getCodeRequest . InputValue = ""
stepOneBajajFDViewModel . getCode ( getCodeRequest , token )
stepOneBajajFDViewModel . getCode ( getCodeRequest , token , activity as BajajFdMainActivity )
stepOneBajajFDViewModel . getCodeMutableData . observe ( viewLifecycleOwner ) { response - >
when ( response ) {
is Resource . Success - > {
@ -223,6 +221,9 @@ class StepOneBajajFDFragment : BaseFragment() {
}
is Resource . Loading - > {
}
is Resource . DataError - > {
}
}
}
@ -234,7 +235,7 @@ class StepOneBajajFDFragment : BaseFragment() {
getCodeRequest . Category = getString ( R . string . minAmountCategory )
getCodeRequest . Language = getString ( R . string . language )
getCodeRequest . InputValue = ""
stepOneBajajFDViewModel . getMinAmount ( getCodeRequest , token )
stepOneBajajFDViewModel . getMinAmount ( getCodeRequest , token , activity as BajajFdMainActivity )
stepOneBajajFDViewModel . getMinAmountMutableData . observe ( viewLifecycleOwner ) { response - >
when ( response ) {
is Resource . Success - > {
@ -270,6 +271,9 @@ class StepOneBajajFDFragment : BaseFragment() {
}
is Resource . Loading - > {
}
is Resource . DataError - > {
}
}
}
@ -281,7 +285,7 @@ class StepOneBajajFDFragment : BaseFragment() {
getCodeRequest . Category = getString ( R . string . MaxAmountCategory )
getCodeRequest . Language = getString ( R . string . language )
getCodeRequest . InputValue = ""
stepOneBajajFDViewModel . getMaxAmount ( getCodeRequest , token )
stepOneBajajFDViewModel . getMaxAmount ( getCodeRequest , token , activity as BajajFdMainActivity )
stepOneBajajFDViewModel . getMaxAmountMutableData . observe ( viewLifecycleOwner ) { response - >
when ( response ) {
is Resource . Success - > {
@ -311,6 +315,9 @@ class StepOneBajajFDFragment : BaseFragment() {
}
is Resource . Loading - > {
}
is Resource . DataError - > {
}
}
}
@ -336,50 +343,59 @@ class StepOneBajajFDFragment : BaseFragment() {
}
private fun maturityAmountApi ( tenure : Int , interest : Double ) {
if ( Common . isNetworkAvailable ( activity as BajajFdMainActivity ) ) {
if ( binding . edtAmount . text . toString ( ) . length > = 4 & & interest ! = 0.0 & & tenure ! = 0 ) {
val maturityAmountRequest = GetMaturityAmountRequest ( )
maturityAmountRequest . FDProvider = getString ( R . string . bajaj )
maturityAmountRequest . FDAmount = binding . edtAmount . text . toString ( ) . toInt ( )
maturityAmountRequest . Frequency = binding . spInterestPayout . text . toString ( )
maturityAmountRequest . Tenure = tenure
maturityAmountRequest . Interest = interest
stepOneBajajFDViewModel . getMaturityAmount ( maturityAmountRequest )
stepOneBajajFDViewModel . getMaturityAmountMutableData . observe ( viewLifecycleOwner ) { response - >
when ( response ) {
is Resource . Success - > {
val getMaturityAmountResponse =
Gson ( ) . fromJson (
response . data ?. toString ( ) ,
GetCalculateMaturityAmountResponse :: class . java
)
getMaturityAmountResponse . Response . StatusCode . let { code - >
when ( code ) {
200 - > {
binding . tvMaturityAmount . text =
getString ( R . string . rs ) . plus ( " " ) . plus (
getMaturityAmountResponse . Response . MaturityAmount . toString ( )
)
}
// 650 -> refreshToken()
else - > {
Common . showDialogValidation (
activity as BajajFdMainActivity ,
getMaturityAmountResponse . Response . Errors [ 0 ] . ErrorMessage
if ( binding . edtAmount . text . toString ( ) . length > = 4 & & interest ! = 0.0 & & tenure ! = 0 & & binding . spInterestPayout . text . toString ( )
. isNotEmpty ( )
) {
val maturityAmountRequest = GetMaturityAmountRequest ( )
maturityAmountRequest . FDProvider = getString ( R . string . bajaj )
maturityAmountRequest . FDAmount = binding . edtAmount . text . toString ( ) . toInt ( )
maturityAmountRequest . Frequency = binding . spInterestPayout . text . toString ( )
maturityAmountRequest . Tenure = tenure
maturityAmountRequest . Interest = interest
stepOneBajajFDViewModel . getMaturityAmount (
maturityAmountRequest ,
activity as BajajFdMainActivity
)
stepOneBajajFDViewModel . getMaturityAmountMutableData . observe ( viewLifecycleOwner ) { response - >
when ( response ) {
is Resource . Success - > {
val getMaturityAmountResponse =
Gson ( ) . fromJson (
response . data ?. toString ( ) ,
GetCalculateMaturityAmountResponse :: class . java
)
getMaturityAmountResponse . Response . StatusCode . let { code - >
when ( code ) {
200 - > {
binding . tvMaturityAmount . text =
getString ( R . string . rs ) . plus ( " " ) . plus (
getMaturityAmountResponse . Response . MaturityAmount . toString ( )
)
}
}
// 650 -> refreshToken()
else - > {
Common . showDialogValidation (
activity as BajajFdMainActivity ,
getMaturityAmountResponse . Response . Errors [ 0 ] . ErrorMessage
)
}
}
}
}
is Resource . Error - > {
response . message ?. let { message - >
Common . showDialogValidation ( activity as BajajFdMainActivity , message )
}
is Resource . Error - > {
response . message ?. let { message - >
Common . showDialogValidation (
activity as BajajFdMainActivity ,
message
)
}
is Resource . Loading - > {
}
is Resource . Loading - > {
}
is Resource . DataError - > {
}
}
}
}
@ -427,77 +443,78 @@ class StepOneBajajFDFragment : BaseFragment() {
}
private fun getRatesApi ( ) {
if ( Common . isNetworkAvailable ( activity as BajajFdMainActivity ) ) {
val getRatesRequest = GetRatesRequest ( )
getRatesRequest . fdProvider = getString ( R . string . bajaj )
getRatesRequest . frequency = binding . spInterestPayout . text . toString ( )
if ( binding . swSeniorCitizen . isChecked ) {
getRatesRequest . type = getString ( R . string . seniorCitizen )
} else {
getRatesRequest . type = getString ( R . string . nonSeniorCitizen )
}
stepOneBajajFDViewModel . getRates ( getRatesRequest , token )
stepOneBajajFDViewModel . getRatesMutableData . observe ( viewLifecycleOwner ) { response - >
when ( response ) {
is Resource . Success - > {
val getRatesResponse : GetRatesResponse =
Gson ( ) . fromJson ( response . data ?. toString ( ) , GetRatesResponse :: class . java )
getRatesResponse . Response . StatusCode . let { code - >
when ( code ) {
200 - > {
if ( listOfTenure . isNotEmpty ( ) ) {
listOfTenure . clear ( )
}
listOfTenure = getRatesResponse . Response . ROIDatalist
// Tenure
if ( listOfTenure . isNotEmpty ( ) ) {
listOfTenure . sortWith { lhs : ROIDataList , rhs : ROIDataList - >
rhs . Tenure . compareTo (
lhs . Tenure
)
}
binding . ORLayout . visibility = View . VISIBLE
val tenureAdapter =
ArrayAdapter (
activity as BajajFdMainActivity ,
R . layout . spinner_dropdown ,
listOfTenure
)
binding . spTenure . setAdapter ( tenureAdapter )
binding . spTenure . setText (
tenureAdapter . getItem ( 0 ) ?. Tenure . plus (
" Months | "
) . plus ( tenureAdapter . getItem ( 0 ) ?. ROI ) . plus ( " %" ) , false
val getRatesRequest = GetRatesRequest ( )
getRatesRequest . fdProvider = getString ( R . string . bajaj )
getRatesRequest . frequency = binding . spInterestPayout . text . toString ( )
if ( binding . swSeniorCitizen . isChecked ) {
getRatesRequest . type = getString ( R . string . seniorCitizen )
} else {
getRatesRequest . type = getString ( R . string . nonSeniorCitizen )
}
stepOneBajajFDViewModel . getRates ( getRatesRequest , token , activity as BajajFdMainActivity )
stepOneBajajFDViewModel . getRatesMutableData . observe ( viewLifecycleOwner ) { response - >
when ( response ) {
is Resource . Success - > {
val getRatesResponse : GetRatesResponse =
Gson ( ) . fromJson ( response . data ?. toString ( ) , GetRatesResponse :: class . java )
getRatesResponse . Response . StatusCode . let { code - >
when ( code ) {
200 - > {
if ( listOfTenure . isNotEmpty ( ) ) {
listOfTenure . clear ( )
}
listOfTenure = getRatesResponse . Response . ROIDatalist
// Tenure
if ( listOfTenure . isNotEmpty ( ) ) {
listOfTenure . sortWith { lhs : ROIDataList , rhs : ROIDataList - >
rhs . Tenure . compareTo (
lhs . Tenure
)
tenure = tenureAdapter . getItem ( 0 ) ?. Tenure . toString ( ) . toInt ( )
interest = tenureAdapter . getItem ( 0 ) ?. ROI ?: 0.0
binding . tvROI . text =
tenureAdapter . getItem ( 0 ) ?. ROI . toString ( ) . plus ( " %" )
setUpRecyclerView ( )
} else {
binding . ORLayout . visibility = View . GONE
}
}
// 650 -> refreshToken()
else - > {
Common . showDialogValidation (
activity as BajajFdMainActivity ,
getRatesResponse . Response . Errors [ 0 ] . ErrorMessage
binding . ORLayout . visibility = View . VISIBLE
val tenureAdapter =
ArrayAdapter (
activity as BajajFdMainActivity ,
R . layout . spinner_dropdown ,
listOfTenure
)
binding . spTenure . setAdapter ( tenureAdapter )
binding . spTenure . setText (
tenureAdapter . getItem ( 0 ) ?. Tenure . plus (
" Months | "
) . plus ( tenureAdapter . getItem ( 0 ) ?. ROI ) . plus ( " %" ) , false
)
tenure = tenureAdapter . getItem ( 0 ) ?. Tenure . toString ( ) . toInt ( )
interest = tenureAdapter . getItem ( 0 ) ?. ROI ?: 0.0
binding . tvROI . text =
tenureAdapter . getItem ( 0 ) ?. ROI . toString ( ) . plus ( " %" )
setUpRecyclerView ( )
} else {
binding . ORLayout . visibility = View . GONE
}
}
// 650 -> refreshToken()
else - > {
Common . showDialogValidation (
activity as BajajFdMainActivity ,
getRatesResponse . Response . Errors [ 0 ] . ErrorMessage
)
}
}
}
}
is Resource . Error - > {
response . message ?. let { message - >
Common . showDialogValidation ( activity as BajajFdMainActivity , message )
}
is Resource . Error - > {
response . message ?. let { message - >
Common . showDialogValidation ( activity as BajajFdMainActivity , message )
}
is Resource . Loading - > {
}
is Resource . Loading - > {
}
is Resource . DataError - > {
}
}
}
}
@ -505,6 +522,6 @@ class StepOneBajajFDFragment : BaseFragment() {
override fun onDestroyView ( ) {
super . onDestroyView ( )
// _binding = null
_binding = null
}
}