Skip to content

Commit 2e69d26

Browse files
committed
view changes
1 parent 684a735 commit 2e69d26

4 files changed

Lines changed: 54 additions & 71 deletions

File tree

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

AnimalsApp/AnimalsApp/Views/RegisterViewController/RegisterViewController.swift

Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ class RegisterViewController: UIViewController {
2626
// MARK: Overrides
2727
override func viewDidLoad() {
2828
super.viewDidLoad()
29+
title = "Cadastrar"
2930
setupUI()
30-
setNavigationItems()
3131
delegateTextField()
3232
notificationCenter()
3333
activityIndicator.hidesWhenStopped = true
@@ -40,46 +40,10 @@ class RegisterViewController: UIViewController {
4040
buttonRegister.backgroundColor = .grayCellFrame
4141
buttonRegister.isUserInteractionEnabled = false
4242

43-
guard let name = textFieldName.text?.testIfIsEmpty(),
44-
let description = textFieldDescription.text?.testIfIsEmpty(),
45-
let age = Int(textFieldAge.text ?? ""),
46-
let species = textFieldSpecie.text?.testIfIsEmpty(),
47-
let image = textFieldImageLink.text?.testIfIsEmpty() else {
48-
showAlerts(alertTitle: "Erro", alertMessage: "Preencha todos os campos")
49-
return }
50-
51-
registerVM.registerAnimal(name: name, description: description, age: age, species: species, image: image) { [weak self] (result) in
52-
53-
switch result {
54-
case .success:
55-
self?.setSuccessAnimation()
56-
self?.registerSucceeded()
57-
58-
case .failure(let error):
59-
print(error.localizedDescription)
60-
guard let alert = self?.fetchAlert(title: "Oops...", message: "Não foi possível cadastrar o novo animal") else { return }
61-
self?.present(alert, animated: true) {
62-
self?.activityIndicator.stopAnimating()
63-
self?.buttonRegister.isUserInteractionEnabled = true
64-
self?.buttonRegister.backgroundColor = .purpleButtonColor
65-
}
66-
}
67-
}
68-
}
69-
70-
// MARK: Methods
71-
private func setNavigationItems() {
72-
title = "Cadastrar"
73-
74-
let appearance = UINavigationBarAppearance()
75-
appearance.configureWithOpaqueBackground()
76-
appearance.titleTextAttributes = [
77-
NSAttributedString.Key.foregroundColor: UIColor.blueTextColor ?? UIColor.blue,
78-
NSAttributedString.Key.font: UIFont(name: "OpenSans", size: 20) ?? UIFont.systemFont(ofSize: 20)]
79-
navigationController?.navigationBar.standardAppearance = appearance
80-
navigationController?.navigationBar.scrollEdgeAppearance = navigationController?.navigationBar.standardAppearance
43+
registerAnimal()
8144
}
8245

46+
// MARK: Methods
8347
private func setupUI() {
8448
[textFieldName, textFieldImageLink, textFieldDescription, textFieldSpecie, textFieldAge].forEach { textField in
8549
textField?.layer.cornerRadius = 8
@@ -106,6 +70,34 @@ class RegisterViewController: UIViewController {
10670
self.view.addGestureRecognizer(UITapGestureRecognizer(target: self.view, action: #selector(UIView.endEditing(_:))))
10771
}
10872

73+
private func registerAnimal() {
74+
guard let name = textFieldName.text?.testIfIsEmpty(),
75+
let description = textFieldDescription.text?.testIfIsEmpty(),
76+
let age = Int(textFieldAge.text ?? ""),
77+
let species = textFieldSpecie.text?.testIfIsEmpty(),
78+
let image = textFieldImageLink.text?.testIfIsEmpty() else {
79+
showAlerts(alertTitle: "Erro", alertMessage: "Preencha todos os campos")
80+
return }
81+
82+
registerVM.registerAnimal(name: name, description: description, age: age, species: species, image: image) { [weak self] (result) in
83+
84+
switch result {
85+
case .success:
86+
self?.setSuccessAnimation()
87+
self?.registerSucceeded()
88+
89+
case .failure(let error):
90+
print(error.localizedDescription)
91+
guard let alert = self?.fetchAlert(title: "Oops...", message: "Não foi possível cadastrar o novo animal") else { return }
92+
self?.present(alert, animated: true) {
93+
self?.activityIndicator.stopAnimating()
94+
self?.buttonRegister.isUserInteractionEnabled = true
95+
self?.buttonRegister.backgroundColor = .purpleButtonColor
96+
}
97+
}
98+
}
99+
}
100+
109101
private func showAlerts(alertTitle: String?, alertMessage: String?) {
110102
let alert = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: .alert)
111103
alert.addAction(UIAlertAction(title: "OK", style: .default) { [weak self] _ in

AnimalsApp/AnimalsApp/Views/TabBarController/MainTabBarController.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@ class MainTabBarController: UITabBarController {
2020

2121
let homeVC = UINavigationController(rootViewController: HomeViewController())
2222
homeVC.tabBarItem = UITabBarItem(title: "Home", image: .homeTabBar, selectedImage: .homeSelectedTabBar)
23+
setupNavigationBar(for: homeVC)
2324

2425
let registerVC = UINavigationController(rootViewController: RegisterViewController())
2526
registerVC.tabBarItem = UITabBarItem(title: "Cadastrar", image: .registerTabBar, selectedImage: .registerSelectedTabBar)
27+
setupNavigationBar(for: registerVC)
2628

2729
let favoritesVC = UINavigationController(rootViewController: FavoritesViewController())
2830
favoritesVC.tabBarItem = UITabBarItem(title: "Favoritos", image: .favoritesTabBar, selectedImage: .favoritesSelectedTabBar)
31+
setupNavigationBar(for: favoritesVC)
2932

3033
viewControllers = [homeVC, registerVC, favoritesVC]
3134
}
@@ -46,4 +49,21 @@ class MainTabBarController: UITabBarController {
4649
}
4750
}
4851

52+
func setupNavigationBar(for navController: UINavigationController) {
53+
let appearance = UINavigationBarAppearance()
54+
appearance.configureWithOpaqueBackground()
55+
appearance.titleTextAttributes = [
56+
NSAttributedString.Key.foregroundColor: UIColor.blueTextColor ?? UIColor.blue,
57+
NSAttributedString.Key.font: UIFont(name: "OpenSans", size: 20) ?? UIFont.systemFont(ofSize: 20)]
58+
59+
navController.navigationBar.standardAppearance = appearance
60+
navController.navigationBar.scrollEdgeAppearance = navController.navigationBar.standardAppearance
61+
62+
// navigationItem.backButtonTitle = ""
63+
64+
navController.navigationBar.layer.shadowOffset = CGSize(width: 0, height: 2)
65+
navController.navigationBar.layer.shadowRadius = 1
66+
navController.navigationBar.layer.shadowOpacity = 0.15
67+
}
68+
4969
}

0 commit comments

Comments
 (0)