|
| 1 | +/* |
| 2 | + * Copyright 2025 Mifos Initiative |
| 3 | + * |
| 4 | + * This Source Code Form is subject to the terms of the Mozilla Public |
| 5 | + * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 6 | + * file, You can obtain one at https://mozilla.org/MPL/2.0/. |
| 7 | + * |
| 8 | + * See https://github.com/openMF/mobile-mobile/blob/master/LICENSE.md |
| 9 | + */ |
| 10 | +package org.mifos.mobile.feature.settings.componenets |
| 11 | + |
| 12 | +import androidx.compose.foundation.clickable |
| 13 | +import androidx.compose.foundation.layout.Arrangement |
| 14 | +import androidx.compose.foundation.layout.Column |
| 15 | +import androidx.compose.foundation.layout.Row |
| 16 | +import androidx.compose.foundation.layout.fillMaxWidth |
| 17 | +import androidx.compose.foundation.layout.height |
| 18 | +import androidx.compose.material3.AlertDialog |
| 19 | +import androidx.compose.material3.MaterialTheme |
| 20 | +import androidx.compose.material3.Text |
| 21 | +import androidx.compose.runtime.Composable |
| 22 | +import androidx.compose.ui.Alignment |
| 23 | +import androidx.compose.ui.Modifier |
| 24 | +import androidx.compose.ui.graphics.Color |
| 25 | +import androidx.compose.ui.platform.testTag |
| 26 | +import mifos_mobile.feature.settings.generated.resources.Res |
| 27 | +import mifos_mobile.feature.settings.generated.resources.feature_settings_logout_action |
| 28 | +import mifos_mobile.feature.settings.generated.resources.feature_settings_logout_description |
| 29 | +import mifos_mobile.feature.settings.generated.resources.feature_settings_logout_message |
| 30 | +import mifos_mobile.feature.settings.generated.resources.feature_settings_logout_now |
| 31 | +import mifos_mobile.feature.settings.generated.resources.feature_settings_logout_title |
| 32 | +import org.jetbrains.compose.resources.StringResource |
| 33 | +import org.jetbrains.compose.resources.stringResource |
| 34 | +import org.jetbrains.compose.ui.tooling.preview.Preview |
| 35 | +import org.mifos.mobile.core.designsystem.component.MifosButton |
| 36 | +import org.mifos.mobile.core.designsystem.theme.AppColors |
| 37 | +import org.mifos.mobile.core.designsystem.theme.DesignToken |
| 38 | +import org.mifos.mobile.core.designsystem.theme.MifosTypography |
| 39 | + |
| 40 | +@Composable |
| 41 | +fun MifosLogoutDialog( |
| 42 | + visibilityState: LogoutDialogState, |
| 43 | +): Unit = when (visibilityState) { |
| 44 | + LogoutDialogState.Hidden -> Unit |
| 45 | + is LogoutDialogState.Shown -> { |
| 46 | + AlertDialog( |
| 47 | + onDismissRequest = visibilityState.onDismiss, |
| 48 | + confirmButton = { |
| 49 | + Column( |
| 50 | + horizontalAlignment = Alignment.CenterHorizontally, |
| 51 | + verticalArrangement = Arrangement.spacedBy( |
| 52 | + space = DesignToken.spacing.medium, |
| 53 | + alignment = Alignment.CenterVertically, |
| 54 | + ), |
| 55 | + ) { |
| 56 | + MifosButton( |
| 57 | + modifier = Modifier |
| 58 | + .fillMaxWidth() |
| 59 | + .height(DesignToken.sizes.buttonHeight), |
| 60 | + shape = DesignToken.shapes.medium, |
| 61 | + onClick = visibilityState.onLogout, |
| 62 | + ) { |
| 63 | + Text( |
| 64 | + text = stringResource(Res.string.feature_settings_logout_now), |
| 65 | + style = MifosTypography.titleMedium, |
| 66 | + ) |
| 67 | + } |
| 68 | + |
| 69 | + Row( |
| 70 | + modifier = Modifier.fillMaxWidth(), |
| 71 | + verticalAlignment = Alignment.CenterVertically, |
| 72 | + horizontalArrangement = Arrangement.spacedBy( |
| 73 | + space = DesignToken.spacing.extraSmall, |
| 74 | + alignment = Alignment.CenterHorizontally, |
| 75 | + ), |
| 76 | + ) { |
| 77 | + Text( |
| 78 | + text = stringResource(visibilityState.message), |
| 79 | + style = MifosTypography.bodySmallEmphasized, |
| 80 | + color = MaterialTheme.colorScheme.secondary, |
| 81 | + ) |
| 82 | + |
| 83 | + Text( |
| 84 | + text = stringResource(visibilityState.messageActionText), |
| 85 | + style = MifosTypography.bodySmallEmphasized, |
| 86 | + color = MaterialTheme.colorScheme.primary, |
| 87 | + modifier = Modifier.clickable { |
| 88 | + visibilityState.onNavigateToHome.invoke() |
| 89 | + }, |
| 90 | + ) |
| 91 | + } |
| 92 | + } |
| 93 | + }, |
| 94 | + title = { |
| 95 | + Text( |
| 96 | + text = stringResource(visibilityState.title), |
| 97 | + style = MifosTypography.headlineSmallEmphasized, |
| 98 | + color = AppColors.customBlack, |
| 99 | + modifier = Modifier |
| 100 | + .fillMaxWidth() |
| 101 | + .testTag("AlertTitleText"), |
| 102 | + ) |
| 103 | + }, |
| 104 | + text = { |
| 105 | + Text( |
| 106 | + text = stringResource(visibilityState.description), |
| 107 | + style = MifosTypography.labelMediumEmphasized, |
| 108 | + color = MaterialTheme.colorScheme.secondary, |
| 109 | + modifier = Modifier |
| 110 | + .fillMaxWidth() |
| 111 | + .testTag("AlertContentText"), |
| 112 | + ) |
| 113 | + }, |
| 114 | + containerColor = Color.White, |
| 115 | + shape = DesignToken.shapes.medium, |
| 116 | + ) |
| 117 | + } |
| 118 | +} |
| 119 | + |
| 120 | +sealed interface LogoutDialogState { |
| 121 | + |
| 122 | + data object Hidden : LogoutDialogState |
| 123 | + |
| 124 | + data class Shown( |
| 125 | + val description: StringResource, |
| 126 | + val title: StringResource, |
| 127 | + val message: StringResource, |
| 128 | + val messageActionText: StringResource, |
| 129 | + val onLogout: () -> Unit, |
| 130 | + val onNavigateToHome: () -> Unit, |
| 131 | + val onDismiss: () -> Unit, |
| 132 | + ) : LogoutDialogState |
| 133 | +} |
| 134 | + |
| 135 | +@Preview |
| 136 | +@Composable |
| 137 | +fun MifosLogoutDialogPreview() { |
| 138 | + MifosLogoutDialog( |
| 139 | + visibilityState = LogoutDialogState.Shown( |
| 140 | + description = Res.string.feature_settings_logout_description, |
| 141 | + title = Res.string.feature_settings_logout_title, |
| 142 | + message = Res.string.feature_settings_logout_message, |
| 143 | + messageActionText = Res.string.feature_settings_logout_action, |
| 144 | + onLogout = { }, |
| 145 | + onNavigateToHome = { }, |
| 146 | + onDismiss = { }, |
| 147 | + ), |
| 148 | + ) |
| 149 | +} |
0 commit comments