Skip to content
Open
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
3 changes: 2 additions & 1 deletion cmp-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
*/

import org.mifos.MifosBuildType
import org.mifos.dynamicVersion

Expand Down Expand Up @@ -154,4 +155,4 @@ dependencyGuard {
modules = true
tree = true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ private val SCRIM_COLOR: Int = Color.TRANSPARENT
* [here](https://github.com/android/nowinandroid/blob/689ef92e41427ab70f82e2c9fe59755441deae92/app/src/main/kotlin/com/google/samples/apps/nowinandroid/MainActivity.kt#L94).
*/
@Suppress("MaxLineLength")
fun ComponentActivity.setupEdgeToEdge(
appThemeFlow: Flow<DarkThemeConfig>,
) {
fun ComponentActivity.setupEdgeToEdge(appThemeFlow: Flow<DarkThemeConfig>) {
lifecycleScope.launch {
lifecycle.repeatOnLifecycle(state = Lifecycle.State.STARTED) {
combine(
Expand All @@ -55,12 +53,13 @@ fun ComponentActivity.setupEdgeToEdge(
// This handles all the settings to go edge-to-edge. We are using a transparent
// scrim for system bars and switching between "light" and "dark" based on the
// system and internal app theme settings.
val style = SystemBarStyle.auto(
darkScrim = SCRIM_COLOR,
lightScrim = SCRIM_COLOR,
// Disabling Dark Mode for this app
detectDarkMode = { false },
)
val style =
SystemBarStyle.auto(
darkScrim = SCRIM_COLOR,
lightScrim = SCRIM_COLOR,
// Disabling Dark Mode for this app
detectDarkMode = { false },
)
enableEdgeToEdge(statusBarStyle = style, navigationBarStyle = style)
}
}
Expand All @@ -75,9 +74,10 @@ fun ComponentActivity.setupEdgeToEdge(
private fun ComponentActivity.isSystemInDarkModeFlow(): Flow<Boolean> =
callbackFlow {
channel.trySend(element = resources.configuration.isSystemInDarkMode)
val listener = Consumer<Configuration> {
channel.trySend(element = it.isSystemInDarkMode)
}
val listener =
Consumer<Configuration> {
channel.trySend(element = it.isSystemInDarkMode)
}
addOnConfigurationChangedListener(listener = listener)
awaitClose { removeOnConfigurationChangedListener(listener = listener) }
}
Expand Down
1 change: 1 addition & 0 deletions cmp-android/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@
<string name="feature_groups_no_more_groups_available">No more Groups Available</string>
<string name="no_more_centers_available">No more Centers Available</string>


<string name="numberofrepayments">Number of repayments</string>

<string name="days_in_year">Days in year</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
<string name="core_designsystem_enter_tenant">Enter a tenant</string>
<string name="core_designsystem_cancel">Cancel</string>
<string name="core_designsystem_dialog_action_ok">Save</string>
<string name="core_designsystem_dialog_success">Success</string>
<string name="core_designsystem_dialog_failure">Failure</string>
<string name="core_designsystem_dialog_continue">Continue</string>
<string name="core_designsystem_mifosStatusDialog">MifosStatusDialog</string>

<string name="core_designsystem_app_title">Mifos</string>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
Expand All @@ -32,6 +35,16 @@ import com.mifos.core.designsystem.theme.MifosTypography
import org.jetbrains.compose.ui.tooling.preview.Preview
import org.jetbrains.compose.ui.tooling.preview.PreviewParameter
import org.jetbrains.compose.ui.tooling.preview.PreviewParameterProvider
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.CheckCircle
import androidx.compose.material.icons.filled.Error
import androidx.compose.ui.graphics.Color
import core.designsystem.generated.resources.Res
import core.designsystem.generated.resources.core_designsystem_dialog_continue
import core.designsystem.generated.resources.core_designsystem_dialog_failure
import core.designsystem.generated.resources.core_designsystem_dialog_success
import core.designsystem.generated.resources.core_designsystem_mifosStatusDialog
import org.jetbrains.compose.resources.stringResource

@Composable
fun MifosBasicDialog(
Expand Down Expand Up @@ -197,6 +210,73 @@ fun MifosBasicDialog(
)
}



enum class MifosDialogStatus { SUCCESS, FAILURE }

@Composable
fun MifosStatusDialog(
status: MifosDialogStatus,
message: String,
onDismissRequest: () -> Unit
) {
data class DialogUI(
val title: String,
val icon: androidx.compose.ui.graphics.vector.ImageVector,
val color: Color
)

val dialogUI: DialogUI = when (status) {
MifosDialogStatus.SUCCESS -> DialogUI(
title = stringResource(Res.string.core_designsystem_dialog_success),
icon = Icons.Filled.CheckCircle,
color = Color(0xFF4CAF50)
)
MifosDialogStatus.FAILURE -> DialogUI(
title = stringResource(Res.string.core_designsystem_dialog_failure),
icon = Icons.Filled.Error,
color = Color(0xFFF44336)
)
}

AlertDialog(
onDismissRequest = onDismissRequest,
icon = {
Icon(
imageVector = dialogUI.icon,
contentDescription = dialogUI.title,
tint = dialogUI.color,
modifier = Modifier
.size(84.dp)
.padding(bottom = 4.dp)
)
},
title = {
Text(
text = dialogUI.title,
style = MaterialTheme.typography.titleLarge
)
},
text = {
Text(
text = message,
style = MaterialTheme.typography.bodyMedium
)
},
confirmButton = {
Button(
onClick = onDismissRequest,
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 8.dp)
) {
Text(stringResource(Res.string.core_designsystem_dialog_continue))
}
},
modifier = Modifier.testTag(stringResource(Res.string.core_designsystem_mifosStatusDialog))
)
}

@Preview
@Composable
private fun MifosBasicDialog_preview() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import androidx.navigation.NavController
import com.mifos.core.designsystem.theme.DesignToken
import com.mifos.core.designsystem.theme.MifosTheme
import com.mifos.core.designsystem.theme.MifosTypography
import com.mifos.core.ui.util.PROFILE_SHOULD_REFRESH_KEY
import org.jetbrains.compose.resources.painterResource
import org.jetbrains.compose.ui.tooling.preview.Preview

Expand Down Expand Up @@ -81,6 +82,9 @@ fun MifosBreadcrumbNavBar(
isActive = index == routes.lastIndex,
onClick = {
if (index != routes.lastIndex && route != "...") {
navController.previousBackStackEntry
?.savedStateHandle
?.set(PROFILE_SHOULD_REFRESH_KEY, true)
navController.popBackStack(route, inclusive = false)
}
},
Expand All @@ -93,10 +97,13 @@ fun MifosBreadcrumbNavBar(
}
}

IconButton(
onClick = { navController.popBackStack() },
modifier = Modifier.size(DesignToken.sizes.iconMedium),
) {

IconButton(onClick = {
navController.previousBackStackEntry
?.savedStateHandle
?.set(PROFILE_SHOULD_REFRESH_KEY, true)
navController.popBackStack()
}) {
Icon(
painter = painterResource(Res.drawable.bread_crumb_back_icon),
contentDescription = "Back",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.mifos.core.ui.util

internal const val PROFILE_SHOULD_REFRESH_KEY = "profile_should_refresh"
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,11 @@
<string name="confirm_text">I Confirm</string>
<string name="dismiss_text">Cancel</string>
<string name="dialog_continue">Continue</string>
<string name="update_success_message">Your profile image has been updated successfully!</string>
<string name="profile_update_error_message">We couldn’t update your profile image. Please try again.</string>
<string name="profile_should_refresh">should refresh</string>
<string name="success">Success</string>
<string name="failure">Failure</string>

<!-- Assign Staff Screen -->
<string name="label_assign_staff">Assign Staff</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import androidclient.feature.client.generated.resources.dialog_continue
import androidclient.feature.client.generated.resources.dialog_unassign_message
import androidclient.feature.client.generated.resources.dismiss_text
import androidclient.feature.client.generated.resources.pen_icon
import androidclient.feature.client.generated.resources.profile_should_refresh
import androidclient.feature.client.generated.resources.scroll_for_more_options
import androidclient.feature.client.generated.resources.staff_unassign_failure_title
import androidclient.feature.client.generated.resources.staff_unassign_success_message
Expand All @@ -44,7 +45,9 @@ import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand All @@ -67,6 +70,7 @@ import com.mifos.core.ui.util.TextUtil
import com.mifos.feature.client.clientDetailsProfile.components.ClientDetailsProfile
import com.mifos.feature.client.clientDetailsProfile.components.ClientProfileDetailsActionItem
import com.mifos.feature.client.clientDetailsProfile.components.clientsDetailsActionItems
import com.mifos.feature.client.utils.PROFILE_SHOULD_REFRESH_KEY
import org.jetbrains.compose.resources.painterResource
import org.jetbrains.compose.resources.stringResource
import org.koin.compose.viewmodel.koinViewModel
Expand All @@ -88,6 +92,20 @@ internal fun ClientProfileDetailsScreen(
viewModel: ClientProfileDetailsViewModel = koinViewModel(),
) {
val state by viewModel.stateFlow.collectAsStateWithLifecycle()
val currentBackStackEntry = navController.currentBackStackEntry
val savedStateHandle = currentBackStackEntry?.savedStateHandle

val profileUpdated by savedStateHandle
?.getStateFlow(PROFILE_SHOULD_REFRESH_KEY, false)
?.collectAsStateWithLifecycle(initialValue = false)
?: remember { mutableStateOf(false) }

LaunchedEffect(profileUpdated) {
if (profileUpdated) {
viewModel.trySendAction(ClientProfileDetailsAction.OnRetry)
savedStateHandle?.set(PROFILE_SHOULD_REFRESH_KEY, false)
}
}

EventsEffect(viewModel.eventFlow) { event ->
when (event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@ import androidclient.feature.client.generated.resources.choose_from_option
import androidclient.feature.client.generated.resources.delete_dialog_message
import androidclient.feature.client.generated.resources.delete_dialog_title
import androidclient.feature.client.generated.resources.delete_photo
import androidclient.feature.client.generated.resources.dialog_continue
import androidclient.feature.client.generated.resources.edit_profile_title
import androidclient.feature.client.generated.resources.feature_client_Image_Upload_Failed
import androidclient.feature.client.generated.resources.feature_client_Image_Upload_Successful
import androidclient.feature.client.generated.resources.from_camera
import androidclient.feature.client.generated.resources.from_gallery
import androidclient.feature.client.generated.resources.profile_update_error_message
import androidclient.feature.client.generated.resources.remove
import androidclient.feature.client.generated.resources.update_profile_photo_message
import androidclient.feature.client.generated.resources.update_success_message
import androidclient.feature.client.generated.resources.upload_new_photo
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
Expand All @@ -48,8 +53,10 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.navigation.NavController
import com.mifos.core.designsystem.component.BasicDialogState
import com.mifos.core.designsystem.component.MifosBasicDialog
import com.mifos.core.designsystem.component.MifosDialogStatus
import com.mifos.core.designsystem.component.MifosOutlinedButton
import com.mifos.core.designsystem.component.MifosScaffold
import com.mifos.core.designsystem.component.MifosStatusDialog
import com.mifos.core.designsystem.component.MifosTextButton
import com.mifos.core.designsystem.icon.MifosIcons
import com.mifos.core.designsystem.theme.DesignToken
Expand All @@ -76,15 +83,6 @@ internal fun ClientProfileEditScreen(
) {
val state by viewModel.stateFlow.collectAsStateWithLifecycle()

EventsEffect(viewModel.eventFlow) { event ->
when (event) {
ClientProfileEditEvent.NavigateBack -> onNavigateBack()
ClientProfileEditEvent.OnSaveSuccess -> {
onNavigateBack()
}
}
}

ClientProfileEditScaffold(
modifier = modifier,
state = state,
Expand Down Expand Up @@ -198,11 +196,18 @@ private fun ClientProfileEditDialogs(
is ClientProfileEditState.DialogState.Loading -> MifosProgressIndicator()

is ClientProfileEditState.DialogState.Error -> {
MifosErrorComponent(
isNetworkConnected = state.networkConnection,
message = state.dialogState.message,
isRetryEnabled = true,
onRetry = onRetry,
MifosStatusDialog(
status = MifosDialogStatus.FAILURE,
message = stringResource(Res.string.profile_update_error_message),
onDismissRequest = { onAction(ClientProfileEditAction.DismissModalBottomSheet) }
)
}

is ClientProfileEditState.DialogState.Success -> {
MifosStatusDialog(
status = MifosDialogStatus.SUCCESS,
message = stringResource(Res.string.update_success_message),
onDismissRequest = { onAction(ClientProfileEditAction.DismissModalBottomSheet) }
)
}

Expand Down
Loading