Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show copied to clipboard snackbar #242

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.text.InlineTextContent
import androidx.compose.foundation.text.appendInlineContent
import androidx.compose.material.SnackbarHostState
import androidx.compose.material.ScaffoldState
import androidx.compose.material.rememberScaffoldState
import androidx.compose.material3.Divider
import androidx.compose.material.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand All @@ -40,7 +41,7 @@ internal fun SendCoinsBackScreen() {
val scrollState = rememberScrollState()
val context = LocalContext.current
val scope = rememberCoroutineScope()
val snackbarHostState = remember { SnackbarHostState() }
val scaffoldState: ScaffoldState = rememberScaffoldState()

val copyAddrString = buildAnnotatedString {
appendInlineContent(id = "copyAddrImageId")
Expand All @@ -57,59 +58,63 @@ internal fun SendCoinsBackScreen() {
)
}
)
Column(
Modifier
.fillMaxSize()
.verticalScroll(state = scrollState)
.background(padawan_theme_background_secondary)
.padding(bottom = 12.dp)
) {
Text(
text = "Send your coins back to us!",
style = PadawanTypography.headlineSmall,
color = padawan_theme_text_headline,
modifier = Modifier
.padding(top = 48.dp, start = 24.dp, end = 24.dp, bottom = 32.dp)
)
Image(
painterResource(R.drawable.return_sats_faucet_address),
contentDescription = "Return sats faucet address image",
modifier = Modifier.padding(start = 50.dp, end = 50.dp, bottom = 20.dp)
)
Scaffold(
scaffoldState = scaffoldState
) { padding ->
Column(
Modifier
.align(Alignment.CenterHorizontally)
.clickable(onClick = { copyToClipboard(context, scope, snackbarHostState) })
.padding(start = 24.dp, end = 24.dp, bottom = 20.dp)
.fillMaxSize()
.verticalScroll(state = scrollState)
.background(padawan_theme_background_secondary)
.padding(padding)
) {
Text(
text = stringResource(R.string.send_coins_back_address),
fontSize = 14.sp
text = "Send your coins back to us!",
style = PadawanTypography.headlineSmall,
color = padawan_theme_text_headline,
modifier = Modifier
.padding(top = 48.dp, start = 24.dp, end = 24.dp, bottom = 32.dp)
)
Divider(
color = padawan_theme_text_faded_secondary,
thickness = 1.dp,
modifier = Modifier.padding(all = 3.dp)
Image(
painterResource(R.drawable.return_sats_faucet_address),
contentDescription = "Return sats faucet address image",
modifier = Modifier.padding(start = 50.dp, end = 50.dp, bottom = 20.dp)
)
Column(
Modifier
.align(Alignment.CenterHorizontally)
.clickable(onClick = { copyToClipboard(context, scope, scaffoldState) })
.padding(start = 24.dp, end = 24.dp, bottom = 20.dp)
) {
Text(
text = stringResource(R.string.send_coins_back_address),
fontSize = 14.sp
)
Divider(
color = padawan_theme_text_faded_secondary,
thickness = 1.dp,
modifier = Modifier.padding(all = 3.dp)
)
Text(
text = copyAddrString,
inlineContent = inlineContentMap,
modifier = Modifier.align(Alignment.End)
)
}
Text(
text = copyAddrString,
inlineContent = inlineContentMap,
modifier = Modifier.align(Alignment.End)
text = stringResource(id = R.string.send_coins_back),
style = PadawanTypography.bodyMedium,
color = padawan_theme_text_faded_secondary,
modifier = Modifier.padding(start = 24.dp, end = 24.dp)
)
}
Text(
text = stringResource(id = R.string.send_coins_back),
style = PadawanTypography.bodyMedium,
color = padawan_theme_text_faded_secondary,
modifier = Modifier.padding(start = 24.dp, end = 24.dp)
)
}
}

fun copyToClipboard(context: Context, scope: CoroutineScope, snackbarHostState: SnackbarHostState) {
fun copyToClipboard(context: Context, scope: CoroutineScope, state: ScaffoldState) {
val clipboard: ClipboardManager = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clip: ClipData = ClipData.newPlainText("", context.getString(R.string.send_coins_back_address))
clipboard.setPrimaryClip(clip)

scope.launch { snackbarHostState.showSnackbar("Copied address to clipboard!") }
scope.launch { state.snackbarHostState.showSnackbar("Copied address to clipboard!") }
}