Commit 797a623a by Dmitriy Stepanets

Merge commit '3e7303ac' into feature/IOS-133-onboarding

parents 55d85f7a 3e7303ac
......@@ -98,16 +98,21 @@ class AppCoordinator: Coordinator {
public func finishAnimation() {
DispatchQueue.main.async {
if Settings.shared.initialOnboardingShowed {
self.finishInitialOnboarding()
if ConfigManager.shared.config.showOnboarding {
if Settings.shared.initialOnboardingShowed {
self.finishInitialOnboarding()
}
else {
let initialOnboarding = OnboardingPageController(coordinator: self)
self.window.rootViewController = initialOnboarding
UIView.transition(with: self.window,
duration: 0.3,
options: .transitionCrossDissolve,
animations: nil)
}
}
else {
let initialOnboarding = OnboardingPageController(coordinator: self)
self.window.rootViewController = initialOnboarding
UIView.transition(with: self.window,
duration: 0.3,
options: .transitionCrossDissolve,
animations: nil)
self.finishInitialOnboarding()
}
}
}
......
......@@ -21,8 +21,18 @@ public struct AppConfig: Codable {
public let shortsLeftBelowCount: Int
public let shortsLastNudgeEnabled: Bool
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.adConfig = adConfig
self.ccpaUpdateInterval = ccpaUpdateInterval
......@@ -31,6 +41,7 @@ public struct AppConfig: Codable {
self.shortsLeftBelowCount = shortsLeftBelowCountKey
self.shortsLastNudgeEnabled = shortsLastNudgeEnabledKey
self.shortsSwipeUpNudgeCount = shortsSwipeUpNudgeCountKey
self.showOnboarding = showOnboarding
}
}
......@@ -47,6 +58,7 @@ public class ConfigManager {
private static let shortsLeftBelowCountKey = "shorts_left_below_nudge_every_x_cards"
private static let shortsLastNudgeEnabledKey = "shorts_swipe_down_nudge_enabled"
private static let shortsSwipeUpNudgeCountKey = "shorts_swipe_up_nudge_on_x_cards"
private static let showOnboardingKey = "ios_show_onboarding"
private let delegates = MulticastDelegate<ConfigManagerDelegate>()
......@@ -61,7 +73,7 @@ public class ConfigManager {
}()
public static let shared = ConfigManager()
public private(set) var isUpdating = false
public var config: AppConfig = AppConfig(popularCities: nil,
adConfig: AdConfig(),
ccpaUpdateInterval: nil,
......@@ -69,12 +81,19 @@ public class ConfigManager {
showAttPrompt: false,
shortsLeftBelowCountKey: 0,
shortsLastNudgeEnabledKey: false,
shortsSwipeUpNudgeCountKey: 0)
shortsSwipeUpNudgeCountKey: 0,
showOnboarding: false)
public func updateConfig() {
log.info("update config")
isUpdating = true
remoteConfig.fetchAndActivate { [weak self] (status, error) in
guard let self = self else { return }
defer {
self.isUpdating = false
}
switch status {
case .successFetchedFromRemote:
self.parseConfigFromFirebase(source: "remote")
......@@ -152,6 +171,9 @@ public class ConfigManager {
let shortsSwipeNudgeCountValue = remoteConfig.configValue(forKey: ConfigManager.shortsSwipeUpNudgeCountKey)
let shortsSwipeNudgeCount = shortsSwipeNudgeCountValue.numberValue.intValue
let showOnboardingValue = remoteConfig.configValue(forKey: ConfigManager.showOnboardingKey)
let showOnboarding = showOnboardingValue.boolValue
DispatchQueue.main.async {
self.config = AppConfig(popularCities: popularCities,
adConfig: adConfig,
......@@ -160,7 +182,8 @@ public class ConfigManager {
showAttPrompt: showAttPrompt,
shortsLeftBelowCountKey: shortsLeftBelowCount,
shortsLastNudgeEnabledKey: shortsLastNudgeEnabled,
shortsSwipeUpNudgeCountKey: shortsSwipeNudgeCount)
shortsSwipeUpNudgeCountKey: shortsSwipeNudgeCount,
showOnboarding: showOnboarding)
self.notifyAboutConfigUpdate()
DispatchQueue.global().async {
let encoder = JSONEncoder()
......
......@@ -11,11 +11,13 @@ import OneWeatherCore
import OneWeatherAnalytics
class SplashAnimationViewController: UIViewController {
private let kAttemptsCount = 3
private let appCoordinator:AppCoordinator
private let backgroundImageView = UIImageView()
private let animation = Animation.named("splash")
private var animationView:AnimationView?
private let playButton = UIButton()
private var currentAttempt = 0
init(appCoordinator:AppCoordinator) {
self.appCoordinator = appCoordinator
......@@ -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() {
analytics(log: .ANALYTICS_FTUE_SPLASH_SEEN)
analytics(set: .splashFTUE, to: true)
self.animationView?.play(completion: {[weak self] _ in
DispatchQueue.global().asyncAfter(deadline: .now() + 0.5) {
self?.appCoordinator.finishAnimation()
self?.finish()
}
})
}
......@@ -76,7 +98,7 @@ class SplashAnimationViewController: UIViewController {
self.animationView?.alpha = 1
} completion: { _ in
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