From 5aadab90a928e1e6a3dbe59205a84dacb6121006 Mon Sep 17 00:00:00 2001 From: Aleksandr Zhukov Date: Mon, 5 Aug 2024 03:32:20 +0200 Subject: [PATCH] Shared: Fix subscription management is not available for MobileContentTrial subscription (#1144) ^ALTAPPS-1317 --- .../presentation/ProfileSettingsReducer.kt | 6 ++-- .../view/ProfileSettingsViewStateMapper.kt | 30 +++++++------------ .../domain/model/SubscriptionType.kt | 3 ++ 3 files changed, 16 insertions(+), 23 deletions(-) diff --git a/shared/src/commonMain/kotlin/org/hyperskill/app/profile_settings/presentation/ProfileSettingsReducer.kt b/shared/src/commonMain/kotlin/org/hyperskill/app/profile_settings/presentation/ProfileSettingsReducer.kt index b19a118236..a76bd4b552 100644 --- a/shared/src/commonMain/kotlin/org/hyperskill/app/profile_settings/presentation/ProfileSettingsReducer.kt +++ b/shared/src/commonMain/kotlin/org/hyperskill/app/profile_settings/presentation/ProfileSettingsReducer.kt @@ -189,8 +189,8 @@ internal class ProfileSettingsReducer : StateReducer { state: State ): ReducerResult = if (state is State.Content) { - state to when (state.subscription?.type) { - SubscriptionType.MOBILE_ONLY -> + state to when { + state.subscription?.type == SubscriptionType.MOBILE_ONLY -> setOf( Action.LogAnalyticEvent( ProfileSettingsClickedHyperskillAnalyticEvent( @@ -199,7 +199,7 @@ internal class ProfileSettingsReducer : StateReducer { ), Action.ViewAction.NavigateTo.SubscriptionManagement ) - SubscriptionType.FREEMIUM -> + state.subscription?.type?.canUpgradeToMobileOnly == true -> setOf( Action.LogAnalyticEvent( ProfileSettingsClickedHyperskillAnalyticEvent( diff --git a/shared/src/commonMain/kotlin/org/hyperskill/app/profile_settings/view/ProfileSettingsViewStateMapper.kt b/shared/src/commonMain/kotlin/org/hyperskill/app/profile_settings/view/ProfileSettingsViewStateMapper.kt index 0ffd1634fb..87d585fc22 100644 --- a/shared/src/commonMain/kotlin/org/hyperskill/app/profile_settings/view/ProfileSettingsViewStateMapper.kt +++ b/shared/src/commonMain/kotlin/org/hyperskill/app/profile_settings/view/ProfileSettingsViewStateMapper.kt @@ -20,21 +20,20 @@ internal class ProfileSettingsViewStateMapper( ViewState.Content( profileSettings = state.profileSettings, isLoadingMagicLink = state.isLoadingMagicLink, - subscriptionState = if (isSubscriptionVisible(state)) { - when (state.subscription?.type) { - SubscriptionType.MOBILE_ONLY -> + subscriptionState = if (state.subscription != null && state.mobileOnlyFormattedPrice != null) { + when { + state.subscription.type == SubscriptionType.MOBILE_ONLY -> { ViewState.Content.SubscriptionState( resourceProvider.getString(SharedResources.strings.settings_subscription_mobile_only) ) - SubscriptionType.FREEMIUM -> { - state.mobileOnlyFormattedPrice?.let { - ViewState.Content.SubscriptionState( - resourceProvider.getString( - SharedResources.strings.settings_subscription_mobile_only_suggestion, - state.mobileOnlyFormattedPrice - ) + } + state.subscription.type.canUpgradeToMobileOnly -> { + ViewState.Content.SubscriptionState( + resourceProvider.getString( + SharedResources.strings.settings_subscription_mobile_only_suggestion, + state.mobileOnlyFormattedPrice ) - } + ) } else -> null } @@ -42,13 +41,4 @@ internal class ProfileSettingsViewStateMapper( null } ) - - private fun isSubscriptionVisible(state: ProfileSettingsFeature.State.Content): Boolean = - state.subscription != null && - state.mobileOnlyFormattedPrice != null && - when (state.subscription.type) { - SubscriptionType.FREEMIUM, - SubscriptionType.MOBILE_ONLY -> true - else -> false - } } \ No newline at end of file diff --git a/shared/src/commonMain/kotlin/org/hyperskill/app/subscriptions/domain/model/SubscriptionType.kt b/shared/src/commonMain/kotlin/org/hyperskill/app/subscriptions/domain/model/SubscriptionType.kt index 1608e58022..c6ae9963a1 100644 --- a/shared/src/commonMain/kotlin/org/hyperskill/app/subscriptions/domain/model/SubscriptionType.kt +++ b/shared/src/commonMain/kotlin/org/hyperskill/app/subscriptions/domain/model/SubscriptionType.kt @@ -9,6 +9,7 @@ enum class SubscriptionType( val isProjectInfoAvailable: Boolean = true, val isCertificateAvailable: Boolean = true, val areHintsLimited: Boolean = false, + val canUpgradeToMobileOnly: Boolean = false, val subscriptionLimitType: SubscriptionLimitType = SubscriptionLimitType.NONE ) { @SerialName("personal") @@ -39,12 +40,14 @@ enum class SubscriptionType( isCertificateAvailable = false, isProjectInfoAvailable = false, areHintsLimited = true, + canUpgradeToMobileOnly = true, subscriptionLimitType = SubscriptionLimitType.PROBLEMS ), MOBILE_CONTENT_TRIAL( isCertificateAvailable = false, isProjectInfoAvailable = false, areHintsLimited = true, + canUpgradeToMobileOnly = true, subscriptionLimitType = SubscriptionLimitType.TOPICS ),