@@ -12,37 +12,112 @@ class HomeViewController: UIViewController, ActivityIndicatorPresenter {
12
12
13
13
// MARK: - Outlets
14
14
15
- @IBOutlet weak var welcomeLabel : UILabel !
16
- @IBOutlet weak var logOut : UIButton !
17
- @IBOutlet weak var deleteAccountButton : UIButton !
15
+ private lazy var welcomeLabel = UILabel . titleLabel (
16
+ text: " homescreen_title " . localized
17
+ )
18
+
19
+ private lazy var logOutButton = UIButton . primaryButton (
20
+ color: . black,
21
+ title: " homescreen_logout_button_title " . localized,
22
+ target: self ,
23
+ action: #selector( tapOnLogOutButton)
24
+ )
25
+
26
+ private lazy var deleteAccountButton = UIButton . primaryButton (
27
+ color: . deleteButton,
28
+ title: " homescreen_delete_button_title " . localized,
29
+ target: self ,
30
+ action: #selector( tapOnDeleteAccount)
31
+ )
32
+
33
+ private lazy var getProfileButton : UIButton = {
34
+ let button = UIButton ( )
35
+ button. translatesAutoresizingMaskIntoConstraints = false
36
+ button. setTitle ( " homescreen_get_profile_button_title " . localized, for: . normal)
37
+ button. setTitleColor ( . blue, for: . normal)
38
+ button. addTarget (
39
+ self ,
40
+ action: #selector( tapOnGetMyProfile) ,
41
+ for: . touchUpInside
42
+ )
43
+
44
+ return button
45
+ } ( )
18
46
19
47
let activityIndicator = UIActivityIndicatorView ( )
20
48
21
- var viewModel : HomeViewModel !
49
+ private var viewModel : HomeViewModel
50
+
51
+ init ( viewModel: HomeViewModel ) {
52
+ self . viewModel = viewModel
53
+ super. init ( nibName: nil , bundle: nil )
54
+ }
55
+
56
+ @available ( * , unavailable)
57
+ required init ? ( coder: NSCoder ) {
58
+ fatalError ( " init(coder:) has not been implemented " )
59
+ }
22
60
23
61
// MARK: - Lifecycle Events
24
62
override func viewDidLoad( ) {
25
63
super. viewDidLoad ( )
64
+
26
65
viewModel. delegate = self
27
- logOut. setRoundBorders ( 22 )
28
- deleteAccountButton. setRoundBorders ( 22 )
66
+ configureViews ( )
29
67
}
30
68
31
69
// MARK: - Actions
32
70
33
- @IBAction func tapOnGetMyProfile( _ sender: Any ) {
71
+ @objc
72
+ func tapOnGetMyProfile( _ sender: Any ) {
34
73
viewModel. loadUserProfile ( )
35
74
}
36
75
37
- @IBAction func tapOnLogOutButton( _ sender: Any ) {
76
+ @objc
77
+ func tapOnLogOutButton( _ sender: Any ) {
38
78
viewModel. logoutUser ( )
39
79
}
40
80
41
- @IBAction func tapOnDeleteAccount( _ sender: Any ) {
81
+ @objc
82
+ func tapOnDeleteAccount( _ sender: Any ) {
42
83
viewModel. deleteAccount ( )
43
84
}
44
85
}
45
86
87
+ private extension HomeViewController {
88
+
89
+ private func configureViews( ) {
90
+ applyDefaultUIConfigs ( )
91
+ view. addSubviews (
92
+ subviews: [ welcomeLabel, logOutButton, deleteAccountButton, getProfileButton]
93
+ )
94
+ activateConstraints ( )
95
+ }
96
+
97
+ private func activateConstraints( ) {
98
+ welcomeLabel. centerHorizontally ( with: view)
99
+ getProfileButton. center ( view)
100
+ logOutButton. attachHorizontally ( to: view)
101
+ deleteAccountButton. attachHorizontally ( to: view)
102
+
103
+ NSLayoutConstraint . activate ( [
104
+ welcomeLabel. topAnchor. constraint (
105
+ equalTo: view. topAnchor,
106
+ constant: UI . ViewController. topMargin
107
+ ) ,
108
+ deleteAccountButton. bottomAnchor. constraint (
109
+ equalTo: view. bottomAnchor,
110
+ constant: - UI. Defaults. margin
111
+ ) ,
112
+ logOutButton. bottomAnchor. constraint (
113
+ equalTo: deleteAccountButton. topAnchor,
114
+ constant: - UI. Button. spacing
115
+ )
116
+ ] )
117
+ }
118
+
119
+ }
120
+
46
121
extension HomeViewController : HomeViewModelDelegate {
47
122
func didUpdateState( to state: HomeViewModelState ) {
48
123
switch state {
0 commit comments