Refactor temporary button text

This commit is contained in:
Andrew 2024-04-08 14:30:53 +09:30
parent b8b98f436d
commit 7d7d2b89bd
3 changed files with 46 additions and 16 deletions

View File

@ -202,26 +202,14 @@ fun RecoveryPasswordCell(seed: String = "", qrBitmap: Bitmap? = null, copySeed:(
AnimatedVisibility(!showQr.value) { AnimatedVisibility(!showQr.value) {
Row(horizontalArrangement = Arrangement.spacedBy(32.dp)) { Row(horizontalArrangement = Arrangement.spacedBy(32.dp)) {
var copied by remember { mutableStateOf(false) }
if (copied) LaunchedEffectAsync {
delay(2.seconds)
copied = false
}
OutlineButton( OutlineButton(
modifier = Modifier.weight(1f), modifier = Modifier.weight(1f),
color = MaterialTheme.colors.onPrimary, color = MaterialTheme.colors.onPrimary,
onClick = { onClick = copySeed,
copySeed() temporaryContent = { Text(stringResource(R.string.copied)) }
copied = true
}
) { ) {
AnimatedVisibility(!copied) {
Text(stringResource(R.string.copy)) Text(stringResource(R.string.copy))
} }
AnimatedVisibility(copied) {
Text(stringResource(R.string.copied))
}
}
OutlineButton(text = stringResource(R.string.qrView), modifier = Modifier.weight(1f), color = MaterialTheme.colors.onPrimary) { showQr.toggle() } OutlineButton(text = stringResource(R.string.qrView), modifier = Modifier.weight(1f), color = MaterialTheme.colors.onPrimary) { showQr.toggle() }
} }
} }

View File

@ -1,6 +1,7 @@
package org.thoughtcrime.securesms.ui package org.thoughtcrime.securesms.ui
import androidx.annotation.DrawableRes import androidx.annotation.DrawableRes
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.BorderStroke import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.Canvas import androidx.compose.foundation.Canvas
import androidx.compose.foundation.ScrollState import androidx.compose.foundation.ScrollState
@ -34,7 +35,11 @@ import androidx.compose.material.Text
import androidx.compose.material.TextButton import androidx.compose.material.TextButton
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha import androidx.compose.ui.draw.alpha
@ -58,6 +63,7 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import androidx.compose.ui.viewinterop.AndroidView import androidx.compose.ui.viewinterop.AndroidView
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import network.loki.messenger.R import network.loki.messenger.R
import org.session.libsession.utilities.recipients.Recipient import org.session.libsession.utilities.recipients.Recipient
@ -66,6 +72,7 @@ import org.thoughtcrime.securesms.components.ProfilePictureView
import org.thoughtcrime.securesms.conversation.disappearingmessages.ui.OptionsCard import org.thoughtcrime.securesms.conversation.disappearingmessages.ui.OptionsCard
import kotlin.math.min import kotlin.math.min
import kotlin.math.roundToInt import kotlin.math.roundToInt
import kotlin.time.Duration.Companion.seconds
@Composable @Composable
fun OutlineButton( fun OutlineButton(
@ -110,6 +117,42 @@ fun OutlineButton(
} }
} }
@Composable
fun OutlineButton(
temporaryContent: @Composable () -> Unit,
modifier: Modifier = Modifier,
color: Color = LocalExtraColors.current.prominentButtonColor,
onClick: () -> Unit = {},
content: @Composable () -> Unit = {}
) {
var clicked by remember { mutableStateOf(false) }
if (clicked) LaunchedEffectAsync {
delay(2.seconds)
clicked = false
}
OutlinedButton(
modifier = modifier,
onClick = {
onClick()
clicked = true
},
border = BorderStroke(1.dp, color),
shape = RoundedCornerShape(percent = 50),
colors = ButtonDefaults.outlinedButtonColors(
contentColor = color,
backgroundColor = Color.Unspecified
)
) {
AnimatedVisibility(clicked) {
temporaryContent()
}
AnimatedVisibility(!clicked) {
content()
}
}
}
@Composable @Composable
fun FilledButton( fun FilledButton(
text: String, text: String,

View File

@ -133,7 +133,6 @@
<string name="AccessibilityId_user_settings">User settings</string> <string name="AccessibilityId_user_settings">User settings</string>
<string name="AccessibilityId_username">Username</string> <string name="AccessibilityId_username">Username</string>
<string name="AccessibilityId_privacy">Privacy</string> <string name="AccessibilityId_privacy">Privacy</string>
<string name="AccessibilityId_recovery_password_menu_item">Recovery password</string>
<string name="AccessibilityId_recovery_password_menu_item">Recovery password menu item</string> <string name="AccessibilityId_recovery_password_menu_item">Recovery password menu item</string>
<string name="AccessibilityId_edit_user_nickname">Edit user nickname</string> <string name="AccessibilityId_edit_user_nickname">Edit user nickname</string>
<string name="AccessibilityId_apply">Apply</string> <string name="AccessibilityId_apply">Apply</string>