Skip to content

Commit d3b9aa5

Browse files
authored
Merge pull request #27 from lauramarson/uiChanges
UI changes
2 parents 0c2ab74 + fe70775 commit d3b9aa5

7 files changed

Lines changed: 150 additions & 79 deletions

File tree

AnimalsApp/AnimalsApp.xcodeproj/project.pbxproj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
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 */; };
1717
A458A094286128FF0057BC34 /* empty.json in Resources */ = {isa = PBXBuildFile; fileRef = A458A093286128FF0057BC34 /* empty.json */; };
18+
A458A09E28628B600057BC34 /* FavoritesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A458A09C28628B600057BC34 /* FavoritesViewController.swift */; };
19+
A458A09F28628B600057BC34 /* FavoritesViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = A458A09D28628B600057BC34 /* FavoritesViewController.xib */; };
1820
A458A09628621A570057BC34 /* StringExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = A458A09528621A570057BC34 /* StringExtensions.swift */; };
1921
A458A09828622EA90057BC34 /* CoreDataMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = A458A09728622EA90057BC34 /* CoreDataMock.swift */; };
2022
A463D0172858EBBB00929A3C /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A463D0162858EBBB00929A3C /* AppDelegate.swift */; };
@@ -29,8 +31,6 @@
2931
A463D0542858F60C00929A3C /* HomeViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = A463D0522858F60C00929A3C /* HomeViewController.xib */; };
3032
A463D0572858F62600929A3C /* RegisterViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A463D0552858F62600929A3C /* RegisterViewController.swift */; };
3133
A463D0582858F62600929A3C /* RegisterViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = A463D0562858F62600929A3C /* RegisterViewController.xib */; };
32-
A463D05D2858F64B00929A3C /* FavoritesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A463D05B2858F64B00929A3C /* FavoritesViewController.swift */; };
33-
A463D05E2858F64B00929A3C /* FavoritesViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = A463D05C2858F64B00929A3C /* FavoritesViewController.xib */; };
3434
A463D06228590D0300929A3C /* Images.swift in Sources */ = {isa = PBXBuildFile; fileRef = A463D06128590D0300929A3C /* Images.swift */; };
3535
A463D065285953F900929A3C /* AnimalTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A463D063285953F900929A3C /* AnimalTableViewCell.swift */; };
3636
A463D066285953F900929A3C /* AnimalTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = A463D064285953F900929A3C /* AnimalTableViewCell.xib */; };
@@ -80,6 +80,8 @@
8080
A458A08B2860BD2D0057BC34 /* Alert+UIViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Alert+UIViewController.swift"; sourceTree = "<group>"; };
8181
A458A0912860F7C40057BC34 /* success.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = success.json; sourceTree = "<group>"; };
8282
A458A093286128FF0057BC34 /* empty.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = empty.json; sourceTree = "<group>"; };
83+
A458A09C28628B600057BC34 /* FavoritesViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FavoritesViewController.swift; sourceTree = "<group>"; };
84+
A458A09D28628B600057BC34 /* FavoritesViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = FavoritesViewController.xib; sourceTree = "<group>"; };
8385
A458A09528621A570057BC34 /* StringExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StringExtensions.swift; sourceTree = "<group>"; };
8486
A458A09728622EA90057BC34 /* CoreDataMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreDataMock.swift; sourceTree = "<group>"; };
8587
A463D0132858EBBB00929A3C /* AnimalsApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = AnimalsApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -98,8 +100,6 @@
98100
A463D0522858F60C00929A3C /* HomeViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = HomeViewController.xib; sourceTree = "<group>"; };
99101
A463D0552858F62600929A3C /* RegisterViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegisterViewController.swift; sourceTree = "<group>"; };
100102
A463D0562858F62600929A3C /* RegisterViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = RegisterViewController.xib; sourceTree = "<group>"; };
101-
A463D05B2858F64B00929A3C /* FavoritesViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FavoritesViewController.swift; sourceTree = "<group>"; };
102-
A463D05C2858F64B00929A3C /* FavoritesViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = FavoritesViewController.xib; sourceTree = "<group>"; };
103103
A463D06128590D0300929A3C /* Images.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Images.swift; sourceTree = "<group>"; };
104104
A463D063285953F900929A3C /* AnimalTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnimalTableViewCell.swift; sourceTree = "<group>"; };
105105
A463D064285953F900929A3C /* AnimalTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = AnimalTableViewCell.xib; sourceTree = "<group>"; };
@@ -273,8 +273,8 @@
273273
A463D0502858F4DE00929A3C /* FavoritesViewController */ = {
274274
isa = PBXGroup;
275275
children = (
276-
A463D05B2858F64B00929A3C /* FavoritesViewController.swift */,
277-
A463D05C2858F64B00929A3C /* FavoritesViewController.xib */,
276+
A458A09C28628B600057BC34 /* FavoritesViewController.swift */,
277+
A458A09D28628B600057BC34 /* FavoritesViewController.xib */,
278278
);
279279
path = FavoritesViewController;
280280
sourceTree = "<group>";
@@ -506,10 +506,10 @@
506506
A458A094286128FF0057BC34 /* empty.json in Resources */,
507507
A463D066285953F900929A3C /* AnimalTableViewCell.xib in Resources */,
508508
A463D06E285A22D300929A3C /* DetailViewController.xib in Resources */,
509+
A458A09F28628B600057BC34 /* FavoritesViewController.xib in Resources */,
509510
A463D0262858EBBD00929A3C /* LaunchScreen.storyboard in Resources */,
510511
A458A0922860F7C40057BC34 /* success.json in Resources */,
511512
A463D0232858EBBD00929A3C /* Assets.xcassets in Resources */,
512-
A463D05E2858F64B00929A3C /* FavoritesViewController.xib in Resources */,
513513
A463D078285A5A8000929A3C /* OpenSans-Regular.ttf in Resources */,
514514
A463D0542858F60C00929A3C /* HomeViewController.xib in Resources */,
515515
);
@@ -649,11 +649,11 @@
649649
A463D071285A373800929A3C /* Animals.swift in Sources */,
650650
A458A086285E58CC0057BC34 /* FavoritesViewModel.swift in Sources */,
651651
A463D04B2858F39000929A3C /* MainTabBarController.swift in Sources */,
652+
A458A09E28628B600057BC34 /* FavoritesViewController.swift in Sources */,
652653
A463D074285A398900929A3C /* HomeViewModel.swift in Sources */,
653654
A463D07A285B8D8E00929A3C /* Colors.swift in Sources */,
654655
A458A09628621A570057BC34 /* StringExtensions.swift in Sources */,
655656
5CA996F8285A98FB00FF5D79 /* RegisterViewModel.swift in Sources */,
656-
A463D05D2858F64B00929A3C /* FavoritesViewController.swift in Sources */,
657657
A463D06D285A22D200929A3C /* DetailViewController.swift in Sources */,
658658
A463D069285A1A5A00929A3C /* WebServices.swift in Sources */,
659659
A463D0532858F60C00929A3C /* HomeViewController.swift in Sources */,

AnimalsApp/AnimalsApp/Views/DetailViewController/DetailViewController.swift

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,8 @@ class DetailViewController: UIViewController {
2121

2222
override func viewDidLoad() {
2323
super.viewDidLoad()
24-
setNavigationItems()
25-
setupDetails()
26-
}
27-
28-
private func setNavigationItems() {
2924
title = "Detalhes"
30-
31-
let appearance = UINavigationBarAppearance()
32-
appearance.configureWithOpaqueBackground()
33-
appearance.titleTextAttributes = [
34-
NSAttributedString.Key.foregroundColor: UIColor.blueTextColor ?? UIColor.blue,
35-
NSAttributedString.Key.font: UIFont(name: "OpenSans", size: 20) ?? UIFont.systemFont(ofSize: 20)]
36-
navigationController?.navigationBar.standardAppearance = appearance
37-
navigationController?.navigationBar.scrollEdgeAppearance = navigationController?.navigationBar.standardAppearance
38-
39-
navigationController?.navigationBar.tintColor = UIColor.blueTextColor
25+
setupDetails()
4026
}
4127

4228
private func setupDetails() {

AnimalsApp/AnimalsApp/Views/FavoritesViewController/FavoritesViewController.swift

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,82 @@ import UIKit
99

1010
class FavoritesViewController: UIViewController {
1111

12+
var favoritesVM: FavoritesViewModel?
13+
14+
@IBOutlet weak var tableView: UITableView!
15+
1216
override func viewDidLoad() {
1317
super.viewDidLoad()
18+
title = "Favoritos"
19+
favoritesVM = FavoritesViewModel()
20+
21+
setTableView()
22+
23+
favoritesVM?.getFavoriteAnimals { [weak self] in self?.tableView.reloadData()
24+
}
25+
}
26+
27+
override func viewWillAppear(_ animated: Bool) {
28+
super.viewWillAppear(animated)
29+
favoritesVM?.getFavoriteAnimals { [weak self] in self?.tableView.reloadData()
30+
}
31+
}
32+
33+
private func setTableView() {
34+
tableView.dataSource = self
35+
tableView.delegate = self
36+
37+
tableView.register(UINib(nibName: "AnimalTableViewCell", bundle: nil), forCellReuseIdentifier: "Animal")
38+
}
39+
}
40+
41+
// MARK: TableView Data Source
42+
extension FavoritesViewController: UITableViewDataSource {
43+
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
44+
return favoritesVM?.numberOfRows() ?? 0
45+
}
46+
47+
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
1448

49+
guard let cell = tableView.dequeueReusableCell(withIdentifier: "Animal", for: indexPath) as? AnimalTableViewCell else {
50+
return UITableViewCell()
1551
}
52+
53+
cell.animal = favoritesVM?.modelAt(indexPath.row)
54+
cell.index = indexPath.row
55+
cell.delegate = self
56+
cell.configure()
57+
58+
return cell
59+
}
1660

1761
}
1862

63+
// MARK: TableView Delegate
64+
extension FavoritesViewController: UITableViewDelegate {
65+
66+
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
67+
let detailVC = DetailViewController(nibName: "DetailViewController", bundle: nil)
68+
69+
let animal = favoritesVM?.modelAt(indexPath.row)
70+
detailVC.animal = animal
1971

72+
navigationController?.pushViewController(detailVC, animated: true)
73+
74+
tableView.deselectRow(at: indexPath, animated: true)
75+
}
76+
77+
}
2078

79+
// MARK: Action Delegate Protocol
80+
extension FavoritesViewController: ActionDelegateProtocol {
81+
func addFavoriteTapped(at index: Int, with image: Data) {
82+
}
83+
84+
func removeFavoriteTapped(at index: Int) {
85+
favoritesVM?.removeFavorite(at: index) { [weak self] in
86+
self?.tableView.reloadData()
87+
}
88+
}
89+
}
2190

AnimalsApp/AnimalsApp/Views/FavoritesViewController/FavoritesViewController.xib

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,45 @@
44
<dependencies>
55
<deployment identifier="iOS"/>
66
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="20020"/>
7+
<capability name="Named colors" minToolsVersion="9.0"/>
78
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
89
<capability name="System colors in document resources" minToolsVersion="11.0"/>
910
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
1011
</dependencies>
1112
<objects>
1213
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="FavoritesViewController" customModule="AnimalsApp" customModuleProvider="target">
1314
<connections>
15+
<outlet property="tableView" destination="Z7H-5c-G5G" id="KBe-qr-ZCy"/>
1416
<outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/>
1517
</connections>
1618
</placeholder>
1719
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
1820
<view clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="i5M-Pr-FkT">
1921
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
2022
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
23+
<subviews>
24+
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" style="plain" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="-1" estimatedSectionHeaderHeight="-1" sectionFooterHeight="-1" estimatedSectionFooterHeight="-1" translatesAutoresizingMaskIntoConstraints="NO" id="Z7H-5c-G5G">
25+
<rect key="frame" x="0.0" y="44" width="414" height="818"/>
26+
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
27+
<color key="separatorColor" name="grayCellFrame"/>
28+
<inset key="separatorInset" minX="0.0" minY="0.0" maxX="0.0" maxY="0.0"/>
29+
</tableView>
30+
</subviews>
2131
<viewLayoutGuide key="safeArea" id="fnl-2z-Ty3"/>
2232
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
33+
<constraints>
34+
<constraint firstItem="Z7H-5c-G5G" firstAttribute="top" secondItem="fnl-2z-Ty3" secondAttribute="top" id="Gij-fh-f3w"/>
35+
<constraint firstItem="fnl-2z-Ty3" firstAttribute="trailing" secondItem="Z7H-5c-G5G" secondAttribute="trailing" id="Mbr-5U-mqf"/>
36+
<constraint firstItem="fnl-2z-Ty3" firstAttribute="bottom" secondItem="Z7H-5c-G5G" secondAttribute="bottom" id="OEE-7F-ts3"/>
37+
<constraint firstItem="Z7H-5c-G5G" firstAttribute="leading" secondItem="fnl-2z-Ty3" secondAttribute="leading" id="e7r-Gn-PgY"/>
38+
</constraints>
2339
<point key="canvasLocation" x="132" y="33"/>
2440
</view>
2541
</objects>
2642
<resources>
43+
<namedColor name="grayCellFrame">
44+
<color red="0.63921568627450975" green="0.63921568627450975" blue="0.63921568627450975" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
45+
</namedColor>
2746
<systemColor name="systemBackgroundColor">
2847
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
2948
</systemColor>

AnimalsApp/AnimalsApp/Views/HomeViewController/HomeViewController.swift

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ class HomeViewController: UIViewController {
2121
// MARK: Overrides
2222
override func viewDidLoad() {
2323
super.viewDidLoad()
24+
title = "Home"
2425
loadingView.startAnimating()
25-
26-
setNavigationItems()
2726
setTableView()
2827

2928
homeVM.loadFavorites { [weak self] in
@@ -44,21 +43,7 @@ class HomeViewController: UIViewController {
4443
homeVM.saveChangesInCoreData()
4544
}
4645

47-
// MARK: Methods
48-
private func setNavigationItems() {
49-
title = "Home"
50-
51-
let appearance = UINavigationBarAppearance()
52-
appearance.configureWithOpaqueBackground()
53-
appearance.titleTextAttributes = [
54-
NSAttributedString.Key.foregroundColor: UIColor.blueTextColor ?? UIColor.blue,
55-
NSAttributedString.Key.font: UIFont(name: "OpenSans", size: 20) ?? UIFont.systemFont(ofSize: 20)]
56-
navigationController?.navigationBar.standardAppearance = appearance
57-
navigationController?.navigationBar.scrollEdgeAppearance = navigationController?.navigationBar.standardAppearance
58-
59-
navigationItem.backButtonTitle = ""
60-
}
61-
46+
// MARK: Methods
6247
private func setTableView() {
6348
tableView.dataSource = self
6449
tableView.delegate = self

0 commit comments

Comments
 (0)