Commit 3e7303ac by Dmitry Stepanets

Added code to wait until ConfigManager finishes updating app configuration

parent f08763a3
...@@ -98,6 +98,7 @@ class AppCoordinator: Coordinator { ...@@ -98,6 +98,7 @@ class AppCoordinator: Coordinator {
public func finishAnimation() { public func finishAnimation() {
DispatchQueue.main.async { DispatchQueue.main.async {
if ConfigManager.shared.config.showOnboarding {
if Settings.shared.initialOnboardingShowed { if Settings.shared.initialOnboardingShowed {
self.finishInitialOnboarding() self.finishInitialOnboarding()
} }
...@@ -110,6 +111,10 @@ class AppCoordinator: Coordinator { ...@@ -110,6 +111,10 @@ class AppCoordinator: Coordinator {
animations: nil) animations: nil)
} }
} }
else {
self.finishInitialOnboarding()
}
}
} }
public func finishInitialOnboarding() { public func finishInitialOnboarding() {
......
...@@ -21,8 +21,18 @@ public struct AppConfig: Codable { ...@@ -21,8 +21,18 @@ public struct AppConfig: Codable {
public let shortsLeftBelowCount: Int public let shortsLeftBelowCount: Int
public let shortsLastNudgeEnabled: Bool public let shortsLastNudgeEnabled: Bool
public let shortsSwipeUpNudgeCount: Int public let shortsSwipeUpNudgeCount: Int
public let showOnboarding: Bool
public init(popularCities: [GeoNamesPlace]?, adConfig: AdConfig, ccpaUpdateInterval: TimeInterval?, nwsAlertsViaMoEngageEnabled: Bool, showAttPrompt: Bool, shortsLeftBelowCountKey: Int, shortsLastNudgeEnabledKey: Bool, shortsSwipeUpNudgeCountKey: Int) {
public init(popularCities: [GeoNamesPlace]?,
adConfig: AdConfig,
ccpaUpdateInterval: TimeInterval?,
nwsAlertsViaMoEngageEnabled: Bool,
showAttPrompt: Bool,
shortsLeftBelowCountKey: Int,
shortsLastNudgeEnabledKey: Bool,
shortsSwipeUpNudgeCountKey: Int,
showOnboarding: Bool
) {
self.popularCities = popularCities self.popularCities = popularCities
self.adConfig = adConfig self.adConfig = adConfig
self.ccpaUpdateInterval = ccpaUpdateInterval self.ccpaUpdateInterval = ccpaUpdateInterval
...@@ -31,6 +41,7 @@ public struct AppConfig: Codable { ...@@ -31,6 +41,7 @@ public struct AppConfig: Codable {
self.shortsLeftBelowCount = shortsLeftBelowCountKey self.shortsLeftBelowCount = shortsLeftBelowCountKey
self.shortsLastNudgeEnabled = shortsLastNudgeEnabledKey self.shortsLastNudgeEnabled = shortsLastNudgeEnabledKey
self.shortsSwipeUpNudgeCount = shortsSwipeUpNudgeCountKey self.shortsSwipeUpNudgeCount = shortsSwipeUpNudgeCountKey
self.showOnboarding = showOnboarding
} }
} }
...@@ -47,6 +58,7 @@ public class ConfigManager { ...@@ -47,6 +58,7 @@ 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 shortsLastNudgeEnabledKey = "shorts_swipe_down_nudge_enabled" private static let shortsLastNudgeEnabledKey = "shorts_swipe_down_nudge_enabled"
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 showOnboardingKey = "ios_show_onboarding"
private let delegates = MulticastDelegate<ConfigManagerDelegate>() private let delegates = MulticastDelegate<ConfigManagerDelegate>()
...@@ -61,7 +73,7 @@ public class ConfigManager { ...@@ -61,7 +73,7 @@ public class ConfigManager {
}() }()
public static let shared = ConfigManager() public static let shared = ConfigManager()
public private(set) var isUpdating = false
public var config: AppConfig = AppConfig(popularCities: nil, public var config: AppConfig = AppConfig(popularCities: nil,
adConfig: AdConfig(), adConfig: AdConfig(),
ccpaUpdateInterval: nil, ccpaUpdateInterval: nil,
...@@ -69,12 +81,19 @@ public class ConfigManager { ...@@ -69,12 +81,19 @@ public class ConfigManager {
showAttPrompt: false, showAttPrompt: false,
shortsLeftBelowCountKey: 0, shortsLeftBelowCountKey: 0,
shortsLastNudgeEnabledKey: false, shortsLastNudgeEnabledKey: false,
shortsSwipeUpNudgeCountKey: 0) shortsSwipeUpNudgeCountKey: 0,
showOnboarding: false)
public func updateConfig() { public func updateConfig() {
log.info("update config") log.info("update config")
isUpdating = true
remoteConfig.fetchAndActivate { [weak self] (status, error) in remoteConfig.fetchAndActivate { [weak self] (status, error) in
guard let self = self else { return } guard let self = self else { return }
defer {
self.isUpdating = false
}
switch status { switch status {
case .successFetchedFromRemote: case .successFetchedFromRemote:
self.parseConfigFromFirebase(source: "remote") self.parseConfigFromFirebase(source: "remote")
...@@ -152,6 +171,9 @@ public class ConfigManager { ...@@ -152,6 +171,9 @@ 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 showOnboardingValue = remoteConfig.configValue(forKey: ConfigManager.showOnboardingKey)
let showOnboarding = showOnboardingValue.boolValue
DispatchQueue.main.async { DispatchQueue.main.async {
self.config = AppConfig(popularCities: popularCities, self.config = AppConfig(popularCities: popularCities,
adConfig: adConfig, adConfig: adConfig,
...@@ -160,7 +182,8 @@ public class ConfigManager { ...@@ -160,7 +182,8 @@ public class ConfigManager {
showAttPrompt: showAttPrompt, showAttPrompt: showAttPrompt,
shortsLeftBelowCountKey: shortsLeftBelowCount, shortsLeftBelowCountKey: shortsLeftBelowCount,
shortsLastNudgeEnabledKey: shortsLastNudgeEnabled, shortsLastNudgeEnabledKey: shortsLastNudgeEnabled,
shortsSwipeUpNudgeCountKey: shortsSwipeNudgeCount) shortsSwipeUpNudgeCountKey: shortsSwipeNudgeCount,
showOnboarding: showOnboarding)
self.notifyAboutConfigUpdate() self.notifyAboutConfigUpdate()
DispatchQueue.global().async { DispatchQueue.global().async {
let encoder = JSONEncoder() let encoder = JSONEncoder()
......
...@@ -11,11 +11,13 @@ import OneWeatherCore ...@@ -11,11 +11,13 @@ import OneWeatherCore
import OneWeatherAnalytics import OneWeatherAnalytics
class SplashAnimationViewController: UIViewController { class SplashAnimationViewController: UIViewController {
private let kAttemptsCount = 3
private let appCoordinator:AppCoordinator private let appCoordinator:AppCoordinator
private let backgroundImageView = UIImageView() private let backgroundImageView = UIImageView()
private let animation = Animation.named("splash") private let animation = Animation.named("splash")
private var animationView:AnimationView? private var animationView:AnimationView?
private let playButton = UIButton() private let playButton = UIButton()
private var currentAttempt = 0
init(appCoordinator:AppCoordinator) { init(appCoordinator:AppCoordinator) {
self.appCoordinator = appCoordinator self.appCoordinator = appCoordinator
...@@ -59,12 +61,32 @@ class SplashAnimationViewController: UIViewController { ...@@ -59,12 +61,32 @@ class SplashAnimationViewController: UIViewController {
} }
} }
private func finish() {
//We need to wait, until ConfigManager finishes updating configuration
//But this is given 3 attempts with a duration of 1 second
if ConfigManager.shared.isUpdating {
if currentAttempt < kAttemptsCount {
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
self.currentAttempt += 1
self.finish()
}
}
else {
self.appCoordinator.finishAnimation()
}
}
else {
self.appCoordinator.finishAnimation()
}
}
private func noCityAnimation() { private func noCityAnimation() {
analytics(log: .ANALYTICS_FTUE_SPLASH_SEEN) analytics(log: .ANALYTICS_FTUE_SPLASH_SEEN)
analytics(set: .splashFTUE, to: true) analytics(set: .splashFTUE, to: true)
self.animationView?.play(completion: {[weak self] _ in self.animationView?.play(completion: {[weak self] _ in
DispatchQueue.global().asyncAfter(deadline: .now() + 0.5) { DispatchQueue.global().asyncAfter(deadline: .now() + 0.5) {
self?.appCoordinator.finishAnimation() self?.finish()
} }
}) })
} }
...@@ -76,7 +98,7 @@ class SplashAnimationViewController: UIViewController { ...@@ -76,7 +98,7 @@ class SplashAnimationViewController: UIViewController {
self.animationView?.alpha = 1 self.animationView?.alpha = 1
} completion: { _ in } completion: { _ in
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
self.appCoordinator.finishAnimation() self.finish()
} }
} }
} }
......
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