Skip to content

Commit 9e7b239

Browse files
committed
feat: Truncate long caption in activity list items
1 parent e563a4b commit 9e7b239

File tree

3 files changed

+62
-32
lines changed

3 files changed

+62
-32
lines changed

app/src/main/java/to/bitkit/services/CoreService.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,8 @@ class ActivityService(
354354
"Gift for mom",
355355
"Split dinner bill",
356356
"Monthly rent",
357-
"Gym membership"
357+
"Gym membership",
358+
"Very long invoice message to test truncation in list",
358359
)
359360

360361
repeat(count) { i ->

app/src/main/java/to/bitkit/ui/components/Text.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,8 @@ fun CaptionB(
349349
text: String,
350350
modifier: Modifier = Modifier,
351351
color: Color = MaterialTheme.colorScheme.primary,
352+
maxLines: Int = Int.MAX_VALUE,
353+
overflow: TextOverflow = if (maxLines == 1) TextOverflow.Ellipsis else TextOverflow.Clip,
352354
) {
353355
Text(
354356
text = text,
@@ -362,6 +364,8 @@ fun CaptionB(
362364
textAlign = TextAlign.Start,
363365
),
364366
modifier = modifier,
367+
maxLines = maxLines,
368+
overflow = overflow,
365369
)
366370
}
367371

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

Lines changed: 56 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import androidx.compose.foundation.layout.width
1010
import androidx.compose.runtime.Composable
1111
import androidx.compose.ui.Alignment
1212
import androidx.compose.ui.Modifier
13+
import androidx.compose.ui.platform.LocalInspectionMode
1314
import androidx.compose.ui.res.stringResource
1415
import androidx.compose.ui.tooling.preview.Preview
1516
import androidx.compose.ui.tooling.preview.PreviewParameter
@@ -20,6 +21,7 @@ import to.bitkit.ext.DatePattern
2021
import to.bitkit.ext.formatted
2122
import to.bitkit.ext.rawId
2223
import to.bitkit.models.PrimaryDisplay
24+
import to.bitkit.models.formatToModernDisplay
2325
import to.bitkit.ui.LocalCurrencies
2426
import to.bitkit.ui.components.BodyMSB
2527
import to.bitkit.ui.components.CaptionB
@@ -70,6 +72,7 @@ fun ActivityRow(
7072
Spacer(modifier = Modifier.width(16.dp))
7173
Column(
7274
verticalArrangement = Arrangement.spacedBy(4.dp),
75+
modifier = Modifier.weight(1f)
7376
) {
7477
TransactionStatusText(
7578
txType = txType,
@@ -91,9 +94,10 @@ fun ActivityRow(
9194
CaptionB(
9295
text = subtitleText,
9396
color = Colors.White64,
97+
maxLines = 1,
9498
)
9599
}
96-
Spacer(modifier = Modifier.weight(1f))
100+
Spacer(modifier = Modifier.width(16.dp))
97101
AmountView(
98102
item = item,
99103
prefix = amountPrefix,
@@ -141,47 +145,68 @@ private fun AmountView(
141145
item: Activity,
142146
prefix: String,
143147
) {
144-
val currency = currencyViewModel ?: return
145-
val (_, _, _, _, displayUnit, primaryDisplay) = LocalCurrencies.current
146148
val amount = when (item) {
147149
is Activity.Lightning -> item.v1.value
148150
is Activity.Onchain -> when (item.v1.txType) {
149151
PaymentType.SENT -> item.v1.value + item.v1.fee
150152
else -> item.v1.value
151153
}
152154
}
155+
156+
val isPreview = LocalInspectionMode.current
157+
if (isPreview) {
158+
AmountViewContent(
159+
title = amount.toLong().formatToModernDisplay(),
160+
titlePrefix = prefix,
161+
subtitle = "$ 123.45",
162+
)
163+
return
164+
}
165+
166+
val currency = currencyViewModel ?: return
167+
val (_, _, _, _, displayUnit, primaryDisplay) = LocalCurrencies.current
168+
153169
currency.convert(sats = amount.toLong())?.let { converted ->
154170
val btcComponents = converted.bitcoinDisplay(displayUnit)
155-
Column(
156-
horizontalAlignment = Alignment.End,
157-
verticalArrangement = Arrangement.spacedBy(2.dp),
171+
if (primaryDisplay == PrimaryDisplay.BITCOIN) {
172+
AmountViewContent(
173+
title = btcComponents.value,
174+
titlePrefix = prefix,
175+
subtitle = "${converted.symbol} ${converted.formatted}",
176+
)
177+
} else {
178+
AmountViewContent(
179+
title = "${converted.symbol} ${converted.formatted}",
180+
titlePrefix = prefix,
181+
subtitle = btcComponents.value,
182+
)
183+
}
184+
}
185+
}
186+
187+
@Composable
188+
private fun AmountViewContent(
189+
title: String,
190+
titlePrefix: String,
191+
subtitle: String,
192+
modifier: Modifier = Modifier,
193+
) {
194+
Column(
195+
modifier = modifier,
196+
horizontalAlignment = Alignment.End,
197+
verticalArrangement = Arrangement.spacedBy(2.dp),
198+
) {
199+
Row(
200+
verticalAlignment = Alignment.CenterVertically,
201+
horizontalArrangement = Arrangement.spacedBy(1.dp),
158202
) {
159-
if (primaryDisplay == PrimaryDisplay.BITCOIN) {
160-
Row(
161-
verticalAlignment = Alignment.CenterVertically,
162-
horizontalArrangement = Arrangement.spacedBy(1.dp),
163-
) {
164-
BodyMSB(text = prefix, color = Colors.White64)
165-
BodyMSB(text = btcComponents.value)
166-
}
167-
CaptionB(
168-
text = "${converted.symbol} ${converted.formatted}",
169-
color = Colors.White64,
170-
)
171-
} else {
172-
Row(
173-
verticalAlignment = Alignment.CenterVertically,
174-
horizontalArrangement = Arrangement.spacedBy(1.dp),
175-
) {
176-
BodyMSB(text = prefix, color = Colors.White64)
177-
BodyMSB(text = "${converted.symbol} ${converted.formatted}")
178-
}
179-
CaptionB(
180-
text = btcComponents.value,
181-
color = Colors.White64,
182-
)
183-
}
203+
BodyMSB(text = titlePrefix, color = Colors.White64)
204+
BodyMSB(text = title)
184205
}
206+
CaptionB(
207+
text = subtitle,
208+
color = Colors.White64,
209+
)
185210
}
186211
}
187212

0 commit comments

Comments
 (0)