Skip to content

Commit d301f59

Browse files
committed
ActivityListView - still missing some configuration
1 parent da0c630 commit d301f59

File tree

2 files changed

+87
-22
lines changed

2 files changed

+87
-22
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
//
2+
// ActivityListView.swift
3+
// FinanceApp
4+
//
5+
// Created by Mauricio on 18/10/22.
6+
//
7+
8+
import UIKit
9+
10+
class ActivityListView: UIView {
11+
12+
private var activities: [Activity] = []
13+
14+
private lazy var tableView: UITableView = {
15+
let tableView = UITableView(frame: .zero)
16+
tableView.translatesAutoresizingMaskIntoConstraints = false
17+
tableView.register(ActivityCellView.self, forCellReuseIdentifier: ActivityCellView.reuseIdentifier)
18+
tableView.register(UITableViewCell.self, forCellReuseIdentifier: UITableViewCell.reuseIdentifier)
19+
20+
return tableView
21+
}()
22+
23+
override init(frame: CGRect) {
24+
super.init(frame: frame)
25+
self.configViews()
26+
self.buildHierarchy()
27+
self.setupConstraints()
28+
}
29+
30+
required init?(coder: NSCoder) {
31+
fatalError("init(coder:) has not been implemented")
32+
}
33+
34+
func updateTableView(with configuration: HomeViewConfiguration) {
35+
activities = configuration.homeData.activity
36+
tableView.reloadData()
37+
}
38+
39+
public func configTableViewProtocol(delegate: UITableViewDelegate, dataSource: UITableViewDataSource){
40+
self.tableView.delegate = delegate
41+
self.tableView.dataSource = dataSource
42+
}
43+
44+
}
45+
46+
extension ActivityListView: ViewCodable {
47+
func configViews (){
48+
backgroundColor = .white
49+
}
50+
51+
func buildHierarchy(){
52+
addSubview(tableView)
53+
}
54+
55+
func setupConstraints(){
56+
NSLayoutConstraint.activate([
57+
tableView.topAnchor.constraint(equalTo: self.topAnchor),
58+
tableView.leadingAnchor.constraint(equalTo: self.leadingAnchor),
59+
tableView.trailingAnchor.constraint(equalTo: self.trailingAnchor),
60+
tableView.bottomAnchor.constraint(equalTo: self.bottomAnchor)
61+
])
62+
}
63+
64+
}

solutions/devsprint-caio-santos-7/FinanceApp/Screens/Home/HomeView.swift

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,29 @@
77

88
import UIKit
99

10-
struct HomeViewConfiguration {
11-
let homeData: HomeData
12-
}
10+
struct HomeViewConfiguration {
11+
let homeData: HomeData
12+
}
1313

14-
final class HomeView: UIView {
1514
private var activities: [Activity] = []
1615

16+
final class HomeView: UIView{
17+
1718
private lazy var accountSummaryView: AccountSummaryView = {
1819
let element = AccountSummaryView()
1920
element.translatesAutoresizingMaskIntoConstraints = false
2021
return element
2122
}()
2223

23-
private lazy var tableView: UITableView = {
24-
let tableView = UITableView(frame: .zero)
25-
tableView.translatesAutoresizingMaskIntoConstraints = false
26-
tableView.register(ActivityCellView.self, forCellReuseIdentifier: ActivityCellView.reuseIdentifier)
27-
tableView.register(UITableViewCell.self, forCellReuseIdentifier: UITableViewCell.reuseIdentifier)
28-
tableView.dataSource = self
29-
return tableView
24+
private lazy var activityListView: ActivityListView = {
25+
let element = ActivityListView()
26+
element.translatesAutoresizingMaskIntoConstraints = false
27+
return element
3028
}()
31-
29+
3230
init() {
3331
super.init(frame: .zero)
32+
self.activityListView.configTableViewProtocol(delegate: self, dataSource: self)
3433
self.setupViews()
3534
}
3635

@@ -39,12 +38,12 @@ final class HomeView: UIView {
3938
}
4039

4140
func updateView(with configuration: HomeViewConfiguration) {
42-
activities = configuration.homeData.activity
4341
accountSummaryView.updateValues(balance: configuration.homeData.balance,
4442
savings: configuration.homeData.savings,
4543
spending: configuration.homeData.spending)
46-
tableView.reloadData()
44+
activityListView.updateTableView(with: configuration)
4745
}
46+
4847
}
4948

5049
private extension HomeView {
@@ -57,7 +56,7 @@ private extension HomeView {
5756

5857
func configureSubviews() {
5958
addSubview(accountSummaryView)
60-
addSubview(tableView)
59+
addSubview(activityListView)
6160
}
6261

6362
func configureSubviewsConstraints() {
@@ -66,15 +65,15 @@ private extension HomeView {
6665
accountSummaryView.leadingAnchor.constraint(equalTo: safeAreaLayoutGuide.leadingAnchor, constant: 16),
6766
accountSummaryView.trailingAnchor.constraint(equalTo: safeAreaLayoutGuide.trailingAnchor, constant: -16),
6867

69-
tableView.topAnchor.constraint(equalTo: accountSummaryView.bottomAnchor, constant: 16),
70-
tableView.leadingAnchor.constraint(equalTo: safeAreaLayoutGuide.leadingAnchor),
71-
tableView.trailingAnchor.constraint(equalTo: safeAreaLayoutGuide.trailingAnchor),
72-
tableView.bottomAnchor.constraint(equalTo: safeAreaLayoutGuide.bottomAnchor)
68+
activityListView.topAnchor.constraint(equalTo: accountSummaryView.bottomAnchor, constant: 16),
69+
activityListView.leadingAnchor.constraint(equalTo: safeAreaLayoutGuide.leadingAnchor),
70+
activityListView.trailingAnchor.constraint(equalTo: safeAreaLayoutGuide.trailingAnchor),
71+
activityListView.bottomAnchor.constraint(equalTo: safeAreaLayoutGuide.bottomAnchor)
7372
])
7473
}
7574
}
7675

77-
extension HomeView: UITableViewDataSource {
76+
extension HomeView: UITableViewDelegate, UITableViewDataSource {
7877
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
7978
return activities.count
8079
}
@@ -84,10 +83,12 @@ extension HomeView: UITableViewDataSource {
8483
indexPath.row < activities.count else {
8584
return .init()
8685
}
87-
88-
8986
cell.updateValues(activity: activities[indexPath.row])
9087
return cell
9188
}
89+
90+
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
91+
print("Função para disparar ação de toque na atividade")
92+
}
9293
}
9394

0 commit comments

Comments
 (0)