Skip to content

Commit

Permalink
Refactor- [:feature:savings] Apply & Fix Detekt, Ktlint Rules (#2688)
Browse files Browse the repository at this point in the history
  • Loading branch information
niyajali authored Sep 2, 2024
1 parent aed62ab commit 25389dd
Show file tree
Hide file tree
Showing 28 changed files with 996 additions and 571 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import androidx.compose.material3.ButtonColors
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.ButtonElevation
import androidx.compose.material3.Icon
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
Expand Down Expand Up @@ -144,6 +145,21 @@ fun MifosOutlinedTextButton(
)
}

@Composable
fun MifosOutlinedButton(
textResId: Int,
onClick: () -> Unit,
modifier: Modifier = Modifier,
) {
OutlinedButton(
onClick = onClick,
modifier = modifier,
content = {
Text(text = stringResource(id = textResId))
},
)
}

@Composable
fun MifosIconTextButton(
text: String,
Expand Down
9 changes: 9 additions & 0 deletions feature/savings/build.gradle.kts
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
9 changes: 9 additions & 0 deletions feature/savings/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +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,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
*/
package org.mifos.mobile.feature.savings.navigation

import androidx.navigation.NavController
Expand All @@ -13,20 +22,28 @@ import org.mifos.mobile.core.common.Constants.SAVINGS_ID
import org.mifos.mobile.core.common.Constants.TRANSFER_PAY_FROM
import org.mifos.mobile.core.common.Constants.TRANSFER_PAY_TO
import org.mifos.mobile.core.common.Constants.TRANSFER_TYPE
import org.mifos.mobile.core.model.entity.accounts.savings.SavingsWithAssociations
import org.mifos.mobile.core.model.entity.payload.ReviewTransferPayload
import org.mifos.mobile.core.model.enums.ChargeType
import org.mifos.mobile.core.model.enums.LoanState
import org.mifos.mobile.core.model.enums.SavingsAccountState
import org.mifos.mobile.core.model.enums.TransferType
import org.mifos.mobile.feature.savings.savings_account.SavingsAccountDetailScreen
import org.mifos.mobile.feature.savings.savings_account_application.SavingsAccountApplicationScreen
import org.mifos.mobile.feature.savings.savings_account_transaction.SavingsAccountTransactionScreen
import org.mifos.mobile.feature.savings.savings_account_withdraw.SavingsAccountWithdrawScreen
import org.mifos.mobile.feature.savings.savings_make_transfer.SavingsMakeTransferScreen
import org.mifos.mobile.feature.savings.savingsAccount.SavingsAccountDetailScreen
import org.mifos.mobile.feature.savings.savingsAccountApplication.SavingsAccountApplicationScreen
import org.mifos.mobile.feature.savings.savingsAccountTransaction.SavingsAccountTransactionScreen
import org.mifos.mobile.feature.savings.savingsAccountWithdraw.SavingsAccountWithdrawScreen
import org.mifos.mobile.feature.savings.savingsMakeTransfer.SavingsMakeTransferScreen

fun NavController.navigateToSavingsMakeTransfer(accountId: Long, outstandingBalance: Double? = null, transferType: String) {
navigate(SavingsNavigation.SavingsMakeTransfer.passArguments(accountId, (outstandingBalance ?: 0.0).toString(), transferType))
fun NavController.navigateToSavingsMakeTransfer(
accountId: Long,
outstandingBalance: Double? = null,
transferType: String,
) {
navigate(
SavingsNavigation.SavingsMakeTransfer.passArguments(
accountId,
(outstandingBalance ?: 0.0).toString(),
transferType,
),
)
}

fun NavController.navigateToSavingsDetailScreen(savingsId: Long) {
Expand All @@ -37,8 +54,8 @@ fun NavController.navigateToSavingsApplicationScreen() {
navigate(
SavingsNavigation.SavingsApplication.passArguments(
savingsId = -1L,
savingsAccountState = SavingsAccountState.CREATE
)
savingsAccountState = SavingsAccountState.CREATE,
),
)
}

Expand All @@ -47,22 +64,47 @@ fun NavGraphBuilder.savingsNavGraph(
viewQrCode: (String) -> Unit,
viewCharges: (ChargeType) -> Unit,
reviewTransfer: (ReviewTransferPayload, TransferType) -> Unit,
callHelpline: () -> Unit
callHelpline: () -> Unit,
) {
navigation(
startDestination = SavingsNavigation.SavingsDetail.route,
route = SavingsNavigation.SavingsBase.route,
) {
savingsDetailRoute(
callUs = callHelpline,
deposit = { navController.navigateToSavingsMakeTransfer(accountId = it, transferType = TRANSFER_PAY_TO) },
makeTransfer = { navController.navigateToSavingsMakeTransfer(accountId = it, transferType = TRANSFER_PAY_FROM) },
deposit = {
navController.navigateToSavingsMakeTransfer(
accountId = it,
transferType = TRANSFER_PAY_TO,
)
},
makeTransfer = {
navController.navigateToSavingsMakeTransfer(
accountId = it,
transferType = TRANSFER_PAY_FROM,
)
},
navigateBack = navController::popBackStack,
updateSavingsAccount = { navController.navigate(SavingsNavigation.SavingsApplication.passArguments(savingsId = it, savingsAccountState = SavingsAccountState.UPDATE)) },
updateSavingsAccount = {
navController.navigate(
SavingsNavigation.SavingsApplication.passArguments(
savingsId = it,
savingsAccountState = SavingsAccountState.UPDATE,
),
)
},
viewCharges = { viewCharges(ChargeType.SAVINGS) },
viewQrCode = viewQrCode,
viewTransaction = { navController.navigate(SavingsNavigation.SavingsTransaction.passArguments(it)) },
withdrawSavingsAccount = { navController.navigate(SavingsNavigation.SavingsWithdraw.passArguments(it)) }
viewTransaction = {
navController.navigate(
SavingsNavigation.SavingsTransaction.passArguments(it),
)
},
withdrawSavingsAccount = {
navController.navigate(
SavingsNavigation.SavingsWithdraw.passArguments(it),
)
},
)

savingsApplication(
Expand All @@ -79,7 +121,7 @@ fun NavGraphBuilder.savingsNavGraph(

savingsMakeTransfer(
navigateBack = navController::popBackStack,
reviewTransfer = reviewTransfer
reviewTransfer = reviewTransfer,
)
}
}
Expand All @@ -93,13 +135,13 @@ fun NavGraphBuilder.savingsDetailRoute(
viewCharges: () -> Unit,
viewQrCode: (String) -> Unit,
callUs: () -> Unit,
deposit: (Long) -> Unit
deposit: (Long) -> Unit,
) {
composable(
route = SavingsNavigation.SavingsDetail.route,
arguments = listOf(
navArgument(name = SAVINGS_ID) { type = NavType.LongType },
)
),
) {
SavingsAccountDetailScreen(
navigateBack = navigateBack,
Expand All @@ -116,14 +158,16 @@ fun NavGraphBuilder.savingsDetailRoute(
}

fun NavGraphBuilder.savingsApplication(
navigateBack: () -> Unit
navigateBack: () -> Unit,
) {
composable(
route = SavingsNavigation.SavingsApplication.route,
arguments = listOf(
navArgument(name = SAVINGS_ID) { type = NavType.LongType },
navArgument(Constants.SAVINGS_ACCOUNT_STATE) { type = NavType.EnumType(SavingsAccountState::class.java) },
)
navArgument(Constants.SAVINGS_ACCOUNT_STATE) {
type = NavType.EnumType(SavingsAccountState::class.java)
},
),
) {
SavingsAccountApplicationScreen(
navigateBack = navigateBack,
Expand All @@ -136,7 +180,7 @@ fun NavGraphBuilder.savingsTransaction(
) {
composable(
route = SavingsNavigation.SavingsTransaction.route,
arguments = listOf(navArgument(name = SAVINGS_ID) { type = NavType.LongType })
arguments = listOf(navArgument(name = SAVINGS_ID) { type = NavType.LongType }),
) {
SavingsAccountTransactionScreen(
navigateBack = navigateBack,
Expand All @@ -149,7 +193,7 @@ fun NavGraphBuilder.savingsWithdraw(
) {
composable(
route = SavingsNavigation.SavingsWithdraw.route,
arguments = listOf(navArgument(SAVINGS_ID) { type = NavType.LongType })
arguments = listOf(navArgument(SAVINGS_ID) { type = NavType.LongType }),
) {
SavingsAccountWithdrawScreen(
navigateBack = { navigateBack() },
Expand All @@ -159,7 +203,7 @@ fun NavGraphBuilder.savingsWithdraw(

fun NavGraphBuilder.savingsMakeTransfer(
navigateBack: () -> Unit,
reviewTransfer: (ReviewTransferPayload, TransferType) -> Unit
reviewTransfer: (ReviewTransferPayload, TransferType) -> Unit,
) {
composable(
route = SavingsNavigation.SavingsMakeTransfer.route,
Expand All @@ -171,12 +215,12 @@ fun NavGraphBuilder.savingsMakeTransfer(
defaultValue = null
},
navArgument(name = TRANSFER_TYPE) { type = NavType.StringType },
)
),
) {
SavingsMakeTransferScreen(
navigateBack = navigateBack,
onCancelledClicked = navigateBack,
reviewTransfer = reviewTransfer
reviewTransfer = reviewTransfer,
)
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
/*
* 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.savings.navigation

import org.mifos.mobile.core.common.Constants
import org.mifos.mobile.core.common.Constants.ACCOUNT_ID
import org.mifos.mobile.core.common.Constants.OUTSTANDING_BALANCE
import org.mifos.mobile.core.common.Constants.SAVINGS_ACCOUNT_STATE
import org.mifos.mobile.core.common.Constants.SAVINGS_ID
import org.mifos.mobile.core.common.Constants.TRANSFER_TYPE
import org.mifos.mobile.core.model.enums.LoanState
import org.mifos.mobile.core.model.enums.SavingsAccountState

const val SAVINGS_NAVIGATION_ROUTE_BASE = "savings_route"
Expand All @@ -18,40 +25,48 @@ const val SAVINGS_MAKE_TRANSFER_SCREEN_ROUTE = "savings_make_transfer_screen_rou

sealed class SavingsNavigation(val route: String) {
data object SavingsBase : SavingsNavigation(
route = SAVINGS_NAVIGATION_ROUTE_BASE
route = SAVINGS_NAVIGATION_ROUTE_BASE,
)

data object SavingsDetail : SavingsNavigation(
route = "$SAVINGS_DETAIL_SCREEN_ROUTE/{$SAVINGS_ID}"
route = "$SAVINGS_DETAIL_SCREEN_ROUTE/{$SAVINGS_ID}",
) {
fun passArguments(savingsId: Long) = "$SAVINGS_DETAIL_SCREEN_ROUTE/$savingsId"
}

data object SavingsApplication : SavingsNavigation(
route = "$SAVINGS_APPLICATION_SCREEN_ROUTE/{${SAVINGS_ID}}/{${SAVINGS_ACCOUNT_STATE}}") {
fun passArguments(savingsId: Long, savingsAccountState: SavingsAccountState) = "$SAVINGS_APPLICATION_SCREEN_ROUTE/${savingsId}/${savingsAccountState}"
route = "$SAVINGS_APPLICATION_SCREEN_ROUTE/{${SAVINGS_ID}}/{${SAVINGS_ACCOUNT_STATE}}",
) {
fun passArguments(
savingsId: Long,
savingsAccountState: SavingsAccountState,
) = "$SAVINGS_APPLICATION_SCREEN_ROUTE/$savingsId/$savingsAccountState"
}

data object SavingsTransaction : SavingsNavigation(
route = "$SAVINGS_TRANSACTION_SCREEN_ROUTE/{${SAVINGS_ID}}"
route = "$SAVINGS_TRANSACTION_SCREEN_ROUTE/{${SAVINGS_ID}}",
) {
fun passArguments(savingsId: Long): String {
return "$SAVINGS_TRANSACTION_SCREEN_ROUTE/$savingsId"
}
}

data object SavingsWithdraw : SavingsNavigation(
route = "$SAVINGS_WITHDRAW_SCREEN_ROUTE/{${SAVINGS_ID}}"
route = "$SAVINGS_WITHDRAW_SCREEN_ROUTE/{${SAVINGS_ID}}",
) {
fun passArguments(savingsId: Long): String {
return "$SAVINGS_WITHDRAW_SCREEN_ROUTE/$savingsId"
}
}

data object SavingsMakeTransfer : SavingsNavigation(
route = "$SAVINGS_MAKE_TRANSFER_SCREEN_ROUTE/{$ACCOUNT_ID}/{$OUTSTANDING_BALANCE}/{$TRANSFER_TYPE}"
route = "$SAVINGS_MAKE_TRANSFER_SCREEN_ROUTE/{$ACCOUNT_ID}/{$OUTSTANDING_BALANCE}/{$TRANSFER_TYPE}",
) {
fun passArguments(accountId: Long, outstandingBalance: String? = null, transferType: String): String {
fun passArguments(
accountId: Long,
outstandingBalance: String? = null,
transferType: String,
): String {
return "$SAVINGS_MAKE_TRANSFER_SCREEN_ROUTE/$accountId/$outstandingBalance/$transferType"
}
}
Expand Down
Loading

0 comments on commit 25389dd

Please sign in to comment.