Skip to content

Commit

Permalink
MIFOSAC-256 implemented compose navigation in loan-module (#2191)
Browse files Browse the repository at this point in the history
  • Loading branch information
itsPronay authored Aug 16, 2024
1 parent 03c83ca commit 634fba5
Show file tree
Hide file tree
Showing 33 changed files with 508 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,5 @@ object Constants {
// Compose Navigation KEY
const val REPORT_TYPE_ITEM = "report_type_item"
const val REPORT_PARAMETER_RESPONSE = "report_parameter_response"
const val LOAN_WITH_ASSOCIATIONS = "loanWithAssociation"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.mifos.core.objects.accounts.loan

import android.os.Parcelable
import kotlinx.parcelize.Parcelize

/**
* Created by Pronay Sarker on 16/08/2024 (7:17 AM)
*/
@Parcelize
data class LoanApprovalData(
val loanID: Int,
val loanWithAssociations: LoanWithAssociations
) : Parcelable
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ import java.util.Locale

@Composable
fun GroupLoanAccountScreen(
groupId: Int,
onBackPressed: () -> Unit
) {
val viewModel: GroupLoanAccountViewModel = hiltViewModel()
val state by viewModel.groupLoanAccountUiState.collectAsStateWithLifecycle()
val loanProducts by viewModel.loanProducts.collectAsStateWithLifecycle()
val groupId by viewModel.groupId.collectAsStateWithLifecycle()

LaunchedEffect(loanProducts) {
if (loanProducts.isNotEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.mifos.feature.loan.group_loan_account

import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.mifos.core.common.utils.Constants
import com.mifos.core.common.utils.Resource
import com.mifos.core.data.GroupLoanPayload
import com.mifos.core.domain.use_cases.CreateGroupLoansAccountUseCase
Expand All @@ -21,9 +23,12 @@ import javax.inject.Inject
class GroupLoanAccountViewModel @Inject constructor(
private val getAllLoanUseCase: GetAllLoanUseCase,
private val getGroupLoansAccountTemplateUseCase: GetGroupLoansAccountTemplateUseCase,
private val createGroupLoansAccountUseCase: CreateGroupLoansAccountUseCase
private val createGroupLoansAccountUseCase: CreateGroupLoansAccountUseCase,
savedStateHandle: SavedStateHandle
) : ViewModel() {

val groupId = savedStateHandle.getStateFlow(key = Constants.GROUP_ID, initialValue = 0)

private val _groupLoanAccountUiState =
MutableStateFlow<GroupLoanAccountUiState>(GroupLoanAccountUiState.Loading)
val groupLoanAccountUiState = _groupLoanAccountUiState.asStateFlow()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ import java.util.Locale

@Composable
fun LoanAccountScreen(
clientId: Int,
onBackPressed: () -> Unit,
dataTable: (List<DataTable>, LoansPayload) -> Unit
) {
val viewModel: LoanAccountViewModel = hiltViewModel()
val state by viewModel.loanAccountUiState.collectAsStateWithLifecycle()
val loanAccountTemplateState by viewModel.loanAccountTemplateUiState.collectAsStateWithLifecycle()
val clientId by viewModel.clientId.collectAsStateWithLifecycle()

LaunchedEffect(Unit) {
viewModel.loadAllLoans()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.mifos.feature.loan.loan_account

import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.mifos.core.common.utils.Constants
import com.mifos.core.common.utils.Resource
import com.mifos.core.data.LoansPayload
import com.mifos.core.domain.use_cases.CreateLoanAccountUseCase
Expand All @@ -20,9 +22,12 @@ import javax.inject.Inject
class LoanAccountViewModel @Inject constructor(
private val getAllLoanUseCase: GetAllLoanUseCase,
private val getLoansAccountTemplateUseCase: GetLoansAccountTemplateUseCase,
private val createLoanAccountUseCase: CreateLoanAccountUseCase
private val createLoanAccountUseCase: CreateLoanAccountUseCase,
savedStateHandle: SavedStateHandle
) : ViewModel() {

val clientId = savedStateHandle.getStateFlow(key = Constants.CLIENT_ID, initialValue = 0)

private val _loanAccountUiState =
MutableStateFlow<LoanAccountUiState>(LoanAccountUiState.Loading)
val loanAccountUiState = _loanAccountUiState.asStateFlow()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,21 @@ import com.mifos.feature.loan.R
/**
* Created by Pronay Sarker on 01/07/2024 (5:50 AM)
*/


@Composable
fun LoanAccountSummaryScreen(
viewModel: LoanAccountSummaryViewModel = hiltViewModel(),
loanAccountNumber: Int,
navigateBack: () -> Unit,
onMoreInfoClicked: () -> Unit,
onMoreInfoClicked: (loanId : Int) -> Unit,
onTransactionsClicked: (loadId: Int) -> Unit,
onRepaymentScheduleClicked: (loanId: Int) -> Unit,
onDocumentsClicked: () -> Unit,
onChargesClicked: () -> Unit,
approveLoan: (loanWithAssociations: LoanWithAssociations) -> Unit,
disburseLoan: () -> Unit,
onDocumentsClicked: (loanId : Int) -> Unit,
onChargesClicked: (loanId : Int) -> Unit,
approveLoan: (loadId : Int, loanWithAssociations: LoanWithAssociations) -> Unit,
disburseLoan: (loanId : Int) -> Unit,
onRepaymentClick: (loanWithAssociations: LoanWithAssociations) -> Unit
) {
val viewModel: LoanAccountSummaryViewModel = hiltViewModel()
val uiState by viewModel.loanAccountSummaryUiState.collectAsStateWithLifecycle()
val loanAccountNumber by viewModel.loanAccountNumber.collectAsStateWithLifecycle()

LaunchedEffect(key1 = Unit) {
viewModel.loadLoanById(loanAccountNumber)
Expand All @@ -92,13 +90,13 @@ fun LoanAccountSummaryScreen(
uiState = uiState,
navigateBack = navigateBack,
onRetry = { viewModel.loadLoanById(loanAccountNumber) },
onMoreInfoClicked = onMoreInfoClicked,
onMoreInfoClicked = { onMoreInfoClicked.invoke(loanAccountNumber) },
onTransactionsClicked = { onTransactionsClicked.invoke(loanAccountNumber) },
onRepaymentScheduleClicked = { onRepaymentScheduleClicked.invoke(loanAccountNumber) },
onDocumentsClicked = onDocumentsClicked,
onChargesClicked = onChargesClicked,
approveLoan = approveLoan,
disburseLoan = disburseLoan,
onDocumentsClicked = { onDocumentsClicked(loanAccountNumber) },
onChargesClicked = { onChargesClicked(loanAccountNumber) },
approveLoan = { approveLoan(loanAccountNumber, it )},
disburseLoan = { disburseLoan(loanAccountNumber) },
makeRepayment = onRepaymentClick
)
}
Expand Down Expand Up @@ -586,7 +584,7 @@ class LoanAccountSummaryPreviewProvider : PreviewParameterProvider<LoanAccountSu
closedObligationsMet = true
),
clientName = "Pronay sarker",
loanOfficerName = "MR. Ching chong",
loanOfficerName = "MR. Ching",
loanProductName = "Group Loan",
summary = demoSummary
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.mifos.feature.loan.loan_account_summary

import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import com.mifos.core.common.utils.Constants
import com.mifos.core.data.repository.LoanAccountSummaryRepository
import com.mifos.core.objects.accounts.loan.LoanWithAssociations
import com.mifos.feature.loan.loan_account.sampleLoanList
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
Expand All @@ -15,8 +18,12 @@ import javax.inject.Inject
* Created by Aditya Gupta on 08/08/23.
*/
@HiltViewModel
class LoanAccountSummaryViewModel @Inject constructor(private val repository: LoanAccountSummaryRepository) :
ViewModel() {
class LoanAccountSummaryViewModel @Inject constructor(
private val repository: LoanAccountSummaryRepository,
savedStateHandle: SavedStateHandle
) : ViewModel() {

val loanAccountNumber = savedStateHandle.getStateFlow(key = Constants.LOAN_ACCOUNT_NUMBER, initialValue = 0)

private val _loanAccountSummaryUiState =
MutableStateFlow<LoanAccountSummaryUiState>(LoanAccountSummaryUiState.ShowProgressbar)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,11 @@ import java.util.Locale

@Composable
fun LoanAccountApprovalScreen(
loanId: Int,
loanWithAssociations : LoanWithAssociations,
navigateBack: () -> Unit,
) {
val viewModel: LoanAccountApprovalViewModel = hiltViewModel()
val uiState by viewModel.loanAccountApprovalUiState.collectAsStateWithLifecycle()

viewModel.loanId = loanId
viewModel.loanWithAssociations = loanWithAssociations

LoanAccountApprovalScreen(
uiState = uiState,
loanWithAssociations = viewModel.loanWithAssociations,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.mifos.feature.loan.loan_approval

import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import com.google.gson.Gson
import com.mifos.core.data.repository.LoanAccountApprovalRepository
import com.mifos.core.network.GenericResponse
import com.mifos.core.objects.accounts.loan.LoanApproval
import com.mifos.core.objects.accounts.loan.LoanApprovalData
import com.mifos.core.objects.accounts.loan.LoanWithAssociations
import com.mifos.core.objects.accounts.savings.SavingsSummaryData
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
Expand All @@ -20,16 +24,19 @@ import javax.inject.Inject
*/
@HiltViewModel
class LoanAccountApprovalViewModel @Inject constructor(
private val repository: LoanAccountApprovalRepository
) :
ViewModel() {
private val repository: LoanAccountApprovalRepository,
savedStateHandle: SavedStateHandle
) : ViewModel() {

private val arg = savedStateHandle.getStateFlow(key = "arg", initialValue = "")
private val loanAccountData: LoanApprovalData = Gson().fromJson(arg.value, LoanApprovalData::class.java)

private val _loanAccountApprovalUiState =
MutableStateFlow<LoanAccountApprovalUiState>(LoanAccountApprovalUiState.Initial)
val loanAccountApprovalUiState: StateFlow<LoanAccountApprovalUiState> get() = _loanAccountApprovalUiState

var loanId = 0
var loanWithAssociations: LoanWithAssociations? = null
var loanId = loanAccountData.loanID
var loanWithAssociations = loanAccountData.loanWithAssociations

fun approveLoan(loanApproval: LoanApproval?) {
_loanAccountApprovalUiState.value = LoanAccountApprovalUiState.ShowProgressbar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ import com.mifos.feature.loan.R
import com.mifos.feature.loan.loan_charge_dialog.LoanChargeDialogScreen

@Composable
fun LoanChargeScreen(loanAccountNumber: Int, onBackPressed: () -> Unit) {
fun LoanChargeScreen(onBackPressed: () -> Unit) {

val viewModel: LoanChargeViewModel = hiltViewModel()
val state by viewModel.loanChargeUiState.collectAsStateWithLifecycle()
val refreshState by viewModel.isRefreshing.collectAsStateWithLifecycle()
val loanAccountNumber by viewModel.loanAccountNumber.collectAsStateWithLifecycle()

LaunchedEffect(Unit) {
viewModel.loadLoanChargesList(loanAccountNumber)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.mifos.feature.loan.loan_charge

import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.mifos.core.common.utils.Constants
import com.mifos.core.common.utils.Resource
import com.mifos.core.domain.use_cases.GetListOfLoanChargesUseCase
import com.mifos.feature.loan.R
Expand All @@ -14,9 +16,12 @@ import javax.inject.Inject

@HiltViewModel
class LoanChargeViewModel @Inject constructor(
private val getListOfLoanChargesUseCase: GetListOfLoanChargesUseCase
private val getListOfLoanChargesUseCase: GetListOfLoanChargesUseCase,
savedStateHandle: SavedStateHandle
) : ViewModel() {

val loanAccountNumber = savedStateHandle.getStateFlow(key = Constants.LOAN_ACCOUNT_NUMBER, initialValue = 0)

private val _loanChargeUiState = MutableStateFlow<LoanChargeUiState>(LoanChargeUiState.Loading)
val loanChargeUiState = _loanChargeUiState.asStateFlow()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,26 +65,22 @@ import java.util.Locale

@Composable
fun LoanAccountDisbursementScreen(
loanId: Int,
navigateBack: () -> Unit,
) {
val viewmodel: LoanAccountDisbursementViewModel = hiltViewModel()
val uiState by viewmodel.loanAccountDisbursementUiState.collectAsStateWithLifecycle()

LaunchedEffect(loanId) {
viewmodel.loanId = loanId
}
val loanId by viewmodel.loadId.collectAsStateWithLifecycle()

LaunchedEffect(key1 = Unit) {
viewmodel.loadLoanTemplate()
viewmodel.loadLoanTemplate(loanId)
}

LoanAccountDisbursementScreen(
uiState = uiState,
navigateBack = navigateBack,
onRetry = { viewmodel.loadLoanTemplate() },
onRetry = { viewmodel.loadLoanTemplate(loanId) },
onDisburseLoan = {
viewmodel.disburseLoan(it)
viewmodel.disburseLoan(loanId, it)
}
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.mifos.feature.loan.loan_disbursement

import androidx.compose.ui.res.stringArrayResource
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import com.mifos.core.common.utils.Constants
import com.mifos.core.data.repository.LoanAccountDisbursementRepository
import com.mifos.core.model.APIEndPoint
import com.mifos.core.network.GenericResponse
Expand All @@ -20,18 +23,19 @@ import javax.inject.Inject
* Created by Aditya Gupta on 10/08/23.
*/
@HiltViewModel
class LoanAccountDisbursementViewModel @Inject constructor(private val repository: LoanAccountDisbursementRepository) :
ViewModel() {
class LoanAccountDisbursementViewModel @Inject constructor(
private val repository: LoanAccountDisbursementRepository,
savedStateHandle: SavedStateHandle
) : ViewModel() {

val loadId = savedStateHandle.getStateFlow(key = Constants.LOAN_ACCOUNT_NUMBER, initialValue = 0)

private val _loanAccountDisbursementUiState = MutableStateFlow<LoanAccountDisbursementUiState>(LoanAccountDisbursementUiState.ShowProgressbar)

val loanAccountDisbursementUiState: StateFlow<LoanAccountDisbursementUiState>
get() = _loanAccountDisbursementUiState

var loanId : Int = 0

fun loadLoanTemplate() {
fun loadLoanTemplate(loanId : Int) {
_loanAccountDisbursementUiState.value = LoanAccountDisbursementUiState.ShowProgressbar
repository.getLoanTransactionTemplate(loanId, APIEndPoint.DISBURSE)
.observeOn(AndroidSchedulers.mainThread())
Expand All @@ -52,7 +56,7 @@ class LoanAccountDisbursementViewModel @Inject constructor(private val repositor
})
}

fun disburseLoan(loanDisbursement: LoanDisbursement?) {
fun disburseLoan(loanId : Int, loanDisbursement: LoanDisbursement?) {
_loanAccountDisbursementUiState.value = LoanAccountDisbursementUiState.ShowProgressbar
repository.disburseLoan(loanId, loanDisbursement)
.observeOn(AndroidSchedulers.mainThread())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mifos.feature.loan.loan_repayment

import android.content.Context
import android.util.Log
import android.widget.Toast
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Arrangement
Expand Down Expand Up @@ -62,6 +63,7 @@ import com.mifos.core.designsystem.theme.DarkGray
import com.mifos.core.objects.PaymentTypeOption
import com.mifos.core.objects.accounts.loan.LoanRepaymentRequest
import com.mifos.core.objects.accounts.loan.LoanRepaymentResponse
import com.mifos.core.objects.accounts.loan.LoanWithAssociations_Table.loanProductName
import com.mifos.core.objects.templates.loans.LoanRepaymentTemplate
import com.mifos.feature.loan.R
import java.text.SimpleDateFormat
Expand All @@ -72,22 +74,13 @@ import java.util.Locale
*/
@Composable
fun LoanRepaymentScreen(
loanId: Int,
clientName: String,
loanAccountNumber: String,
amountInArrears: Double?,
loanProductName: String,
navigateBack: () -> Unit
) {
val viewmodel: LoanRepaymentViewModel = hiltViewModel()
val uiState by viewmodel.loanRepaymentUiState.collectAsStateWithLifecycle()

LaunchedEffect(key1 = Unit) {
viewmodel.loanId = loanId
viewmodel.clientName = clientName
viewmodel.loanAccountNumber = loanAccountNumber
viewmodel.amountInArrears = amountInArrears
viewmodel.loanProductName = loanProductName
Log.d("debugPrint", "LoanId: ${viewmodel.loanId}")
viewmodel.checkDatabaseLoanRepaymentByLoanId()
}

Expand Down
Loading

0 comments on commit 634fba5

Please sign in to comment.