Skip to content

Commit

Permalink
Implement new support us footer on PremiumHome screen (#296)
Browse files Browse the repository at this point in the history
  • Loading branch information
mehmedalijaK authored Feb 4, 2025
1 parent 78deb07 commit 73e0585
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ data class MembershipStatusResponse(
@SerialName("renews_on") val renewsOn: Long? = null,
@SerialName("origin") val origin: String? = null,
@SerialName("edited_shoutout") val editedShoutout: String? = null,
@SerialName("donated_btc") val donatedBtc: String? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ data class PremiumMembership(
val renewsOn: Long? = null,
val origin: String? = null,
val editedShoutout: String? = null,
val donatedBtc: String? = null,
) {
fun isExpired() = expiresOn != null && Clock.System.now().epochSeconds > expiresOn
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ import net.primal.android.premium.ui.PremiumBadge
import net.primal.android.premium.ui.PrimalPremiumTable
import net.primal.android.premium.ui.toHumanReadableString
import net.primal.android.premium.utils.isPremiumFreeTier
import net.primal.android.premium.utils.isPrimalLegendTier
import net.primal.android.theme.AppTheme
import net.primal.android.wallet.utils.CurrencyConversionUtils.toSats

@Composable
fun PremiumHomeScreen(
Expand Down Expand Up @@ -97,7 +99,7 @@ private fun PremiumHomeScreen(
Scaffold(
topBar = {
PrimalTopAppBar(
title = stringResource(id = R.string.premium_member_title),
title = stringResource(id = R.string.premium_home_member_title),
navigationIcon = PrimalIcons.ArrowBack,
onNavigationIconClick = onClose,
showDivider = false,
Expand All @@ -106,14 +108,14 @@ private fun PremiumHomeScreen(
bottomBar = {
if (state.membership?.isExpired() == true) {
BottomBarButton(
text = stringResource(id = R.string.premium_renew_subscription),
text = stringResource(id = R.string.premium_home_renew_subscription),
onClick = {
onRenewSubscription(state.membership.premiumName)
},
)
} else {
BottomBarButton(
text = stringResource(id = R.string.premium_manage_premium_button),
text = stringResource(id = R.string.premium_home_premium_button),
onClick = onManagePremium,
)
}
Expand Down Expand Up @@ -164,7 +166,7 @@ private fun PremiumHomeScreen(
if (state.membership.isPremiumFreeTier()) {
Text(
modifier = Modifier.padding(horizontal = 36.dp),
text = stringResource(id = R.string.premium_member_early_primal_user),
text = stringResource(id = R.string.premium_home_member_early_primal_user),
color = AppTheme.extraColorScheme.onSurfaceVariantAlt2,
style = AppTheme.typography.bodyMedium,
textAlign = TextAlign.Center,
Expand All @@ -186,17 +188,26 @@ private fun PremiumHomeScreen(
state.membership.isExpired() -> {
Text(
color = AppTheme.extraColorScheme.onSurfaceVariantAlt2,
text = stringResource(id = R.string.premium_expired_subscription_notice),
text = stringResource(id = R.string.premium_home_expired_subscription_notice),
style = AppTheme.typography.bodyMedium,
textAlign = TextAlign.Center,
)
}

else -> {
SupportUsNotice(
visible = state.showSupportUsNotice,
onSupportPrimal = onSupportPrimal,
)
if (state.showSupportUsNotice) {
if (state.membership.isPrimalLegendTier()) {
SupportUsNoticeLegend(
visible = state.membership.donatedBtc != null,
donatedSats = state.membership.donatedBtc?.toSats()?.toLong() ?: 0L,
onSupportPrimal = onSupportPrimal,
)
} else {
SupportUsNoticePremium(
onSupportPrimal = onSupportPrimal,
)
}
}
}
}
}
Expand Down Expand Up @@ -230,38 +241,34 @@ private fun BottomBarButton(
}

@Composable
private fun SupportUsNotice(visible: Boolean, onSupportPrimal: () -> Unit) {
private fun SupportUsNoticePremium(onSupportPrimal: () -> Unit) {
Column(
modifier = Modifier.alpha(if (visible) 1.0f else 0.0f),
modifier = Modifier,
verticalArrangement = Arrangement.spacedBy(8.dp, Alignment.CenterVertically),
horizontalAlignment = Alignment.CenterHorizontally,
) {
Text(
color = AppTheme.extraColorScheme.onSurfaceVariantAlt2,
text = stringResource(id = R.string.premium_enjoying_primal),
text = stringResource(id = R.string.premium_home_enjoying_primal),
style = AppTheme.typography.bodyMedium,
textAlign = TextAlign.Center,
)
Row {
Text(
color = AppTheme.extraColorScheme.onSurfaceVariantAlt2,
text = stringResource(id = R.string.premium_enjoying_primal_if_so) + " ",
text = stringResource(id = R.string.premium_home_enjoying_primal_if_so) + " ",
style = AppTheme.typography.bodyMedium,
)
Text(
modifier = Modifier
.clickable(
enabled = visible,
onClick = onSupportPrimal,
),
modifier = Modifier.clickable(onClick = onSupportPrimal),
style = AppTheme.typography.bodyMedium,
text = buildAnnotatedString {
withStyle(
style = SpanStyle(
color = AppTheme.colorScheme.secondary,
),
) {
append(stringResource(id = R.string.premium_support_us))
append(stringResource(id = R.string.premium_home_support_us))
}
withStyle(
style = SpanStyle(
Expand All @@ -275,3 +282,56 @@ private fun SupportUsNotice(visible: Boolean, onSupportPrimal: () -> Unit) {
}
}
}

@Composable
private fun SupportUsNoticeLegend(
visible: Boolean,
donatedSats: Long,
onSupportPrimal: () -> Unit,
) {
Column(
modifier = Modifier.alpha(if (visible) 1.0f else 0.0f),
verticalArrangement = Arrangement.spacedBy(8.dp, Alignment.CenterVertically),
horizontalAlignment = Alignment.CenterHorizontally,
) {
Row {
Text(
color = AppTheme.extraColorScheme.onSurfaceVariantAlt2,
text = stringResource(id = R.string.premium_home_legend_contribution_title) + " ",
style = AppTheme.typography.bodyMedium,
)
Text(
modifier = Modifier.clickable(onClick = onSupportPrimal),
style = AppTheme.typography.bodyMedium,
fontWeight = FontWeight.SemiBold,
text = buildAnnotatedString {
withStyle(
style = SpanStyle(
color = AppTheme.colorScheme.onBackground,
),
) {
append(donatedSats.let { "%,d sats".format(it) })
}
},
)
}
if (donatedSats > 0L) {
Text(
color = AppTheme.extraColorScheme.onSurfaceVariantAlt2,
text = stringResource(id = R.string.premium_home_legend_support_appreciation),
style = AppTheme.typography.bodyMedium,
textAlign = TextAlign.Center,
)
}
Text(
modifier = Modifier
.clickable(
onClick = onSupportPrimal,
),
color = AppTheme.colorScheme.secondary,
text = stringResource(id = R.string.premium_home_legend_contribute_more),
style = AppTheme.typography.bodyMedium,
textAlign = TextAlign.Center,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import net.primal.android.premium.home.PremiumHomeContract.UiEvent
import net.primal.android.premium.home.PremiumHomeContract.UiState
import net.primal.android.premium.legend.domain.asLegendaryCustomization
import net.primal.android.premium.repository.PremiumRepository
import net.primal.android.premium.utils.isPrimalLegendTier
import net.primal.android.profile.repository.ProfileRepository
import net.primal.android.user.accounts.active.ActiveAccountStore
import net.primal.android.user.repository.UserRepository
Expand Down Expand Up @@ -131,7 +130,7 @@ class PremiumHomeViewModel @Inject constructor(
val clientConfigShowSupport = premiumRepository.shouldShowSupportUsNotice()
setState {
copy(
showSupportUsNotice = clientConfigShowSupport && !membership.isPrimalLegendTier(),
showSupportUsNotice = clientConfigShowSupport,
)
}
} catch (error: WssException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ class PremiumRepository @Inject constructor(
recurring = this.recurring,
origin = this.origin,
editedShoutout = this.editedShoutout,
donatedBtc = this.donatedBtc,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ fun PrimalPremiumTable(
PrimalDivider()
if (premiumMembership.isPrimalLegendTier()) {
PrimalPremiumTableRow(
key = stringResource(id = R.string.premium_table_expires),
value = stringResource(id = R.string.premium_table_never),
key = stringResource(id = R.string.premium_home_table_expires),
value = stringResource(id = R.string.premium_home_table_never),
alwaysHideApply = true,
)
} else {
PrimalPremiumTableRow(
key = when {
premiumMembership.isExpired() -> stringResource(id = R.string.premium_table_expired_on)
premiumMembership.recurring -> stringResource(id = R.string.premium_table_renews_on)
else -> stringResource(id = R.string.premium_table_expires_on)
premiumMembership.isExpired() -> stringResource(id = R.string.premium_home_table_expired_on)
premiumMembership.recurring -> stringResource(id = R.string.premium_home_table_renews_on)
else -> stringResource(id = R.string.premium_home_table_expires_on)
},
value = when {
premiumMembership.recurring && premiumMembership.renewsOn != null ->
Expand All @@ -80,7 +80,7 @@ fun PrimalPremiumTable(
premiumMembership.expiresOn != null -> Instant.ofEpochSecond(premiumMembership.expiresOn)
.formatToDefaultDateFormat(FormatStyle.LONG)

else -> stringResource(R.string.premium_table_never)
else -> stringResource(R.string.premium_home_table_never)
},
alwaysHideApply = true,
)
Expand Down Expand Up @@ -148,7 +148,7 @@ private fun PrimalPremiumTableRow(
}
Text(
modifier = Modifier.clickable { onApplyClick?.invoke() },
text = stringResource(id = R.string.premium_table_apply),
text = stringResource(id = R.string.premium_home_table_apply),
color = AppTheme.colorScheme.secondary,
style = AppTheme.typography.bodyMedium,
)
Expand Down
33 changes: 18 additions & 15 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -160,21 +160,24 @@
<string name="premium_promo_code_apply_button">Apply Promo Code</string>
<string name="premium_promo_code_cancel_button">Cancel</string>

<string name="premium_member_title">Premium</string>
<string name="premium_member_early_primal_user">Hey there! You are an early Primal user who interacted with our team, so we gave you 6 months of Primal Premium for free. ♥\uFE0F\uD83E\uDEC2</string>
<string name="premium_manage_premium_button">Manage Premium</string>
<string name="premium_renew_subscription">Renew Subscription</string>
<string name="premium_extend_subscription">Extend Subscription</string>
<string name="premium_enjoying_primal">Are you enjoying Primal?</string>
<string name="premium_enjoying_primal_if_so">If so, see how you can</string>
<string name="premium_support_us">support us</string>
<string name="premium_table_expires">Expires</string>
<string name="premium_table_never">Never</string>
<string name="premium_table_renews_on">Renews on</string>
<string name="premium_table_expires_on">Expires on</string>
<string name="premium_table_expired_on">Expired on</string>
<string name="premium_table_apply">apply</string>
<string name="premium_expired_subscription_notice">Your Primal Premium subscription has expired.\nYou can renew it below:</string>
<string name="premium_home_member_title">Premium</string>
<string name="premium_home_member_early_primal_user">Hey there! You are an early Primal user who interacted with our team, so we gave you 6 months of Primal Premium for free. ♥\uFE0F\uD83E\uDEC2</string>
<string name="premium_home_premium_button">Manage Premium</string>
<string name="premium_home_renew_subscription">Renew Subscription</string>
<string name="premium_home_extend_subscription">Extend Subscription</string>
<string name="premium_home_enjoying_primal">Are you enjoying Primal?</string>
<string name="premium_home_enjoying_primal_if_so">If so, see how you can</string>
<string name="premium_home_support_us">support us</string>
<string name="premium_home_table_expires">Expires</string>
<string name="premium_home_table_never">Never</string>
<string name="premium_home_table_renews_on">Renews on</string>
<string name="premium_home_table_expires_on">Expires on</string>
<string name="premium_home_table_expired_on">Expired on</string>
<string name="premium_home_table_apply">apply</string>
<string name="premium_home_expired_subscription_notice">Your Primal Premium subscription has expired.\nYou can renew it below:</string>
<string name="premium_home_legend_contribution_title">Your contribution to Primal:</string>
<string name="premium_home_legend_support_appreciation">Thank you for your support! 💜🫂</string>
<string name="premium_home_legend_contribute_more">Want to contribute more?</string>

<string name="premium_support_primal_title">Support Primal</string>

Expand Down

0 comments on commit 73e0585

Please sign in to comment.