@@ -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