Skip to content

Commit

Permalink
Public keys and hashes are show single line with copy action and elli…
Browse files Browse the repository at this point in the history
…psis at the end
  • Loading branch information
micbakos-rdx committed Jun 26, 2024
1 parent de5862a commit 298080a
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ import androidx.compose.ui.text.PlaceholderVerticalAlign
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.sp
import com.babylon.wallet.android.R
import com.babylon.wallet.android.designsystem.theme.RadixTheme
import com.babylon.wallet.android.presentation.ui.composables.ExpandableText
import com.babylon.wallet.android.presentation.ui.composables.actionableaddress.ActionableAddressView
import com.babylon.wallet.android.presentation.ui.modifier.throttleClickable
import com.babylon.wallet.android.utils.copyToClipboard
import com.babylon.wallet.android.utils.openUrl
import com.radixdlt.sargon.Address
import com.radixdlt.sargon.NonFungibleGlobalId
Expand Down Expand Up @@ -164,17 +167,32 @@ fun MetadataValueView(
MetadataType.Bool,
is MetadataType.Integer,
MetadataType.Bytes,
MetadataType.Enum,
MetadataType.Enum -> Text(
modifier = modifier,
text = metadata.value,
style = style,
color = color,
textAlign = if (isRenderedInNewLine) TextAlign.Start else TextAlign.End,
maxLines = 2
)

MetadataType.PublicKeyEcdsaSecp256k1,
MetadataType.PublicKeyEddsaEd25519,
MetadataType.PublicKeyHashEcdsaSecp256k1,
MetadataType.PublicKeyHashEddsaEd25519 -> Text(
modifier = modifier,
modifier = modifier.throttleClickable {
context.copyToClipboard(
label = metadata.key,
value = metadata.value,
successMessage = context.getString(R.string.addressAction_copiedToClipboard)
)
},
text = metadata.value,
style = style,
color = color,
textAlign = if (isRenderedInNewLine) TextAlign.Start else TextAlign.End,
maxLines = 2
textAlign = TextAlign.End,
maxLines = 1,
overflow = TextOverflow.Ellipsis
)

MetadataType.String -> ExpandableText(
Expand All @@ -186,7 +204,7 @@ fun MetadataValueView(
),
toggleStyle = style.copy(
color = RadixTheme.colors.gray2
),
)
)

MetadataType.Instant -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.babylon.wallet.android.presentation.settings.debug.profile

import android.content.ClipData
import androidx.compose.foundation.background
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.WindowInsets
Expand Down Expand Up @@ -31,11 +30,11 @@ import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.Typeface
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.sp
import androidx.core.content.getSystemService
import com.babylon.wallet.android.R
import com.babylon.wallet.android.designsystem.theme.RadixTheme
import com.babylon.wallet.android.presentation.common.FullscreenCircularProgressContent
import com.babylon.wallet.android.presentation.ui.composables.RadixCenteredTopAppBar
import com.babylon.wallet.android.utils.copyToClipboard

@Composable
fun InspectProfileScreen(
Expand Down Expand Up @@ -82,13 +81,10 @@ fun InspectProfileScreen(
containerColor = RadixTheme.colors.gray4,
contentColor = RadixTheme.colors.gray1,
onClick = {
context.getSystemService<android.content.ClipboardManager>()?.let { clipboardManager ->
val clipData = ClipData.newPlainText(
"Radix Address",
state.rawSnapshot
)
clipboardManager.setPrimaryClip(clipData)
}
context.copyToClipboard(
label = "Radix Profile",
value = state.rawSnapshot.orEmpty()
)
}
) {
Icon(painter = painterResource(id = R.drawable.ic_copy), contentDescription = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import com.babylon.wallet.android.domain.usecases.VerifyAddressOnLedgerUseCase
import com.babylon.wallet.android.presentation.ui.RadixWalletPreviewTheme
import com.babylon.wallet.android.presentation.ui.composables.AccountQRCodeView
import com.babylon.wallet.android.presentation.ui.composables.BottomSheetWrapper
import com.babylon.wallet.android.utils.copyToClipboard
import com.babylon.wallet.android.utils.encodeUtf8
import com.babylon.wallet.android.utils.openUrl
import com.radixdlt.sargon.AccountAddress
Expand Down Expand Up @@ -469,20 +470,11 @@ private sealed interface OnAction {
) : CallbackBasedAction {

override fun onAction(context: Context) {
context.getSystemService<android.content.ClipboardManager>()?.let { clipboardManager ->

val clipData = ClipData.newPlainText(
"Radix Address",
actionableAddress.copyable
)

clipboardManager.setPrimaryClip(clipData)

// From Android 13, the system handles the copy confirmation
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.S_V2) {
Toast.makeText(context, R.string.addressAction_copiedToClipboard, Toast.LENGTH_SHORT).show()
}
}
context.copyToClipboard(
label = "Radix Address",
value = actionableAddress.copyable.orEmpty(),
successMessage = context.getString(R.string.addressAction_copiedToClipboard)
)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.babylon.wallet.android.utils

import android.content.ActivityNotFoundException
import android.content.ClipData
import android.content.ComponentName
import android.content.Context
import android.content.ContextWrapper
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.widget.Toast
import androidx.core.content.getSystemService
import androidx.core.net.toUri
import androidx.fragment.app.FragmentActivity
import androidx.navigation.NavController
Expand Down Expand Up @@ -39,6 +42,28 @@ suspend fun Context.biometricAuthenticateSuspend(allowIfDeviceIsNotSecure: Boole

fun Context.openUrl(url: String) = openUrl(url.toUri())

fun Context.copyToClipboard(
label: String,
value: String,
// Used only for Android versions < Android 13
successMessage: String? = null
) {
getSystemService<android.content.ClipboardManager>()?.let { clipboardManager ->

val clipData = ClipData.newPlainText(
label,
value
)

clipboardManager.setPrimaryClip(clipData)

// From Android 13, the system handles the copy confirmation
if (successMessage != null && Build.VERSION.SDK_INT <= Build.VERSION_CODES.S_V2) {
Toast.makeText(this, successMessage, Toast.LENGTH_SHORT).show()
}
}
}

@Suppress("SwallowedException")
fun Context.openUrl(uri: Uri) {
val intent = Intent(Intent.ACTION_VIEW).apply {
Expand Down

0 comments on commit 298080a

Please sign in to comment.