Skip to content

Commit 373774e

Browse files
authored
Merge branch 'main' into main
2 parents 78fef3c + fcb0b99 commit 373774e

File tree

4 files changed

+213
-37
lines changed

4 files changed

+213
-37
lines changed

solutions/devsprint-vinicius-carvalho-3/DeliveryApp.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
/* Begin PBXBuildFile section */
1010
1E2324E328871F2F00414138 /* ViewCode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E2324E228871F2F00414138 /* ViewCode.swift */; };
1111
1E2324E5288720CA00414138 /* LoadingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E2324E4288720CA00414138 /* LoadingView.swift */; };
12+
1EAC8D92288A22E900A37973 /* AddressView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EAC8D91288A22E900A37973 /* AddressView.swift */; };
13+
8B113973288865DE00A42625 /* EmptyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8B113972288865DE00A42625 /* EmptyView.swift */; };
1214
98228D7D27BC489F006A38BB /* Address.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98228D7C27BC489F006A38BB /* Address.swift */; };
1315
98228D7F27BC490E006A38BB /* RestaurantDetails.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98228D7E27BC490E006A38BB /* RestaurantDetails.swift */; };
1416
983271C6272752B50010C63A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 983271C5272752B50010C63A /* Assets.xcassets */; };
@@ -50,6 +52,8 @@
5052
/* Begin PBXFileReference section */
5153
1E2324E228871F2F00414138 /* ViewCode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewCode.swift; sourceTree = "<group>"; };
5254
1E2324E4288720CA00414138 /* LoadingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingView.swift; sourceTree = "<group>"; };
55+
1EAC8D91288A22E900A37973 /* AddressView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddressView.swift; sourceTree = "<group>"; };
56+
8B113972288865DE00A42625 /* EmptyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyView.swift; sourceTree = "<group>"; };
5357
98228D7C27BC489F006A38BB /* Address.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Address.swift; sourceTree = "<group>"; };
5458
98228D7E27BC490E006A38BB /* RestaurantDetails.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RestaurantDetails.swift; sourceTree = "<group>"; };
5559
983271B9272752AF0010C63A /* DeliveryApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DeliveryApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -258,6 +262,8 @@
258262
98C4368027ADADC000D9048A /* SampleComponentView.swift */,
259263
1E2324E4288720CA00414138 /* LoadingView.swift */,
260264
BBEED0AE2889FFA500463533 /* MenuItemCell.swift */,
265+
1EAC8D91288A22E900A37973 /* AddressView.swift */,
266+
8B113972288865DE00A42625 /* EmptyView.swift */,
261267
);
262268
path = Components;
263269
sourceTree = "<group>";
@@ -384,7 +390,9 @@
384390
98AF573627ADB34C00339A66 /* DebugViewController.swift in Sources */,
385391
98AF572327ADB16E00339A66 /* SceneDelegate.swift in Sources */,
386392
98AF572427ADB16E00339A66 /* SampleComponentView.swift in Sources */,
393+
8B113973288865DE00A42625 /* EmptyView.swift in Sources */,
387394
98AF572527ADB16E00339A66 /* HomeViewController.swift in Sources */,
395+
1EAC8D92288A22E900A37973 /* AddressView.swift in Sources */,
388396
98AF572627ADB16E00339A66 /* HomeView.swift in Sources */,
389397
98AF572727ADB16E00339A66 /* AddressSearchViewController.swift in Sources */,
390398
98AF572827ADB16E00339A66 /* AddressListView.swift in Sources */,
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
//
2+
// AddressView.swift
3+
// DeliveryApp
4+
//
5+
// Created by Vitor Conceicao on 21/07/22.
6+
//
7+
8+
import UIKit
9+
10+
final class AddressView: UIView {
11+
private lazy var addressLabel: UILabel = {
12+
let addressLabel = UILabel()
13+
addressLabel.font = .boldSystemFont(ofSize: 15)
14+
return addressLabel
15+
}()
16+
17+
private lazy var editButton: UIButton = {
18+
let buttonVerticalPadding: CGFloat = 10.0
19+
let buttonHorizontalPadding: CGFloat = 16.0
20+
21+
let editButton = UIButton(configuration: .plain())
22+
editButton.configuration?.subtitle = "Editar"
23+
editButton.configuration?.background.strokeColor = .systemBlue
24+
editButton.configuration?.background.strokeWidth = 2.0
25+
editButton.configuration?.cornerStyle = .large
26+
editButton.configuration?.contentInsets = NSDirectionalEdgeInsets(top: buttonVerticalPadding,
27+
leading: buttonHorizontalPadding,
28+
bottom: buttonVerticalPadding,
29+
trailing: buttonHorizontalPadding)
30+
editButton.setContentHuggingPriority(.defaultHigh, for: .horizontal)
31+
return editButton
32+
}()
33+
34+
private lazy var horizontalStackView: UIStackView = {
35+
let horizontalStackView = UIStackView()
36+
horizontalStackView.axis = .horizontal
37+
horizontalStackView.spacing = spacing
38+
horizontalStackView.distribution = .fill
39+
horizontalStackView.alignment = .center
40+
horizontalStackView.translatesAutoresizingMaskIntoConstraints = false
41+
return horizontalStackView
42+
}()
43+
44+
// MARK: private properties
45+
46+
private let spacing: CGFloat = 16.0
47+
48+
// MARK: inits
49+
50+
convenience init() {
51+
self.init(frame: .zero)
52+
setup()
53+
}
54+
55+
// MARK: configuration
56+
57+
struct AddressViewConfiguration {
58+
let address: String
59+
}
60+
61+
// MARK: methods
62+
63+
func updateView(with configuration: AddressViewConfiguration) {
64+
addressLabel.text = configuration.address
65+
}
66+
}
67+
68+
extension AddressView: ViewCode {
69+
func setupSubviews() {
70+
horizontalStackView.addArrangedSubview(addressLabel)
71+
horizontalStackView.addArrangedSubview(editButton)
72+
73+
addSubview(horizontalStackView)
74+
}
75+
76+
func setupConstraints() {
77+
setupHorizontalStackViewConstraints()
78+
}
79+
80+
private func setupHorizontalStackViewConstraints() {
81+
NSLayoutConstraint.activate([
82+
horizontalStackView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: spacing),
83+
horizontalStackView.topAnchor.constraint(equalTo: topAnchor, constant: spacing),
84+
horizontalStackView.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -spacing)
85+
])
86+
}
87+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
//
2+
// EmptyView.swift
3+
// DeliveryApp
4+
//
5+
// Created by Raline Maria da Silva on 20/07/22.
6+
//
7+
8+
import UIKit
9+
10+
class EmptyView: UIView {
11+
12+
private lazy var titleLabel: UILabel = {
13+
let titleLabel = UILabel()
14+
titleLabel.text = "Endereço não encontrado"
15+
titleLabel.font = UIFont.systemFont(ofSize: 17, weight: .bold)
16+
17+
return titleLabel
18+
}()
19+
20+
private lazy var subtitleLabel: UILabel = {
21+
let subtitleLabel = UILabel()
22+
subtitleLabel.text = "Procure por ruas com número e bairro utilizando o campo de busca"
23+
subtitleLabel.numberOfLines = 0
24+
subtitleLabel.textAlignment = .center
25+
subtitleLabel.font = UIFont.systemFont(ofSize: 13, weight: .regular)
26+
subtitleLabel.textColor = UIColor(red: 0.322, green: 0.322, blue: 0.322, alpha: 1)
27+
28+
return subtitleLabel
29+
}()
30+
31+
private lazy var stackView: UIStackView = {
32+
let stack = UIStackView (arrangedSubviews: [titleLabel, subtitleLabel])
33+
stack.translatesAutoresizingMaskIntoConstraints = false
34+
stack.axis = .vertical
35+
stack.alignment = .center
36+
stack.distribution = .fillEqually
37+
stack.spacing = 10
38+
39+
return stack
40+
}()
41+
42+
override init(frame: CGRect) {
43+
super .init(frame: frame)
44+
setupSubviews()
45+
setupConstraints()
46+
setupExtraConfiguration()
47+
}
48+
49+
required init?(coder: NSCoder) {
50+
fatalError("init(coder:) has not been implemented")
51+
}
52+
53+
}
54+
55+
extension EmptyView: ViewCode {
56+
func setupSubviews() {
57+
addSubview(stackView)
58+
}
59+
60+
func setupConstraints() {
61+
let constraint = [
62+
stackView.centerXAnchor.constraint(equalTo: centerXAnchor),
63+
stackView.centerYAnchor.constraint(equalTo: centerYAnchor),
64+
stackView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 52),
65+
stackView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -52)
66+
67+
]
68+
constraint.forEach {(item) in
69+
item.isActive = true
70+
}
71+
}
72+
73+
func setupExtraConfiguration() {
74+
self.translatesAutoresizingMaskIntoConstraints = false
75+
}
76+
77+
}

solutions/devsprint-vinicius-carvalho-3/DeliveryApp/Screens/Home/HomeView.swift

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,72 +17,76 @@ final class HomeView: UIView {
1717
private let restaurantCellIdentifier = "RestaurantCellIdentifier"
1818

1919
private var restaurants: [Restaurant] = []
20+
21+
private lazy var addressView: AddressView = {
22+
let addressView = AddressView()
23+
addressView.updateView(with: .init(address: "R. Guiratinga, 500"))
24+
addressView.translatesAutoresizingMaskIntoConstraints = false
25+
return addressView
26+
}()
2027

2128
private lazy var tableView: UITableView = {
22-
2329
let tableView = UITableView(frame: .zero)
2430
tableView.translatesAutoresizingMaskIntoConstraints = false
25-
tableView.register(UITableViewCell.self, forCellReuseIdentifier: self.restaurantCellIdentifier)
31+
tableView.register(UITableViewCell.self, forCellReuseIdentifier: restaurantCellIdentifier)
2632
tableView.dataSource = self
2733
return tableView
2834
}()
2935

30-
init() {
31-
32-
super.init(frame: .zero)
33-
34-
self.setupViews()
35-
}
36-
37-
required init?(coder: NSCoder) {
38-
fatalError("init(coder:) has not been implemented")
36+
convenience init() {
37+
self.init(frame: .zero)
38+
setup()
3939
}
4040

4141
func updateView(with restaurants: [Restaurant]) {
42-
4342
self.restaurants = restaurants
44-
self.tableView.reloadData()
43+
tableView.reloadData()
4544
}
4645
}
4746

48-
private extension HomeView {
49-
50-
func setupViews() {
51-
52-
self.backgroundColor = .white
53-
54-
self.configureSubviews()
55-
self.configureSubviewsConstraints()
47+
extension HomeView: ViewCode {
48+
func setupSubviews() {
49+
addSubview(addressView)
50+
addSubview(tableView)
5651
}
57-
58-
func configureSubviews() {
59-
60-
self.addSubview(self.tableView)
52+
53+
func setupConstraints() {
54+
setupTableViewConstraints()
55+
setupAddressViewConstraints()
6156
}
62-
63-
func configureSubviewsConstraints() {
64-
57+
58+
func setupExtraConfiguration() {
59+
backgroundColor = .white
60+
}
61+
62+
private func setupTableViewConstraints() {
6563
NSLayoutConstraint.activate([
66-
67-
self.tableView.leadingAnchor.constraint(equalTo: self.safeAreaLayoutGuide.leadingAnchor),
68-
self.tableView.trailingAnchor.constraint(equalTo: self.safeAreaLayoutGuide.trailingAnchor),
69-
self.tableView.topAnchor.constraint(equalTo: self.safeAreaLayoutGuide.topAnchor),
70-
self.tableView.bottomAnchor.constraint(equalTo: self.safeAreaLayoutGuide.bottomAnchor)
64+
tableView.leadingAnchor.constraint(equalTo: safeAreaLayoutGuide.leadingAnchor),
65+
tableView.trailingAnchor.constraint(equalTo: safeAreaLayoutGuide.trailingAnchor),
66+
tableView.topAnchor.constraint(equalTo: addressView.bottomAnchor),
67+
tableView.bottomAnchor.constraint(equalTo: safeAreaLayoutGuide.bottomAnchor)
68+
])
69+
}
70+
71+
private func setupAddressViewConstraints() {
72+
NSLayoutConstraint.activate([
73+
addressView.leadingAnchor.constraint(equalTo: safeAreaLayoutGuide.leadingAnchor),
74+
addressView.trailingAnchor.constraint(equalTo: safeAreaLayoutGuide.trailingAnchor),
75+
addressView.topAnchor.constraint(equalTo: safeAreaLayoutGuide.topAnchor)
7176
])
7277
}
7378
}
7479

7580
extension HomeView: UITableViewDataSource {
7681

7782
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
78-
79-
return self.restaurants.count
83+
return restaurants.count
8084
}
8185

8286
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
8387

84-
let cell = tableView.dequeueReusableCell(withIdentifier: self.restaurantCellIdentifier)!
85-
cell.textLabel?.text = self.restaurants[indexPath.row].name
88+
let cell = tableView.dequeueReusableCell(withIdentifier: restaurantCellIdentifier)!
89+
cell.textLabel?.text = restaurants[indexPath.row].name
8690
return cell
8791
}
8892
}

0 commit comments

Comments
 (0)