Commit a936f5c7 by Dmitry Stepanets

[IOS-287]: Moved presentation logic to FeatureAvailabilityManager

parent c5aa9e6c
...@@ -231,6 +231,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate { ...@@ -231,6 +231,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
} }
return storeManager.everHadSubscription return storeManager.everHadSubscription
} }
let initialSubscriptionShown = ClosureFeatureAvailabilityChecker {
return Settings.shared.initialSubscriptionShown
}
let ccpaHelper = CCPAHelper.shared
let firstTimeUser = ClosureFeatureAvailabilityChecker { [weak ccpaHelper] in
guard let ccpaHelper = ccpaHelper else {
return false
}
return ccpaHelper.isNewUser
}
let isPhone = DeviceTypeFeatureAvailabilityChecker(deviceType: .phone) let isPhone = DeviceTypeFeatureAvailabilityChecker(deviceType: .phone)
...@@ -257,6 +267,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate { ...@@ -257,6 +267,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
break // config only break // config only
case .subscription: case .subscription:
break // configOnly break // configOnly
case .subscriptionNudge:
break //config only
case .initialSubscriptionNudge:
availabilityCheckers[feature] = !initialSubscriptionShown && firstTimeUser && !premium
case .subscriptionForPro: case .subscriptionForPro:
availabilityCheckers[feature] = premium availabilityCheckers[feature] = premium
case .extendedDailyForecast: case .extendedDailyForecast:
......
...@@ -31,6 +31,8 @@ ...@@ -31,6 +31,8 @@
"a9_refresh_rate": 0, "a9_refresh_rate": 0,
"placements": {} "placements": {}
}</string> }</string>
<key>ios_premium_nudge_show_to_ftu</key>
<false/>
<key>ios_terceptsdk_enabled</key> <key>ios_terceptsdk_enabled</key>
<true/> <true/>
</dict> </dict>
......
...@@ -23,6 +23,8 @@ public class ConfigManager { ...@@ -23,6 +23,8 @@ public class ConfigManager {
private static let shortsLeftBelowCountKey = "shorts_left_below_nudge_every_x_cards" private static let shortsLeftBelowCountKey = "shorts_left_below_nudge_every_x_cards"
private static let shortsSwipeUpNudgeCountKey = "shorts_swipe_up_nudge_on_x_cards" private static let shortsSwipeUpNudgeCountKey = "shorts_swipe_up_nudge_on_x_cards"
private static let subscriptionConfigKey = "ios_subscription_config" private static let subscriptionConfigKey = "ios_subscription_config"
private static let premiumNudgeSessionShowing = "ios_premium_nudge_sessions_between_showing"
private static let premiumNudgeTotalTimes = "ios_premium_nudge_total_times_to_show"
private let delegates = MulticastDelegate<ConfigManagerDelegate>() private let delegates = MulticastDelegate<ConfigManagerDelegate>()
...@@ -43,10 +45,13 @@ public class ConfigManager { ...@@ -43,10 +45,13 @@ public class ConfigManager {
ccpaUpdateInterval: nil, ccpaUpdateInterval: nil,
shortsLeftBelowCountKey: 0, shortsLeftBelowCountKey: 0,
shortsSwipeUpNudgeCountKey: 0, shortsSwipeUpNudgeCountKey: 0,
premiumNudgeSessionShowing: 0,
premiumNudgeTotalTimes: 0,
explicitFeatureAvailability: [ explicitFeatureAvailability: [
.nwsAlertsViaMoEngage: true, .nwsAlertsViaMoEngage: true,
.attPrompt: false, .attPrompt: false,
.shortsLastNudge: false, .shortsLastNudge: false,
.subscriptionNudge: false,
.onboarding: false, .onboarding: false,
.terceptSdk: false .terceptSdk: false
], subscriptionsConfig: SubscriptionsListConfig() ], subscriptionsConfig: SubscriptionsListConfig()
...@@ -142,6 +147,12 @@ public class ConfigManager { ...@@ -142,6 +147,12 @@ public class ConfigManager {
let shortsSwipeNudgeCountValue = remoteConfig.configValue(forKey: ConfigManager.shortsSwipeUpNudgeCountKey) let shortsSwipeNudgeCountValue = remoteConfig.configValue(forKey: ConfigManager.shortsSwipeUpNudgeCountKey)
let shortsSwipeNudgeCount = shortsSwipeNudgeCountValue.numberValue.intValue let shortsSwipeNudgeCount = shortsSwipeNudgeCountValue.numberValue.intValue
let premiumNudgeSessionShownigValue = remoteConfig.configValue(forKey: ConfigManager.premiumNudgeSessionShowing)
let premiumNudgeSessionShowngCount = premiumNudgeSessionShownigValue.numberValue.intValue
let premiumNudgeTotalTimesValue = remoteConfig.configValue(forKey: ConfigManager.premiumNudgeTotalTimes)
let premiumNudgeTotalTimesCount = premiumNudgeTotalTimesValue.numberValue.intValue
let featureAvailability = parseFeatureAvailability() let featureAvailability = parseFeatureAvailability()
var subscriptionsConfig = SubscriptionsListConfig() var subscriptionsConfig = SubscriptionsListConfig()
...@@ -161,6 +172,8 @@ public class ConfigManager { ...@@ -161,6 +172,8 @@ public class ConfigManager {
ccpaUpdateInterval:ccpaUpdateInterval, ccpaUpdateInterval:ccpaUpdateInterval,
shortsLeftBelowCountKey: shortsLeftBelowCount, shortsLeftBelowCountKey: shortsLeftBelowCount,
shortsSwipeUpNudgeCountKey: shortsSwipeNudgeCount, shortsSwipeUpNudgeCountKey: shortsSwipeNudgeCount,
premiumNudgeSessionShowing: premiumNudgeSessionShowngCount,
premiumNudgeTotalTimes: premiumNudgeTotalTimesCount,
explicitFeatureAvailability: featureAvailability, explicitFeatureAvailability: featureAvailability,
subscriptionsConfig: subscriptionsConfig subscriptionsConfig: subscriptionsConfig
) )
...@@ -194,11 +207,13 @@ fileprivate extension AppFeature { ...@@ -194,11 +207,13 @@ fileprivate extension AppFeature {
return "ios_show_att_prompt" return "ios_show_att_prompt"
case .shortsLastNudge: case .shortsLastNudge:
return "shorts_swipe_down_nudge_enabled" return "shorts_swipe_down_nudge_enabled"
case .subscriptionNudge:
return "ios_premium_nudge_show_to_ftu"
case .onboarding: case .onboarding:
return "ios_show_onboarding" return "ios_show_onboarding"
case .terceptSdk: case .terceptSdk:
return "ios_terceptsdk_enabled" return "ios_terceptsdk_enabled"
case .ads, .airQualityIndex, .minutelyForecast, .shorts, .subscription, .subscriptionForPro, .extendedDailyForecast, .extendedHourlyForecast: case .ads, .airQualityIndex, .minutelyForecast, .shorts, .subscription, .subscriptionForPro, .extendedDailyForecast, .extendedHourlyForecast, .initialSubscriptionNudge:
return nil return nil
// don't use 'default', so that we didn't add new features here in the future. // don't use 'default', so that we didn't add new features here in the future.
} }
......
...@@ -41,7 +41,7 @@ class SubscriptionPopUpViewController: UIViewController { ...@@ -41,7 +41,7 @@ class SubscriptionPopUpViewController: UIViewController {
self.view.layoutIfNeeded() self.view.layoutIfNeeded()
} }
Settings.shared.initialSubscriptionShowed = true Settings.shared.initialSubscriptionShown = true
} }
} }
......
...@@ -103,7 +103,7 @@ class TodayViewModel: ViewModelProtocol { ...@@ -103,7 +103,7 @@ class TodayViewModel: ViewModelProtocol {
self.initializeAllAdsIfNeeded() self.initializeAllAdsIfNeeded()
PushNotificationsManager.shared.registerForRemoteNotifications(completion: { [weak self] in PushNotificationsManager.shared.registerForRemoteNotifications(completion: { [weak self] in
guard let self = self else { return } guard let self = self else { return }
if !Settings.shared.initialSubscriptionShowed && CCPAHelper.shared.isNewUser { if self.featureAvailabilityManager.isAvailable(feature: .initialSubscriptionNudge) {
self.delegate?.showSubscriptionPopup(viewModel: self) self.delegate?.showSubscriptionPopup(viewModel: self)
} }
}) })
......
...@@ -22,5 +22,7 @@ public enum AppFeature: String, Codable, CaseIterable { ...@@ -22,5 +22,7 @@ public enum AppFeature: String, Codable, CaseIterable {
case subscription case subscription
/// Discounted subscription for people who previously purchased an in-app to remove ads /// Discounted subscription for people who previously purchased an in-app to remove ads
case subscriptionForPro case subscriptionForPro
case subscriptionNudge
case initialSubscriptionNudge
case terceptSdk case terceptSdk
} }
...@@ -15,12 +15,16 @@ public struct AppConfig: Codable { ...@@ -15,12 +15,16 @@ public struct AppConfig: Codable {
public let shortsSwipeUpNudgeCount: Int public let shortsSwipeUpNudgeCount: Int
private let explicitFeatureAvailability: [AppFeature: Bool] private let explicitFeatureAvailability: [AppFeature: Bool]
public let subscriptionsConfig: SubscriptionsListConfig public let subscriptionsConfig: SubscriptionsListConfig
public let premiumNudgeSessionShowing: Int
public let premiumNudgeTotalTimes: Int
public init(popularCities: [GeoNamesPlace]?, public init(popularCities: [GeoNamesPlace]?,
adConfig: AdConfig, adConfig: AdConfig,
ccpaUpdateInterval: TimeInterval?, ccpaUpdateInterval: TimeInterval?,
shortsLeftBelowCountKey: Int, shortsLeftBelowCountKey: Int,
shortsSwipeUpNudgeCountKey: Int, shortsSwipeUpNudgeCountKey: Int,
premiumNudgeSessionShowing: Int,
premiumNudgeTotalTimes: Int,
explicitFeatureAvailability: [AppFeature: Bool], explicitFeatureAvailability: [AppFeature: Bool],
subscriptionsConfig: SubscriptionsListConfig subscriptionsConfig: SubscriptionsListConfig
) { ) {
...@@ -31,6 +35,8 @@ public struct AppConfig: Codable { ...@@ -31,6 +35,8 @@ public struct AppConfig: Codable {
self.shortsSwipeUpNudgeCount = shortsSwipeUpNudgeCountKey self.shortsSwipeUpNudgeCount = shortsSwipeUpNudgeCountKey
self.explicitFeatureAvailability = explicitFeatureAvailability self.explicitFeatureAvailability = explicitFeatureAvailability
self.subscriptionsConfig = subscriptionsConfig self.subscriptionsConfig = subscriptionsConfig
self.premiumNudgeSessionShowing = premiumNudgeSessionShowing
self.premiumNudgeTotalTimes = premiumNudgeTotalTimes
} }
public func isEnabled(feature: AppFeature) -> Bool { public func isEnabled(feature: AppFeature) -> Bool {
......
...@@ -101,8 +101,8 @@ public class Settings { ...@@ -101,8 +101,8 @@ public class Settings {
@UserDefaultsBasicValue(key: "shorts_showed_swipeUp_count", userDefaults: UserDefaults.appDefaults) @UserDefaultsBasicValue(key: "shorts_showed_swipeUp_count", userDefaults: UserDefaults.appDefaults)
public var shortsSwipeUpNudgeShowedCount = 0 public var shortsSwipeUpNudgeShowedCount = 0
@UserDefaultsBasicValue(key: "initial_subscription_showed", userDefaults: UserDefaults.appDefaults) @UserDefaultsBasicValue(key: "initial_subscription_shown", userDefaults: UserDefaults.appDefaults)
public var initialSubscriptionShowed = false public var initialSubscriptionShown = false
#warning("Not implemented!") #warning("Not implemented!")
//TODO: implement store in UserDefaults and configure via UI in debug builds. //TODO: implement store in UserDefaults and configure via UI in debug builds.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment