Skip to content

Commit fbb9eee

Browse files
authored
Merge pull request #23 from lauramarson/feature/alert
Feature/alert
2 parents 953c892 + ad25600 commit fbb9eee

5 files changed

Lines changed: 58 additions & 14 deletions

File tree

AnimalsApp/AnimalsApp.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
A458A086285E58CC0057BC34 /* FavoritesViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A458A085285E58CC0057BC34 /* FavoritesViewModel.swift */; };
1515
A458A08C2860BD2D0057BC34 /* Alert+UIViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A458A08B2860BD2D0057BC34 /* Alert+UIViewController.swift */; };
1616
A458A0922860F7C40057BC34 /* success.json in Resources */ = {isa = PBXBuildFile; fileRef = A458A0912860F7C40057BC34 /* success.json */; };
17+
A458A094286128FF0057BC34 /* empty.json in Resources */ = {isa = PBXBuildFile; fileRef = A458A093286128FF0057BC34 /* empty.json */; };
1718
A463D0172858EBBB00929A3C /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A463D0162858EBBB00929A3C /* AppDelegate.swift */; };
1819
A463D0212858EBBB00929A3C /* AnimalsApp.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = A463D01F2858EBBB00929A3C /* AnimalsApp.xcdatamodeld */; };
1920
A463D0232858EBBD00929A3C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A463D0222858EBBD00929A3C /* Assets.xcassets */; };
@@ -74,6 +75,7 @@
7475
A458A085285E58CC0057BC34 /* FavoritesViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FavoritesViewModel.swift; sourceTree = "<group>"; };
7576
A458A08B2860BD2D0057BC34 /* Alert+UIViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Alert+UIViewController.swift"; sourceTree = "<group>"; };
7677
A458A0912860F7C40057BC34 /* success.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = success.json; sourceTree = "<group>"; };
78+
A458A093286128FF0057BC34 /* empty.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = empty.json; sourceTree = "<group>"; };
7779
A463D0132858EBBB00929A3C /* AnimalsApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = AnimalsApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
7880
A463D0162858EBBB00929A3C /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
7981
A463D0202858EBBB00929A3C /* AnimalsApp.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = AnimalsApp.xcdatamodel; sourceTree = "<group>"; };
@@ -168,6 +170,7 @@
168170
isa = PBXGroup;
169171
children = (
170172
A458A0912860F7C40057BC34 /* success.json */,
173+
A458A093286128FF0057BC34 /* empty.json */,
171174
);
172175
path = Animations;
173176
sourceTree = "<group>";
@@ -464,6 +467,7 @@
464467
files = (
465468
A463D04C2858F39000929A3C /* MainTabBarController.xib in Resources */,
466469
A463D0582858F62600929A3C /* RegisterViewController.xib in Resources */,
470+
A458A094286128FF0057BC34 /* empty.json in Resources */,
467471
A463D066285953F900929A3C /* AnimalTableViewCell.xib in Resources */,
468472
A463D06E285A22D300929A3C /* DetailViewController.xib in Resources */,
469473
A463D0262858EBBD00929A3C /* LaunchScreen.storyboard in Resources */,

AnimalsApp/AnimalsApp/Resources/Animations/empty.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

AnimalsApp/AnimalsApp/Views/HomeViewController/HomeViewController.swift

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77

88
import UIKit
9+
import Lottie
910

1011
class HomeViewController: UIViewController {
1112

@@ -15,28 +16,22 @@ class HomeViewController: UIViewController {
1516
// MARK: Outlets
1617
@IBOutlet var tableView: UITableView!
1718
@IBOutlet weak var loadingView: UIActivityIndicatorView!
19+
@IBOutlet weak var emptyAnimationView: AnimationView!
1820

1921
// MARK: Overrides
2022
override func viewDidLoad() {
2123
super.viewDidLoad()
2224
loadingView.startAnimating()
2325

24-
tableView.dataSource = self
25-
tableView.delegate = self
26-
27-
tableView.register(UINib(nibName: "AnimalTableViewCell", bundle: nil), forCellReuseIdentifier: "Animal")
28-
2926
setNavigationItems()
27+
setTableView()
28+
3029
homeVM.loadFavorites { [weak self] in
3130
self?.populateTableView()
3231
}
33-
34-
let refreshControl = UIRefreshControl()
35-
refreshControl.addTarget(self, action: #selector(reloadAnimals), for: .valueChanged)
36-
tableView.refreshControl = refreshControl
3732

38-
let notificationCenter = NotificationCenter.default
39-
notificationCenter.addObserver(self, selector: #selector(saveChanges), name: UIApplication.willResignActiveNotification, object: nil)
33+
setRefreshControl()
34+
notificationCenter()
4035
}
4136

4237
override func viewWillAppear(_ animated: Bool) {
@@ -64,7 +59,17 @@ class HomeViewController: UIViewController {
6459
navigationItem.backButtonTitle = ""
6560
}
6661

62+
private func setTableView() {
63+
tableView.dataSource = self
64+
tableView.delegate = self
65+
66+
tableView.register(UINib(nibName: "AnimalTableViewCell", bundle: nil), forCellReuseIdentifier: "Animal")
67+
}
68+
6769
private func populateTableView() {
70+
emptyAnimationView.isHidden = true
71+
emptyAnimationView.stop()
72+
6873
homeVM.getAllAnimals { [weak self] (result) in
6974

7075
switch result {
@@ -80,9 +85,34 @@ class HomeViewController: UIViewController {
8085
guard let alert = self?.fetchAlert(title: "Oops...", message: "Não foi possível carregar os animais") else { return }
8186
self?.present(alert, animated: true)
8287
}
88+
89+
if (self?.homeVM.animals.isEmpty ?? true) {
90+
self?.emptyAnimationView.isHidden = false
91+
self?.setEmptyAnimation()
92+
}
8393
}
8494
}
8595

96+
private func setEmptyAnimation() {
97+
emptyAnimationView.isHidden = false
98+
emptyAnimationView.contentMode = .scaleAspectFit
99+
emptyAnimationView.loopMode = .loop
100+
emptyAnimationView.animationSpeed = 1
101+
tableView.isHidden = true
102+
emptyAnimationView.play()
103+
}
104+
105+
private func notificationCenter() {
106+
let notificationCenter = NotificationCenter.default
107+
notificationCenter.addObserver(self, selector: #selector(saveChanges), name: UIApplication.willResignActiveNotification, object: nil)
108+
}
109+
110+
private func setRefreshControl() {
111+
let refreshControl = UIRefreshControl()
112+
refreshControl.addTarget(self, action: #selector(reloadAnimals), for: .valueChanged)
113+
tableView.refreshControl = refreshControl
114+
}
115+
86116
@objc
87117
private func reloadAnimals(refreshControl: UIRefreshControl) {
88118
populateTableView()

AnimalsApp/AnimalsApp/Views/HomeViewController/HomeViewController.xib

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<objects>
1313
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="HomeViewController" customModule="AnimalsApp" customModuleProvider="target">
1414
<connections>
15+
<outlet property="emptyAnimationView" destination="TJt-B1-8gf" id="NeJ-cd-3ZM"/>
1516
<outlet property="loadingView" destination="3je-EF-sGM" id="mFG-Xj-K4G"/>
1617
<outlet property="tableView" destination="Siv-wY-ZEk" id="zHW-EM-j8u"/>
1718
<outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/>
@@ -30,16 +31,27 @@
3031
<activityIndicatorView hidden="YES" opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" hidesWhenStopped="YES" style="large" translatesAutoresizingMaskIntoConstraints="NO" id="3je-EF-sGM">
3132
<rect key="frame" x="188.5" y="429.5" width="37" height="37"/>
3233
</activityIndicatorView>
34+
<view hidden="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="TJt-B1-8gf" customClass="AnimationView" customModule="Lottie">
35+
<rect key="frame" x="0.0" y="44" width="414" height="818"/>
36+
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
37+
<userDefinedRuntimeAttributes>
38+
<userDefinedRuntimeAttribute type="string" keyPath="animationName" value="empty"/>
39+
</userDefinedRuntimeAttributes>
40+
</view>
3341
</subviews>
3442
<viewLayoutGuide key="safeArea" id="fnl-2z-Ty3"/>
3543
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
3644
<constraints>
45+
<constraint firstItem="fnl-2z-Ty3" firstAttribute="bottom" secondItem="TJt-B1-8gf" secondAttribute="bottom" id="0hG-wp-V08"/>
3746
<constraint firstItem="fnl-2z-Ty3" firstAttribute="trailing" secondItem="Siv-wY-ZEk" secondAttribute="trailing" id="CK9-kj-fPh"/>
3847
<constraint firstItem="fnl-2z-Ty3" firstAttribute="bottom" secondItem="Siv-wY-ZEk" secondAttribute="bottom" id="Fs7-zJ-zOE"/>
3948
<constraint firstItem="3je-EF-sGM" firstAttribute="centerX" secondItem="i5M-Pr-FkT" secondAttribute="centerX" id="IXw-Qp-7bN"/>
4049
<constraint firstItem="Siv-wY-ZEk" firstAttribute="top" secondItem="fnl-2z-Ty3" secondAttribute="top" id="Mug-YL-ycT"/>
50+
<constraint firstItem="fnl-2z-Ty3" firstAttribute="trailing" secondItem="TJt-B1-8gf" secondAttribute="trailing" id="N84-y4-Cib"/>
4151
<constraint firstItem="Siv-wY-ZEk" firstAttribute="leading" secondItem="fnl-2z-Ty3" secondAttribute="leading" id="RJW-a7-pVc"/>
52+
<constraint firstItem="TJt-B1-8gf" firstAttribute="top" secondItem="fnl-2z-Ty3" secondAttribute="top" id="SbK-mf-c5J"/>
4253
<constraint firstItem="3je-EF-sGM" firstAttribute="centerY" secondItem="i5M-Pr-FkT" secondAttribute="centerY" id="sUh-hY-zSM"/>
54+
<constraint firstItem="TJt-B1-8gf" firstAttribute="leading" secondItem="fnl-2z-Ty3" secondAttribute="leading" id="thz-we-c9M"/>
4355
</constraints>
4456
<point key="canvasLocation" x="131.8840579710145" y="83.705357142857139"/>
4557
</view>

AnimalsApp/AnimalsApp/Views/RegisterViewController/RegisterViewController.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import Lottie
1111
class RegisterViewController: UIViewController {
1212
// MARK: Properties
1313
private var registerVM = RegisterViewModel()
14-
// private var animationView: AnimationView?
1514

1615
// MARK: Outlets
1716
@IBOutlet weak var scrollView: UIScrollView!
@@ -139,8 +138,6 @@ class RegisterViewController: UIViewController {
139138
}
140139
}
141140

142-
143-
144141
private func notificationCenter() {
145142
let notificationCenter = NotificationCenter.default
146143
notificationCenter.addObserver(self, selector: #selector(adjustForKeyboard), name: UIResponder.keyboardWillHideNotification, object: nil)

0 commit comments

Comments
 (0)