Commit 8c8185a9 by Demid Merzlyakov

Fix onboarding bug, performance improvements.

parent 46cf9f62
......@@ -251,6 +251,7 @@
CEC5270325E7BB4000DA58A5 /* WdtSurfaceObservation.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEC5270225E7BB4000DA58A5 /* WdtSurfaceObservation.swift */; };
CEC5275D25E8E50B00DA58A5 /* WdtDailySummary.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEC5275C25E8E50B00DA58A5 /* WdtDailySummary.swift */; };
CEC5276025E92DDA00DA58A5 /* WdtHourlySummary.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEC5275F25E92DDA00DA58A5 /* WdtHourlySummary.swift */; };
CEC7D8C42639FAF600B8836D /* Global.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEC7D8C32639FAF500B8836D /* Global.swift */; };
CEC8FBAF2639756A0001A6BF /* OnboardingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEC8FBAE2639756A0001A6BF /* OnboardingViewController.swift */; };
CEC8FBB2263976240001A6BF /* OnboardingCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEC8FBB1263976240001A6BF /* OnboardingCoordinator.swift */; };
CEC8FBB5263976400001A6BF /* OnboardingViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEC8FBB4263976400001A6BF /* OnboardingViewModel.swift */; };
......@@ -267,7 +268,7 @@
CEE0A1A226317A3F0044C257 /* NWSSeverityLevel.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEE0A1A126317A3F0044C257 /* NWSSeverityLevel.swift */; };
CEE0A1A426317A8F0044C257 /* NWSAlertInfoParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEE0A1A326317A8F0044C257 /* NWSAlertInfoParser.swift */; };
CEF959652600C2F900975FAA /* AnalyticsService.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEF959642600C2F900975FAA /* AnalyticsService.swift */; };
CEF959692600C30500975FAA /* Global.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEF959682600C30500975FAA /* Global.swift */; };
CEF959692600C30500975FAA /* AnalyticsGlobal.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEF959682600C30500975FAA /* AnalyticsGlobal.swift */; };
CEF9596C2600C32E00975FAA /* AnalyticsEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEF9596B2600C32E00975FAA /* AnalyticsEvent.swift */; };
CEF959742600C3A400975FAA /* FlurryAnalyticsService.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEF959732600C3A400975FAA /* FlurryAnalyticsService.swift */; };
CEF959902600C5A800975FAA /* MoEngageAnalyticsService.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEF9598F2600C5A800975FAA /* MoEngageAnalyticsService.swift */; };
......@@ -573,6 +574,7 @@
CEC5270225E7BB4000DA58A5 /* WdtSurfaceObservation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WdtSurfaceObservation.swift; sourceTree = "<group>"; };
CEC5275C25E8E50B00DA58A5 /* WdtDailySummary.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WdtDailySummary.swift; sourceTree = "<group>"; };
CEC5275F25E92DDA00DA58A5 /* WdtHourlySummary.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WdtHourlySummary.swift; sourceTree = "<group>"; };
CEC7D8C32639FAF500B8836D /* Global.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Global.swift; sourceTree = "<group>"; };
CEC8FBAE2639756A0001A6BF /* OnboardingViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingViewController.swift; sourceTree = "<group>"; };
CEC8FBB1263976240001A6BF /* OnboardingCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingCoordinator.swift; sourceTree = "<group>"; };
CEC8FBB4263976400001A6BF /* OnboardingViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingViewModel.swift; sourceTree = "<group>"; };
......@@ -589,7 +591,7 @@
CEE0A1A126317A3F0044C257 /* NWSSeverityLevel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NWSSeverityLevel.swift; sourceTree = "<group>"; };
CEE0A1A326317A8F0044C257 /* NWSAlertInfoParser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NWSAlertInfoParser.swift; sourceTree = "<group>"; };
CEF959642600C2F900975FAA /* AnalyticsService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalyticsService.swift; sourceTree = "<group>"; };
CEF959682600C30500975FAA /* Global.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Global.swift; sourceTree = "<group>"; };
CEF959682600C30500975FAA /* AnalyticsGlobal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalyticsGlobal.swift; sourceTree = "<group>"; };
CEF9596B2600C32E00975FAA /* AnalyticsEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalyticsEvent.swift; sourceTree = "<group>"; };
CEF959732600C3A400975FAA /* FlurryAnalyticsService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlurryAnalyticsService.swift; sourceTree = "<group>"; };
CEF9598F2600C5A800975FAA /* MoEngageAnalyticsService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoEngageAnalyticsService.swift; sourceTree = "<group>"; };
......@@ -1444,6 +1446,7 @@
CDA5542C25EF7C9700A2E08C /* ReusableCellProtocol.swift */,
CD37D404260DFFDD002669D6 /* CellFactory.swift */,
CE13B7EA2624805F007CBD4D /* Constants.swift */,
CEC7D8C32639FAF500B8836D /* Global.swift */,
);
path = Common;
sourceTree = "<group>";
......@@ -1535,7 +1538,7 @@
CEF959632600C2E300975FAA /* Analytics */ = {
isa = PBXGroup;
children = (
CEF959682600C30500975FAA /* Global.swift */,
CEF959682600C30500975FAA /* AnalyticsGlobal.swift */,
CEF9596B2600C32E00975FAA /* AnalyticsEvent.swift */,
CEF959972600C88100975FAA /* AnalyticsParameter.swift */,
CEF959922600C63500975FAA /* Analytics.swift */,
......@@ -1891,7 +1894,7 @@
CD67616A262575CD0079D273 /* MapLegendGradientView.swift in Sources */,
CE578FD325F7E89400E8B85D /* DayTimeWeather.swift in Sources */,
CD593BCC2608A4F200C93428 /* ForecastDailyCell.swift in Sources */,
CEF959692600C30500975FAA /* Global.swift in Sources */,
CEF959692600C30500975FAA /* AnalyticsGlobal.swift in Sources */,
CEAFF08925DFC6B200DF4EBF /* CurrentWeather.swift in Sources */,
CD866A72260F6A5300E96A5C /* SettingsDetailsCell.swift in Sources */,
CD6761802625B0F50079D273 /* RadarLayerCell.swift in Sources */,
......@@ -2080,6 +2083,7 @@
CE13B821262480B3007CBD4D /* Scheduler.swift in Sources */,
CEDE4F0F25EFA3B4007457E9 /* UpdatableModelObjectInTime.swift in Sources */,
CE13B81E262480B3007CBD4D /* AdCacheManager.swift in Sources */,
CEC7D8C42639FAF600B8836D /* Global.swift in Sources */,
CE13B72B26245D0D007CBD4D /* HealthStatus.swift in Sources */,
CE8962A426175DF500CA274A /* _CorePollutant.swift in Sources */,
CEBAC1C82638240800A89681 /* DeeplinksRouter.swift in Sources */,
......
//
// Global.swift
// AnalyticsGlobal.swift
// 1Weather
//
// Created by Demid Merzlyakov on 16.03.2021.
......
//
// Global.swift
// 1Weather
//
// Created by Demid Merzlyakov on 29.04.2021.
//
import Foundation
/// Does the work on the main thread. If the current thread is the main thread, does the work in place. Otherwise dispatches it asynchronously.
func onMain(_ work: @escaping () -> ()) {
if Thread.isMainThread {
work()
}
else {
DispatchQueue.main.async {
work()
}
}
}
......@@ -125,28 +125,28 @@ class DeeplinksRouter {
}
public func openToday() {
DispatchQueue.main.async {
onMain {
self.log.info("open Today")
self.appCoordinator.openToday()
}
}
public func openForecast(timePeriod: TimePeriod?) {
DispatchQueue.main.async {
onMain {
self.log.info("open Forecast")
self.appCoordinator.openForecast(timePeriod: timePeriod)
}
}
public func openAlerts() {
DispatchQueue.main.async {
onMain {
self.log.info("open Alerts")
self.appCoordinator.openNotifications()
}
}
public func openPrecipitation() {
DispatchQueue.main.async {
onMain {
self.log.info("open Precipitation")
//not implemented
self.openToday()
......@@ -154,14 +154,14 @@ class DeeplinksRouter {
}
public func openRadar() {
DispatchQueue.main.async {
onMain {
self.log.info("open Radar")
self.appCoordinator.openRadar()
}
}
public func openSunMoon() {
DispatchQueue.main.async {
onMain {
self.log.info("open SunMoon")
//not implemented
self.openToday()
......@@ -169,7 +169,7 @@ class DeeplinksRouter {
}
public func openVideo() {
DispatchQueue.main.async {
onMain {
self.log.info("open Video")
//not implemented
self.openToday()
......@@ -177,7 +177,7 @@ class DeeplinksRouter {
}
public func openWeatherDetail() {
DispatchQueue.main.async {
onMain {
self.log.info("open WeatherDetail")
//not implemented
self.openToday()
......
......@@ -52,12 +52,12 @@ public class LocationManager {
private var _locations = [Location]()
private var _selectedLocationIndex: Int?
private func set(locations: [Location], selectedIndex: Int?) {
DispatchQueue.main.async { [weak self] in
self?._locations = locations
self?._selectedLocationIndex = selectedIndex
self?.lastSeenCityId = self?.selectedLocation?.cityId
self?.handleLocationsChange(locationsChanged: true, selectedLocationChanged: true)
self?.updateEverythingIfNeeded()
onMain {
self._locations = locations
self._selectedLocationIndex = selectedIndex
self.lastSeenCityId = self.selectedLocation?.cityId
self.handleLocationsChange(locationsChanged: true, selectedLocationChanged: true)
self.updateEverythingIfNeeded()
}
}
......@@ -140,7 +140,7 @@ public class LocationManager {
guard index < locations.count else {
// assertionFailure("This shouldn't happen. Got to investigate.")
// But in runtime we can handle it gracefully
DispatchQueue.main.async {
onMain {
self.selectedLocationIndex = self.locations.count > 0 ? 0 : nil
}
return nil
......@@ -178,7 +178,7 @@ public class LocationManager {
private var loadedLocations = false
private var actionAfterLocationLoad: (([Location]) -> ())?
public func doAfterLocationLoad(_ action: @escaping ([Location]) -> ()) {
DispatchQueue.main.async {
onMain {
if self.loadedLocations {
action(self.locations)
}
......@@ -205,12 +205,11 @@ public class LocationManager {
self.nwsAlertsManager.delegates.add(delegate: self)
storage.load { [weak self] (locations, selectedIndex, error) in
DispatchQueue.main.async {
onMain {
guard let self = self else { return }
defer {
self.actionAfterLocationLoad?(self.locations)
}
self.loadedLocations = true
guard error == nil else {
self.log.error("Error while loading locations: \(error!)")
return
......@@ -231,6 +230,7 @@ public class LocationManager {
}
}
}
self.loadedLocations = true
}
}
}
......@@ -391,7 +391,7 @@ public class LocationManager {
}
private func makeChanges(to location: Location, in operation: String, changes: @escaping (Location) -> Location, completion: (() -> ())? = nil) {
DispatchQueue.main.async {
onMain {
defer {
completion?()
}
......@@ -446,7 +446,7 @@ public class LocationManager {
}
else {
makeLocation(from: partialLocation) { (location) in
DispatchQueue.main.async { [weak self] in
onMain { [weak self] in
if let location = location {
self?.addIfNeeded(location: location, selectLocation: selectLocation)
}
......@@ -571,7 +571,7 @@ extension LocationManager: DeviceLocationMonitorDelegate {
}
func deviceLocationMonitor(_ monitor: DeviceLocationMonitor, authorizationStatusChanged locationIsAllowed: Bool) {
DispatchQueue.main.async {
onMain {
if !locationIsAllowed && self.locations.first?.deviceLocation == true {
self.log.debug("device location: remove due to error")
self.locations = [Location](self.locations.suffix(from: 1))
......
......@@ -85,8 +85,8 @@ private struct SettingsDataSource {
class SettingsCellFactory: CellFactoryProtocol {
//Private
private let viewModel:SettingsViewModel
private let sections:[SettingsDataSource] = {
private let viewModel: SettingsViewModel
private let sections: [SettingsDataSource] = {
var array = [SettingsDataSource]()
if #available(iOS 13, *) {
......
......@@ -70,7 +70,7 @@ class ForecastViewModel: ViewModelProtocol {
//MARK:- LocationManager Delegate
extension ForecastViewModel: LocationManagerDelegate {
func locationManager(_ locationManager: LocationManager, changedSelectedLocation newLocation: Location?) {
DispatchQueue.main.async {
onMain {
self.location = newLocation
self.selectDailyWeatherAt(index: 0)
self.selectHourlyWeatherAt(index: 0)
......
......@@ -43,7 +43,7 @@ class TodayViewModel: ViewModelProtocol {
private var adsInitialized = false
private func initializeAllAdsIfNeeded() {
DispatchQueue.main.async {
onMain {
guard !self.adsInitialized else { return }
self.adsInitialized = true
CCPAHelper.shared.updateCCPAStatus(reason: "initialization")
......@@ -94,7 +94,7 @@ class TodayViewModel: ViewModelProtocol {
//MARK:- LocationManager Delegate
extension TodayViewModel: LocationManagerDelegate {
func locationManager(_ locationManager: LocationManager, changedSelectedLocation newLocation: Location?) {
DispatchQueue.main.async {
onMain {
self.location = newLocation
self.todayCellFactory.setNeedsUpdate()
self.delegate?.viewModelDidChange(model: self)
......
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