Skip to content

Commit 715bcfe

Browse files
committed
chore(chat): improve wording of message content for returns
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent a5378fd commit 715bcfe

4 files changed

Lines changed: 121 additions & 66 deletions

File tree

app/src/main/java/com/getcode/ui/components/chat/ChatNode.kt

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@ import com.getcode.model.Currency
2626
import com.getcode.model.GenericAmount
2727
import com.getcode.model.MessageContent
2828
import com.getcode.model.Title
29+
import com.getcode.model.Verb
2930
import com.getcode.theme.BrandLight
3031
import com.getcode.theme.CodeTheme
3132
import com.getcode.util.DateUtils
3233
import com.getcode.util.Kin
3334
import com.getcode.util.formatted
3435
import com.getcode.utils.FormatUtils
3536
import com.getcode.ui.components.Badge
37+
import com.getcode.ui.components.chat.utils.localizedText
3638
import java.util.Locale
3739

3840
object ChatNodeDefaults {
@@ -136,39 +138,4 @@ private val Chat.messagePreview: String
136138
}
137139

138140
return filtered.map { it.localizedText }.joinToString(" ")
139-
}
140-
141-
val MessageContent.localizedText: String
142-
@Composable get() {
143-
return when (val content = this) {
144-
is MessageContent.Exchange -> {
145-
val amount = when (val kinAmount = content.amount) {
146-
is GenericAmount.Exact -> {
147-
val currency =
148-
LocalCurrencyUtils.current?.getCurrency(kinAmount.currencyCode.name)
149-
kinAmount.amount.formatted(currency = currency ?: Currency.Kin)
150-
}
151-
152-
is GenericAmount.Partial -> {
153-
FormatUtils.formatCurrency(kinAmount.fiat.amount, Locale.getDefault())
154-
}
155-
}
156-
157-
"You ${content.verb.toString().lowercase()} $amount"
158-
}
159-
160-
is MessageContent.Localized -> {
161-
with(LocalContext.current) {
162-
val resId = resources.getIdentifier(
163-
content.value,
164-
"string",
165-
BuildConfig.APPLICATION_ID
166-
).let { if (it == 0) null else it }
167-
168-
resId?.let { getString(it) }.orEmpty()
169-
}
170-
}
171-
172-
MessageContent.SodiumBox -> "<! encrypted content !>"
173-
}
174141
}

app/src/main/java/com/getcode/ui/components/chat/MessageNode.kt

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import com.getcode.model.Verb
2929
import com.getcode.theme.BrandDark
3030
import com.getcode.theme.BrandLight
3131
import com.getcode.theme.CodeTheme
32+
import com.getcode.ui.components.chat.utils.localizedText
3233
import com.getcode.util.formatTimeRelatively
3334
import com.getcode.view.main.home.components.PriceWithFlag
3435
import kotlinx.datetime.Instant
@@ -145,22 +146,39 @@ private fun MessagePayment(
145146
verticalArrangement = Arrangement.spacedBy(CodeTheme.dimens.grid.x2),
146147
horizontalAlignment = Alignment.CenterHorizontally,
147148
) {
148-
Text(
149-
text = verb.localizedText,
150-
style = CodeTheme.typography.body1.copy(fontWeight = FontWeight.W500)
151-
)
152-
153-
PriceWithFlag(
154-
currencyCode = amount.rate.currency,
155-
amount = amount,
156-
text = { price ->
157-
Text(
158-
text = price,
159-
color = Color.White,
160-
style = CodeTheme.typography.h3
161-
)
162-
}
163-
)
149+
if (verb == Verb.Returned) {
150+
PriceWithFlag(
151+
currencyCode = amount.rate.currency,
152+
amount = amount,
153+
text = { price ->
154+
Text(
155+
text = price,
156+
color = Color.White,
157+
style = CodeTheme.typography.h3
158+
)
159+
}
160+
)
161+
Text(
162+
text = verb.localizedText,
163+
style = CodeTheme.typography.body1.copy(fontWeight = FontWeight.W500)
164+
)
165+
} else {
166+
Text(
167+
text = verb.localizedText,
168+
style = CodeTheme.typography.body1.copy(fontWeight = FontWeight.W500)
169+
)
170+
PriceWithFlag(
171+
currencyCode = amount.rate.currency,
172+
amount = amount,
173+
text = { price ->
174+
Text(
175+
text = price,
176+
color = Color.White,
177+
style = CodeTheme.typography.h3
178+
)
179+
}
180+
)
181+
}
164182
}
165183
}
166184

@@ -182,17 +200,4 @@ private fun MessageText(modifier: Modifier = Modifier, text: String, date: Insta
182200
color = BrandLight,
183201
)
184202
}
185-
}
186-
187-
private val Verb.localizedText: String
188-
@SuppressLint("DiscouragedApi")
189-
@Composable get() = with(LocalContext.current) context@{
190-
if (this@localizedText == Verb.Unknown) stringResource(id = R.string.title_unknown)
191-
val resId = resources.getIdentifier(
192-
"subtitle_verb_${this@localizedText.toString().lowercase()}",
193-
"string",
194-
BuildConfig.APPLICATION_ID
195-
).let { if (it == 0) null else it }
196-
197-
resId?.let { getString(it) }.orEmpty()
198-
}
203+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package com.getcode.ui.components.chat.utils
2+
3+
import android.annotation.SuppressLint
4+
import androidx.compose.runtime.Composable
5+
import androidx.compose.ui.platform.LocalContext
6+
import androidx.compose.ui.res.stringResource
7+
import com.getcode.BuildConfig
8+
import com.getcode.LocalCurrencyUtils
9+
import com.getcode.R
10+
import com.getcode.model.Currency
11+
import com.getcode.model.GenericAmount
12+
import com.getcode.model.MessageContent
13+
import com.getcode.model.Verb
14+
import com.getcode.util.Kin
15+
import com.getcode.util.formatted
16+
import com.getcode.utils.FormatUtils
17+
import java.util.Locale
18+
19+
internal val MessageContent.localizedText: String
20+
@Composable get() {
21+
return when (val content = this) {
22+
is MessageContent.Exchange -> {
23+
val amount = when (val kinAmount = content.amount) {
24+
is GenericAmount.Exact -> {
25+
val currency =
26+
LocalCurrencyUtils.current?.getCurrency(kinAmount.currencyCode.name)
27+
kinAmount.amount.formatted(currency = currency ?: Currency.Kin)
28+
}
29+
30+
is GenericAmount.Partial -> {
31+
FormatUtils.formatCurrency(kinAmount.fiat.amount, Locale.getDefault())
32+
}
33+
}
34+
35+
val localized = content.verb.localizedText
36+
37+
when (content.verb) {
38+
Verb.Deposited,
39+
Verb.Gave,
40+
Verb.Paid,
41+
Verb.Purchased,
42+
Verb.Received,
43+
Verb.Sent,
44+
Verb.Spent,
45+
Verb.Unknown,
46+
Verb.Withdrew -> {
47+
"$localized $amount"
48+
}
49+
Verb.Returned -> {
50+
"$amount $localized"
51+
}
52+
53+
}
54+
}
55+
56+
is MessageContent.Localized -> {
57+
with(LocalContext.current) {
58+
val resId = resources.getIdentifier(
59+
content.value,
60+
"string",
61+
BuildConfig.APPLICATION_ID
62+
).let { if (it == 0) null else it }
63+
64+
resId?.let { getString(it) }.orEmpty()
65+
}
66+
}
67+
68+
MessageContent.SodiumBox -> "<! encrypted content !>"
69+
}
70+
}
71+
72+
val Verb.localizedText: String
73+
@SuppressLint("DiscouragedApi")
74+
@Composable get() = with(LocalContext.current) context@{
75+
if (this@localizedText == Verb.Unknown) stringResource(id = R.string.title_unknown)
76+
val resId = resources.getIdentifier(
77+
"subtitle_verb_${this@localizedText.toString().lowercase()}",
78+
"string",
79+
BuildConfig.APPLICATION_ID
80+
).let { if (it == 0) null else it }
81+
82+
resId?.let { getString(it) }.orEmpty()
83+
}

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@
306306
<string name="subtitle_verb_withdrew">You withdrew</string>
307307
<string name="subtitle_verb_deposited">You deposited</string>
308308
<string name="subtitle_verb_sent">You sent</string>
309-
<string name="subtitle_verb_returned">You returned</string>
309+
<string name="subtitle_verb_returned">was returned to you</string>
310310
<string name="subtitle_verb_spent">You spent</string>
311311
<string name="subtitle_verb_paid">You paid</string>
312312
<string name="subtitle_verb_purchased">You purchased</string>

0 commit comments

Comments
 (0)