Commit a936f5c7 by Dmitry Stepanets

[IOS-287]: Moved presentation logic to FeatureAvailabilityManager

parent c5aa9e6c
......@@ -231,6 +231,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
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)
......@@ -257,6 +267,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
break // config only
case .subscription:
break // configOnly
case .subscriptionNudge:
break //config only
case .initialSubscriptionNudge:
availabilityCheckers[feature] = !initialSubscriptionShown && firstTimeUser && !premium
case .subscriptionForPro:
availabilityCheckers[feature] = premium
case .extendedDailyForecast:
......
......@@ -31,6 +31,8 @@
"a9_refresh_rate": 0,
"placements": {}
}</string>
<key>ios_premium_nudge_show_to_ftu</key>
<false/>
<key>ios_terceptsdk_enabled</key>
<true/>
</dict>
......
......@@ -23,6 +23,8 @@ public class ConfigManager {
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 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>()
......@@ -43,10 +45,13 @@ public class ConfigManager {
ccpaUpdateInterval: nil,
shortsLeftBelowCountKey: 0,
shortsSwipeUpNudgeCountKey: 0,
premiumNudgeSessionShowing: 0,
premiumNudgeTotalTimes: 0,
explicitFeatureAvailability: [
.nwsAlertsViaMoEngage: true,
.attPrompt: false,
.shortsLastNudge: false,
.subscriptionNudge: false,
.onboarding: false,
.terceptSdk: false
], subscriptionsConfig: SubscriptionsListConfig()
......@@ -142,6 +147,12 @@ public class ConfigManager {
let shortsSwipeNudgeCountValue = remoteConfig.configValue(forKey: ConfigManager.shortsSwipeUpNudgeCountKey)
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()
var subscriptionsConfig = SubscriptionsListConfig()
......@@ -161,6 +172,8 @@ public class ConfigManager {
ccpaUpdateInterval:ccpaUpdateInterval,
shortsLeftBelowCountKey: shortsLeftBelowCount,
shortsSwipeUpNudgeCountKey: shortsSwipeNudgeCount,
premiumNudgeSessionShowing: premiumNudgeSessionShowngCount,
premiumNudgeTotalTimes: premiumNudgeTotalTimesCount,
explicitFeatureAvailability: featureAvailability,
subscriptionsConfig: subscriptionsConfig
)
......@@ -194,11 +207,13 @@ fileprivate extension AppFeature {
return "ios_show_att_prompt"
case .shortsLastNudge:
return "shorts_swipe_down_nudge_enabled"
case .subscriptionNudge:
return "ios_premium_nudge_show_to_ftu"
case .onboarding:
return "ios_show_onboarding"
case .terceptSdk:
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
// don't use 'default', so that we didn't add new features here in the future.
}
......
......@@ -41,7 +41,7 @@ class SubscriptionPopUpViewController: UIViewController {
self.view.layoutIfNeeded()
}
Settings.shared.initialSubscriptionShowed = true
Settings.shared.initialSubscriptionShown = true
}
}
......
......@@ -103,7 +103,7 @@ class TodayViewModel: ViewModelProtocol {
self.initializeAllAdsIfNeeded()
PushNotificationsManager.shared.registerForRemoteNotifications(completion: { [weak self] in
guard let self = self else { return }
if !Settings.shared.initialSubscriptionShowed && CCPAHelper.shared.isNewUser {
if self.featureAvailabilityManager.isAvailable(feature: .initialSubscriptionNudge) {
self.delegate?.showSubscriptionPopup(viewModel: self)
}
})
......
......@@ -22,5 +22,7 @@ public enum AppFeature: String, Codable, CaseIterable {
case subscription
/// Discounted subscription for people who previously purchased an in-app to remove ads
case subscriptionForPro
case subscriptionNudge
case initialSubscriptionNudge
case terceptSdk
}
......@@ -15,12 +15,16 @@ public struct AppConfig: Codable {
public let shortsSwipeUpNudgeCount: Int
private let explicitFeatureAvailability: [AppFeature: Bool]
public let subscriptionsConfig: SubscriptionsListConfig
public let premiumNudgeSessionShowing: Int
public let premiumNudgeTotalTimes: Int
public init(popularCities: [GeoNamesPlace]?,
adConfig: AdConfig,
ccpaUpdateInterval: TimeInterval?,
shortsLeftBelowCountKey: Int,
shortsSwipeUpNudgeCountKey: Int,
premiumNudgeSessionShowing: Int,
premiumNudgeTotalTimes: Int,
explicitFeatureAvailability: [AppFeature: Bool],
subscriptionsConfig: SubscriptionsListConfig
) {
......@@ -31,6 +35,8 @@ public struct AppConfig: Codable {
self.shortsSwipeUpNudgeCount = shortsSwipeUpNudgeCountKey
self.explicitFeatureAvailability = explicitFeatureAvailability
self.subscriptionsConfig = subscriptionsConfig
self.premiumNudgeSessionShowing = premiumNudgeSessionShowing
self.premiumNudgeTotalTimes = premiumNudgeTotalTimes
}
public func isEnabled(feature: AppFeature) -> Bool {
......
......@@ -101,8 +101,8 @@ public class Settings {
@UserDefaultsBasicValue(key: "shorts_showed_swipeUp_count", userDefaults: UserDefaults.appDefaults)
public var shortsSwipeUpNudgeShowedCount = 0
@UserDefaultsBasicValue(key: "initial_subscription_showed", userDefaults: UserDefaults.appDefaults)
public var initialSubscriptionShowed = false
@UserDefaultsBasicValue(key: "initial_subscription_shown", userDefaults: UserDefaults.appDefaults)
public var initialSubscriptionShown = false
#warning("Not implemented!")
//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