Skip to content

Commit 43f73c3

Browse files
authored
Merge pull request #528 from code-payments/feat/splat-tipcard-if-unseen
feat: splat "Receive" (Tip Card) if unseen
2 parents 1b1af6f + e694890 commit 43f73c3

6 files changed

Lines changed: 41 additions & 9 deletions

File tree

api/src/main/java/com/getcode/model/PrefBool.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ sealed class PrefsBool(val value: String) {
2525
data object IS_ELIGIBLE_GET_FIRST_KIN_AIRDROP: PrefsBool("is_eligible_get_first_kin_airdrop"), InternalRouting
2626
data object IS_ELIGIBLE_GIVE_FIRST_KIN_AIRDROP: PrefsBool("is_eligible_give_first_kin_airdrop"), InternalRouting
2727
data object HAS_REMOVED_LOCAL_CURRENCY: PrefsBool("removed_local_currency"), InternalRouting
28+
data object DISMISSED_TIP_CARD_BANNER : PrefsBool("dismissed_tip_card_banner"), InternalRouting
2829
data object SEEN_TIP_CARD : PrefsBool("seen_tip_card"), InternalRouting
2930
data object STARTED_TIP_CONNECT: PrefsBool("started_tip_connect"), InternalRouting
3031

api/src/main/java/com/getcode/network/ChatHistoryController.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class ChatHistoryController @Inject constructor(
116116
chatFlows[chatId] = it
117117
}
118118

119-
val unreadCount = notifications
119+
val notificationsUnreadCount = notifications
120120
.filterNotNull()
121121
// Ignore muted chats and unsubscribed chats
122122
.map { it.filter { c -> !c.isMuted && c.isSubscribed } }

api/src/main/java/com/getcode/network/TipController.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,13 @@ class TipController @Inject constructor(
164164
userMetadata = null
165165
}
166166

167+
fun seenTipCardBanner() {
168+
prefRepository.set(PrefsBool.DISMISSED_TIP_CARD_BANNER, true)
169+
endVerification()
170+
}
171+
167172
fun clearTwitterSplat() {
168173
prefRepository.set(PrefsBool.SEEN_TIP_CARD, true)
169-
endVerification()
170174
}
171175

172176
fun generateTipVerification(): String? {

app/src/main/java/com/getcode/ui/components/Badge.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ fun Badge(
2929
exitTransition: ExitTransition = fadeOut() + scaleOut(tween(durationMillis = 300))
3030
) {
3131
AnimatedVisibility(modifier = modifier, visible = count > 0, enter = enterTransition, exit = exitTransition) {
32-
val text = when {
33-
count in 1..99 -> "$count"
32+
val text = when (count) {
33+
0 -> ""
34+
in 1..99 -> "$count"
3435
else -> "99+"
3536
}
3637

app/src/main/java/com/getcode/view/main/home/HomeViewModel.kt

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ data class HomeUiModel(
151151
val billState: BillState = BillState.Default,
152152
val restrictionType: RestrictionType? = null,
153153
val isRemoteSendLoading: Boolean = false,
154-
val chatUnreadCount: Int = 0,
154+
val splatTipCard: Boolean = false,
155+
val notificationUnreadCount: Int = 0,
155156
val buyModule: Feature = BuyModuleFeature(),
156157
val requestKin: Feature = RequestKinFeature(),
157158
val actions: List<HomeAction> = listOf(HomeAction.GIVE_KIN, HomeAction.TIP_CARD, HomeAction.BALANCE),
@@ -238,6 +239,18 @@ class HomeViewModel @Inject constructor(
238239
}.launchIn(viewModelScope)
239240

240241
tipController.showTwitterSplat
242+
.onEach { splat ->
243+
viewModelScope.launch {
244+
if (splat) {
245+
delay(300)
246+
} else {
247+
delay(500)
248+
}
249+
uiFlow.update {
250+
it.copy(splatTipCard = splat)
251+
}
252+
}
253+
}
241254
.filter { it }
242255
.onEach { delay(500) }
243256
.flatMapLatest { tipController.connectedAccount }
@@ -258,7 +271,7 @@ class HomeViewModel @Inject constructor(
258271
primaryAction = ::presentShareableTipCard,
259272
secondaryText = resources.getString(R.string.action_later),
260273
secondaryAction = {
261-
tipController.clearTwitterSplat()
274+
tipController.seenTipCardBanner()
262275
}
263276
)
264277
)
@@ -333,11 +346,11 @@ class HomeViewModel @Inject constructor(
333346
}
334347
}.launchIn(viewModelScope)
335348

336-
historyController.unreadCount
349+
historyController.notificationsUnreadCount
337350
.distinctUntilChanged()
338351
.map { it }
339352
.onEach { count ->
340-
uiFlow.update { it.copy(chatUnreadCount = count) }
353+
uiFlow.update { it.copy(notificationUnreadCount = count) }
341354
}.launchIn(viewModelScope)
342355

343356
prefRepository.observeOrDefault(PrefsBool.LOG_SCAN_TIMES, false)

app/src/main/java/com/getcode/view/main/home/components/HomeBottom.kt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ internal fun HomeBottom(
7979
badge = {
8080
Badge(
8181
modifier = Modifier.padding(top = 6.dp, end = 1.dp),
82-
count = state.chatUnreadCount,
82+
count = state.notificationUnreadCount,
8383
color = ChatNodeDefaults.UnreadIndicator,
8484
enterTransition = scaleIn(
8585
animationSpec = tween(
@@ -98,6 +98,19 @@ internal fun HomeBottom(
9898
label = stringResource(R.string.action_receive),
9999
painter = painterResource(R.drawable.ic_tip_card),
100100
onClick = { onPress(action) },
101+
badge = {
102+
Badge(
103+
modifier = Modifier.padding(top = 6.dp, end = 1.dp),
104+
count = if (state.splatTipCard) 1 else 0,
105+
color = ChatNodeDefaults.UnreadIndicator,
106+
enterTransition = scaleIn(
107+
animationSpec = tween(
108+
durationMillis = 300,
109+
delayMillis = 1000
110+
)
111+
) + fadeIn()
112+
)
113+
}
101114
)
102115
}
103116

0 commit comments

Comments
 (0)