Skip to content

Commit

Permalink
refactor #2546: migrate loan application screen to compose
Browse files Browse the repository at this point in the history
  • Loading branch information
AvneetSingh2001 committed May 9, 2024
1 parent d1d3399 commit f369bc1
Show file tree
Hide file tree
Showing 10 changed files with 180 additions and 185 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class SelfServiceInterceptor(private val preferencesHelper: PreferencesHelper) :
companion object {
const val HEADER_TENANT = "Fineract-Platform-TenantId"
const val HEADER_AUTH = "Authorization"
const val DEFAULT_TENANT = "default"
const val DEFAULT_TENANT = "gsoc"
const val CONTENT_TYPE = "Content-Type"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ interface LoanRepository {
loanWithdraw: LoanWithdraw?,
): Flow<ResponseBody?>?

fun template(): Flow<LoanTemplate?>?
fun template(): Flow<LoanTemplate?>

fun getLoanTemplateByProduct(
productId: Int?
): Flow<LoanTemplate?>?
): Flow<LoanTemplate?>
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ class LoanRepositoryImp @Inject constructor(private val dataManager: DataManager
}
}

override fun template(): Flow<LoanTemplate?>? {
override fun template(): Flow<LoanTemplate?> {
return flow {
emit(dataManager.loanTemplate())
}
}

override fun getLoanTemplateByProduct(productId: Int?): Flow<LoanTemplate?>? {
override fun getLoanTemplateByProduct(productId: Int?): Flow<LoanTemplate?> {
return flow {
emit(dataManager.getLoanTemplateByProduct(productId))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Divider
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import org.mifos.mobile.R
import org.mifos.mobile.core.ui.component.MifosTitleDescDoubleLine
import org.mifos.mobile.core.ui.component.MifosTextTitleDescDoubleLine
import org.mifos.mobile.models.guarantor.GuarantorPayload
import org.mifos.mobile.utils.DateHelper

Expand All @@ -22,45 +23,44 @@ fun GuarantorDetailContent(
.fillMaxSize()
.padding(16.dp)) {

MifosTitleDescDoubleLine(
MifosTextTitleDescDoubleLine(
title = stringResource(id = R.string.first_name),
description = data.firstname ?: "",
descriptionStyle = MaterialTheme.typography.bodyLarge
)

Divider(modifier = Modifier.padding(vertical = 8.dp))
HorizontalDivider(modifier = Modifier.padding(vertical = 8.dp))

MifosTitleDescDoubleLine(
MifosTextTitleDescDoubleLine(
title = stringResource(id = R.string.last_name),
description = data.lastname ?: "",
descriptionStyle = MaterialTheme.typography.bodyLarge
)

Divider(modifier = Modifier.padding(vertical = 8.dp))
HorizontalDivider(modifier = Modifier.padding(vertical = 8.dp))

MifosTitleDescDoubleLine(
MifosTextTitleDescDoubleLine(
title = stringResource(id = R.string.office_name),
description = data.officeName ?: "",
descriptionStyle = MaterialTheme.typography.bodyLarge
)

Divider(modifier = Modifier.padding(vertical = 8.dp))
HorizontalDivider(modifier = Modifier.padding(vertical = 8.dp))

MifosTitleDescDoubleLine(
MifosTextTitleDescDoubleLine(
title = stringResource(id = R.string.guarantor_type),
description = data.guarantorType?.value ?: "",
descriptionStyle = MaterialTheme.typography.bodyLarge
)

Divider(modifier = Modifier.padding(vertical = 8.dp))
HorizontalDivider(modifier = Modifier.padding(vertical = 8.dp))

MifosTitleDescDoubleLine(
MifosTextTitleDescDoubleLine(
title = stringResource(id = R.string.joined_date),
description = DateHelper.getDateAsString(data.joinedDate),
descriptionStyle = MaterialTheme.typography.bodyLarge
)

Divider(modifier = Modifier.padding(vertical = 8.dp))

HorizontalDivider(modifier = Modifier.padding(vertical = 8.dp))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,23 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.core.text.isDigitsOnly
import org.mifos.mobile.R
import org.mifos.mobile.core.ui.component.MifosDropDownTextField
import org.mifos.mobile.core.ui.component.MifosOutlinedTextField
import org.mifos.mobile.core.ui.component.MifosTextTitleDescDrawableSingleLine
import org.mifos.mobile.core.ui.component.MifosTextTitleDescSingleLine
import org.mifos.mobile.core.ui.theme.MifosMobileTheme
import org.mifos.mobile.utils.DateHelper
import org.mifos.mobile.utils.DateHelper.FORMAT_dd_MM_yyyy
import org.mifos.mobile.utils.PresentOrFutureSelectableDates
import java.text.SimpleDateFormat
import java.util.Locale


@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun LoanApplicationContent(
Expand All @@ -63,13 +69,16 @@ fun LoanApplicationContent(
var selectedLoanProduct by rememberSaveable { mutableStateOf(uiData.selectedLoanProduct) }
var selectedLoanPurpose by rememberSaveable { mutableStateOf(uiData.selectedLoanPurpose) }
val datePickerState = rememberDatePickerState(selectableDates = PresentOrFutureSelectableDates)
var principalAmount by rememberSaveable(stateSaver = TextFieldValue.Saver) {
mutableStateOf(TextFieldValue(uiData.principalAmount ?: ""))
}

LaunchedEffect(key1 = selectedLoanProduct) {
principalAmountError = null
selectedLoanProductError = null
}

LaunchedEffect(key1 = uiData.principalAmount) {
LaunchedEffect(key1 = principalAmount) {
principalAmountError = null
}

Expand Down Expand Up @@ -133,17 +142,18 @@ fun LoanApplicationContent(

Spacer(modifier = Modifier.height(8.dp))

OutlinedTextField(
value = uiData.principalAmount ?: "",
onValueChange = { setPrincipalAmount(it) },
label = { Text(text = stringResource(id = R.string.principal_amount)) },
isError = principalAmountError != null,
MifosOutlinedTextField(
value = principalAmount,
onValueChange = {
principalAmount = it
setPrincipalAmount(principalAmount.text)
},
label = R.string.principal_amount,
error = principalAmountError != null,
modifier = Modifier.fillMaxWidth(),
supportingText = { if(principalAmountError != null) Text(text = principalAmountError!!) },
keyboardOptions = KeyboardOptions(
imeAction = ImeAction.Done,
keyboardType = KeyboardType.Number
),
supportingText = if(principalAmountError != null) principalAmountError ?: "" else "",
imeAction = ImeAction.Done,
keyboardType = KeyboardType.Number,
)

Spacer(modifier = Modifier.height(8.dp))
Expand Down Expand Up @@ -175,16 +185,12 @@ fun LoanApplicationContent(
onClick = {
selectedLoanProductError = null
principalAmountError = null
if(uiData.selectedLoanProduct.isNullOrBlank()) {
selectedLoanProductError = context.getString(R.string.select_loan_product_field)
} else if(uiData.principalAmount.isNullOrBlank()) {
principalAmountError = context.getString(R.string.enter_amount)
} else if(uiData.principalAmount == ".") {
principalAmountError = context.getString(R.string.invalid_amount)
} else if(uiData.principalAmount.orEmpty().matches("^0*".toRegex())) {
principalAmountError = context.getString(R.string.amount_greater_than_zero)
} else {
reviewClicked()
when {
uiData.selectedLoanProduct.isNullOrBlank() -> { selectedLoanProductError = context.getString(R.string.select_loan_product_field) }
principalAmount.text.isNullOrBlank() || !principalAmount.text.isDigitsOnly() -> { principalAmountError = context.getString(R.string.enter_amount) }
principalAmount.text == "." -> { principalAmountError = context.getString(R.string.invalid_amount) }
principalAmount.text.matches("^0*".toRegex()) -> { principalAmountError = context.getString(R.string.amount_greater_than_zero) }
else -> { reviewClicked() }
}
},
modifier = Modifier.fillMaxWidth()
Expand All @@ -200,18 +206,22 @@ fun LoanApplicationContent(
confirmButton = {
TextButton(
onClick = {
val timeInMillis = datePickerState.selectedDateMillis
val formattedDate = SimpleDateFormat("dd-MM-yyyy", Locale.getDefault()).format(timeInMillis)
expectedDisbursementDate = formattedDate
setDisbursementDate(formattedDate)
val formattedDate = DateHelper.getSpecificFormat(
format = FORMAT_dd_MM_yyyy,
dateLong = datePickerState.selectedDateMillis
)
formattedDate?.let {
expectedDisbursementDate = formattedDate
setDisbursementDate(formattedDate)
}
showDatePicker = false
}
) { Text("OK") }
) { Text(stringResource(id = R.string.dialog_action_ok)) }
},
dismissButton = {
TextButton(
onClick = { showDatePicker = false }
) { Text("Cancel") }
) { Text(stringResource(id = R.string.dialog_action_cancel)) }
},
colors = DatePickerDefaults.colors(
containerColor = MaterialTheme.colorScheme.surface,
Expand Down
Loading

0 comments on commit f369bc1

Please sign in to comment.