Use new Compose AlertDialog in LandingActivity

This commit is contained in:
Andrew 2024-06-17 17:23:02 +09:30
parent bbd5fc6156
commit 0c83db0855
3 changed files with 114 additions and 15 deletions

View File

@ -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)
}

View File

@ -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<DialogButtonModel>? = 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)
}

View File

@ -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)