override fun onSelected()

in app/src/main/java/org/apache/fineract/ui/online/review/AddLoanReviewFragment.kt [119:241]


    override fun onSelected() {

        val loanAccount = onNavigationBarListener?.loanAccount
        val loanParameters = loanAccount?.getLoanParameters()
        val selectedProduct = onNavigationBarListener?.selectedProduct
        creditWorthinessSnapshot = onNavigationBarListener?.creditWorthinessSnapshot
        val paymentCycle = loanParameters?.paymentCycle
        val repayUnit = loanParameters?.paymentCycle?.temporalUnit?.toLowerCase()

        tvProduct.text = selectedProduct
        tvShortName.text = loanAccount?.identifier
        tvPrincipalAmount.text = loanParameters?.maximumBalance.toString()
        tvTerm.text = loanParameters?.termRange?.maximum.toString()
        tvTermUnitType.text = loanParameters?.termRange?.temporalUnit
        tvRepay.text = loanParameters?.paymentCycle?.period.toString()
        tvRepayUnitType.text = repayUnit

        creditWorthinessSnapshot?.forEachIndexed { index, creditWorthinessSnapshot ->

            when (index) {
                0 -> {

                    if (creditWorthinessSnapshot.incomeSources.isEmpty() &&
                            creditWorthinessSnapshot.debts.isEmpty()) {
                        llHeadTwo.visibility = View.GONE
                    } else {
                        llHeadTwo.visibility = View.VISIBLE
                    }

                    if (creditWorthinessSnapshot.incomeSources.isEmpty()) {
                        llIncome.visibility = View.GONE
                    } else {
                        llIncome.visibility = View.VISIBLE
                        incomeAdapter.setCreditWorthinessFactors(creditWorthinessSnapshot.incomeSources)
                        incomeAdapter.notifyDataSetChanged()
                        tvTotalIncome.text = getString(R.string.total_income,
                                setPrecision(showTotalIncome(0)))
                    }

                    if (creditWorthinessSnapshot.debts.isEmpty()) {
                        llDebts.visibility = View.GONE
                    } else {
                        llDebts.visibility = View.VISIBLE
                        debtAdapter.setCreditWorthinessFactors(creditWorthinessSnapshot.debts)
                        debtAdapter.notifyDataSetChanged()
                        tvTotalDebt.text = getString(R.string.total_debt,
                                setPrecision(showTotalDebts(0)))
                    }
                }

                1 -> {

                    if (creditWorthinessSnapshot.incomeSources.isEmpty()) {
                        llCosignerIncome.visibility = View.GONE
                    } else {
                        llCosignerIncome.visibility = View.VISIBLE
                        incomeCoSignerAdapter.setCreditWorthinessFactors(creditWorthinessSnapshot.incomeSources)
                        incomeCoSignerAdapter.notifyDataSetChanged()
                        tvCosignerTotalIncome.text = getString(R.string.total_income,
                                setPrecision(showTotalIncome(1)))
                    }

                    if (creditWorthinessSnapshot.debts.isEmpty()) {
                        llCosignerDebts.visibility = View.GONE
                    } else {
                        llCosignerDebts.visibility = View.VISIBLE
                        debtCoSignerAdapter.setCreditWorthinessFactors(creditWorthinessSnapshot.debts)
                        debtCoSignerAdapter.notifyDataSetChanged()
                        tvCosignerTotalDebt.text = getString(R.string.total_debt,
                                setPrecision(showTotalDebts(1)))
                    }

                    tvCoSignerName.text = creditWorthinessSnapshot.forCustomer
                }
            }
        }

        repayUnitType.forEachIndexed { index, repayType ->

            if (repayType == repayUnit) {

                when (index) {

                    0 -> {
                        llOn.visibility = View.VISIBLE
                        llOnThe.visibility = View.GONE
                        llIn.visibility = View.GONE
                        tvRepayUnitWeek.text = days[paymentCycle?.alignmentDay!!]
                    }

                    1 -> {
                        llOnThe.visibility = View.VISIBLE
                        llOn.visibility = View.GONE
                        llIn.visibility = View.GONE

                        if (paymentCycle?.alignmentWeek == null) {
                            tvOnThe.text = repayOnMonths[paymentCycle?.alignmentDay!!]
                        } else {
                            tvOnThe.text = timeSlots[paymentCycle.alignmentWeek!!]
                            tvOnType.text = days[paymentCycle.alignmentDay!!]
                        }
                    }

                    2 -> {
                        llIn.visibility = View.VISIBLE
                        llOnThe.visibility = View.VISIBLE
                        llOn.visibility = View.GONE

                        if (paymentCycle?.alignmentWeek == null) {
                            tvOnThe.text = repayOnMonths[paymentCycle?.alignmentDay!!]
                            tvOnType.text = getString(R.string.day)
                        } else {
                            tvOnThe.text = timeSlots[paymentCycle.alignmentWeek!!]
                            tvOnType.text = days[paymentCycle.alignmentDay!!]
                        }

                        tvRepayYearMonth.text = months[paymentCycle.alignmentMonth!!]
                    }
                }
            }
        }

    }