Skip to content

Commit 58692d3

Browse files
authored
Merge pull request #71 from viniciusbin/main
Adicionando userviewprofile
2 parents 9b59b25 + c089bfc commit 58692d3

File tree

7 files changed

+222
-10
lines changed

7 files changed

+222
-10
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ extension HomeView: UITableViewDataSource, UITableViewDelegate {
9797
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
9898
delegate?.showActivityDetails()
9999
print("touched")
100-
//delegate?.didSelectActivity()
100+
delegate?.didSelectActivity()
101101
}
102102

103103
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {

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

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,25 @@ class HomeViewController: UIViewController {
4646
}
4747

4848
private func profilePictureNavBar() {
49-
let profilePicture = UIView(frame: CGRect(x: 0, y: 0, width: 40, height: 40))
50-
let image = UIImageView(frame: CGRect(x: 0, y: 0, width: 40, height: 40))
51-
image.image = UIImage(named: "avatar-placeholder")
52-
image.contentMode = .scaleAspectFit
53-
image.layer.cornerRadius = 22.5
54-
image.layer.masksToBounds = true
55-
profilePicture.addSubview(image)
56-
let rightBarButton = UIBarButtonItem(customView: profilePicture)
49+
// let profilePicture = UIView(frame: CGRect(x: 0, y: 0, width: 40, height: 40))
50+
// let image = UIImageView(frame: CGRect(x: 0, y: 0, width: 40, height: 40))
51+
// image.image = UIImage(named: "avatar-placeholder")
52+
// image.contentMode = .scaleAspectFit
53+
// image.layer.cornerRadius = 22.5
54+
// image.layer.masksToBounds = true
55+
// profilePicture.addSubview(image)
56+
// let rightBarButton = UIBarButtonItem(customView: profilePicture)
57+
let rightBarButton = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector (showUserProfile))
5758
navigationItem.rightBarButtonItem = rightBarButton
59+
// rightBarButton.target = self
60+
// rightBarButton.action = #selector(showUserProfile)
5861
}
62+
63+
@objc func showUserProfile() {
64+
present(UserProfileViewController(), animated: true)
65+
print("clicado")
66+
}
67+
5968
}
6069

6170
extension HomeViewController: HomeViewDelegate {

solutions/devsprint-caio-santos-7/FinanceApp/Screens/UserProfile/UserProfileHeaderView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ final class UserProfileHeaderView: UIStackView {
6262

6363
override init(frame: CGRect) {
6464
super.init(frame: frame)
65-
backgroundColor = .systemGray5
65+
backgroundColor = .init(hexString: "#F2F2F7")
6666
setupView()
6767
}
6868

solutions/devsprint-caio-santos-7/FinanceApp/Screens/UserProfile/UserProfileView.swift

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,113 @@
88
import UIKit
99

1010
class UserProfileView: UIView {
11+
12+
var userData = ["Phone", "E-mail", "Address"]
13+
var userModel = ["+55(11)99999-9999", "user@devpass.com", "Rua Bela Cintra, 495"]
14+
var testModel = ["Personal data", "Bank account", "Taxes"]
15+
var generalModel = ["Need help?", "About Devpass"]
16+
var appModel = ["App Version"]
17+
var versionModel = ["1.0 (1)"]
18+
19+
private lazy var headerStackView: UserProfileHeaderView = {
20+
let stack = UserProfileHeaderView()
21+
stack.translatesAutoresizingMaskIntoConstraints = false
22+
return stack
23+
}()
24+
25+
private lazy var tableView: UITableView = {
26+
let tableView = UITableView(frame: .zero, style: .insetGrouped)
27+
tableView.translatesAutoresizingMaskIntoConstraints = false
28+
tableView.register(UserProfileViewCell.self, forCellReuseIdentifier: UserProfileViewCell.identifier)
29+
// tableView.register(UserProfileViewGeneralCell.self, forCellReuseIdentifier: UserProfileViewGeneralCell.identifier)
30+
tableView.register(UITableViewCell.self, forCellReuseIdentifier: UITableViewCell.reuseIdentifier)
31+
return tableView
32+
}()
33+
34+
override init(frame: CGRect) {
35+
super.init(frame: frame)
36+
self.tableView.delegate = self
37+
self.tableView.dataSource = self
38+
self.setupView()
39+
}
40+
41+
required init?(coder: NSCoder) {
42+
fatalError("init(coder:) has not been implemented")
43+
}
44+
}
45+
46+
extension UserProfileView: ViewCodable {
47+
48+
func buildHierarchy() {
49+
addSubview(headerStackView)
50+
addSubview(tableView)
51+
}
52+
53+
func setupConstraints() {
54+
NSLayoutConstraint.activate([
55+
headerStackView.topAnchor.constraint(equalTo: topAnchor, constant: 32),
56+
headerStackView.leadingAnchor.constraint(equalTo: leadingAnchor),
57+
headerStackView.trailingAnchor.constraint(equalTo: trailingAnchor),
58+
59+
tableView.topAnchor.constraint(lessThanOrEqualTo: headerStackView.bottomAnchor, constant: 8),
60+
tableView.leadingAnchor.constraint(equalTo: leadingAnchor),
61+
tableView.trailingAnchor.constraint(equalTo: trailingAnchor),
62+
tableView.bottomAnchor.constraint(equalTo: bottomAnchor)
63+
])
64+
}
65+
66+
func applyAdditionalChanges() {
67+
backgroundColor = .init(hexString: "#F2F2F7")
68+
}
69+
}
1170

71+
extension UserProfileView: UITableViewDelegate, UITableViewDataSource {
72+
73+
func numberOfSections(in tableView: UITableView) -> Int {
74+
return 2
75+
}
76+
77+
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
78+
if section == 0 {
79+
return "MY ACCOUNT"
80+
} else {
81+
return "GENERAL"
82+
}
83+
}
84+
85+
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
86+
if section == 0 {
87+
return userData.count + testModel.count
88+
} else {
89+
return generalModel.count + appModel.count
90+
}
91+
}
92+
93+
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
94+
if indexPath.section == 0 && indexPath.row < 3 {
95+
let cell = tableView.dequeueReusableCell(withIdentifier: UserProfileViewCell.identifier, for: indexPath) as! UserProfileViewCell
96+
cell.configure(leftLabel: userData[indexPath.row] , rightLabel: userModel[indexPath.row])
97+
return cell
98+
} else if indexPath.section == 0 && indexPath.row > 2 && indexPath.row < 6 {
99+
let buttonCell: UITableViewCell = .createCell(for: tableView, at: indexPath)!
100+
buttonCell.textLabel?.text = self.testModel[indexPath.row - 3]
101+
buttonCell.accessoryType = .disclosureIndicator
102+
return buttonCell
103+
} else if indexPath.section == 1 && indexPath.row < 2 {
104+
let buttonCell: UITableViewCell = .createCell(for: tableView, at: indexPath)!
105+
buttonCell.textLabel?.text = generalModel[indexPath.row]
106+
buttonCell.accessoryType = .disclosureIndicator
107+
return buttonCell
108+
} else {
109+
let versionCell = tableView.dequeueReusableCell(withIdentifier: UserProfileViewCell.identifier, for: indexPath) as! UserProfileViewCell
110+
versionCell.configure(leftLabel: appModel[indexPath.row - 2], rightLabel: versionModel[indexPath.row - 2])
111+
return versionCell
112+
}
113+
}
114+
115+
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
116+
// Chamar um método
117+
118+
tableView.deselectRow(at: indexPath, animated: false)
119+
}
12120
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
//
2+
// UserProfileViewCell.swift
3+
// FinanceApp
4+
//
5+
// Created by Vinicius on 20/10/22.
6+
//
7+
8+
import UIKit
9+
10+
class UserProfileViewCell: UITableViewCell {
11+
12+
static let identifier = "UserProfileViewCell"
13+
14+
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
15+
super.init(style: style, reuseIdentifier: reuseIdentifier)
16+
contentView.backgroundColor = .white
17+
setupView()
18+
}
19+
20+
required init?(coder: NSCoder) {
21+
fatalError("init(coder:) has not been implemented")
22+
}
23+
24+
override func layoutSubviews() {
25+
super.layoutSubviews()
26+
}
27+
28+
private lazy var leftLabel: UILabel = {
29+
let label = UILabel()
30+
label.translatesAutoresizingMaskIntoConstraints = false
31+
label.text = "Phone"
32+
label.font = .systemFont(ofSize: 16, weight: .semibold)
33+
label.numberOfLines = 0
34+
return label
35+
}()
36+
37+
private lazy var rightLabel: UILabel = {
38+
let label = UILabel()
39+
label.translatesAutoresizingMaskIntoConstraints = false
40+
label.text = "teste"
41+
label.font = .systemFont(ofSize: 14, weight: .regular)
42+
label.textColor = .lightGray
43+
44+
return label
45+
}()
46+
47+
48+
}
49+
50+
extension UserProfileViewCell: ViewCodable {
51+
52+
public func configure(leftLabel: String, rightLabel: String) {
53+
self.leftLabel.text = leftLabel
54+
self.rightLabel.text = rightLabel
55+
}
56+
57+
func buildHierarchy() {
58+
contentView.addSubview(leftLabel)
59+
contentView.addSubview(rightLabel)
60+
}
61+
62+
63+
func setupConstraints() {
64+
NSLayoutConstraint.activate([
65+
leftLabel.centerYAnchor.constraint(equalTo: contentView.centerYAnchor),
66+
leftLabel.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 16),
67+
leftLabel.heightAnchor.constraint(equalToConstant: 48),
68+
// leftLabel.widthAnchor.constraint(equalToConstant: 48),
69+
70+
rightLabel.centerYAnchor.constraint(equalTo: contentView.centerYAnchor),
71+
rightLabel.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -16),
72+
rightLabel.heightAnchor.constraint(equalToConstant: 48),
73+
// rightLabel.widthAnchor.constraint(equalToConstant: 48)
74+
])
75+
}
76+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// UserProfileViewTests.swift
3+
// FinanceAppTests
4+
//
5+
// Created by Caio Santos on 21/10/22.
6+
//
7+
@testable import FinanceApp
8+
import SnapshotTesting
9+
import XCTest
10+
11+
final class UserProfileViewTests: XCTestCase {
12+
13+
func testRenderView() {
14+
let component = UserProfileView()
15+
assertSnapshot(matching: component, as: .image(size: CGSize(width: UIScreen.main.bounds.width,
16+
height: UIScreen.main.bounds.height)))
17+
}
18+
19+
}
100 KB
Loading

0 commit comments

Comments
 (0)