mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 01:07:47 +00:00
Cleanup
This commit is contained in:
parent
351f2d9c57
commit
b63f63585b
@ -165,9 +165,8 @@ fun RecoveryPasswordCell(seed: String, copySeed:() -> Unit = {}) {
|
||||
)
|
||||
SlimOutlineButton(
|
||||
stringResource(R.string.qrView),
|
||||
modifier = Modifier.weight(1f),
|
||||
onClick = { showQr = !showQr }
|
||||
)
|
||||
Modifier.weight(1f),
|
||||
) { showQr = !showQr }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,8 +9,9 @@ import androidx.compose.ui.unit.TextUnit
|
||||
import androidx.compose.ui.unit.sp
|
||||
|
||||
fun boldStyle(size: TextUnit) = TextStyle.Default.copy(
|
||||
fontSize = size,
|
||||
lineHeight = size * 1.2,
|
||||
fontWeight = FontWeight.Bold,
|
||||
fontSize = size
|
||||
)
|
||||
|
||||
fun defaultStyle(size: TextUnit, fontFamily: FontFamily? = TextStyle.Default.fontFamily) = TextStyle.Default.copy(
|
||||
@ -20,6 +21,7 @@ fun defaultStyle(size: TextUnit, fontFamily: FontFamily? = TextStyle.Default.fon
|
||||
)
|
||||
|
||||
val xl = defaultStyle(18.sp)
|
||||
|
||||
val large = defaultStyle(16.sp)
|
||||
|
||||
val base = defaultStyle(14.sp)
|
||||
|
@ -4,16 +4,14 @@ import android.annotation.SuppressLint
|
||||
import androidx.compose.material.ExperimentalMaterialApi
|
||||
import androidx.compose.material.LocalMinimumInteractiveComponentEnforcement
|
||||
import androidx.compose.material.LocalTextStyle
|
||||
import androidx.compose.material.MaterialTheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import org.thoughtcrime.securesms.ui.baseBold
|
||||
import org.thoughtcrime.securesms.ui.extraSmall
|
||||
import org.thoughtcrime.securesms.ui.extraSmallBold
|
||||
import org.thoughtcrime.securesms.ui.smallBold
|
||||
|
||||
interface ButtonSize {
|
||||
@OptIn(ExperimentalMaterialApi::class)
|
||||
@ -36,11 +34,6 @@ object LargeButtonSize: ButtonSize {
|
||||
override val minHeight = 41.dp
|
||||
}
|
||||
|
||||
object MediumButtonSize: ButtonSize {
|
||||
override val textStyle @Composable get() = smallBold
|
||||
override val minHeight = 34.dp
|
||||
}
|
||||
|
||||
object SlimButtonSize: ButtonSize {
|
||||
override val textStyle @Composable get() = extraSmallBold
|
||||
override val minHeight = 29.dp
|
||||
|
@ -33,119 +33,6 @@ import org.thoughtcrime.securesms.ui.contentDescription
|
||||
import kotlin.time.Duration
|
||||
import kotlin.time.Duration.Companion.seconds
|
||||
|
||||
//@Composable
|
||||
//fun OutlineButton(
|
||||
// text: String,
|
||||
// modifier: Modifier = Modifier,
|
||||
// size: ButtonSize = LargeButtonSize,
|
||||
// color: Color = LocalPalette.current.buttonOutline,
|
||||
// onClick: () -> Unit
|
||||
//) {
|
||||
// OutlineButton(
|
||||
// modifier = modifier,
|
||||
// size = size,
|
||||
// color = color,
|
||||
// onClick = onClick
|
||||
// ) {
|
||||
// SessionButtonText(text = text, style = size.textStyle, color = color)
|
||||
// }
|
||||
//}
|
||||
//
|
||||
///**
|
||||
// * Base implementation of [SessionOutlinedButton]
|
||||
// */
|
||||
//@Composable
|
||||
//fun OutlineButton(
|
||||
// modifier: Modifier = Modifier,
|
||||
// size: ButtonSize = LargeButtonSize,
|
||||
// enabled: Boolean = true,
|
||||
// interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
|
||||
// color: Color = LocalPalette.current.buttonOutline,
|
||||
// border: BorderStroke = BorderStroke(1.dp, if (enabled) color else LocalPalette.current.disabled),
|
||||
// shape: Shape = MaterialTheme.shapes.small,
|
||||
// onClick: () -> Unit,
|
||||
// content: @Composable () -> Unit = {}
|
||||
//) {
|
||||
// Button(
|
||||
// modifier = modifier.heightIn(min = size.minHeight),
|
||||
// enabled = enabled,
|
||||
// interactionSource = interactionSource,
|
||||
// onClick = onClick,
|
||||
// border = border,
|
||||
// shape = shape,
|
||||
// type = ButtonType.Outline,
|
||||
// color = color
|
||||
// ) {
|
||||
// size.applyTextStyle {
|
||||
// content()
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
@Composable
|
||||
fun SlimOutlineCopyButton(
|
||||
modifier: Modifier = Modifier,
|
||||
color: Color = LocalPalette.current.buttonOutline,
|
||||
onClick: () -> Unit
|
||||
) {
|
||||
OutlineCopyButton(modifier, SlimButtonSize, color, onClick)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun OutlineCopyButton(
|
||||
modifier: Modifier = Modifier,
|
||||
size: ButtonSize = LargeButtonSize,
|
||||
color: Color = LocalPalette.current.buttonOutline,
|
||||
onClick: () -> Unit
|
||||
) {
|
||||
val interactionSource = remember { MutableInteractionSource() }
|
||||
|
||||
Button(
|
||||
modifier = modifier.contentDescription(R.string.AccessibilityId_copy_button),
|
||||
interactionSource = interactionSource,
|
||||
size = size,
|
||||
type = ButtonType.Outline,
|
||||
color = color,
|
||||
onClick = onClick
|
||||
) {
|
||||
TemporaryClickedContent(
|
||||
interactionSource = interactionSource,
|
||||
content = { Text(stringResource(R.string.copy)) },
|
||||
temporaryContent = { Text(stringResource(R.string.copied)) }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun TemporaryClickedContent(
|
||||
modifier: Modifier = Modifier,
|
||||
interactionSource: MutableInteractionSource,
|
||||
content: @Composable () -> Unit,
|
||||
temporaryContent: @Composable () -> Unit,
|
||||
temporaryDelay: Duration = 2.seconds
|
||||
) {
|
||||
var clicked by remember { mutableStateOf(false) }
|
||||
|
||||
LaunchedEffectAsync {
|
||||
interactionSource.releases.collectLatest {
|
||||
clicked = true
|
||||
delay(temporaryDelay)
|
||||
clicked = false
|
||||
}
|
||||
}
|
||||
|
||||
// Using a Box because the Buttons add children in a Row
|
||||
// and they will jank as they are added and removed.
|
||||
Box(contentAlignment = Alignment.Center) {
|
||||
AnimatedVisibility(!clicked, enter = fadeIn(), exit = fadeOut()) {
|
||||
content()
|
||||
}
|
||||
AnimatedVisibility(clicked, enter = fadeIn(), exit = fadeOut()) {
|
||||
temporaryContent()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface ButtonType {
|
||||
@Composable fun border(color: Color, enabled: Boolean): BorderStroke?
|
||||
@Composable fun buttonColors(color: Color): ButtonColors
|
||||
@ -252,3 +139,66 @@ fun Button(
|
||||
@Composable fun SlimOutlineButton(onClick: () -> Unit, modifier: Modifier = Modifier, color: Color = LocalPalette.current.buttonOutline, enabled: Boolean = true, content: @Composable () -> Unit) {
|
||||
Button(onClick, color, ButtonType.Outline, modifier, enabled, SlimButtonSize) { content() }
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun SlimOutlineCopyButton(
|
||||
modifier: Modifier = Modifier,
|
||||
color: Color = LocalPalette.current.buttonOutline,
|
||||
onClick: () -> Unit
|
||||
) {
|
||||
OutlineCopyButton(modifier, SlimButtonSize, color, onClick)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun OutlineCopyButton(
|
||||
modifier: Modifier = Modifier,
|
||||
size: ButtonSize = LargeButtonSize,
|
||||
color: Color = LocalPalette.current.buttonOutline,
|
||||
onClick: () -> Unit
|
||||
) {
|
||||
val interactionSource = remember { MutableInteractionSource() }
|
||||
|
||||
Button(
|
||||
modifier = modifier.contentDescription(R.string.AccessibilityId_copy_button),
|
||||
interactionSource = interactionSource,
|
||||
size = size,
|
||||
type = ButtonType.Outline,
|
||||
color = color,
|
||||
onClick = onClick
|
||||
) {
|
||||
TemporaryClickedContent(
|
||||
interactionSource = interactionSource,
|
||||
content = { Text(stringResource(R.string.copy)) },
|
||||
temporaryContent = { Text(stringResource(R.string.copied)) }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun TemporaryClickedContent(
|
||||
interactionSource: MutableInteractionSource,
|
||||
content: @Composable () -> Unit,
|
||||
temporaryContent: @Composable () -> Unit,
|
||||
temporaryDelay: Duration = 2.seconds
|
||||
) {
|
||||
var clicked by remember { mutableStateOf(false) }
|
||||
|
||||
LaunchedEffectAsync {
|
||||
interactionSource.releases.collectLatest {
|
||||
clicked = true
|
||||
delay(temporaryDelay)
|
||||
clicked = false
|
||||
}
|
||||
}
|
||||
|
||||
// Using a Box because the Buttons add children in a Row
|
||||
// and they will jank as they are added and removed.
|
||||
Box(contentAlignment = Alignment.Center) {
|
||||
AnimatedVisibility(!clicked, enter = fadeIn(), exit = fadeOut()) {
|
||||
content()
|
||||
}
|
||||
AnimatedVisibility(clicked, enter = fadeIn(), exit = fadeOut()) {
|
||||
temporaryContent()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user