Skip to content

Commit

Permalink
Implement clickable PremiumBadge on PremiumHomeScreen (#301)
Browse files Browse the repository at this point in the history
  • Loading branch information
markocic authored Feb 4, 2025
1 parent 78deb07 commit 545a8e2
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/detekt-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<ID>LongMethod:PremiumBuyingScreen.kt$@OptIn(ExperimentalMaterial3Api::class) @Composable private fun PremiumBuyingScreen( state: PremiumBuyingContract.UiState, eventPublisher: (PremiumBuyingContract.UiEvent) -&gt; Unit, screenCallbacks: PremiumBuyingContract.ScreenCallbacks, )</ID>
<ID>LongMethod:PremiumContactListScreen.kt$@OptIn(ExperimentalMaterial3Api::class, ExperimentalFoundationApi::class) @Composable private fun PremiumContactListScreen( state: PremiumContactListContract.UiState, eventPublisher: (PremiumContactListContract.UiEvent) -&gt; Unit, snackbarHostState: SnackbarHostState, onClose: () -&gt; Unit, )</ID>
<ID>LongMethod:PremiumContentBackupScreen.kt$@OptIn(ExperimentalMaterial3Api::class) @Composable fun PremiumContentBackupScreen( state: PremiumContentBackupContract.UiState, eventPublisher: (PremiumContentBackupContract.UiEvent) -&gt; Unit, onClose: () -&gt; Unit, )</ID>
<ID>LongMethod:PremiumHomeScreen.kt$@OptIn(ExperimentalMaterial3Api::class) @Composable private fun PremiumHomeScreen( state: PremiumHomeContract.UiState, onClose: () -&gt; Unit, onRenewSubscription: (primalName: String) -&gt; Unit, onManagePremium: () -&gt; Unit, onSupportPrimal: () -&gt; Unit, eventPublisher: (PremiumHomeContract.UiEvent) -&gt; Unit, )</ID>
<ID>LongMethod:PremiumHomeScreen.kt$@OptIn(ExperimentalMaterial3Api::class) @Composable private fun PremiumHomeScreen( state: PremiumHomeContract.UiState, onClose: () -&gt; Unit, onRenewSubscription: (primalName: String) -&gt; Unit, onManagePremium: () -&gt; Unit, onSupportPrimal: () -&gt; Unit, onLegendCardClick: (String) -&gt; Unit, eventPublisher: (PremiumHomeContract.UiEvent) -&gt; Unit, )</ID>
<ID>LongMethod:PremiumOrderHistoryScreen.kt$@Composable private fun SubscriptionHeader( modifier: Modifier, state: PremiumOrderHistoryContract.UiState, onExtendSubscription: (primalName: String) -&gt; Unit, onCancelSubscription: () -&gt; Unit, )</ID>
<ID>LongMethod:PremiumOrderHistoryScreen.kt$@OptIn(ExperimentalMaterial3Api::class, ExperimentalFoundationApi::class) @Composable private fun PremiumOrderHistoryScreen( state: PremiumOrderHistoryContract.UiState, eventPublisher: (PremiumOrderHistoryContract.UiEvent) -&gt; Unit, onExtendSubscription: (primalName: String) -&gt; Unit, onClose: () -&gt; Unit, )</ID>
<ID>LongMethod:PremiumPurchaseStage.kt$@ExperimentalMaterial3Api @Composable fun PremiumPurchaseStage( state: PremiumBuyingContract.UiState, onBack: () -&gt; Unit, onLearnMoreClick: () -&gt; Unit, eventPublisher: (PremiumBuyingContract.UiEvent) -&gt; Unit, )</ID>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,7 @@ private fun NavGraphBuilder.premiumHome(route: String, navController: NavControl
onClose = { navController.navigateUp() },
onRenewSubscription = { navController.navigateToPremiumExtendSubscription(primalName = it) },
onManagePremium = { navController.navigateToPremiumManage() },
onLegendCardClick = { navController.navigateToPremiumLegendCard(profileId = it) },
onSupportPrimal = { navController.navigateToPremiumSupportPrimal() },
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import net.primal.android.premium.legend.domain.LegendaryCustomization
interface PremiumHomeContract {

data class UiState(
val profileId: String? = null,
val avatarCdnImage: CdnImage? = null,
val profileNostrAddress: String? = null,
val profileLightningAddress: String? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ 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

@Composable
Expand All @@ -54,6 +55,7 @@ fun PremiumHomeScreen(
onRenewSubscription: (primalName: String) -> Unit,
onManagePremium: () -> Unit,
onSupportPrimal: () -> Unit,
onLegendCardClick: (String) -> Unit,
) {
val uiState = viewModel.state.collectAsState()

Expand All @@ -70,6 +72,7 @@ fun PremiumHomeScreen(
onRenewSubscription = onRenewSubscription,
onManagePremium = onManagePremium,
onSupportPrimal = onSupportPrimal,
onLegendCardClick = onLegendCardClick,
eventPublisher = viewModel::setEvent,
)
}
Expand All @@ -82,6 +85,7 @@ private fun PremiumHomeScreen(
onRenewSubscription: (primalName: String) -> Unit,
onManagePremium: () -> Unit,
onSupportPrimal: () -> Unit,
onLegendCardClick: (String) -> Unit,
eventPublisher: (PremiumHomeContract.UiEvent) -> Unit,
) {
val snackbarHostState = remember { SnackbarHostState() }
Expand Down Expand Up @@ -153,6 +157,9 @@ private fun PremiumHomeScreen(

if (state.membership != null) {
PremiumBadge(
modifier = Modifier.clickable(enabled = state.membership.isPrimalLegendTier()) {
state.profileId?.let { onLegendCardClick(it) }
},
firstCohort = state.membership.cohort1,
secondCohort = state.membership.cohort2,
membershipExpired = state.membership.isExpired(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class PremiumHomeViewModel @Inject constructor(
activeAccountStore.activeUserAccount.collect {
setState {
copy(
profileId = it.pubkey,
avatarCdnImage = it.avatarCdnImage,
profileNostrAddress = it.internetIdentifier,
profileLightningAddress = it.lightningAddress,
Expand Down

0 comments on commit 545a8e2

Please sign in to comment.