|
| 1 | +/* |
| 2 | + * Copyright 2024 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-wallet/blob/master/LICENSE.md |
| 9 | + */ |
| 10 | +package org.mifospay.feature.send.money |
| 11 | + |
| 12 | +import androidx.compose.foundation.layout.Arrangement |
| 13 | +import androidx.compose.foundation.layout.Column |
| 14 | +import androidx.compose.foundation.layout.Spacer |
| 15 | +import androidx.compose.foundation.layout.fillMaxWidth |
| 16 | +import androidx.compose.foundation.layout.height |
| 17 | +import androidx.compose.foundation.layout.padding |
| 18 | +import androidx.compose.foundation.layout.size |
| 19 | +import androidx.compose.material3.AlertDialog |
| 20 | +import androidx.compose.material3.ButtonDefaults |
| 21 | +import androidx.compose.material3.Card |
| 22 | +import androidx.compose.material3.CardDefaults |
| 23 | +import androidx.compose.material3.Icon |
| 24 | +import androidx.compose.material3.IconButton |
| 25 | +import androidx.compose.material3.IconButtonDefaults |
| 26 | +import androidx.compose.material3.ListItem |
| 27 | +import androidx.compose.material3.ListItemDefaults |
| 28 | +import androidx.compose.material3.Text |
| 29 | +import androidx.compose.material3.TextButton |
| 30 | +import androidx.compose.runtime.Composable |
| 31 | +import androidx.compose.ui.Modifier |
| 32 | +import androidx.compose.ui.text.style.TextAlign |
| 33 | +import androidx.compose.ui.unit.dp |
| 34 | +import org.mifospay.core.designsystem.component.MifosButton |
| 35 | +import org.mifospay.core.designsystem.icon.MifosIcons |
| 36 | +import template.core.base.designsystem.theme.KptTheme |
| 37 | + |
| 38 | +@Composable |
| 39 | +fun ContactNotFoundDialog( |
| 40 | + showDialog: Boolean, |
| 41 | + selectedOption: SharingOption, |
| 42 | + onOptionSelected: (SharingOption) -> Unit, |
| 43 | + onNotNowClick: () -> Unit, |
| 44 | + onSetAsDefaultClick: () -> Unit, |
| 45 | + onDismiss: () -> Unit, |
| 46 | + modifier: Modifier = Modifier, |
| 47 | +) { |
| 48 | + if (showDialog) { |
| 49 | + AlertDialog( |
| 50 | + onDismissRequest = onDismiss, |
| 51 | + modifier = modifier, |
| 52 | + title = { |
| 53 | + Text( |
| 54 | + text = "Set preferred ways to share", |
| 55 | + style = KptTheme.typography.headlineSmall, |
| 56 | + color = KptTheme.colorScheme.onSurface, |
| 57 | + ) |
| 58 | + }, |
| 59 | + text = { |
| 60 | + Column( |
| 61 | + modifier = Modifier.fillMaxWidth(), |
| 62 | + verticalArrangement = Arrangement.spacedBy(KptTheme.spacing.md), |
| 63 | + ) { |
| 64 | + Text( |
| 65 | + text = "Your choice will be recommended for future sharing of any contact.", |
| 66 | + style = KptTheme.typography.bodyMedium, |
| 67 | + color = KptTheme.colorScheme.onSurface.copy(alpha = 0.7f), |
| 68 | + textAlign = TextAlign.Start, |
| 69 | + ) |
| 70 | + |
| 71 | + Spacer(modifier = Modifier.height(KptTheme.spacing.sm)) |
| 72 | + |
| 73 | + SharingOptionItem( |
| 74 | + option = SharingOption.WHATSAPP, |
| 75 | + title = "WhatsApp", |
| 76 | + subtitle = "Share via WhatsApp", |
| 77 | + isSelected = selectedOption == SharingOption.WHATSAPP, |
| 78 | + onClick = { onOptionSelected(SharingOption.WHATSAPP) }, |
| 79 | + ) |
| 80 | + |
| 81 | + SharingOptionItem( |
| 82 | + option = SharingOption.SMS, |
| 83 | + title = "SMS", |
| 84 | + subtitle = "Share via SMS", |
| 85 | + isSelected = selectedOption == SharingOption.SMS, |
| 86 | + onClick = { onOptionSelected(SharingOption.SMS) }, |
| 87 | + ) |
| 88 | + } |
| 89 | + }, |
| 90 | + confirmButton = { |
| 91 | + MifosButton( |
| 92 | + onClick = onSetAsDefaultClick, |
| 93 | + modifier = Modifier.fillMaxWidth(), |
| 94 | + colors = ButtonDefaults.buttonColors( |
| 95 | + containerColor = KptTheme.colorScheme.primary, |
| 96 | + contentColor = KptTheme.colorScheme.onPrimary, |
| 97 | + ), |
| 98 | + ) { |
| 99 | + Text( |
| 100 | + text = "Set as default", |
| 101 | + style = KptTheme.typography.labelLarge, |
| 102 | + ) |
| 103 | + } |
| 104 | + }, |
| 105 | + dismissButton = { |
| 106 | + TextButton( |
| 107 | + onClick = onNotNowClick, |
| 108 | + modifier = Modifier.fillMaxWidth(), |
| 109 | + ) { |
| 110 | + Text( |
| 111 | + text = "Not now", |
| 112 | + style = KptTheme.typography.labelLarge, |
| 113 | + color = KptTheme.colorScheme.primary, |
| 114 | + ) |
| 115 | + } |
| 116 | + }, |
| 117 | + containerColor = KptTheme.colorScheme.surface, |
| 118 | + shape = KptTheme.shapes.large, |
| 119 | + ) |
| 120 | + } |
| 121 | +} |
| 122 | + |
| 123 | +@Composable |
| 124 | +private fun SharingOptionItem( |
| 125 | + option: SharingOption, |
| 126 | + title: String, |
| 127 | + subtitle: String, |
| 128 | + isSelected: Boolean, |
| 129 | + onClick: () -> Unit, |
| 130 | + modifier: Modifier = Modifier, |
| 131 | +) { |
| 132 | + Card( |
| 133 | + modifier = modifier |
| 134 | + .fillMaxWidth() |
| 135 | + .padding(vertical = 2.dp), |
| 136 | + shape = KptTheme.shapes.small, |
| 137 | + colors = CardDefaults.cardColors( |
| 138 | + containerColor = if (isSelected) { |
| 139 | + KptTheme.colorScheme.primaryContainer |
| 140 | + } else { |
| 141 | + KptTheme.colorScheme.surface |
| 142 | + }, |
| 143 | + ), |
| 144 | + elevation = CardDefaults.cardElevation( |
| 145 | + defaultElevation = if (isSelected) 2.dp else 0.dp, |
| 146 | + ), |
| 147 | + ) { |
| 148 | + ListItem( |
| 149 | + headlineContent = { |
| 150 | + Text( |
| 151 | + text = title, |
| 152 | + style = KptTheme.typography.bodyLarge, |
| 153 | + color = if (isSelected) { |
| 154 | + KptTheme.colorScheme.onPrimaryContainer |
| 155 | + } else { |
| 156 | + KptTheme.colorScheme.onSurface |
| 157 | + }, |
| 158 | + ) |
| 159 | + }, |
| 160 | + supportingContent = { |
| 161 | + Text( |
| 162 | + text = subtitle, |
| 163 | + style = KptTheme.typography.bodyMedium, |
| 164 | + color = if (isSelected) { |
| 165 | + KptTheme.colorScheme.onPrimaryContainer.copy(alpha = 0.7f) |
| 166 | + } else { |
| 167 | + KptTheme.colorScheme.onSurface.copy(alpha = 0.7f) |
| 168 | + }, |
| 169 | + ) |
| 170 | + }, |
| 171 | + leadingContent = { |
| 172 | + Icon( |
| 173 | + imageVector = when (option) { |
| 174 | + SharingOption.WHATSAPP -> MifosIcons.Share |
| 175 | + SharingOption.SMS -> MifosIcons.Share |
| 176 | + }, |
| 177 | + contentDescription = title, |
| 178 | + modifier = Modifier.size(24.dp), |
| 179 | + tint = if (isSelected) { |
| 180 | + KptTheme.colorScheme.onPrimaryContainer |
| 181 | + } else { |
| 182 | + KptTheme.colorScheme.onSurface.copy(alpha = 0.7f) |
| 183 | + }, |
| 184 | + ) |
| 185 | + }, |
| 186 | + trailingContent = { |
| 187 | + IconButton( |
| 188 | + onClick = onClick, |
| 189 | + colors = IconButtonDefaults.iconButtonColors( |
| 190 | + contentColor = if (isSelected) { |
| 191 | + KptTheme.colorScheme.onPrimaryContainer |
| 192 | + } else { |
| 193 | + KptTheme.colorScheme.onSurface.copy(alpha = 0.7f) |
| 194 | + }, |
| 195 | + ), |
| 196 | + ) { |
| 197 | + Icon( |
| 198 | + imageVector = if (isSelected) { |
| 199 | + MifosIcons.RadioButtonChecked |
| 200 | + } else { |
| 201 | + MifosIcons.RadioButtonUnchecked |
| 202 | + }, |
| 203 | + contentDescription = if (isSelected) "Selected" else "Not selected", |
| 204 | + modifier = Modifier.size(20.dp), |
| 205 | + ) |
| 206 | + } |
| 207 | + }, |
| 208 | + colors = ListItemDefaults.colors( |
| 209 | + containerColor = androidx.compose.ui.graphics.Color.Transparent, |
| 210 | + ), |
| 211 | + ) |
| 212 | + } |
| 213 | +} |
0 commit comments