From 8a70c1cdb867082a1bd36b275030f434ffa183f1 Mon Sep 17 00:00:00 2001 From: Hemant Khadase Date: Tue, 10 Jan 2023 15:36:05 +0530 Subject: [PATCH] added missing code --- .../niveshfd/adapter/PaymentModeAdapter.kt | 59 ++++++++++-------- .../ui/fragment/StepFourNiveshFDFragment.kt | 3 +- .../ui/fragment/StepOneNiveshFDFragment.kt | 5 ++ .../ui/fragment/StepTwoNiveshFDFragment.kt | 62 ++++++++++++++----- .../production/niveshfd/util/ProgressUtil.kt | 11 +++- .../niveshfd/viewModel/MyObseravble.kt | 12 ++++ .../res/layout/item_payment_list_preview.xml | 9 +-- 7 files changed, 111 insertions(+), 50 deletions(-) create mode 100644 app/src/main/java/com/nivesh/production/niveshfd/viewModel/MyObseravble.kt diff --git a/app/src/main/java/com/nivesh/production/niveshfd/adapter/PaymentModeAdapter.kt b/app/src/main/java/com/nivesh/production/niveshfd/adapter/PaymentModeAdapter.kt index 2ec7ce5..5d64252 100644 --- a/app/src/main/java/com/nivesh/production/niveshfd/adapter/PaymentModeAdapter.kt +++ b/app/src/main/java/com/nivesh/production/niveshfd/adapter/PaymentModeAdapter.kt @@ -5,17 +5,19 @@ import android.view.View import android.view.ViewGroup import android.widget.ImageView import android.widget.TextView +import androidx.cardview.widget.CardView import androidx.recyclerview.widget.RecyclerView import com.nivesh.production.niveshfd.R import com.nivesh.production.niveshfd.model.GetCodes class PaymentModeAdapter( - private val bankList: List?, - private val selectedAccount: String? = null + private val listOfPayMode: MutableList, + + private var selectedAmount: String? = null ) : RecyclerView.Adapter() { inner class BankListViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { - val bankSelector: ImageView = itemView.findViewById(R.id.bankSelector) - val tvBankName: TextView = itemView.findViewById(R.id.tvBankName) + val paymentSelector: ImageView = itemView.findViewById(R.id.paymentSelector) + val paymentMethod: TextView = itemView.findViewById(R.id.paymentMethod) val tvUpiMsg: TextView = itemView.findViewById(R.id.tvUpiMsg) } @@ -36,38 +38,35 @@ class PaymentModeAdapter( } override fun onBindViewHolder(holder: BankListViewHolder, position: Int) { - val bankList = bankList?.get(position) - if (bankList != null) { + val listOfPayMode = listOfPayMode?.get(position) + if (listOfPayMode != null) { holder.itemView.apply { - holder.tvBankName.text = bankList.Value - if (bankList.Value.equals("UPI")){ + + holder.paymentMethod.text = listOfPayMode.Value + if (listOfPayMode.Value.equals("UPI")) { holder.tvUpiMsg.text = context.getString(R.string.upto1LakhOnly) - }else{ + } else { holder.tvUpiMsg.text = "" } - if (selectedAccount == bankList.Value && checkedPosition == -2 - ) { - holder.bankSelector.setBackgroundResource(R.drawable.ic_select_green) + + + if (selectedAmount !=null && (checkedPosition == -2)) { + holder.paymentSelector.setBackgroundResource(R.drawable.ic_select_green) checkedPosition = holder.adapterPosition } else if (checkedPosition == -1) { - holder.bankSelector.setBackgroundResource(R.drawable.ic_select_outline) + holder.paymentSelector.setBackgroundResource(R.drawable.ic_select_outline) } else if (checkedPosition == holder.adapterPosition) { - holder.bankSelector.setBackgroundResource(R.drawable.ic_select_green) + holder.paymentSelector.setBackgroundResource(R.drawable.ic_select_green) } else { - holder.bankSelector.setBackgroundResource(R.drawable.ic_select_outline) + holder.paymentSelector.setBackgroundResource(R.drawable.ic_select_outline) } - setOnClickListener { - onItemClickListener?.let { - it(bankList) - - holder.bankSelector.setBackgroundResource(R.drawable.ic_select_green) - if (checkedPosition != holder.adapterPosition) { - notifyItemChanged(checkedPosition) - checkedPosition = holder.adapterPosition - - } + holder.itemView.setOnClickListener { + holder.paymentSelector.setBackgroundResource(R.drawable.ic_select_green) + if (checkedPosition != holder.adapterPosition) { + notifyItemChanged(checkedPosition) + checkedPosition = holder.adapterPosition } } } @@ -75,7 +74,7 @@ class PaymentModeAdapter( } override fun getItemCount(): Int { - return bankList?.size!! + return listOfPayMode?.size!! } private var onItemClickListener: ((GetCodes) -> Unit)? = null @@ -87,8 +86,14 @@ class PaymentModeAdapter( fun getSelected(): GetCodes? { return if (checkedPosition != -1) { - bankList?.get(checkedPosition) + listOfPayMode?.get(checkedPosition) } else null } + + private fun removeItem(position: Int) { + listOfPayMode?.removeAt(position) + notifyItemRemoved(position) + listOfPayMode?.let { notifyItemRangeChanged(position, it.size) } + } } \ No newline at end of file diff --git a/app/src/main/java/com/nivesh/production/niveshfd/ui/fragment/StepFourNiveshFDFragment.kt b/app/src/main/java/com/nivesh/production/niveshfd/ui/fragment/StepFourNiveshFDFragment.kt index a1fbd5f..d03000e 100644 --- a/app/src/main/java/com/nivesh/production/niveshfd/ui/fragment/StepFourNiveshFDFragment.kt +++ b/app/src/main/java/com/nivesh/production/niveshfd/ui/fragment/StepFourNiveshFDFragment.kt @@ -235,7 +235,6 @@ class StepFourNiveshFDFragment : Fragment() { getFDDetailsRequest.NiveshClientCode = (activity as NiveshFdMainActivity).getClientDetailsResponse.ObjectResponse?.clientDetails?.clientMasterMFD?.CLIENT_CODE getFDDetailsRequest.UniqueId = (activity as NiveshFdMainActivity).uniqueId - ProgressUtil.showLoading(activity as NiveshFdMainActivity) (activity as NiveshFdMainActivity).viewModel.getFDDetails( getFDDetailsRequest, token, @@ -285,7 +284,7 @@ class StepFourNiveshFDFragment : Fragment() { } } is Resource.Loading -> { - ProgressUtil.hideLoading() + } is Resource.DataError -> { diff --git a/app/src/main/java/com/nivesh/production/niveshfd/ui/fragment/StepOneNiveshFDFragment.kt b/app/src/main/java/com/nivesh/production/niveshfd/ui/fragment/StepOneNiveshFDFragment.kt index bef87f2..830326f 100644 --- a/app/src/main/java/com/nivesh/production/niveshfd/ui/fragment/StepOneNiveshFDFragment.kt +++ b/app/src/main/java/com/nivesh/production/niveshfd/ui/fragment/StepOneNiveshFDFragment.kt @@ -13,6 +13,7 @@ import android.view.ViewGroup import android.widget.ArrayAdapter import android.widget.RadioButton import androidx.fragment.app.Fragment +import androidx.fragment.app.activityViewModels import androidx.recyclerview.widget.DefaultItemAnimator import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView.LayoutManager @@ -27,12 +28,14 @@ import com.nivesh.production.niveshfd.util.Common.Companion.commonErrorMethod import com.nivesh.production.niveshfd.util.Common.Companion.removeError import com.nivesh.production.niveshfd.util.Constants.Companion.token import com.nivesh.production.niveshfd.util.Resource +import com.nivesh.production.niveshfd.viewModel.MyObseravble class StepOneNiveshFDFragment : Fragment() { private var _binding: FragmentNiveshfdStepOneBinding? = null private val binding get() = _binding!! + private val observerViewModel: MyObseravble by activityViewModels() private lateinit var rgMaturity: RadioButton private lateinit var listOfTenure: MutableList private lateinit var recyclerViewDropDownAdapter: HorizontalRecyclerViewAdapter @@ -115,8 +118,10 @@ class StepOneNiveshFDFragment : Fragment() { // Next Button binding.btnNext.setOnClickListener { if (validation()) { + (activity as NiveshFdMainActivity).fdInvestmentDetails.FDAmount = binding.edtAmount.text.toString().toDouble() + observerViewModel.data.value = binding.edtAmount.text.toString() (activity as NiveshFdMainActivity).fdInvestmentDetails.Frequency = binding.spInterestPayout.text.toString() (activity as NiveshFdMainActivity).fdInvestmentDetails.Tenure = tenure diff --git a/app/src/main/java/com/nivesh/production/niveshfd/ui/fragment/StepTwoNiveshFDFragment.kt b/app/src/main/java/com/nivesh/production/niveshfd/ui/fragment/StepTwoNiveshFDFragment.kt index 1ba7d6f..c550aa4 100644 --- a/app/src/main/java/com/nivesh/production/niveshfd/ui/fragment/StepTwoNiveshFDFragment.kt +++ b/app/src/main/java/com/nivesh/production/niveshfd/ui/fragment/StepTwoNiveshFDFragment.kt @@ -18,6 +18,7 @@ import android.widget.RadioButton import android.widget.TextView import androidx.core.content.ContextCompat import androidx.fragment.app.Fragment +import androidx.fragment.app.activityViewModels import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView @@ -44,6 +45,7 @@ import com.nivesh.production.niveshfd.util.Common.Companion.showDialogValidation import com.nivesh.production.niveshfd.util.Constants.Companion.token import com.nivesh.production.niveshfd.util.ProgressUtil import com.nivesh.production.niveshfd.util.Resource +import com.nivesh.production.niveshfd.viewModel.MyObseravble import java.util.* @@ -52,6 +54,7 @@ class StepTwoNiveshFDFragment : Fragment() { private var _binding: FragmentNiveshfdStepTwoBinding? = null private val binding get() = _binding!! + private val observerViewModel: MyObseravble by activityViewModels() private lateinit var listOfTitle: List private lateinit var listOfGender: List private lateinit var listOfAnnualIncome: List @@ -682,8 +685,7 @@ class StepTwoNiveshFDFragment : Fragment() { bankListAdapter.getSelected()?.AccountNumber (activity as NiveshFdMainActivity).fdBankDetails.BankName = bankListAdapter.getSelected()?.BankName - (activity as NiveshFdMainActivity).fdBankDetails.PaymentMode = - rbPaymentMode.text.toString() + (activity as NiveshFdMainActivity).fdBankDetails.PaymentMode = paymentModeAdapter.getSelected()?.Value (activity as NiveshFdMainActivity).createFDApplicantRequest.ApplicantDetails = (activity as NiveshFdMainActivity).applicantDetails @@ -898,7 +900,7 @@ class StepTwoNiveshFDFragment : Fragment() { if (getBankValidationApiResponse.Message == getString(R.string.accountVerified)) { val clientBankList = ClientBanklist() clientBankList.AccountNumber = bankAccount - clientBankList.AccountType = "sb" + clientBankList.AccountType = rbBank.text.toString() clientBankList.BankName = binding.edtBankName.text.toString() clientBankList.BranchName = @@ -1037,10 +1039,10 @@ class StepTwoNiveshFDFragment : Fragment() { private fun guardianCodeVisibility(visibility: Int) { binding.tlGuardianName.visibility = visibility - binding.tlGuardianName.visibility = visibility - binding.tlGuardianName.visibility = visibility - binding.tlGuardianName.visibility = visibility - binding.tlGuardianName.visibility = visibility + binding.tlGuardianAddress.visibility = visibility + binding.tlGuardianAge.visibility = visibility + binding.tlGuardianPinCode.visibility = visibility + binding.tlGuardianRelation.visibility = visibility } @@ -1210,7 +1212,7 @@ class StepTwoNiveshFDFragment : Fragment() { 200 -> { if (getCodeResponse.Response.GetCodesList.isNotEmpty()) { listOfPayMode = getCodeResponse.Response.GetCodesList - setUpRecyclerViewPaymentMode(listOfPayMode) + setUpRecyclerViewPaymentMode(listOfPayMode as MutableList) } } // 650 -> refreshToken() @@ -1239,7 +1241,28 @@ class StepTwoNiveshFDFragment : Fragment() { } } - private fun setUpRecyclerViewPaymentMode(listOfPayMode: List) { + private fun setUpRecyclerViewPaymentMode(listOfPayMode: MutableList) { + + observerViewModel.data.observe(viewLifecycleOwner) { + val tempList= mutableListOf() + tempList.addAll(listOfPayMode) + val amountEntered:String = observerViewModel.data.value.toString() + if( amountEntered.toDouble()>100000.0) { + for (list in listOfPayMode) { + if (list.Value == "UPI") { + tempList.remove(list) + break + } + } + } + binding.rvPaymentMode.layoutManager = + GridLayoutManager(activity as NiveshFdMainActivity, 2) + paymentModeAdapter = PaymentModeAdapter( + tempList, + listOfPayMode[0].Value + ) + binding.rvPaymentMode.adapter = paymentModeAdapter + } binding.rvPaymentMode.layoutManager = GridLayoutManager(activity as NiveshFdMainActivity, 2) @@ -1337,16 +1360,25 @@ class StepTwoNiveshFDFragment : Fragment() { R.layout.spinner_dropdown, listOfRelationShip ) - binding.spNomineeRelation.setAdapter(adapter) - binding.spNomineeRelation.setText( - adapter.getItem(0)?.Value, - false - ) + + val nomineeRelation = (activity as NiveshFdMainActivity).getClientDetailsResponse.ObjectResponse?.clientDetails?.clientMasterMFD?.Nominees?.get(0)?.NomineeRelationship + if (nomineeRelation.isNullOrEmpty()) { + binding.spNomineeRelation.setText(adapter.getItem(0)?.Label, + false) + }else{ + for (title in listOfRelationShip) { + if (title.Label == nomineeRelation) { + binding.spNomineeRelation.setText(title.Label , + false) + break + } + } + } binding.spGuardianRelation.setAdapter(adapter) binding.spGuardianRelation.setText( - adapter.getItem(0)?.Value, + adapter.getItem(0)?.Label, false ) } diff --git a/app/src/main/java/com/nivesh/production/niveshfd/util/ProgressUtil.kt b/app/src/main/java/com/nivesh/production/niveshfd/util/ProgressUtil.kt index ab0c4bc..52b21a2 100644 --- a/app/src/main/java/com/nivesh/production/niveshfd/util/ProgressUtil.kt +++ b/app/src/main/java/com/nivesh/production/niveshfd/util/ProgressUtil.kt @@ -8,6 +8,10 @@ import android.graphics.drawable.ColorDrawable import android.util.Log import android.view.Window import android.widget.ProgressBar +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers.IO +import kotlinx.coroutines.delay +import kotlinx.coroutines.launch @SuppressLint("StaticFieldLeak") object ProgressUtil{ @@ -41,8 +45,11 @@ object ProgressUtil{ fun hideLoading(){ try { - if(alertDialog.isShowing){ - alertDialog.dismiss() + CoroutineScope(IO).launch { + delay(1000) + if(alertDialog.isShowing){ + alertDialog.dismiss() + } } } catch (e: UninitializedPropertyAccessException) { Log.e("TAG","AlertDialog UninitializedPropertyAccessException") diff --git a/app/src/main/java/com/nivesh/production/niveshfd/viewModel/MyObseravble.kt b/app/src/main/java/com/nivesh/production/niveshfd/viewModel/MyObseravble.kt new file mode 100644 index 0000000..f096ed1 --- /dev/null +++ b/app/src/main/java/com/nivesh/production/niveshfd/viewModel/MyObseravble.kt @@ -0,0 +1,12 @@ +package com.nivesh.production.niveshfd.viewModel + +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel + +open class MyObseravble : ViewModel() +{ + val data = MutableLiveData() + fun data(item: String) { + data.value = item + } +} diff --git a/app/src/main/res/layout/item_payment_list_preview.xml b/app/src/main/res/layout/item_payment_list_preview.xml index a43261e..5b9e9ca 100644 --- a/app/src/main/res/layout/item_payment_list_preview.xml +++ b/app/src/main/res/layout/item_payment_list_preview.xml @@ -8,7 +8,8 @@ app:cardElevation="2dp" app:cardMaxElevation="1dp" app:cardPreventCornerOverlap="true" - app:cardUseCompatPadding="true"> + app:cardUseCompatPadding="true" + android:id="@+id/cardView"> - + \ No newline at end of file