Skip to content

Commit

Permalink
Refactor- [:feature:client-charge] Apply & Fix Detekt, Ktlint Rules (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
niyajali authored Aug 31, 2024
1 parent 1704351 commit 64609f6
Show file tree
Hide file tree
Showing 20 changed files with 172 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import org.mifos.mobile.feature.beneficiary.navigation.beneficiaryNavGraph
import org.mifos.mobile.feature.beneficiary.navigation.navigateToAddBeneficiaryScreen
import org.mifos.mobile.feature.beneficiary.navigation.navigateToBeneficiaryApplicationScreen
import org.mifos.mobile.feature.beneficiary.navigation.navigateToBeneficiaryListScreen
import org.mifos.mobile.feature.client_charge.navigation.clientChargeNavGraph
import org.mifos.mobile.feature.client_charge.navigation.navigateToClientChargeScreen
import org.mifos.mobile.feature.charge.navigation.clientChargeNavGraph
import org.mifos.mobile.feature.charge.navigation.navigateToClientChargeScreen
import org.mifos.mobile.feature.guarantor.navigation.guarantorNavGraph
import org.mifos.mobile.feature.guarantor.navigation.navigateToGuarantorScreen
import org.mifos.mobile.feature.help.navigation.helpNavGraph
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import org.mifos.mobile.R
import org.mifos.mobile.models.Charge
import org.mifos.mobile.models.Page
import org.mifos.mobile.repositories.ClientChargeRepositoryImp
import org.mifos.mobile.feature.client_charge.viewmodel.ClientChargeViewModel
import org.mifos.mobile.util.RxSchedulersOverrideRule
import org.mifos.mobile.utils.ClientChargeUiState
import org.mockito.Mock
Expand Down Expand Up @@ -45,12 +44,12 @@ class ClientChargeViewModelTest {
@Mock
private lateinit var clientChargeUiStateObserver: Observer<ClientChargeUiState>

private lateinit var viewModel: org.mifos.mobile.feature.client_charge.viewmodel.ClientChargeViewModel
private lateinit var viewModel: org.mifos.mobile.feature.charge.viewmodel.ClientChargeViewModel

@Before
fun setUp() {
MockitoAnnotations.openMocks(this)
viewModel = org.mifos.mobile.feature.client_charge.viewmodel.ClientChargeViewModel(
viewModel = org.mifos.mobile.feature.charge.viewmodel.ClientChargeViewModel(
clientChargeRepositoryImp
)
}
Expand Down
2 changes: 1 addition & 1 deletion config/detekt/detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ complexity:
threshold: 15
ComplexCondition:
active: true
threshold: 4
threshold: 5
ComplexInterface:
active: false
threshold: 10
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/mobile-mobile/blob/master/LICENSE.md
*/
plugins {
alias(libs.plugins.mifos.android.feature)
alias(libs.plugins.mifos.android.library.compose)
Expand Down
File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions feature/client-charge/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2024 Mifos Initiative
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file,
You can obtain one at https://mozilla.org/MPL/2.0/.
See https://github.com/openMF/mobile-mobile/blob/master/LICENSE.md
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
package org.mifos.mobile.feature.client_charge.navigation
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/mobile-mobile/blob/master/LICENSE.md
*/
package org.mifos.mobile.feature.charge.navigation

import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
Expand All @@ -8,7 +17,7 @@ import androidx.navigation.compose.navigation
import androidx.navigation.navArgument
import org.mifos.mobile.core.common.Constants.CHARGE_TYPE
import org.mifos.mobile.core.model.enums.ChargeType
import org.mifos.mobile.feature.client_charge.screens.ClientChargeScreen
import org.mifos.mobile.feature.charge.screens.ClientChargeScreen

fun NavController.navigateToClientChargeScreen(
chargeType: ChargeType,
Expand All @@ -34,10 +43,10 @@ fun NavGraphBuilder.clientChargeScreenRoute(
) {
composable(
route = ClientChargeNavigation.ClientChargeScreen.route,
arguments = listOf(navArgument(CHARGE_TYPE) { type = NavType.StringType })
arguments = listOf(navArgument(CHARGE_TYPE) { type = NavType.StringType }),
) {
ClientChargeScreen(
navigateBack = navigateBack,
)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
package org.mifos.mobile.feature.client_charge.navigation
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/mobile-mobile/blob/master/LICENSE.md
*/
package org.mifos.mobile.feature.charge.navigation

import org.mifos.mobile.core.common.Constants.CHARGE_TYPE
import org.mifos.mobile.core.model.enums.ChargeType
Expand All @@ -21,4 +30,4 @@ sealed class ClientChargeNavigation(var route: String) {
) {
fun passArguments(chargeType: ChargeType) = "$CLIENT_CHARGE_SCREEN_ROUTE/${chargeType.name}"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
package org.mifos.mobile.feature.client_charge.screens
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/mobile-mobile/blob/master/LICENSE.md
*/
package org.mifos.mobile.feature.charge.screens

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
Expand All @@ -21,7 +30,6 @@ import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import androidx.compose.ui.unit.dp
Expand All @@ -39,39 +47,44 @@ import org.mifos.mobile.core.ui.component.EmptyDataView
import org.mifos.mobile.core.ui.component.MifosErrorComponent
import org.mifos.mobile.core.ui.component.MifosProgressIndicator
import org.mifos.mobile.core.ui.component.MifosTextTitleDescSingleLine
import org.mifos.mobile.feature.client_charge.R
import org.mifos.mobile.feature.client_charge.utils.ClientChargeState
import org.mifos.mobile.feature.client_charge.viewmodel.ClientChargeViewModel
import org.mifos.mobile.core.ui.utils.DevicePreviews
import org.mifos.mobile.feature.charge.R
import org.mifos.mobile.feature.charge.utils.ClientChargeState
import org.mifos.mobile.feature.charge.viewmodel.ClientChargeViewModel

@Composable
fun ClientChargeScreen(
internal fun ClientChargeScreen(
navigateBack: () -> Unit,
modifier: Modifier = Modifier,
viewModel: ClientChargeViewModel = hiltViewModel(),
navigateBack: () -> Unit
) {
val uiState by viewModel.clientChargeUiState.collectAsStateWithLifecycle()

ClientChargeScreen(
uiState = uiState,
navigateBack = navigateBack,
onRetry = { viewModel.loadCharges() }
onRetry = viewModel::loadCharges,
modifier = modifier,
)
}

@Composable
fun ClientChargeScreen(
private fun ClientChargeScreen(
uiState: ClientChargeState,
navigateBack: () -> Unit,
onRetry: () -> Unit
onRetry: () -> Unit,
modifier: Modifier = Modifier,
) {
val context = LocalContext.current
MifosScaffold(
topBarTitleResId = R.string.client_charges,
navigateBack = navigateBack,
modifier = modifier,
content = { paddingValues ->
Box(
modifier = Modifier
.padding(paddingValues = paddingValues)
.fillMaxSize()
.fillMaxSize(),
) {
when (uiState) {
is ClientChargeState.Loading -> {
Expand All @@ -82,7 +95,7 @@ fun ClientChargeScreen(
MifosErrorComponent(
isNetworkConnected = Network.isConnected(context),
isRetryEnabled = true,
onRetry = onRetry
onRetry = onRetry,
)
}

Expand All @@ -91,25 +104,25 @@ fun ClientChargeScreen(
EmptyDataView(
modifier = Modifier.fillMaxSize(),
icon = R.drawable.ic_charges,
error = R.string.error_no_charge
error = R.string.error_no_charge,
)
} else {
ClientChargeContent(
modifier = Modifier.padding(horizontal = 16.dp),
chargesList = uiState.charges
chargesList = uiState.charges,
)
}
}
}
}
}
},
)
}

@Composable
fun ClientChargeContent(
private fun ClientChargeContent(
chargesList: List<Charge>,
modifier: Modifier = Modifier,
chargesList: List<Charge>
) {
LazyColumn(modifier = modifier) {
items(items = chargesList) { charge ->
Expand All @@ -120,37 +133,43 @@ fun ClientChargeContent(
}

@Composable
fun ClientChargeItem(
charge: Charge
private fun ClientChargeItem(
charge: Charge,
modifier: Modifier = Modifier,
) {
val currencyRepresentation = charge.currency?.displaySymbol ?: charge.currency?.code ?: ""

OutlinedCard(
modifier = Modifier
.fillMaxWidth()
modifier = modifier
.fillMaxWidth(),
) {
Row(
modifier = Modifier.height(intrinsicSize = IntrinsicSize.Max)
modifier = Modifier.height(intrinsicSize = IntrinsicSize.Max),
) {
VerticalDivider(
thickness = 5.dp,
color = if (charge.isChargePaid || charge.isChargeWaived || charge.paid || charge.waived) RedErrorDark
else GreenSuccess,
modifier = Modifier.fillMaxHeight()
color = if (charge.isChargePaid || charge.isChargeWaived ||
charge.paid || charge.waived
) {
RedErrorDark
} else {
GreenSuccess
},
modifier = Modifier.fillMaxHeight(),
)
Column(
modifier = Modifier.padding(16.dp),
) {
Text(
text = charge.name ?: "",
style = MaterialTheme.typography.bodyLarge
style = MaterialTheme.typography.bodyLarge,
)

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

Text(
text = if (charge.dueDate.isNotEmpty()) DateHelper.getDateAsString(charge.dueDate) else "",
style = MaterialTheme.typography.bodyLarge
style = MaterialTheme.typography.bodyLarge,
)

Spacer(modifier = Modifier.height(8.dp))
Expand All @@ -160,57 +179,57 @@ fun ClientChargeItem(
description = stringResource(
id = R.string.string_and_string,
currencyRepresentation,
CurrencyUtil.formatCurrency(charge.amount)
)
CurrencyUtil.formatCurrency(charge.amount),
),
)

MifosTextTitleDescSingleLine(
title = stringResource(id = R.string.amount_paid),
description = stringResource(
id = R.string.string_and_string,
currencyRepresentation,
CurrencyUtil.formatCurrency(charge.amountPaid)
)
CurrencyUtil.formatCurrency(charge.amountPaid),
),
)

MifosTextTitleDescSingleLine(
title = stringResource(id = R.string.amount_waived),
description = stringResource(
id = R.string.string_and_string,
currencyRepresentation,
CurrencyUtil.formatCurrency(charge.amountWaived)
)
CurrencyUtil.formatCurrency(charge.amountWaived),
),
)

MifosTextTitleDescSingleLine(
title = stringResource(id = R.string.amount_outstanding),
description = stringResource(
id = R.string.string_and_string,
currencyRepresentation,
CurrencyUtil.formatCurrency(charge.amountOutstanding)
)
CurrencyUtil.formatCurrency(charge.amountOutstanding),
),
)
}
}
}
}


@Preview(showSystemUi = true)
@DevicePreviews
@Composable
fun ClientChargeScreenPreview(
@PreviewParameter(ClientChargeUiStatesPreviews::class) uiState: ClientChargeState
private fun ClientChargeScreenPreview(
@PreviewParameter(ClientChargeUiStatesPreviews::class)
uiState: ClientChargeState,
) {
MifosMobileTheme {
ClientChargeScreen(
uiState = uiState,
navigateBack = { },
onRetry = { }
onRetry = { },
)
}
}

class ClientChargeUiStatesPreviews : PreviewParameterProvider<ClientChargeState> {
internal class ClientChargeUiStatesPreviews : PreviewParameterProvider<ClientChargeState> {
override val values: Sequence<ClientChargeState>
get() = sequenceOf(
ClientChargeState.Success(listOf(Charge(), Charge())),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/mobile-mobile/blob/master/LICENSE.md
*/
package org.mifos.mobile.feature.charge.utils

import org.mifos.mobile.core.datastore.model.Charge

internal sealed class ClientChargeState {
data object Loading : ClientChargeState()
data class Error(val message: String?) : ClientChargeState()
data class Success(val charges: List<Charge>) : ClientChargeState()
}
Loading

0 comments on commit 64609f6

Please sign in to comment.