From 39ec2064542515d9c65c494ec31f1318245d5fdd Mon Sep 17 00:00:00 2001 From: Javier Cicchelli Date: Wed, 12 Apr 2023 12:50:26 +0200 Subject: [PATCH] Implemented the outlets of the LocationsListViewController view controller. --- .../LocationsListViewController.swift | 60 ++++++++++++++++--- 1 file changed, 51 insertions(+), 9 deletions(-) diff --git a/Apps/Locations/Sources/Screens/LocationsList/LocationsListViewController.swift b/Apps/Locations/Sources/Screens/LocationsList/LocationsListViewController.swift index cc35c26..3868d89 100644 --- a/Apps/Locations/Sources/Screens/LocationsList/LocationsListViewController.swift +++ b/Apps/Locations/Sources/Screens/LocationsList/LocationsListViewController.swift @@ -13,7 +13,19 @@ class LocationsListViewController: BaseViewController { // MARK: Properties - var viewModel: LocationsListViewModeling + private let viewModel: LocationsListViewModeling + + // MARK: Outlets + + private lazy var error = ErrorMessageView() + private lazy var loading = LoadingSpinnerView() + private lazy var table = { + let table = UITableView(frame: .zero, style: .plain) + + table.translatesAutoresizingMaskIntoConstraints = false + + return table + }() // MARK: Initialisers @@ -31,14 +43,9 @@ class LocationsListViewController: BaseViewController { override func viewDidLoad() { super.viewDidLoad() - - navigationItem.rightBarButtonItem = UIBarButtonItem( - title: "Add", - style: .plain, - target: self, - action: #selector(addLocationPressed) - ) - title = "Locations" + + setupBar() + setupView() } } @@ -49,6 +56,41 @@ private extension LocationsListViewController { // MARK: Functions + func setupBar() { + navigationController?.navigationBar.prefersLargeTitles = true + navigationController?.navigationBar.tintColor = .red + navigationItem.rightBarButtonItem = .init( + title: "Add", + style: .plain, + target: self, + action: #selector(addLocationPressed) + ) + title = "Locations" + } + + func setupView() { + view.addSubview(table) + view.addSubview(error) + view.addSubview(loading) + + error.isHidden = true + error.onRetry = { print("RETRY BUTTON PRESSED!") } + + loading.isHidden = true + + NSLayoutConstraint.activate([ + error.widthAnchor.constraint(equalToConstant: 300), + view.centerXAnchor.constraint(equalTo: error.centerXAnchor), + view.centerYAnchor.constraint(equalTo: error.centerYAnchor), + view.centerXAnchor.constraint(equalTo: loading.centerXAnchor), + view.centerYAnchor.constraint(equalTo: loading.centerYAnchor), + view.bottomAnchor.constraint(equalTo: table.bottomAnchor), + view.leadingAnchor.constraint(equalTo: table.leadingAnchor), + view.topAnchor.constraint(equalTo: table.topAnchor), + view.trailingAnchor.constraint(equalTo: table.trailingAnchor), + ]) + } + @objc func addLocationPressed() { viewModel.openAddLocation() }