Skip to content

Commit 27134fe

Browse files
committed
Places now update after data migration runs on the home page
1 parent 3486928 commit 27134fe

2 files changed

Lines changed: 33 additions & 32 deletions

File tree

TCAT/AppDelegate.swift

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
3636
GMSServices.provideAPIKey(Keys.googleMaps.value)
3737
GMSPlacesClient.provideAPIKey(Keys.googlePlaces.value)
3838

39-
// v1.2.2 Data Migration
40-
41-
print("Begin Data Migration")
42-
if VersionStore.shared.savedAppVersion <= WhatsNew.Version(major: 1, minor: 2, patch: 1) {
43-
migrationToNewPlacesModel { (success, errorDescription) in
44-
print("Data Migration Complete - Success: \(success), Error: \(errorDescription ?? "n/a")")
45-
let payload = DataMigrationOnePointThreePayload(success: success, errorDescription: errorDescription)
46-
Analytics.shared.log(payload)
47-
}
48-
}
49-
5039
// Update shortcut items
5140
AppShortcuts.shared.updateShortcutItems()
5241

@@ -80,6 +69,19 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
8069
let rootVC = showOnboarding ? OnboardingViewController(initialViewing: true) : HomeViewController()
8170
let navigationController = showOnboarding ? OnboardingNavigationController(rootViewController: rootVC) :
8271
CustomNavigationController(rootViewController: rootVC)
72+
73+
// v1.2.2 Data Migration
74+
print("Begin Data Migration")
75+
if VersionStore.shared.savedAppVersion <= WhatsNew.Version(major: 1, minor: 2, patch: 1) {
76+
migrationToNewPlacesModel { (success, errorDescription) in
77+
if let homeViewController = rootVC as? HomeViewController {
78+
homeViewController.viewWillAppear(false)
79+
}
80+
print("Data Migration Complete - Success: \(success), Error: \(errorDescription ?? "n/a")")
81+
let payload = DataMigrationOnePointThreePayload(success: success, errorDescription: errorDescription)
82+
Analytics.shared.log(payload)
83+
}
84+
}
8385

8486
// Initalize window without storyboard
8587
self.window = UIWindow(frame: UIScreen.main.bounds)

TCAT/Controllers/HomeViewController.swift

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,8 @@ class HomeViewController: UIViewController {
5757
override func viewDidLoad() {
5858
super.viewDidLoad()
5959

60-
// Fetch Places
61-
recentLocations = SearchTableViewManager.shared.retrievePlaces(for: Constants.UserDefaults.recentSearch)
62-
favorites = SearchTableViewManager.shared.retrievePlaces(for: Constants.UserDefaults.favorites)
63-
60+
updatePlaces()
61+
6462
// Add Notification Observers
6563
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), name: UIResponder.keyboardWillShowNotification, object: nil)
6664
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name: UIResponder.keyboardWillHideNotification, object: nil)
@@ -86,7 +84,6 @@ class HomeViewController: UIViewController {
8684

8785
tableView.snp.makeConstraints { (make) in
8886
make.leading.trailing.bottom.equalToSuperview()
89-
9087
if #available(iOS 11.0, *) {
9188
make.top.equalTo(view.safeAreaLayoutGuide.snp.top)
9289
} else {
@@ -151,13 +148,10 @@ class HomeViewController: UIViewController {
151148
return
152149
}
153150

154-
// Dismiss current banner, if any
151+
// Dismiss current banner or loading indicator, if any
155152
banner?.dismiss()
156153
banner = nil
157-
158-
// Dismiss current loading indicator, if any
159-
loadingIndicator?.removeFromSuperview()
160-
loadingIndicator = nil
154+
removeLoadingIndicator()
161155

162156
switch reachability.connection {
163157
case .none:
@@ -180,19 +174,15 @@ class HomeViewController: UIViewController {
180174
reachability?.stopNotifier()
181175
NotificationCenter.default.removeObserver(self, name: .reachabilityChanged, object: reachability)
182176

183-
// Remove banner
177+
// Remove banner and loading indicator
184178
banner?.dismiss()
185179
banner = nil
186-
187-
// Remove activity indicator
188-
loadingIndicator?.removeFromSuperview()
189-
loadingIndicator = nil
180+
removeLoadingIndicator()
190181
}
191182

192183
override func viewWillAppear(_ animated: Bool) {
193184
super.viewWillAppear(animated)
194-
recentLocations = SearchTableViewManager.shared.retrievePlaces(for: Constants.UserDefaults.recentSearch)
195-
favorites = SearchTableViewManager.shared.retrievePlaces(for: Constants.UserDefaults.favorites)
185+
updatePlaces()
196186
if !isNetworkDown {
197187
sections = createSections()
198188
}
@@ -206,6 +196,11 @@ class HomeViewController: UIViewController {
206196
StoreReviewHelper.checkAndAskForReview()
207197

208198
}
199+
200+
func updatePlaces() {
201+
recentLocations = SearchTableViewManager.shared.retrievePlaces(for: Constants.UserDefaults.recentSearch)
202+
favorites = SearchTableViewManager.shared.retrievePlaces(for: Constants.UserDefaults.favorites)
203+
}
209204

210205
func createSections() -> [Section] {
211206
var allSections: [Section] = []
@@ -538,7 +533,7 @@ extension HomeViewController: DZNEmptyDataSetSource, DZNEmptyDataSetDelegate {
538533
return NSAttributedString(string: title, attributes: [.foregroundColor: Colors.tcatBlue])
539534
}
540535

541-
func setUpLoadingIndicator() {
536+
func setupLoadingIndicator() {
542537
loadingIndicator = LoadingIndicator()
543538
if let loadingIndicator = loadingIndicator {
544539
view.addSubview(loadingIndicator)
@@ -548,9 +543,14 @@ extension HomeViewController: DZNEmptyDataSetSource, DZNEmptyDataSetDelegate {
548543
}
549544
}
550545
}
546+
547+
func removeLoadingIndicator() {
548+
loadingIndicator?.removeFromSuperview()
549+
loadingIndicator = nil
550+
}
551551

552552
func emptyDataSet(_ scrollView: UIScrollView, didTap didTapButton: UIButton) {
553-
setUpLoadingIndicator()
553+
setupLoadingIndicator()
554554
if isLoading {
555555
tableView.reloadData()
556556

@@ -562,8 +562,7 @@ extension HomeViewController: DZNEmptyDataSetSource, DZNEmptyDataSetDelegate {
562562
self.searchBar.text = nil
563563
self.searchBar.placeholder = Constants.General.searchPlaceholder
564564
}
565-
self.loadingIndicator?.removeFromSuperview()
566-
self.loadingIndicator = nil
565+
self.removeLoadingIndicator()
567566
self.tableView.reloadData()
568567
}
569568
}

0 commit comments

Comments
 (0)