@@ -20,7 +20,7 @@ class RegisterViewController: UIViewController {
2020 @IBOutlet weak var textFieldSpecie : UITextField !
2121 @IBOutlet weak var textFieldAge : UITextField !
2222 @IBOutlet weak var buttonRegister : UIButton !
23- // @IBOutlet weak var activityIndicator: UIActivityIndicatorView!
23+ @IBOutlet weak var activityIndicator : UIActivityIndicatorView !
2424
2525 // MARK: Overrides
2626 override func viewDidLoad( ) {
@@ -29,11 +29,14 @@ class RegisterViewController: UIViewController {
2929 setNavigationItems ( )
3030 delegateTextField ( )
3131 notificationCenter ( )
32- // activityIndicator.hidesWhenStopped = true
32+ activityIndicator. hidesWhenStopped = true
3333 }
3434
3535 // MARK: Actions
3636 @IBAction func handlerButtonRegister( _ sender: Any ) {
37+ activityIndicator. startAnimating ( )
38+ buttonRegister. backgroundColor = . grayCellFrame
39+ buttonRegister. isUserInteractionEnabled = false
3740
3841 guard let name = textFieldName. text? . testIfIsEmpty ( ) ,
3942 let description = textFieldDescription. text? . testIfIsEmpty ( ) ,
@@ -43,10 +46,8 @@ class RegisterViewController: UIViewController {
4346 showAlerts ( alertTitle: " Erro " , alertMessage: " Preencha todos os campos " )
4447 return }
4548
46- // activityIndicator.startAnimating()
47- registerVM. registerAnimal ( name: name, description: description, age: age, species: species, image: image) {
48- // self.activityIndicator.stopAnimating()
49- print ( " oi " )
49+ registerVM. registerAnimal ( name: name, description: description, age: age, species: species, image: image) { [ weak self] in
50+ self ? . registerSucceeded ( )
5051 }
5152 }
5253
@@ -72,11 +73,11 @@ class RegisterViewController: UIViewController {
7273 }
7374
7475 let attributes = [ NSAttributedString . Key. foregroundColor: UIColor . grayTextColor ?? UIColor . systemGray, NSAttributedString . Key. font: UIFont ( name: " OpenSans " , size: 16 ) ?? UIFont . systemFont ( ofSize: 16 ) ]
75- textFieldName. attributedPlaceholder = NSAttributedString ( string: " Nome" , attributes: attributes)
76- textFieldImageLink. attributedPlaceholder = NSAttributedString ( string: " Link da imagem" , attributes: attributes)
77- textFieldDescription. attributedPlaceholder = NSAttributedString ( string: " Descrição" , attributes: attributes)
78- textFieldSpecie. attributedPlaceholder = NSAttributedString ( string: " Espécie" , attributes: attributes)
79- textFieldAge. attributedPlaceholder = NSAttributedString ( string: " Idade" , attributes: attributes)
76+ textFieldName. attributedPlaceholder = NSAttributedString ( string: " Nome " , attributes: attributes)
77+ textFieldImageLink. attributedPlaceholder = NSAttributedString ( string: " Link da imagem " , attributes: attributes)
78+ textFieldDescription. attributedPlaceholder = NSAttributedString ( string: " Descrição " , attributes: attributes)
79+ textFieldSpecie. attributedPlaceholder = NSAttributedString ( string: " Espécie " , attributes: attributes)
80+ textFieldAge. attributedPlaceholder = NSAttributedString ( string: " Idade " , attributes: attributes)
8081 buttonRegister. layer. cornerRadius = 10
8182 }
8283
@@ -91,10 +92,24 @@ class RegisterViewController: UIViewController {
9192
9293 private func showAlerts( alertTitle: String ? , alertMessage: String ? ) {
9394 let alert = UIAlertController ( title: alertTitle, message: alertMessage, preferredStyle: . alert)
94- alert. addAction ( UIAlertAction ( title: " OK " , style: . default, handler: nil ) )
95+ alert. addAction ( UIAlertAction ( title: " OK " , style: . default) { [ weak self] _ in
96+ self ? . activityIndicator. stopAnimating ( )
97+ self ? . buttonRegister. isUserInteractionEnabled = true
98+ self ? . buttonRegister. backgroundColor = . purpleButtonColor
99+ } )
100+
95101 present ( alert, animated: true )
96102 }
97103
104+ private func registerSucceeded( ) {
105+ activityIndicator. stopAnimating ( )
106+ buttonRegister. isUserInteractionEnabled = true
107+ buttonRegister. backgroundColor = . purpleButtonColor
108+ [ textFieldName, textFieldImageLink, textFieldDescription, textFieldSpecie, textFieldAge] . forEach { textField in
109+ textField? . text = " "
110+ }
111+ }
112+
98113 private func notificationCenter( ) {
99114 let notificationCenter = NotificationCenter . default
100115 notificationCenter. addObserver ( self , selector: #selector( adjustForKeyboard) , name: UIResponder . keyboardWillHideNotification, object: nil )
0 commit comments