-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implementando a ActivityList e ActivityListCell 🔗 #79
Open
RickyMarq
wants to merge
1
commit into
devpass-tech:main
Choose a base branch
from
RickyMarq:feature_ActivityListView
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
solutions/devsprint-pedro-alvarez-2/FinanceApp/Extensions/ViewCodePipeline.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// ViewCodePipeline.swift | ||
// FinanceApp | ||
// | ||
// Created by Henrique Marques on 10/12/22. | ||
// | ||
|
||
import Foundation | ||
|
||
protocol ViewCodePipeline { | ||
func initView() | ||
func setupView() | ||
func configureSubviews() | ||
func configureSubviewsConstraints() | ||
|
||
} | ||
|
||
extension ViewCodePipeline { | ||
func initView() { | ||
setupView() | ||
configureSubviews() | ||
configureSubviewsConstraints() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,71 @@ | |
|
||
import UIKit | ||
|
||
class ActivityCellView { | ||
class ActivityCellView: UITableViewCell { | ||
|
||
static let identifier = "ActivityCellView" | ||
|
||
lazy var iconImageView: UIImageView = { | ||
let image = UIImage(named: "bag.circle.fill") | ||
let imageView = UIImageView(image: image) | ||
imageView.translatesAutoresizingMaskIntoConstraints = false | ||
imageView.frame.size = CGSize(width: 48, height: 48) | ||
return imageView | ||
}() | ||
|
||
lazy var storeLabel: UILabel = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Colocar como |
||
let label = UILabel() | ||
label.translatesAutoresizingMaskIntoConstraints = false | ||
label.textColor = .label | ||
return label | ||
}() | ||
|
||
lazy var valueLabel: UILabel = { | ||
let label = UILabel() | ||
label.translatesAutoresizingMaskIntoConstraints = false | ||
label.textColor = .secondaryLabel | ||
return label | ||
}() | ||
|
||
|
||
|
||
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { | ||
super.init(style: style, reuseIdentifier: reuseIdentifier) | ||
initView() | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
super.init(coder: coder) | ||
} | ||
} | ||
|
||
extension ActivityCellView: ViewCodePipeline { | ||
|
||
func setupView() { | ||
self.backgroundColor = .systemBackground | ||
} | ||
|
||
func configureSubviews() { | ||
self.addSubview(self.iconImageView) | ||
self.addSubview(self.storeLabel) | ||
self.addSubview(self.valueLabel) | ||
} | ||
|
||
func configureSubviewsConstraints() { | ||
NSLayoutConstraint.activate([ | ||
|
||
self.iconImageView.leftAnchor.constraint(equalTo: self.leftAnchor, constant: 15), | ||
self.iconImageView.heightAnchor.constraint(equalToConstant: 48), | ||
self.iconImageView.widthAnchor.constraint(equalToConstant: 48), | ||
self.iconImageView.centerYAnchor.constraint(equalTo: self.centerYAnchor), | ||
|
||
self.storeLabel.leftAnchor.constraint(equalTo: self.iconImageView.rightAnchor, constant: 10), | ||
self.storeLabel.centerYAnchor.constraint(equalTo: self.centerYAnchor, constant: -10), | ||
|
||
self.valueLabel.topAnchor.constraint(equalTo: self.storeLabel.bottomAnchor, constant: 2.5), | ||
self.valueLabel.leftAnchor.constraint(equalTo: self.storeLabel.leftAnchor), | ||
]) | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,18 +10,21 @@ import UIKit | |
class HomeViewController: UIViewController { | ||
|
||
private let service = FinanceService() | ||
|
||
|
||
var activityListView: ActivityListView? | ||
var ActivityData: [Activity] = [] | ||
|
||
private let homeView: HomeView = { | ||
|
||
let homeView = HomeView() | ||
return homeView | ||
}() | ||
|
||
override func viewDidLoad() { | ||
|
||
self.activityListView?.activityListTableViewProtocols(delegate: self, dataSource: self) | ||
navigationItem.title = "Finance App 💰" | ||
navigationController?.navigationBar.prefersLargeTitles = true | ||
|
||
self.fetchActivityData() | ||
service.fetchHomeData { homeData in | ||
|
||
guard let homeData = homeData else { | ||
|
@@ -36,8 +39,69 @@ class HomeViewController: UIViewController { | |
} | ||
} | ||
} | ||
|
||
func fetchActivityData() { | ||
service.fetchHomeData { data in | ||
guard let data = data else {return} | ||
self.ActivityData = data.activity | ||
DispatchQueue.main.async { | ||
self.activityListView?.activity.stopAnimating() | ||
self.activityListView?.activityListTableView.reloadData() | ||
} | ||
} | ||
} | ||
|
||
|
||
override func loadView() { | ||
self.view = homeView | ||
activityListView = ActivityListView() | ||
self.view = activityListView | ||
} | ||
} | ||
|
||
extension HomeViewController: UITableViewDelegate, UITableViewDataSource { | ||
|
||
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | ||
return ActivityData.count | ||
} | ||
|
||
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | ||
let cell: ActivityCellView? = tableView.dequeueReusableCell(withIdentifier: ActivityCellView.identifier, for: indexPath) as? ActivityCellView | ||
let index = ActivityData[indexPath.row] | ||
cell?.storeLabel.text = index.name | ||
cell?.valueLabel.text = "$\(index.price) • \(index.time)" | ||
|
||
if index.name == "Mall" { | ||
cell?.iconImageView.tintColor = .systemPurple | ||
cell?.iconImageView.image = UIImage(imageLiteralResourceName: "bag.circle.fill") | ||
} else if index.name == "Food Court" { | ||
cell?.iconImageView.tintColor = .systemCyan | ||
cell?.iconImageView.image = UIImage(imageLiteralResourceName: "fork.knife.circle.fill") | ||
} else if index.name == "Oceanic Airlines" { | ||
cell?.iconImageView.tintColor = .systemOrange | ||
cell?.iconImageView.image = UIImage(imageLiteralResourceName: "airplane.circle.fill") | ||
} else if index.name == "Gym Membership" { | ||
cell?.iconImageView.tintColor = .systemRed | ||
cell?.iconImageView.image = UIImage(imageLiteralResourceName: "heart.circle.fill") | ||
} else if index.name == "Private Transport" { | ||
cell?.iconImageView.tintColor = .systemGreen | ||
cell?.iconImageView.image = UIImage(imageLiteralResourceName: "car.circle.fill") | ||
} | ||
|
||
cell?.accessoryType = .disclosureIndicator | ||
return cell ?? UITableViewCell() | ||
} | ||
|
||
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { | ||
return "Activity" | ||
} | ||
|
||
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { | ||
tableView.deselectRow(at: indexPath, animated: true) | ||
} | ||
|
||
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { | ||
return 70 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nunca usem este método |
||
} | ||
|
||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
intrinsicContentSize