Skip to content

Commit b7b1568

Browse files
committed
feat: extend func. of app alert dialog to edit dialog
1 parent a84c856 commit b7b1568

File tree

3 files changed

+57
-14
lines changed

3 files changed

+57
-14
lines changed

core/designsystem/src/main/kotlin/com/espressodev/gptmap/core/designsystem/component/Dialog.kt

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,71 @@ import androidx.compose.material3.Icon
66
import androidx.compose.material3.Text
77
import androidx.compose.material3.TextButton
88
import androidx.compose.runtime.Composable
9+
import androidx.compose.runtime.mutableStateOf
10+
import androidx.compose.runtime.saveable.rememberSaveable
911
import androidx.compose.ui.Modifier
1012
import androidx.compose.ui.graphics.vector.ImageVector
1113
import androidx.compose.ui.res.stringResource
12-
import androidx.compose.ui.text.style.TextAlign
14+
import com.espressodev.gptmap.core.designsystem.GmIcons
1315
import com.espressodev.gptmap.core.designsystem.R.string as AppText
1416

1517
@Composable
16-
fun AppAlertDialog(
17-
icon: ImageVector,
18+
fun GmAlertDialog(
1819
@StringRes title: Int,
19-
@StringRes text: Int,
2020
onConfirm: () -> Unit,
2121
onDismiss: () -> Unit,
22+
text: @Composable () -> Unit,
2223
modifier: Modifier = Modifier,
24+
icon: ImageVector? = null,
2325
) {
26+
val dialogIcon: @Composable (() -> Unit)? = when (icon) {
27+
null -> null
28+
else -> {
29+
{ Icon(imageVector = icon, contentDescription = null) }
30+
}
31+
}
2432
AlertDialog(
25-
icon = { Icon(icon, null) },
33+
icon = dialogIcon,
2634
title = { Text(stringResource(title)) },
27-
text = { Text(stringResource(text), textAlign = TextAlign.Center) },
35+
text = text,
2836
onDismissRequest = onDismiss,
2937
confirmButton = {
30-
TextButton(onClick = {
31-
onConfirm()
32-
}) { Text(stringResource(AppText.confirm)) }
38+
TextButton(onClick = onConfirm) { Text(stringResource(AppText.confirm)) }
3339
},
3440
dismissButton = {
3541
TextButton(onClick = onDismiss) { Text(stringResource(AppText.dismiss)) }
3642
},
3743
modifier = modifier
3844
)
3945
}
46+
47+
@Composable
48+
fun GmEditAlertDialog(
49+
@StringRes title: Int,
50+
@StringRes textFieldLabel: Int,
51+
onConfirm: (String) -> Unit,
52+
onDismiss: () -> Unit
53+
) {
54+
val (text, onValueChange) = rememberSaveable { mutableStateOf("") }
55+
val (isError, setIsError) = rememberSaveable { mutableStateOf(value = false) }
56+
GmAlertDialog(
57+
title = title,
58+
onConfirm = {
59+
if (text.isNotBlank()) {
60+
onConfirm(text)
61+
} else {
62+
setIsError(true)
63+
}
64+
},
65+
onDismiss = onDismiss,
66+
text = {
67+
DefaultTextField(
68+
value = text,
69+
label = textFieldLabel,
70+
leadingIcon = GmIcons.EditDefault,
71+
onValueChange = onValueChange,
72+
isError = isError
73+
)
74+
}
75+
)
76+
}

core/designsystem/src/main/kotlin/com/espressodev/gptmap/core/designsystem/component/TextField.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ fun MapTextField(
6363
overflow = TextOverflow.Ellipsis
6464
)
6565
},
66-
modifier = modifier.height(52.dp).shadow(4.dp, shape),
66+
modifier = modifier
67+
.height(52.dp)
68+
.shadow(4.dp, shape),
6769
trailingIcon = {
6870
if (shouldShownClearIcon) {
6971
IconButton(onClick = { onValueChange("") }) {
@@ -104,6 +106,7 @@ fun DefaultTextField(
104106
onValueChange: (String) -> Unit,
105107
modifier: Modifier = Modifier,
106108
enabled: Boolean = true,
109+
isError: Boolean = false,
107110
) {
108111
val showClearIcon by remember(value) { derivedStateOf { value.isNotEmpty() } }
109112
OutlinedTextField(
@@ -117,14 +120,13 @@ fun DefaultTextField(
117120
},
118121
trailingIcon = {
119122
if (showClearIcon) {
120-
IconButton(onClick = {
121-
onValueChange("")
122-
}) {
123+
IconButton(onClick = { onValueChange("") }) {
123124
Icon(GmIcons.CancelOutlined, null)
124125
}
125126
}
126127
},
127-
onValueChange = onValueChange
128+
onValueChange = onValueChange,
129+
isError = isError,
128130
)
129131
}
130132

core/designsystem/src/main/res/values/strings.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,8 @@
104104

105105
<!-- Profile -->
106106
<string name="profile_top_bar_header">Profile</string>
107+
108+
<!-- Screenshot Gallery -->
109+
<string name="screenshot_gallery_edit_dialog_title">Rename Screenshot</string>
110+
<string name="screenshot_gallery_edit_dialog_text_field_placeholder">Enter new name</string>
107111
</resources>

0 commit comments

Comments
 (0)