Skip to content

Commit bea7164

Browse files
committed
feat: Activity details invoice message copy to clipboard
1 parent 4d7e486 commit bea7164

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

app/src/main/java/to/bitkit/ui/screens/wallets/activity/ActivityItemScreen.kt

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ import androidx.compose.ui.tooling.preview.Preview
2828
import androidx.compose.ui.unit.dp
2929
import androidx.lifecycle.compose.collectAsStateWithLifecycle
3030
import to.bitkit.R
31+
import to.bitkit.ext.ellipsisMiddle
3132
import to.bitkit.ext.idValue
3233
import to.bitkit.ext.toActivityItemDate
3334
import to.bitkit.ext.toActivityItemTime
35+
import to.bitkit.models.Toast
3436
import to.bitkit.ui.Routes
37+
import to.bitkit.ui.appViewModel
3538
import to.bitkit.ui.components.BalanceHeaderView
3639
import to.bitkit.ui.components.BodySSB
3740
import to.bitkit.ui.components.ButtonSize
@@ -43,8 +46,10 @@ import to.bitkit.ui.scaffold.AppTopBar
4346
import to.bitkit.ui.scaffold.CloseNavIcon
4447
import to.bitkit.ui.scaffold.ScreenColumn
4548
import to.bitkit.ui.screens.wallets.activity.components.ActivityIcon
49+
import to.bitkit.ui.shared.util.clickableAlpha
4650
import to.bitkit.ui.theme.AppThemeSurface
4751
import to.bitkit.ui.theme.Colors
52+
import to.bitkit.ui.utils.copyToClipboard
4853
import to.bitkit.ui.utils.getScreenTitleRes
4954
import to.bitkit.viewmodels.ActivityListViewModel
5055
import uniffi.bitkitcore.Activity
@@ -65,6 +70,9 @@ fun ActivityItemScreen(
6570
val item = activities?.find { it.idValue == activityItem.id }
6671
?: return
6772

73+
val app = appViewModel ?: return
74+
val copyToastTitle = stringResource(R.string.common__copied)
75+
6876
ScreenColumn {
6977
AppTopBar(
7078
titleText = stringResource(item.getScreenTitleRes()),
@@ -74,6 +82,13 @@ fun ActivityItemScreen(
7482
ActivityItemView(
7583
item = item,
7684
onExploreClick = onExploreClick,
85+
onCopy = { text ->
86+
app.toast(
87+
type = Toast.ToastType.SUCCESS,
88+
title = copyToastTitle,
89+
description = text.ellipsisMiddle(40)
90+
)
91+
}
7792
)
7893
}
7994
}
@@ -83,6 +98,7 @@ fun ActivityItemScreen(
8398
private fun ActivityItemView(
8499
item: Activity,
85100
onExploreClick: (String) -> Unit,
101+
onCopy: (String) -> Unit,
86102
) {
87103
val isLightning = item is Activity.Lightning
88104
val accentColor = if (isLightning) Colors.Purple else Colors.Brand
@@ -267,7 +283,14 @@ private fun ActivityItemView(
267283

268284
// Note section for Lightning payments with message
269285
if (item is Activity.Lightning && item.v1.message.isNotEmpty()) {
270-
Column(modifier = Modifier.fillMaxWidth()) {
286+
val message = item.v1.message
287+
Column(
288+
modifier = Modifier
289+
.fillMaxWidth()
290+
.clickableAlpha(onClick = copyToClipboard(message) {
291+
onCopy(message)
292+
})
293+
) {
271294
Caption13Up(
272295
text = stringResource(R.string.wallet__activity_invoice_note),
273296
color = Colors.White64,
@@ -283,7 +306,7 @@ private fun ActivityItemView(
283306
.background(Colors.White10)
284307
) {
285308
Title(
286-
text = item.v1.message,
309+
text = message,
287310
color = Colors.White,
288311
modifier = Modifier.padding(24.dp),
289312
)
@@ -511,6 +534,7 @@ private fun PreviewLightningSent() {
511534
)
512535
),
513536
onExploreClick = {},
537+
onCopy = {},
514538
)
515539
}
516540
}
@@ -544,6 +568,7 @@ private fun PreviewOnchain() {
544568
)
545569
),
546570
onExploreClick = {},
571+
onCopy = {},
547572
)
548573
}
549574
}

0 commit comments

Comments
 (0)