Move NotificationRadioButton

This commit is contained in:
Andrew 2024-06-17 19:51:25 +09:30
parent c59637f7ec
commit 01fc02c8cc
2 changed files with 72 additions and 57 deletions

View File

@ -1,9 +1,16 @@
package org.thoughtcrime.securesms.onboarding.messagenotifications
import androidx.annotation.StringRes
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.ButtonDefaults
import androidx.compose.material.RadioButton
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
@ -11,6 +18,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.unit.dp
import network.loki.messenger.R
import org.thoughtcrime.securesms.onboarding.ui.ContinueButton
import org.thoughtcrime.securesms.ui.LocalDimensions
@ -18,18 +26,15 @@ import org.thoughtcrime.securesms.ui.PreviewTheme
import org.thoughtcrime.securesms.ui.SessionColorsParameterProvider
import org.thoughtcrime.securesms.ui.base
import org.thoughtcrime.securesms.ui.color.Colors
import org.thoughtcrime.securesms.ui.components.NotificationRadioButton
import org.thoughtcrime.securesms.ui.color.LocalColors
import org.thoughtcrime.securesms.ui.color.radioButtonColors
import org.thoughtcrime.securesms.ui.components.Button
import org.thoughtcrime.securesms.ui.components.ButtonType
import org.thoughtcrime.securesms.ui.contentDescription
import org.thoughtcrime.securesms.ui.h4
@Preview
@Composable
private fun MessageNotificationsScreenPreview(
@PreviewParameter(SessionColorsParameterProvider::class) colors: Colors
) {
PreviewTheme(colors) {
MessageNotificationsScreen()
}
}
import org.thoughtcrime.securesms.ui.h8
import org.thoughtcrime.securesms.ui.h9
import org.thoughtcrime.securesms.ui.small
@Composable
internal fun MessageNotificationsScreen(
@ -68,3 +73,59 @@ internal fun MessageNotificationsScreen(
ContinueButton(Modifier.align(Alignment.CenterHorizontally), onContinue)
}
}
@Composable
private fun NotificationRadioButton(
@StringRes title: Int,
@StringRes explanation: Int,
@StringRes tag: Int? = null,
@StringRes contentDescription: Int? = null,
selected: Boolean = false,
onClick: () -> Unit = {}
) {
Row {
Button(
onClick = onClick,
modifier = Modifier
.weight(1f)
.contentDescription(contentDescription),
type = ButtonType.Outline,
color = LocalColors.current.text,
border = BorderStroke(
width = ButtonDefaults.OutlinedBorderSize,
color = if (selected) LocalColors.current.primary else LocalColors.current.borders
),
shape = RoundedCornerShape(8.dp)
) {
Column(
verticalArrangement = Arrangement.spacedBy(6.dp)
) {
Text(stringResource(title), style = h8)
Text(stringResource(explanation), style = small)
tag?.let {
Text(
stringResource(it),
color = LocalColors.current.primary,
style = h9
)
}
}
}
RadioButton(
selected = selected,
modifier = Modifier.align(Alignment.CenterVertically),
onClick = onClick,
colors = LocalColors.current.radioButtonColors()
)
}
}
@Preview
@Composable
private fun MessageNotificationsScreenPreview(
@PreviewParameter(SessionColorsParameterProvider::class) colors: Colors
) {
PreviewTheme(colors) {
MessageNotificationsScreen()
}
}

View File

@ -322,52 +322,6 @@ fun BorderlessHtmlButton(
}
}
@Composable
fun NotificationRadioButton(
@StringRes title: Int,
@StringRes explanation: Int,
@StringRes tag: Int? = null,
@StringRes contentDescription: Int? = null,
selected: Boolean = false,
onClick: () -> Unit = {}
) {
Row {
Button(
onClick = onClick,
modifier = Modifier
.weight(1f)
.contentDescription(contentDescription),
type = ButtonType.Outline,
color = LocalColors.current.text,
border = BorderStroke(
width = ButtonDefaults.OutlinedBorderSize,
color = if (selected) LocalColors.current.primary else LocalColors.current.borders
),
shape = RoundedCornerShape(8.dp)
) {
Column(
verticalArrangement = Arrangement.spacedBy(6.dp)
) {
Text(stringResource(title), style = h8)
Text(stringResource(explanation), style = small)
tag?.let {
Text(
stringResource(it),
color = LocalColors.current.primary,
style = h9
)
}
}
}
RadioButton(
selected = selected,
modifier = Modifier.align(Alignment.CenterVertically),
onClick = onClick,
colors = LocalColors.current.radioButtonColors()
)
}
}
val MutableInteractionSource.releases
get() = interactions.filter { it is PressInteraction.Release }