Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmp-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ android {
}
}

@Suppress("UnstableApiUsage")
testOptions {
unitTests {
isIncludeAndroidResources = true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* Copyright 2025 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/android-client/blob/master/LICENSE.md
*/
package com.mifos.feature.client.createShareAccount

import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.viewmodel.compose.viewModel
import com.mifos.core.designsystem.component.MifosScaffold
import com.mifos.core.ui.components.MifosStepper
import com.mifos.core.ui.components.Step
import com.mifos.core.ui.util.EventsEffect
import com.mifos.feature.client.createShareAccount.pages.ChargesPage
import com.mifos.feature.client.createShareAccount.pages.DetailsPage
import com.mifos.feature.client.createShareAccount.pages.PreviewPage
import com.mifos.feature.client.createShareAccount.pages.TermsPage

@Composable
internal fun ShareAccountScreen(
onNavigateBack: () -> Unit,
onFinish: () -> Unit,
modifier: Modifier = Modifier,
viewModel: ShareAccountViewModel = viewModel(),
) {
val state by viewModel.stateFlow.collectAsStateWithLifecycle()

EventsEffect(viewModel.eventFlow) { event ->
when (event) {
ShareAccountEvent.NavigateBack -> onNavigateBack()
ShareAccountEvent.Finish -> onFinish()
}
}

ShareAccountScaffold(
modifier = modifier,
state = state,
onAction = { viewModel.trySendAction(it) },
)
}

@Composable
private fun ShareAccountScaffold(
state: ShareAccountState,
modifier: Modifier = Modifier,
onAction: (ShareAccountAction) -> Unit,
) {
val steps = remember {
listOf(
Step(name = "Details") {
DetailsPage(
onNext = { onAction(ShareAccountAction.NextStep) },
)
},
Step(name = "Terms") {
TermsPage(
onNext = { onAction(ShareAccountAction.NextStep) },
)
},
Step(name = "Charges") {
ChargesPage(
onNext = { onAction(ShareAccountAction.NextStep) },
)
},
Step(name = "Preview") {
PreviewPage(
onNext = { onAction(ShareAccountAction.Finish) },
)
},
)
}

MifosScaffold(
title = "Create Share Account",
onBackPressed = { onAction(ShareAccountAction.NavigateBack) },
modifier = modifier,
) { paddingValues ->
if (state.dialogState == null) {
MifosStepper(
steps = steps,
currentIndex = state.currentStep,
onStepChange = { newIndex ->
onAction(ShareAccountAction.OnStepChange(newIndex))
},
modifier = Modifier
.fillMaxWidth()
.padding(paddingValues),
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2025 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/android-client/blob/master/LICENSE.md
*/
package com.mifos.feature.client.createShareAccount

import com.mifos.core.ui.util.BaseViewModel
import kotlinx.coroutines.flow.update

class ShareAccountViewModel : BaseViewModel<ShareAccountState, ShareAccountEvent, ShareAccountAction> (ShareAccountState()) {

override fun handleAction(action: ShareAccountAction) {
when (action) {
ShareAccountAction.NextStep -> {
mutableStateFlow.update { state ->
val maxIndex = 3 // total steps - 1
state.copy(currentStep = (state.currentStep + 1).coerceAtMost(maxIndex))
}
}
is ShareAccountAction.OnStepChange -> {
mutableStateFlow.update { it.copy(currentStep = action.index) }
}
ShareAccountAction.NavigateBack -> {
sendEvent(ShareAccountEvent.NavigateBack)
}
ShareAccountAction.Finish -> {
sendEvent(ShareAccountEvent.Finish)
}
}
}
}

data class ShareAccountState(
val currentStep: Int = 0,
val dialogState: Any? = null,
)

sealed class ShareAccountAction {
object NextStep : ShareAccountAction()
data class OnStepChange(val index: Int) : ShareAccountAction()
object NavigateBack : ShareAccountAction()
object Finish : ShareAccountAction()
}

sealed class ShareAccountEvent {
object NavigateBack : ShareAccountEvent()
object Finish : ShareAccountEvent()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2025 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/android-client/blob/master/LICENSE.md
*/
package com.mifos.feature.client.createShareAccount

import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.composable
import kotlinx.serialization.Serializable

@Serializable
data object ShareAccountRoute

fun NavGraphBuilder.shareAccountDestination() {
composable<ShareAccountRoute> {
ShareAccountScreen(
onNavigateBack = {},
onFinish = {},
)
}
}

fun NavController.navigateToShareAccountRoute() {
this.navigate(
ShareAccountRoute,
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2025 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/android-client/blob/master/LICENSE.md
*/
package com.mifos.feature.client.createShareAccount.pages

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp

@Composable
fun ChargesPage(onNext: () -> Unit) {
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Text("Charges Page")
Spacer(Modifier.height(8.dp))
Button(onClick = onNext) {
Text("Next Button")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2025 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/android-client/blob/master/LICENSE.md
*/
package com.mifos.feature.client.createShareAccount.pages

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp

@Composable
fun DetailsPage(onNext: () -> Unit) {
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Text("Details Page")
Spacer(Modifier.height(8.dp))
Button(onClick = onNext) {
Text("Next Button")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2025 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/android-client/blob/master/LICENSE.md
*/
package com.mifos.feature.client.createShareAccount.pages

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp

@Composable
fun PreviewPage(onNext: () -> Unit) {
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Text("Preview Page")
Spacer(Modifier.height(8.dp))
Button(onClick = onNext) {
Text("Next Button")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2025 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/android-client/blob/master/LICENSE.md
*/
package com.mifos.feature.client.createShareAccount.pages

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp

@Composable
fun TermsPage(onNext: () -> Unit) {
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Text("Terms Page")
Spacer(Modifier.height(8.dp))
Button(onClick = onNext) {
Text("Next Button")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ import com.mifos.feature.client.clientUpdateDefaultAccount.navigateToUpdateDefau
import com.mifos.feature.client.clientUpdateDefaultAccount.updateDefaultAccountDestination
import com.mifos.feature.client.clientsList.ClientListScreen
import com.mifos.feature.client.createNewClient.CreateNewClientScreen
import com.mifos.feature.client.createShareAccount.navigateToShareAccountRoute
import com.mifos.feature.client.createShareAccount.shareAccountDestination
import com.mifos.feature.client.documentPreviewScreen.createDocumentPreviewRoute
import com.mifos.feature.client.documentPreviewScreen.navigateToDocumentPreviewRoute
import com.mifos.feature.client.fixedDepositAccount.clientFixedDepositAccountDestination
Expand Down Expand Up @@ -302,9 +304,9 @@ fun NavGraphBuilder.clientNavGraph(
)
clientApplyNewApplicationRoute(
onNavigateBack = navController::popBackStack,
onNavigateApplyShareAccount = navController::navigateToShareAccountRoute,
onNavigateApplyLoanAccount = navController::navigateToNewLoanAccountRoute,
onNavigateApplySavingsAccount = navController::navigateToSavingsAccountRoute,
onNavigateApplyShareAccount = { },
onNavigateApplyRecurringAccount = { },
onNavigateApplyFixedAccount = { },
navController = navController,
Expand Down Expand Up @@ -334,6 +336,8 @@ fun NavGraphBuilder.clientNavGraph(
loadMoreSavingsAccountInfo = navController::navigateToDataTable,
loadDocuments = navController::navigateToDocumentListScreen,
)

shareAccountDestination()
}
}

Expand Down