1
1
package org.mifos.mobilewallet.mifospay.settings.ui
2
2
3
- import MifosDialogBox
4
3
import androidx.compose.foundation.background
5
4
import androidx.compose.foundation.layout.Column
6
5
import androidx.compose.foundation.layout.Row
@@ -27,14 +26,26 @@ import org.mifos.mobilewallet.mifospay.designsystem.component.MifosItemCard
27
26
import org.mifos.mobilewallet.mifospay.designsystem.component.MifosTopBar
28
27
import org.mifos.mobilewallet.mifospay.designsystem.theme.mifosText
29
28
import org.mifos.mobilewallet.mifospay.designsystem.theme.styleSettingsButton
29
+ import org.mifos.mobilewallet.mifospay.ui.utility.DialogState
30
+ import org.mifos.mobilewallet.mifospay.ui.utility.DialogType
31
+
32
+ /* *
33
+ * @author pratyush
34
+ * @since 12/02/2024
35
+ */
30
36
31
37
@Composable
32
38
fun SettingsScreen (
33
39
backPress : () -> Unit ,
34
40
disable : () -> Unit ,
35
41
logout : () -> Unit
36
42
) {
37
- var currentDialog by remember { mutableStateOf(DialogType .NONE ) }
43
+ var dialogState by remember { mutableStateOf(DialogState ()) }
44
+
45
+ DialogManager (
46
+ dialogState = dialogState,
47
+ onDismiss = { dialogState = DialogState (type = DialogType .NONE ) }
48
+ )
38
49
39
50
Scaffold (
40
51
topBar = {
@@ -69,7 +80,12 @@ fun SettingsScreen(
69
80
70
81
Row (modifier = Modifier .padding(8 .dp)) {
71
82
MifosItemCard (
72
- onClick = { currentDialog = DialogType .DISABLE_ACCOUNT },
83
+ onClick = {
84
+ dialogState = DialogState (
85
+ type = DialogType .DISABLE_ACCOUNT ,
86
+ onConfirm = { disable.invoke() }
87
+ )
88
+ },
73
89
colors = CardDefaults .cardColors(Color .Black )
74
90
) {
75
91
Text (
@@ -84,7 +100,12 @@ fun SettingsScreen(
84
100
85
101
Row (modifier = Modifier .padding(8 .dp)) {
86
102
MifosItemCard (
87
- onClick = { currentDialog = DialogType .LOGOUT },
103
+ onClick = {
104
+ dialogState = DialogState (
105
+ type = DialogType .LOGOUT ,
106
+ onConfirm = { logout() }
107
+ )
108
+ },
88
109
colors = CardDefaults .cardColors(Color .Black )
89
110
) {
90
111
Text (
@@ -99,40 +120,6 @@ fun SettingsScreen(
99
120
}
100
121
}
101
122
102
- if (currentDialog != DialogType .NONE ) {
103
- MifosDialogBox (
104
- showDialog = true ,
105
- onDismiss = { currentDialog = DialogType .NONE },
106
- title = when (currentDialog) {
107
- DialogType .DISABLE_ACCOUNT -> R .string.alert_disable_account
108
- DialogType .LOGOUT -> R .string.log_out_title
109
- else -> R .string.empty
110
- },
111
- message = when (currentDialog) {
112
- DialogType .DISABLE_ACCOUNT -> R .string.alert_disable_account_desc
113
- else -> R .string.empty
114
- },
115
- confirmButtonText = when (currentDialog) {
116
- DialogType .DISABLE_ACCOUNT -> R .string.ok
117
- DialogType .LOGOUT -> R .string.yes
118
- else -> R .string.empty
119
- },
120
- dismissButtonText = when (currentDialog) {
121
- DialogType .DISABLE_ACCOUNT -> R .string.cancel
122
- DialogType .LOGOUT -> R .string.no
123
- else -> R .string.empty
124
- },
125
- onConfirm = {
126
- when (currentDialog) {
127
- DialogType .DISABLE_ACCOUNT -> disable()
128
- DialogType .LOGOUT -> logout()
129
- else -> {}
130
- }
131
- currentDialog = DialogType .NONE
132
- }
133
- )
134
- }
135
-
136
123
}
137
124
138
125
@Preview(showSystemUi = true )
0 commit comments