From 27d318e6f0e521b5cb99cc0f3fa816baf7284aa0 Mon Sep 17 00:00:00 2001 From: lauchaves Date: Thu, 24 Oct 2024 23:45:59 -0600 Subject: [PATCH] Fix clipboard copy --- .../FinalizeAccountCreationScreen.kt | 164 +++++++----------- 1 file changed, 60 insertions(+), 104 deletions(-) diff --git a/wallet_app/app/src/main/java/com/example/walletapp/ui/onboarding/FinalizeAccountCreationScreen.kt b/wallet_app/app/src/main/java/com/example/walletapp/ui/onboarding/FinalizeAccountCreationScreen.kt index 072ddfc6..92424c69 100644 --- a/wallet_app/app/src/main/java/com/example/walletapp/ui/onboarding/FinalizeAccountCreationScreen.kt +++ b/wallet_app/app/src/main/java/com/example/walletapp/ui/onboarding/FinalizeAccountCreationScreen.kt @@ -26,6 +26,10 @@ import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp +import android.content.ClipboardManager +import android.content.ClipData +import android.widget.Toast +import androidx.compose.ui.graphics.painter.Painter import androidx.core.graphics.toColorInt import com.example.walletapp.R @@ -87,24 +91,28 @@ fun FinalizeAccountCreationScreen(onContinue: () -> Unit) { @Composable fun AccountInfoView(onContinue: () -> Unit) { - - val context = (LocalContext.current as Activity) + val context = LocalContext.current as Activity + val clipboardManager = LocalContext.current.getSystemService(ClipboardManager::class.java) var checked by remember { mutableStateOf(true) } + val accountName = "Starknet" + val privateKey = "q78ggh277ibckewjtnM" - - Column ( + Column( verticalArrangement = Arrangement.Center, modifier = Modifier.padding(16.dp) - ) { - - Text(text= "Account Information", style = TextStyle(color = Color.White, fontWeight = FontWeight.ExtraBold, fontSize = 22.sp)) + Text( + text = "Account Information", + style = TextStyle(color = Color.White, fontWeight = FontWeight.ExtraBold, fontSize = 22.sp) + ) Spacer(modifier = Modifier.height(10.dp)) - Card ( + + Card( backgroundColor = Color("#141462".toColorInt()), shape = RoundedCornerShape(size = 8.dp), - modifier = Modifier.fillMaxWidth() + modifier = Modifier + .fillMaxWidth() .background(color = Color("#141462".toColorInt())) .padding(top = 15.dp, start = 15.dp, end = 15.dp, bottom = 15.dp) ) { @@ -113,31 +121,27 @@ fun AccountInfoView(onContinue: () -> Unit) { modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween ) { - Box(){ - Column { - Text(text= "Account name", style = TextStyle(color = Color("#8D8DBB".toColorInt()), fontWeight = FontWeight.Medium, fontSize = 15.sp)) - Spacer(modifier = Modifier.height(4.dp)) - Text(text= "Starknet", style = TextStyle(color = Color.White, fontWeight = FontWeight.Medium, fontSize = 15.sp)) - - } + Column { + Text( + text = "Account name", + style = TextStyle(color = Color("#8D8DBB".toColorInt()), fontWeight = FontWeight.Medium, fontSize = 15.sp) + ) + Spacer(modifier = Modifier.height(4.dp)) + Text( + text = accountName, + style = TextStyle(color = Color.White, fontWeight = FontWeight.Medium, fontSize = 15.sp) + ) } - - Box( - modifier = Modifier - .width(30.dp) - .height(30.dp) - .background(color = Color.Transparent) - .border(width = 1.dp, color = Color.White, shape = RoundedCornerShape(4.dp)) - .padding(4.dp), - ) { + IconButton(onClick = { + clipboardManager.setPrimaryClip(ClipData.newPlainText("Account Name", accountName)) + Toast.makeText(context, "Account name copied", Toast.LENGTH_SHORT).show() + }) { Image( painter = painterResource(id = R.drawable.content_copy), contentDescription = "Copy", modifier = Modifier.size(20.dp) ) } - - } Spacer(modifier = Modifier.height(30.dp)) @@ -146,39 +150,33 @@ fun AccountInfoView(onContinue: () -> Unit) { modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween ) { - Box(){ - Column { - Text(text= "Private key", style = TextStyle(color = Color("#8D8DBB".toColorInt()), fontWeight = FontWeight.Medium, fontSize = 15.sp)) - Spacer(modifier = Modifier.height(4.dp)) - Text(text= "q78ggh277ibckewjtnM", style = TextStyle(color = Color.White, fontWeight = FontWeight.Medium, fontSize = 15.sp)) - - } + Column { + Text( + text = "Private key", + style = TextStyle(color = Color("#8D8DBB".toColorInt()), fontWeight = FontWeight.Medium, fontSize = 15.sp) + ) + Spacer(modifier = Modifier.height(4.dp)) + Text( + text = privateKey, + style = TextStyle(color = Color.White, fontWeight = FontWeight.Medium, fontSize = 15.sp) + ) } - - - Box( - modifier = Modifier - .width(30.dp) - .height(30.dp) - .background(color = Color.Transparent) - .border(width = 1.dp, color = Color.White, shape = RoundedCornerShape(4.dp)) - .padding(4.dp), - ) { + IconButton(onClick = { + clipboardManager.setPrimaryClip(ClipData.newPlainText("Private Key", privateKey)) + Toast.makeText(context, "Private key copied", Toast.LENGTH_SHORT).show() + }) { Image( painter = painterResource(id = R.drawable.content_copy), contentDescription = "Copy", - modifier = Modifier - .size(20.dp) + modifier = Modifier.size(20.dp) ) } - - - } } } Spacer(modifier = Modifier.height(30.dp)) + Button( onClick = {}, colors = ButtonDefaults.buttonColors(backgroundColor = Color("#1B1B76".toColorInt()), contentColor = Color.White), @@ -186,61 +184,46 @@ fun AccountInfoView(onContinue: () -> Unit) { .background(color = Color("#141462".toColorInt())) .height(51.dp) .border(width = 1.dp, color = Color("#1B1B76".toColorInt()), shape = RoundedCornerShape(8.dp)) - ) { Row( modifier = Modifier.fillMaxWidth(), - verticalAlignment = Alignment.CenterVertically, + verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.Center - - - ){ - + ) { Icon( imageVector = Icons.Filled.Refresh, - contentDescription = "Backward Arrow", + contentDescription = "Generate new key", modifier = Modifier.padding(start = 8.dp), tint = Color.White ) - Spacer(modifier = Modifier.width(10.dp)) - - Text(text = "Generate new private key", style = TextStyle(color = Color("#A3A3C1".toColorInt()), fontSize = 16.sp, fontWeight = FontWeight.Medium)) + Text(text = "Generate new private key", style = TextStyle(color = Color("#A3A3C1".toColorInt()), fontSize = 16.sp, fontWeight = FontWeight.Medium)) } } - Spacer(modifier = Modifier.height(8.dp)) - - Button( - onClick = { /* TOOD */ }, + onClick = { /* TODO */ }, colors = ButtonDefaults.buttonColors(backgroundColor = Color("#1B1B76".toColorInt()), contentColor = Color.White), modifier = Modifier.fillMaxWidth() .background(color = Color("#1B1B76".toColorInt())) .height(51.dp) .border(width = 1.dp, color = Color("#CBC5C5".toColorInt()), shape = RoundedCornerShape(8.dp)) - - ) { Row( modifier = Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.Center - ){ - + ) { Icon( imageVector = Icons.Outlined.Info, - contentDescription = "Backward Arrow", + contentDescription = "Use existing key", modifier = Modifier.padding(start = 8.dp), tint = Color.White ) - Spacer(modifier = Modifier.width(10.dp)) - - Text(text = "Use existing private key", style = TextStyle(color = Color.White, fontSize = 16.sp, - fontWeight = FontWeight.Medium)) + Text(text = "Use existing private key", style = TextStyle(color = Color.White, fontSize = 16.sp, fontWeight = FontWeight.Medium)) } } @@ -248,26 +231,18 @@ fun AccountInfoView(onContinue: () -> Unit) { Box( modifier = Modifier - .background(color = Color("#221451".toColorInt(), )) + .background(color = Color("#221451".toColorInt())) .height(74.dp) .border(width = 1.dp, color = Color("#221451".toColorInt()), shape = RoundedCornerShape(16.dp)) .padding(16.dp) - - ){ - Row(){ - - + ) { + Row { Icon( imageVector = Icons.Outlined.Info, contentDescription = "Info", tint = Color("#E45F61".toColorInt()) ) - - Spacer(modifier = Modifier.width(10.dp)) - - - Text( text = "Store your private key securely. In case of its lost or stolen, access to funds will be lost without the possibility of recovery", style = TextStyle(color = Color("#E45F61".toColorInt()), fontSize = 14.sp) @@ -275,16 +250,9 @@ fun AccountInfoView(onContinue: () -> Unit) { } } - Spacer(modifier = Modifier.height(20.dp)) - - - Row( - verticalAlignment = Alignment.CenterVertically, - - ) { - + Row(verticalAlignment = Alignment.CenterVertically) { Checkbox( modifier = Modifier.border(width = 1.dp, color = Color("#54DC84".toColorInt()), shape = RoundedCornerShape(30.dp)) .height(25.dp) @@ -292,10 +260,7 @@ fun AccountInfoView(onContinue: () -> Unit) { checked = checked, onCheckedChange = { checked = it }, colors = CheckboxDefaults.colors(checkedColor = Color.Transparent, checkmarkColor = Color("#54DC84".toColorInt())), - ) - - Spacer(modifier = Modifier.width(10.dp)) Text( "I have read the information and saved the private key", @@ -303,10 +268,8 @@ fun AccountInfoView(onContinue: () -> Unit) { ) } - Spacer(modifier = Modifier.weight(1f)) - // TODO(#109): pressing continue on this screen should save the account information to the device Button( onClick = onContinue, contentPadding = ButtonDefaults.ContentPadding, @@ -316,9 +279,7 @@ fun AccountInfoView(onContinue: () -> Unit) { .fillMaxWidth() .height(49.dp) ) { - Row( - verticalAlignment = Alignment.CenterVertically - ) { + Row(verticalAlignment = Alignment.CenterVertically) { Text("Continue") Icon( imageVector = Icons.Filled.ArrowForward, @@ -329,12 +290,8 @@ fun AccountInfoView(onContinue: () -> Unit) { } } - Spacer(modifier = Modifier.height(20.dp)) - - } - } @@ -342,4 +299,3 @@ fun AccountInfoView(onContinue: () -> Unit) { -