Skip to content

Commit

Permalink
Refactor- [:feature:transfer-process] Apply & Fix Detekt, Ktlint Rules (
Browse files Browse the repository at this point in the history
  • Loading branch information
niyajali authored Sep 2, 2024
1 parent 865175d commit 1229a0a
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 137 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,7 @@ fun RootNavGraph(
navigateToOssLicense = { startActivity(context, OssLicensesMenuActivity::class.java) }
)

transferProcessNavGraph(
navController = navController
)
transferProcessNavGraph(navigateBack = navController::popBackStack)

beneficiaryNavGraph(
navController = navController,
Expand Down
17 changes: 9 additions & 8 deletions feature/transfer-process/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 All @@ -9,13 +18,5 @@ android {
}

dependencies {
implementation(projects.core.ui)
implementation(projects.core.common)
implementation(projects.core.model)
implementation(projects.core.data)
implementation(libs.squareup.retrofit.converter.gson)

testImplementation(libs.junit)
androidTestImplementation(libs.androidx.test.ext.junit)
androidTestImplementation(libs.espresso.core)
}

This file was deleted.

9 changes: 9 additions & 0 deletions feature/transfer-process/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.transfer.process

import android.widget.Toast
Expand All @@ -13,7 +22,6 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
Expand All @@ -28,71 +36,72 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
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
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import org.mifos.mobile.core.common.Network
import org.mifos.mobile.core.designsystem.components.MifosButton
import org.mifos.mobile.core.designsystem.components.MifosScaffold
import org.mifos.mobile.core.designsystem.theme.MifosMobileTheme
import org.mifos.mobile.core.model.entity.payload.TransferPayload
import org.mifos.mobile.core.ui.component.MifosErrorComponent
import org.mifos.mobile.core.ui.component.MifosProgressIndicatorOverlay

import org.mifos.mobile.core.ui.utils.DevicePreviews

@Composable
fun TransferProcessScreen(
internal fun TransferProcessScreen(
navigateBack: () -> Unit,
modifier: Modifier = Modifier,
viewModel: TransferProcessViewModel = hiltViewModel(),
navigateBack: () -> Unit
) {
val uiState by viewModel.transferUiState.collectAsStateWithLifecycle()
val payload by viewModel.transferPayload.collectAsStateWithLifecycle()

TransferProcessScreen(
uiState = uiState,
transfer = { viewModel.makeTransfer() },
transfer = viewModel::makeTransfer,
payload = payload,
navigateBack = navigateBack,
modifier = modifier,
)
}

@Composable
fun TransferProcessScreen(
private fun TransferProcessScreen(
uiState: TransferProcessUiState,
payload: TransferPayload?,
transfer: () -> Unit,
navigateBack: () -> Unit,
modifier: Modifier = Modifier,
) {
val context = LocalContext.current

MifosScaffold(
topBarTitleResId = R.string.transfer,
navigateBack = navigateBack,
modifier = modifier,
content = { paddingValues ->
Box(
modifier = Modifier
.padding(paddingValues)
.fillMaxSize()
.fillMaxSize(),
) {

TransferProcessContent(
payload = payload,
transfer = transfer,
cancelClicked = navigateBack
cancelClicked = navigateBack,
)

when (uiState) {
is TransferProcessUiState.Loading -> {
MifosProgressIndicatorOverlay()
}
is TransferProcessUiState.Loading -> MifosProgressIndicatorOverlay()

is TransferProcessUiState.Success -> {
Toast.makeText(
context,
R.string.transferred_successfully,
Toast.LENGTH_SHORT
Toast.LENGTH_SHORT,
).show()
navigateBack()
}
Expand All @@ -104,46 +113,47 @@ fun TransferProcessScreen(
is TransferProcessUiState.Initial -> Unit
}
}
}
},
)
}

@Composable
fun TransferProcessContent(
private fun TransferProcessContent(
payload: TransferPayload?,
transfer: () -> Unit,
cancelClicked: () -> Unit
cancelClicked: () -> Unit,
modifier: Modifier = Modifier,
) {
val scrollState = rememberScrollState()

Column(
modifier = Modifier
modifier = modifier
.fillMaxSize()
.verticalScroll(scrollState)
.verticalScroll(scrollState),
) {
Card(
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
colors = CardDefaults.cardColors(
containerColor = MaterialTheme.colorScheme.background
containerColor = MaterialTheme.colorScheme.background,
),
border = BorderStroke(1.dp, Color.LightGray)
border = BorderStroke(1.dp, Color.LightGray),
) {
Column(
modifier = Modifier
.fillMaxWidth()
.padding(14.dp)
.padding(14.dp),
) {
Column(
modifier = Modifier
.fillMaxWidth()
.padding(bottom = 12.dp),
horizontalAlignment = Alignment.CenterHorizontally
horizontalAlignment = Alignment.CenterHorizontally,
) {
Text(
text = stringResource(id = R.string.amount),
color = MaterialTheme.colorScheme.primary
color = MaterialTheme.colorScheme.primary,
)

Text(text = payload?.transferAmount.toString())
Expand All @@ -152,57 +162,57 @@ fun TransferProcessContent(
Text(
text = stringResource(id = R.string.transfer_from_savings),
fontWeight = FontWeight(500),
color = Color.Gray
color = Color.Gray,
)

Text(
text = stringResource(id = R.string.pay_to),
modifier = Modifier.padding(top = 8.dp),
color = MaterialTheme.colorScheme.primary
color = MaterialTheme.colorScheme.primary,
)

Text(
text = payload?.fromAccountNumber.toString(),
modifier = Modifier.padding(top = 4.dp, bottom = 2.dp)
modifier = Modifier.padding(top = 4.dp, bottom = 2.dp),
)

HorizontalDivider()

Text(
text = stringResource(id = R.string.pay_from),
modifier = Modifier.padding(top = 8.dp),
color = MaterialTheme.colorScheme.primary
color = MaterialTheme.colorScheme.primary,
)

Text(
text = payload?.fromAccountNumber.toString(),
modifier = Modifier.padding(top = 4.dp, bottom = 2.dp)
modifier = Modifier.padding(top = 4.dp, bottom = 2.dp),
)

HorizontalDivider()

Text(
text = stringResource(id = R.string.date),
modifier = Modifier.padding(top = 8.dp),
color = MaterialTheme.colorScheme.primary
color = MaterialTheme.colorScheme.primary,
)

Text(
text = payload?.transferDate.toString(),
modifier = Modifier.padding(top = 4.dp, bottom = 2.dp)
modifier = Modifier.padding(top = 4.dp, bottom = 2.dp),
)

HorizontalDivider()

Text(
text = stringResource(id = R.string.remark),
modifier = Modifier.padding(top = 8.dp),
color = MaterialTheme.colorScheme.primary
color = MaterialTheme.colorScheme.primary,
)

Text(
text = payload?.transferDescription.toString(),
modifier = Modifier.padding(top = 4.dp, bottom = 2.dp)
modifier = Modifier.padding(top = 4.dp, bottom = 2.dp),
)

HorizontalDivider()
Expand All @@ -211,49 +221,45 @@ fun TransferProcessContent(

Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.End
horizontalArrangement = Arrangement.End,
) {
Row(
horizontalArrangement = Arrangement.spacedBy(30.dp),
) {
Button(
onClick = { cancelClicked() },
MifosButton(
textResId = R.string.cancel,
onClick = cancelClicked,
colors = ButtonDefaults.buttonColors(
containerColor = Color.Transparent,
contentColor = MaterialTheme.colorScheme.primary
)
) {
Text(text = stringResource(id = R.string.cancel))
}
Button(
onClick = {
transfer()
}
) {
Text(text = stringResource(id = R.string.transfer))
}
contentColor = MaterialTheme.colorScheme.primary,
),
)
MifosButton(
textResId = R.string.transfer,
onClick = transfer,
)
}
}
}
}
}
}


class UiStatesParameterProvider : PreviewParameterProvider<TransferProcessUiState> {
internal class UiStatesParameterProvider : PreviewParameterProvider<TransferProcessUiState> {
override val values: Sequence<TransferProcessUiState>
get() = sequenceOf(
TransferProcessUiState.Initial,
TransferProcessUiState.Loading,
TransferProcessUiState.Error(null),
TransferProcessUiState.Success
TransferProcessUiState.Success,
)
}

@Preview(showSystemUi = true)
@DevicePreviews
@Composable
fun TransferProcessScreenPreview(
@PreviewParameter(UiStatesParameterProvider::class) transferUiState: TransferProcessUiState
private fun TransferProcessScreenPreview(
@PreviewParameter(UiStatesParameterProvider::class)
transferUiState: TransferProcessUiState,
) {
MifosMobileTheme {
TransferProcessScreen(
Expand All @@ -263,11 +269,10 @@ fun TransferProcessScreenPreview(
fromAccountNumber = "1234567890",
toAccountNumber = "0987654321",
transferDate = "2021-09-01",
transferDescription = "Transfer Description"
transferDescription = "Transfer Description",
),
transfer = {},
navigateBack = {},
)
}
}

Loading

0 comments on commit 1229a0a

Please sign in to comment.