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

Feat: Change copy icon and text after clicked #269

Merged
Show file tree
Hide file tree
Changes from 1 commit
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,15 +14,16 @@ 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.Scaffold
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.rememberCoroutineScope
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
Expand All @@ -34,6 +35,7 @@ import androidx.compose.ui.unit.sp
import com.goldenraven.padawanwallet.R
import com.goldenraven.padawanwallet.theme.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

@Composable
Expand All @@ -43,19 +45,30 @@ internal fun SendCoinsBackScreen() {
val scope = rememberCoroutineScope()
val scaffoldState: ScaffoldState = rememberScaffoldState()

val (copyClicked, setCopyClicked) = remember { mutableStateOf(false) }

val copyAddrString = buildAnnotatedString {
appendInlineContent(id = "copyAddrImageId")
append(stringResource(id = R.string.copyAddrStr))
if (!copyClicked) append(stringResource(id = R.string.copyAddrStr)) else append(stringResource(R.string.textCopied))
}

val inlineContentMap = mapOf(
"copyAddrImageId" to InlineTextContent(
Placeholder(17.sp, 17.sp, PlaceholderVerticalAlign.TextCenter)
) {
Image(
painterResource(R.drawable.hicon_add_square),
contentDescription = "Copy to clipboard image",
)
if (copyClicked) {
Image(
painter = painterResource(R.drawable.ic_checked),
contentDescription = "Checkmark image",
colorFilter = ColorFilter.tint(Color.Green)

)
} else {
Image(
painter = painterResource(R.drawable.hicon_add_square),
contentDescription = "Copy to clipboard image",
)
}
}
)
Scaffold(
Expand Down Expand Up @@ -83,7 +96,10 @@ internal fun SendCoinsBackScreen() {
Column(
Modifier
.align(Alignment.CenterHorizontally)
.clickable(onClick = { copyToClipboard(context, scope, scaffoldState) })
.clickable(onClick = {
setCopyClicked(true)
copyToClipboard(context, scope, scaffoldState, setCopyClicked)
})
.padding(start = 24.dp, end = 24.dp, bottom = 20.dp)
) {
Text(
Expand Down Expand Up @@ -111,10 +127,13 @@ internal fun SendCoinsBackScreen() {
}
}

fun copyToClipboard(context: Context, scope: CoroutineScope, state: ScaffoldState) {
fun copyToClipboard(context: Context, scope: CoroutineScope, state: ScaffoldState, setCopyClicked: (Boolean) -> Unit) {
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 { state.snackbarHostState.showSnackbar("Copied address to clipboard!") }
scope.launch {
state.snackbarHostState.showSnackbar("Copied address to clipboard!")
delay(1000)
setCopyClicked(false)
}
}
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_checked.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M16.59,7.58L10,14.17l-3.59,-3.58L5,12l5,5 8,-8zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8 -8,8z"/>
</vector>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,6 @@
<string name="copyAddrStr">Copy</string>
<string name="errorFaucet">Error: Faucet Not Available</string>
<string name="oneTimeFaucet">Error: you\'ve already received testnet coins!</string>
<string name="textCopied">Copied</string>

</resources>