From 5061d3724b6fcd09d01b04b75e055955745f6577 Mon Sep 17 00:00:00 2001 From: ThomasSession Date: Fri, 12 Jul 2024 11:02:46 +1000 Subject: [PATCH] Dialogs do not have a 'x' button by default --- .../securesms/onboarding/landing/Landing.kt | 1 + .../thoughtcrime/securesms/ui/AlertDialog.kt | 79 ++++++++++++++++--- 2 files changed, 69 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/onboarding/landing/Landing.kt b/app/src/main/java/org/thoughtcrime/securesms/onboarding/landing/Landing.kt index f9b5eff141..00d39fdce1 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/onboarding/landing/Landing.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/onboarding/landing/Landing.kt @@ -79,6 +79,7 @@ internal fun LandingScreen( onDismissRequest = { isUrlDialogVisible = false }, title = stringResource(R.string.urlOpen), text = stringResource(R.string.urlOpenBrowser), + showCloseButton = true, // display the 'x' button buttons = listOf( DialogButtonModel( text = GetString(R.string.activity_landing_terms_of_service), diff --git a/app/src/main/java/org/thoughtcrime/securesms/ui/AlertDialog.kt b/app/src/main/java/org/thoughtcrime/securesms/ui/AlertDialog.kt index bc3abcce5a..0911284d9f 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/ui/AlertDialog.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/ui/AlertDialog.kt @@ -1,5 +1,6 @@ package org.thoughtcrime.securesms.ui +import androidx.compose.foundation.background import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.IntrinsicSize @@ -20,14 +21,19 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.RectangleShape import androidx.compose.ui.graphics.takeOrElse import androidx.compose.ui.res.painterResource +import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp import network.loki.messenger.R import org.thoughtcrime.securesms.ui.theme.LocalColors import org.thoughtcrime.securesms.ui.theme.LocalDimensions +import org.thoughtcrime.securesms.ui.theme.PreviewTheme import org.thoughtcrime.securesms.ui.theme.h7 import org.thoughtcrime.securesms.ui.theme.large import org.thoughtcrime.securesms.ui.theme.largeBold + class DialogButtonModel( val text: GetString, val contentDescription: GetString = text, @@ -41,8 +47,9 @@ fun AlertDialog( onDismissRequest: () -> Unit, title: String? = null, text: String? = null, - content: @Composable () -> Unit = {}, - buttons: List? = null + buttons: List? = null, + showCloseButton: Boolean = false, + content: @Composable () -> Unit = {} ) { androidx.compose.material.AlertDialog( onDismissRequest, @@ -50,15 +57,18 @@ fun AlertDialog( backgroundColor = LocalColors.current.backgroundSecondary, buttons = { Box { - IconButton( - onClick = onDismissRequest, - modifier = Modifier.align(Alignment.TopEnd) - ) { - Icon( - painter = painterResource(id = R.drawable.ic_dialog_x), - tint = LocalColors.current.text, - contentDescription = "back" - ) + // only show the 'x' button is required + if(showCloseButton) { + IconButton( + onClick = onDismissRequest, + modifier = Modifier.align(Alignment.TopEnd) + ) { + Icon( + painter = painterResource(id = R.drawable.ic_dialog_x), + tint = LocalColors.current.text, + contentDescription = "back" + ) + } } Column(modifier = Modifier.fillMaxWidth()) { @@ -129,3 +139,50 @@ fun DialogButton(text: String, modifier: Modifier, color: Color = Color.Unspecif ) } } + +@Preview +@Composable +fun PreviewSimpleDialog(){ + PreviewTheme { + AlertDialog( + onDismissRequest = {}, + title = stringResource(R.string.warning), + text = stringResource(R.string.you_cannot_go_back_further_in_order_to_stop_loading_your_account_session_needs_to_quit), + buttons = listOf( + DialogButtonModel( + GetString(stringResource(R.string.quit)), + color = LocalColors.current.danger, + onClick = {} + ), + DialogButtonModel( + GetString(stringResource(R.string.cancel)) + ) + ) + ) + } +} + +@Preview +@Composable +fun PreviewXCloseDialog(){ + PreviewTheme { + AlertDialog( + title = stringResource(R.string.urlOpen), + text = stringResource(R.string.urlOpenBrowser), + showCloseButton = true, // display the 'x' button + buttons = listOf( + DialogButtonModel( + text = GetString(R.string.activity_landing_terms_of_service), + contentDescription = GetString(R.string.AccessibilityId_terms_of_service_button), + onClick = {} + ), + DialogButtonModel( + text = GetString(R.string.activity_landing_privacy_policy), + contentDescription = GetString(R.string.AccessibilityId_privacy_policy_button), + onClick = {} + ) + ), + onDismissRequest = {} + ) + } +}