125 lines
3.3 KiB
Swift
Raw Normal View History

[Feature] Locations list (#10) This PR contains the work done to fetch a set of locations from a remote server to then persist them into the persistence stack and finally to display these data into the locations list screen. To give further details about the work done: - [x] implemented the `LoadingSpinnerView` and `ErrorMessageView` custom views; - [x] implemented the outlets of the `LocationsListViewController` view controller; - [x] add properties and functions to the `LocationsListViewModeling` protocol to support reactive updates, load data, and table data source conformances; - [x] deactivated the Location entity code generation from the Core Data model in the `Persistence` library; - [x] add fetch requests builder functions to the `NSFetchRequest+Location` extension in the `Persistence` library; - [x] implemented the `LoadRemoteLocationUseCase` use case; - [x] implemented the loading of locations in the LocationsListViewModel view model; - [x] implemented properties and functions in the LocationsListViewModel view model to support the table data source conformance of the `LocationsListViewController` view controller; - [x] implemented the `LocationViewCell` custom cell; - [x] registered the `LocationViewCell` with the table of the `LocationsListViewController` view controller and implemented its update with real data from Location entities. Co-authored-by: Javier Cicchelli <javier@rock-n-code.com> Reviewed-on: https://repo.rock-n-code.com/rock-n-code/deep-linking-assignment/pulls/10
2023-04-12 16:58:27 +00:00
//
// ErrorMessageView.swift
// Locations
//
// Created by Javier Cicchelli on 12/04/2023.
// Copyright © 2023 Röck+Cöde. All rights reserved.
//
import UIKit
class ErrorMessageView: UIView {
// MARK: Typealiases
typealias OnRetryClosure = () -> Void
// MARK: Properties
var onRetry: OnRetryClosure?
// MARK: Outlets
private lazy var stack: UIStackView = {
let stack = UIStackView()
stack.alignment = .center
stack.axis = .vertical
stack.distribution = .fill
stack.spacing = 32
stack.translatesAutoresizingMaskIntoConstraints = false
return stack
}()
private lazy var title = {
let label = UILabel()
label.font = .preferredFont(forTextStyle: .largeTitle)
label.numberOfLines = 0
label.lineBreakMode = .byWordWrapping
label.text = "Some error title goes in here..."
label.textAlignment = .center
label.translatesAutoresizingMaskIntoConstraints = false
return label
}()
private lazy var message = {
let label = UILabel()
label.font = .preferredFont(forTextStyle: .body)
label.lineBreakMode = .byWordWrapping
label.numberOfLines = 0
label.text = "Some long, descriptive, explanatory error message goes in here..."
label.textAlignment = .center
label.textColor = .secondaryLabel
label.translatesAutoresizingMaskIntoConstraints = false
return label
}()
private lazy var retry = {
let button = UIButton()
button.backgroundColor = .red
button.translatesAutoresizingMaskIntoConstraints = false
button.layer.borderColor = UIColor.red.cgColor
button.layer.borderWidth = 1
button.layer.cornerRadius = 5
button.titleLabel?.font = .preferredFont(forTextStyle: .headline)
button.addTarget(self, action: #selector(retryPressed), for: .touchUpInside)
button.setTitle("Try again", for: .normal)
return button
}()
// MARK: Initialisers
init() {
super.init(frame: .zero)
setupView()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
// MARK: - Helpers
private extension ErrorMessageView {
// MARK: Functions
func setupView() {
backgroundColor = .clear
translatesAutoresizingMaskIntoConstraints = false
addSubview(stack)
stack.addArrangedSubview(title)
stack.addArrangedSubview(message)
stack.addArrangedSubview(retry)
stack.setCustomSpacing(160, after: message)
NSLayoutConstraint.activate([
bottomAnchor.constraint(equalTo: stack.bottomAnchor),
leadingAnchor.constraint(equalTo: stack.leadingAnchor),
topAnchor.constraint(equalTo: stack.topAnchor),
trailingAnchor.constraint(equalTo: stack.trailingAnchor),
retry.heightAnchor.constraint(equalToConstant: 44),
retry.leadingAnchor.constraint(equalTo: stack.leadingAnchor),
retry.trailingAnchor.constraint(equalTo: stack.trailingAnchor),
])
}
@objc func retryPressed() {
onRetry?()
}
}