From 0c83db08552e6727dd544c5b17b90fc9ecb4f1fa Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 17 Jun 2024 17:23:02 +0930 Subject: [PATCH] Use new Compose AlertDialog in LandingActivity --- .../securesms/onboarding/LandingActivity.kt | 39 ++++---- .../thoughtcrime/securesms/ui/AlertDialog.kt | 89 +++++++++++++++++++ .../securesms/ui/SessionTypography.kt | 1 + 3 files changed, 114 insertions(+), 15 deletions(-) create mode 100644 app/src/main/java/org/thoughtcrime/securesms/ui/AlertDialog.kt diff --git a/app/src/main/java/org/thoughtcrime/securesms/onboarding/LandingActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/onboarding/LandingActivity.kt index 1d353fb102..22de24c887 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/onboarding/LandingActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/onboarding/LandingActivity.kt @@ -45,7 +45,9 @@ import org.thoughtcrime.securesms.BaseActionBarActivity import org.thoughtcrime.securesms.crypto.IdentityKeyUtil import org.thoughtcrime.securesms.onboarding.pickname.startPickDisplayNameActivity import org.thoughtcrime.securesms.service.KeyCachingService -import org.thoughtcrime.securesms.showOpenUrlDialog +import org.thoughtcrime.securesms.ui.AlertDialog +import org.thoughtcrime.securesms.ui.DialogButtonModel +import org.thoughtcrime.securesms.ui.GetString import org.thoughtcrime.securesms.ui.LocalDimensions import org.thoughtcrime.securesms.ui.PreviewTheme import org.thoughtcrime.securesms.ui.SessionColorsParameterProvider @@ -107,6 +109,26 @@ class LandingActivity: BaseActionBarActivity() { var count by remember { mutableStateOf(0) } val listState = rememberLazyListState() + var isUrlDialogVisible by remember { mutableStateOf(false) } + + if (isUrlDialogVisible) { + AlertDialog( + onDismissRequest = { isUrlDialogVisible = false }, + title = stringResource(R.string.urlOpen), + text = stringResource(R.string.urlOpenBrowser), + buttons = listOf( + DialogButtonModel( + GetString(R.string.activity_landing_terms_of_service), + GetString(R.string.AccessibilityId_terms_of_service_button), + ) { open("https://getsession.org/terms-of-service") }, + DialogButtonModel( + GetString(R.string.activity_landing_privacy_policy), + GetString(R.string.AccessibilityId_privacy_policy_button), + ) { open("https://getsession.org/privacy-policy") } + ) + ) + } + LaunchedEffect(Unit) { delay(500.milliseconds) while(count < MESSAGES.size) { @@ -175,26 +197,13 @@ class LandingActivity: BaseActionBarActivity() { .fillMaxWidth() .align(Alignment.CenterHorizontally) .contentDescription(R.string.AccessibilityId_open_url), - onClick = ::openDialog + onClick = { isUrlDialogVisible = true } ) Spacer(modifier = Modifier.height(LocalDimensions.current.itemSpacingExtraSmall)) } } } - private fun openDialog() { - showOpenUrlDialog { - button( - R.string.activity_landing_terms_of_service, - contentDescriptionRes = R.string.AccessibilityId_terms_of_service_button - ) { open("https://getsession.org/terms-of-service") } - button( - R.string.activity_landing_privacy_policy, - contentDescriptionRes = R.string.AccessibilityId_privacy_policy_button - ) { open("https://getsession.org/privacy-policy") } - } - } - private fun open(url: String) { Intent(Intent.ACTION_VIEW, Uri.parse(url)).let(::startActivity) } diff --git a/app/src/main/java/org/thoughtcrime/securesms/ui/AlertDialog.kt b/app/src/main/java/org/thoughtcrime/securesms/ui/AlertDialog.kt new file mode 100644 index 0000000000..579d4111b1 --- /dev/null +++ b/app/src/main/java/org/thoughtcrime/securesms/ui/AlertDialog.kt @@ -0,0 +1,89 @@ +package org.thoughtcrime.securesms.ui + +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material.Text +import androidx.compose.material.TextButton +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.RectangleShape +import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.unit.dp +import org.thoughtcrime.securesms.ui.color.LocalColors +import org.thoughtcrime.securesms.ui.components.BorderlessButton + +class DialogButtonModel( + val text: GetString, + val contentDescription: GetString = text, + val onClick: () -> Unit +) + +@Composable +fun AlertDialog( + onDismissRequest: () -> Unit, + title: String? = null, + text: String? = null, + buttons: List? = null +) { + androidx.compose.material.AlertDialog( + onDismissRequest, + shape = RoundedCornerShape(12.dp), + backgroundColor = LocalColors.current.backgroundSecondary, + buttons = { + Box { + Column(modifier = Modifier.fillMaxWidth()) { + Column( + horizontalAlignment = Alignment.CenterHorizontally, + modifier = Modifier + .fillMaxWidth() + .padding(top = 24.dp) + .padding(horizontal = 24.dp) + ) { + title?.let { + Text(it, textAlign = TextAlign.Center, style = h7, modifier = Modifier.padding(bottom = 8.dp)) + } + text?.let { + Text(it, textAlign = TextAlign.Center, style = large, modifier = Modifier.padding(bottom = 8.dp)) + } + } + buttons?.takeIf { it.isNotEmpty() }?.let { + Row { + it.forEach { + TextButton( + modifier = Modifier + .contentDescription(it.contentDescription()) + .weight(1f), + shape = RectangleShape, + onClick = { + it.onClick + onDismissRequest() + } + ) { + Text( + it.text(), + color = LocalColors.current.text, + style = largeBold, + modifier = Modifier.padding( + top = 16.dp, + bottom = 24.dp + ) + ) + } + } + } + } + } + } + } + ) +} + +@Composable +fun DialogButton(text: String, contentDescription: String, onClick: () -> Unit) { + BorderlessButton(text, modifier = Modifier.contentDescription(contentDescription), onClick = onClick) +} diff --git a/app/src/main/java/org/thoughtcrime/securesms/ui/SessionTypography.kt b/app/src/main/java/org/thoughtcrime/securesms/ui/SessionTypography.kt index 210286c8d8..426c6f8dc4 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/ui/SessionTypography.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/ui/SessionTypography.kt @@ -23,6 +23,7 @@ fun defaultStyle(size: TextUnit, fontFamily: FontFamily? = TextStyle.Default.fon val xl = defaultStyle(18.sp) val large = defaultStyle(16.sp) +val largeBold = boldStyle(16.sp) val base = defaultStyle(14.sp) val baseBold = boldStyle(14.sp)