@@ -12,37 +12,112 @@ class HomeViewController: UIViewController, ActivityIndicatorPresenter {
1212
1313 // MARK: - Outlets
1414
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+ } ( )
1846
1947 let activityIndicator = UIActivityIndicatorView ( )
2048
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+ }
2260
2361 // MARK: - Lifecycle Events
2462 override func viewDidLoad( ) {
2563 super. viewDidLoad ( )
64+
2665 viewModel. delegate = self
27- logOut. setRoundBorders ( 22 )
28- deleteAccountButton. setRoundBorders ( 22 )
66+ configureViews ( )
2967 }
3068
3169 // MARK: - Actions
3270
33- @IBAction func tapOnGetMyProfile( _ sender: Any ) {
71+ @objc
72+ func tapOnGetMyProfile( _ sender: Any ) {
3473 viewModel. loadUserProfile ( )
3574 }
3675
37- @IBAction func tapOnLogOutButton( _ sender: Any ) {
76+ @objc
77+ func tapOnLogOutButton( _ sender: Any ) {
3878 viewModel. logoutUser ( )
3979 }
4080
41- @IBAction func tapOnDeleteAccount( _ sender: Any ) {
81+ @objc
82+ func tapOnDeleteAccount( _ sender: Any ) {
4283 viewModel. deleteAccount ( )
4384 }
4485}
4586
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+
46121extension HomeViewController : HomeViewModelDelegate {
47122 func didUpdateState( to state: HomeViewModelState ) {
48123 switch state {
0 commit comments