|
|
@ -1,7 +1,7 @@ |
|
|
|
package com.nivesh.production.bajajfd.ui.fragment |
|
|
|
|
|
|
|
import GetRatesResponse |
|
|
|
import ROIDatalist |
|
|
|
import ROIDataList |
|
|
|
import android.os.Bundle |
|
|
|
import android.text.Editable |
|
|
|
import android.text.TextWatcher |
|
|
@ -12,11 +12,16 @@ import android.view.ViewGroup |
|
|
|
import android.widget.ArrayAdapter |
|
|
|
import android.widget.RadioButton |
|
|
|
import androidx.fragment.app.Fragment |
|
|
|
import com.google.android.material.textfield.TextInputLayout |
|
|
|
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.databinding.FragmentBajajfdStepOneBinding |
|
|
|
import com.nivesh.production.bajajfd.interfaces.BajajFDInterface |
|
|
|
import com.nivesh.production.bajajfd.model.GetCalculateMaturityAmountResponse |
|
|
|
import com.nivesh.production.bajajfd.model.GetMaturityAmountRequest |
|
|
|
import com.nivesh.production.bajajfd.model.GetRatesRequest |
|
|
|
import com.nivesh.production.bajajfd.ui.activity.BajajFdMainActivity |
|
|
|
import com.nivesh.production.bajajfd.util.Common |
|
|
@ -31,9 +36,10 @@ class StepOneBajajFDFragment : Fragment() { |
|
|
|
private lateinit var bajajFDInterface: BajajFDInterface |
|
|
|
private lateinit var stepOneBajajFDViewModel: StepOneBajajFDViewModel |
|
|
|
private lateinit var rgMaturity: RadioButton |
|
|
|
private lateinit var listOfTenure: MutableList<ROIDatalist> |
|
|
|
private var tenure :Int = 0 |
|
|
|
private var interest : Double = 0.0 |
|
|
|
private lateinit var listOfTenure: MutableList<ROIDataList> |
|
|
|
private var tenure: Int = 0 |
|
|
|
private var interest: Double = 0.0 |
|
|
|
private lateinit var recyclerViewDropDownAdapter: HorizontalRecyclerViewAdapter |
|
|
|
|
|
|
|
companion object { |
|
|
|
fun getInstance(fdInterface: BajajFDInterface): StepOneBajajFDFragment { |
|
|
@ -56,6 +62,7 @@ class StepOneBajajFDFragment : Fragment() { |
|
|
|
stepOneBajajFDViewModel = (activity as BajajFdMainActivity).stepOneBajajFDViewModel |
|
|
|
|
|
|
|
listOfTenure = ArrayList() |
|
|
|
// setUpRecyclerView() |
|
|
|
|
|
|
|
// Amount |
|
|
|
binding.edtAmount.addTextChangedListener(object : TextWatcher { |
|
|
@ -63,6 +70,7 @@ class StepOneBajajFDFragment : Fragment() { |
|
|
|
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {} |
|
|
|
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { |
|
|
|
removeError(binding.tlDepositAmount) |
|
|
|
maturityAmountApi(tenure, interest) |
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
@ -78,19 +86,33 @@ class StepOneBajajFDFragment : Fragment() { |
|
|
|
removeError(binding.tlInterestPayout) |
|
|
|
binding.tvFrequency.text = |
|
|
|
(activity as BajajFdMainActivity).listOfFrequency[position].Value |
|
|
|
getRatesApi() |
|
|
|
if (!binding.tvFrequency.text.equals("Cumulative")) { |
|
|
|
binding.txtCumulativeNon.text = getString(R.string.nonCumulativeROI) |
|
|
|
} else { |
|
|
|
binding.txtCumulativeNon.text = getString(R.string.cumulativeROI) |
|
|
|
} |
|
|
|
|
|
|
|
maturityAmountApi(tenure, interest) |
|
|
|
|
|
|
|
if (binding.edtAmount.text.toString().trim().isNotEmpty()) { |
|
|
|
getRatesApi() |
|
|
|
} else { |
|
|
|
// please enter Amount first |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Tenure |
|
|
|
if (listOfTenure.isNotEmpty()) { |
|
|
|
binding.spTenure.setOnItemClickListener { _, _, position, _ -> |
|
|
|
removeError(binding.tlInterestTenure) |
|
|
|
Log.e("Tenure", "--->".plus(listOfTenure[position].Tenure)) |
|
|
|
binding.spTenure.setOnItemClickListener { _, _, position, _ -> |
|
|
|
removeError(binding.tlInterestTenure) |
|
|
|
if (listOfTenure.isNotEmpty()) { |
|
|
|
tenure = listOfTenure[position].Tenure.toInt() |
|
|
|
interest = listOfTenure[position].ROI |
|
|
|
binding.tvROI.text = interest.toString().plus(" %") |
|
|
|
maturityAmountApi(tenure, interest) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Senior / Non Senior Citizen |
|
|
|
binding.swSeniorCitizen.setOnCheckedChangeListener { _, _ -> |
|
|
|
getRatesApi() |
|
|
@ -107,25 +129,29 @@ class StepOneBajajFDFragment : Fragment() { |
|
|
|
Log.e("DeductTax", "-->" + binding.rbDeductTax.isChecked) |
|
|
|
} |
|
|
|
|
|
|
|
binding.tvROI.text = "" |
|
|
|
binding.tvMaturityAmount.text = "" |
|
|
|
|
|
|
|
// Next Button |
|
|
|
binding.btnNext.setOnClickListener { |
|
|
|
if (validation()) { |
|
|
|
(activity as BajajFdMainActivity).fdInvestmentDetails.FDAmount = binding.edtAmount.text.toString().toDouble() |
|
|
|
(activity as BajajFdMainActivity).fdInvestmentDetails.Frequency = binding.spInterestPayout.text.toString() |
|
|
|
(activity as BajajFdMainActivity).fdInvestmentDetails.FDAmount = |
|
|
|
binding.edtAmount.text.toString().toDouble() |
|
|
|
(activity as BajajFdMainActivity).fdInvestmentDetails.Frequency = |
|
|
|
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.Provider = "Bajaj" |
|
|
|
(activity as BajajFdMainActivity).fdInvestmentDetails.Provider = |
|
|
|
getString(R.string.bajaj) |
|
|
|
(activity as BajajFdMainActivity).fdInvestmentDetails.IPAddress = "" |
|
|
|
(activity as BajajFdMainActivity).fdInvestmentDetails.Device = "App" |
|
|
|
(activity as BajajFdMainActivity).fdInvestmentDetails.Device = |
|
|
|
getString(R.string.app) |
|
|
|
(activity as BajajFdMainActivity).fdInvestmentDetails.Source = "nivesh" |
|
|
|
if (binding.swSeniorCitizen.isChecked){ |
|
|
|
(activity as BajajFdMainActivity).fdInvestmentDetails.CitizenType = getString(R.string.seniorCitizen) |
|
|
|
}else{ |
|
|
|
(activity as BajajFdMainActivity).fdInvestmentDetails.CitizenType = getString(R.string.nonSeniorCitizen) |
|
|
|
if (binding.swSeniorCitizen.isChecked) { |
|
|
|
(activity as BajajFdMainActivity).fdInvestmentDetails.CitizenType = |
|
|
|
getString(R.string.seniorCitizen) |
|
|
|
} else { |
|
|
|
(activity as BajajFdMainActivity).fdInvestmentDetails.CitizenType = |
|
|
|
getString(R.string.nonSeniorCitizen) |
|
|
|
} |
|
|
|
(activity as BajajFdMainActivity).fdInvestmentDetails.CustomerType = "" |
|
|
|
(activity as BajajFdMainActivity).fdInvestmentDetails.CKYCNumber = "" |
|
|
@ -133,22 +159,103 @@ class StepOneBajajFDFragment : Fragment() { |
|
|
|
bajajFDInterface.stepOneApi("stepOneResponse") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return root |
|
|
|
} |
|
|
|
|
|
|
|
private fun setUpRecyclerView() { |
|
|
|
|
|
|
|
recyclerViewDropDownAdapter = HorizontalRecyclerViewAdapter( |
|
|
|
activity as BajajFdMainActivity, |
|
|
|
listOfTenure |
|
|
|
) { position -> |
|
|
|
tenure = listOfTenure[position].Tenure.toInt() |
|
|
|
interest = listOfTenure[position].ROI |
|
|
|
binding.tvROI.text = interest.toString().plus(" %") |
|
|
|
maturityAmountApi(tenure, interest) |
|
|
|
} |
|
|
|
val mLayoutManager: LayoutManager = |
|
|
|
LinearLayoutManager(activity, LinearLayoutManager.HORIZONTAL, true) |
|
|
|
binding.rvTenure.layoutManager = mLayoutManager |
|
|
|
binding.rvTenure.setHasFixedSize(true) |
|
|
|
binding.rvTenure.itemAnimator = DefaultItemAnimator() |
|
|
|
binding.rvTenure.adapter = recyclerViewDropDownAdapter |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun maturityAmountApi(tenure: Int, interest: Double) { |
|
|
|
if (Common.isNetworkAvailable(activity as BajajFdMainActivity)) { |
|
|
|
if (binding.edtAmount.text.toString().isNotEmpty() && interest.toString().isNotEmpty() && tenure.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) |
|
|
|
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( |
|
|
|
getMaturityAmountResponse.Response.MaturityAmount.toString() |
|
|
|
) |
|
|
|
} |
|
|
|
// 650 -> refreshToken() |
|
|
|
else -> {} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
is Resource.Error -> { |
|
|
|
response.message?.let { message -> |
|
|
|
Log.e(" ", "An error occurred:$message") |
|
|
|
} |
|
|
|
} |
|
|
|
is Resource.Loading -> { |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun validation(): Boolean { |
|
|
|
return if (binding.edtAmount.text.toString().isEmpty()) { |
|
|
|
Common.commonErrorMethod(binding.edtAmount, binding.tlDepositAmount, "") |
|
|
|
Common.commonErrorMethod( |
|
|
|
binding.edtAmount, |
|
|
|
binding.tlDepositAmount, |
|
|
|
getString(R.string.emptyAmount) |
|
|
|
) |
|
|
|
} else if (binding.spInterestPayout.text.toString().toDouble() <= 5000) { |
|
|
|
Common.commonSpinnerErrorMethod( |
|
|
|
binding.spInterestPayout, |
|
|
|
binding.tlInterestPayout, |
|
|
|
getString(R.string.validMinAmount) |
|
|
|
) |
|
|
|
} else if (binding.spInterestPayout.text.isEmpty()) { |
|
|
|
Common.commonSpinnerErrorMethod( |
|
|
|
binding.spInterestPayout, |
|
|
|
binding.tlInterestPayout, |
|
|
|
"" |
|
|
|
getString(R.string.emptyInterestPayout) |
|
|
|
) |
|
|
|
} else if (binding.spTenure.text.isEmpty()) { |
|
|
|
Common.commonSpinnerErrorMethod(binding.spTenure, binding.tlInterestTenure, "") |
|
|
|
Common.commonSpinnerErrorMethod( |
|
|
|
binding.spTenure, |
|
|
|
binding.tlInterestTenure, |
|
|
|
getString(R.string.emptyInterestTenure) |
|
|
|
) |
|
|
|
} else { |
|
|
|
true |
|
|
|
} |
|
|
@ -157,7 +264,7 @@ class StepOneBajajFDFragment : Fragment() { |
|
|
|
private fun getRatesApi() { |
|
|
|
if (Common.isNetworkAvailable(activity as BajajFdMainActivity)) { |
|
|
|
val getRatesRequest = GetRatesRequest() |
|
|
|
getRatesRequest.fdProvider = "Bajaj" |
|
|
|
getRatesRequest.fdProvider = getString(R.string.bajaj) |
|
|
|
getRatesRequest.frequency = binding.spInterestPayout.text.toString() |
|
|
|
if (binding.swSeniorCitizen.isChecked) { |
|
|
|
getRatesRequest.type = getString(R.string.seniorCitizen) |
|
|
@ -177,13 +284,21 @@ class StepOneBajajFDFragment : Fragment() { |
|
|
|
listOfTenure.clear() |
|
|
|
} |
|
|
|
listOfTenure = getRatesResponse.Response.ROIDatalist |
|
|
|
val adapter = |
|
|
|
ArrayAdapter( |
|
|
|
activity as BajajFdMainActivity, |
|
|
|
R.layout.spinner_dropdown, |
|
|
|
listOfTenure |
|
|
|
) |
|
|
|
binding.spTenure.setAdapter(adapter) |
|
|
|
// 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) |
|
|
|
setUpRecyclerView() |
|
|
|
}else{ |
|
|
|
binding.ORLayout.visibility = View.GONE |
|
|
|
} |
|
|
|
} |
|
|
|
// 650 -> refreshToken() |
|
|
|
else -> {} |
|
|
|