diff --git a/GHFollowers.xcodeproj/project.pbxproj b/GHFollowers.xcodeproj/project.pbxproj index 2459301..8ac94c8 100644 --- a/GHFollowers.xcodeproj/project.pbxproj +++ b/GHFollowers.xcodeproj/project.pbxproj @@ -41,6 +41,7 @@ 7DB7350D243F523700E7B09B /* PersistanceManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB7350C243F523700E7B09B /* PersistanceManager.swift */; }; 7DB7350F243F8AC100E7B09B /* FavoriteCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB7350E243F8AC100E7B09B /* FavoriteCell.swift */; }; 7DB7351224409BFE00E7B09B /* GFTabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB7351124409BFE00E7B09B /* GFTabBarController.swift */; }; + 7DB735142443929200E7B09B /* GFDataLoadingVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB735132443929200E7B09B /* GFDataLoadingVC.swift */; }; 7DFAC88A242A86D200F5780C /* GFAlertContainerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DFAC889242A86D200F5780C /* GFAlertContainerView.swift */; }; /* End PBXBuildFile section */ @@ -81,6 +82,7 @@ 7DB7350C243F523700E7B09B /* PersistanceManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PersistanceManager.swift; sourceTree = ""; }; 7DB7350E243F8AC100E7B09B /* FavoriteCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FavoriteCell.swift; sourceTree = ""; }; 7DB7351124409BFE00E7B09B /* GFTabBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GFTabBarController.swift; sourceTree = ""; }; + 7DB735132443929200E7B09B /* GFDataLoadingVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GFDataLoadingVC.swift; sourceTree = ""; }; 7DFAC889242A86D200F5780C /* GFAlertContainerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GFAlertContainerView.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -270,6 +272,7 @@ 7D7C66592438A2B300733687 /* ItemInfoVCs-SuperClass+SubClass */, 7D98BB49242A55ED006C53E9 /* GFAlertVC.swift */, 7DA45F842433FAF800AB426F /* GFUserInfoheaderVC.swift */, + 7DB735132443929200E7B09B /* GFDataLoadingVC.swift */, ); path = ViewControllers; sourceTree = ""; @@ -358,6 +361,7 @@ 7D98BB40242917E4006C53E9 /* GFButton.swift in Sources */, 7D98BB3C24290771006C53E9 /* SearchVC.swift in Sources */, 7DA45F7A242FB95700AB426F /* GFEmptyStateView.swift in Sources */, + 7DB735142443929200E7B09B /* GFDataLoadingVC.swift in Sources */, 7D98BB4A242A55ED006C53E9 /* GFAlertVC.swift in Sources */, 7DA45F66242B760500AB426F /* User.swift in Sources */, 7DA45F6F242BC47D00AB426F /* FollowerCell.swift in Sources */, diff --git a/GHFollowers.xcodeproj/project.xcworkspace/xcuserdata/vasilis.xcuserdatad/UserInterfaceState.xcuserstate b/GHFollowers.xcodeproj/project.xcworkspace/xcuserdata/vasilis.xcuserdatad/UserInterfaceState.xcuserstate index 54c831b..5c58321 100644 Binary files a/GHFollowers.xcodeproj/project.xcworkspace/xcuserdata/vasilis.xcuserdatad/UserInterfaceState.xcuserstate and b/GHFollowers.xcodeproj/project.xcworkspace/xcuserdata/vasilis.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/GHFollowers/Components/ViewControllers/GFDataLoadingVC.swift b/GHFollowers/Components/ViewControllers/GFDataLoadingVC.swift new file mode 100644 index 0000000..dfe53be --- /dev/null +++ b/GHFollowers/Components/ViewControllers/GFDataLoadingVC.swift @@ -0,0 +1,67 @@ +// +// GFDataLoadingVC.swift +// GHFollowers +// +// Created by Vasileios Gkreen on 12/04/2020. +// Copyright © 2020 Vasileios Gkreen. All rights reserved. +// + +import UIKit + +class GFDataLoadingVC: UIViewController { + + var containerView: UIView! + + func showLoadingView() { + // init container view and set it to fill the entire screen + containerView = UIView(frame: view.bounds) + // add the container view into the VC view (which ever is going to call this func) + view.addSubview(containerView) + + containerView.backgroundColor = .systemBackground + containerView.alpha = 0 + + // animate alpha + UIView.animate(withDuration: 0.25) { + self.containerView.alpha = 0.8 + } + + + // add activity indicator + let activityIndicator = UIActivityIndicatorView(style: .large) + containerView.addSubview(activityIndicator) + + activityIndicator.translatesAutoresizingMaskIntoConstraints = false + + // center indicator on containerView + NSLayoutConstraint.activate([ + activityIndicator.centerYAnchor.constraint(equalTo: view.centerYAnchor), + activityIndicator.centerXAnchor.constraint(equalTo: view.centerXAnchor) + ]) + + activityIndicator.startAnimating() + + } + + func dismissLoadingView() { + // We will always going to dismiss Loading View from a background thread + // because we call this function from the Network manager closure (promise) + // to avoid that we need to throw it in the main thread + DispatchQueue.main.async { + self.containerView.removeFromSuperview() + self.containerView = nil + } + } + + + // calling this function from a VC we wiil pass the message and a the view so we know where to constrain it + func showEmptyStateView(with message: String, in view: UIView) { + let emptyStateView = GFEmptyStateView(message: message) + // fill up the entire screen + emptyStateView.frame = view.bounds + // add it to the VC subView + view.addSubview(emptyStateView) + } + + +} diff --git a/GHFollowers/Extensions/UIViewController+EXT.swift b/GHFollowers/Extensions/UIViewController+EXT.swift index e48f3c5..927d472 100644 --- a/GHFollowers/Extensions/UIViewController+EXT.swift +++ b/GHFollowers/Extensions/UIViewController+EXT.swift @@ -11,7 +11,7 @@ import SafariServices // We cant save variables inside an extension so we decalre a 'global' variable inside this file // This global var with the keyword 'fileprivate' is available only in this file and not the entire programm -fileprivate var containerView: UIView! +// fileprivate var containerView: UIView! // This extension is to be applied to all UIViewControllers used in this app @@ -35,58 +35,6 @@ extension UIViewController { } - func showLoadingView() { - // init container view and set it to fill the entire screen - containerView = UIView(frame: view.bounds) - // add the container view into the VC view (which ever is going to call this func) - view.addSubview(containerView) - - containerView.backgroundColor = .systemBackground - containerView.alpha = 0 - - // animate alpha - UIView.animate(withDuration: 0.25) { - containerView.alpha = 0.8 - } - - - // add activity indicator - let activityIndicator = UIActivityIndicatorView(style: .large) - containerView.addSubview(activityIndicator) - - activityIndicator.translatesAutoresizingMaskIntoConstraints = false - - // center indicator on containerView - NSLayoutConstraint.activate([ - activityIndicator.centerYAnchor.constraint(equalTo: view.centerYAnchor), - activityIndicator.centerXAnchor.constraint(equalTo: view.centerXAnchor) - ]) - - activityIndicator.startAnimating() - - } - - func dismissLoadingView() { - // We will always going to dismiss Loading View from a background thread - // because we call this function from the Network manager closure (promise) - // to avoid that we need to throw it in the main thread - DispatchQueue.main.async { - containerView.removeFromSuperview() - containerView = nil - } - } - - - // calling this function from a VC we wiil pass the message and a the view so we know where to constrain it - func showEmptyStateView(with message: String, in view: UIView) { - let emptyStateView = GFEmptyStateView(message: message) - // fill up the entire screen - emptyStateView.frame = view.bounds - // add it to the VC subView - view.addSubview(emptyStateView) - } - - func preserntSafariVC(with url: URL) { let safariVC = SFSafariViewController(url: url) safariVC.preferredControlTintColor = .systemGreen diff --git a/GHFollowers/Screens/FavoriteListVC.swift b/GHFollowers/Screens/FavoriteListVC.swift index dd78927..3896960 100644 --- a/GHFollowers/Screens/FavoriteListVC.swift +++ b/GHFollowers/Screens/FavoriteListVC.swift @@ -8,7 +8,7 @@ import UIKit -class FavoriteListVC: UIViewController { +class FavoriteListVC: GFDataLoadingVC { let tableView = UITableView() var favorites: [Follower] = [] diff --git a/GHFollowers/Screens/FollowerListVC.swift b/GHFollowers/Screens/FollowerListVC.swift index 5a56192..880a302 100644 --- a/GHFollowers/Screens/FollowerListVC.swift +++ b/GHFollowers/Screens/FollowerListVC.swift @@ -16,7 +16,7 @@ protocol FollowerListVCDelegate: class { -class FollowerListVC: UIViewController { +class FollowerListVC: GFDataLoadingVC { // enums are hashable by default enum Section {