Skip to content

Commit 472a847

Browse files
committed
Adicionando userviewprofile
1 parent 9b59b25 commit 472a847

File tree

5 files changed

+289
-9
lines changed

5 files changed

+289
-9
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/UserProfileView.swift

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,111 @@
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)
27+
tableView.translatesAutoresizingMaskIntoConstraints = false
28+
tableView.register(UserProfileViewCell.self, forCellReuseIdentifier: UserProfileViewCell.identifier)
29+
tableView.register(UserProfileViewGeneralCell.self, forCellReuseIdentifier: UserProfileViewGeneralCell.identifier)
30+
return tableView
31+
}()
32+
33+
override init(frame: CGRect) {
34+
super.init(frame: frame)
35+
self.tableView.delegate = self
36+
self.tableView.dataSource = self
37+
self.configViews()
38+
self.buildHierarchy()
39+
self.setupConstraints()
40+
}
41+
42+
required init?(coder: NSCoder) {
43+
fatalError("init(coder:) has not been implemented")
44+
}
45+
}
46+
47+
extension UserProfileView: ViewCodable {
48+
49+
func configViews (){
50+
backgroundColor = .white
51+
}
52+
53+
func buildHierarchy(){
54+
addSubview(headerStackView)
55+
addSubview(tableView)
56+
}
57+
58+
func setupConstraints(){
59+
NSLayoutConstraint.activate([
60+
headerStackView.topAnchor.constraint(equalTo: topAnchor),
61+
headerStackView.leadingAnchor.constraint(equalTo: leadingAnchor),
62+
headerStackView.trailingAnchor.constraint(equalTo: trailingAnchor),
63+
64+
tableView.topAnchor.constraint(lessThanOrEqualTo: headerStackView.bottomAnchor, constant: 16),
65+
tableView.leadingAnchor.constraint(equalTo: leadingAnchor),
66+
tableView.trailingAnchor.constraint(equalTo: trailingAnchor),
67+
tableView.bottomAnchor.constraint(equalTo: bottomAnchor)
68+
])
69+
}
70+
}
1171

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

0 commit comments

Comments
 (0)