From 3c734672a67b41d4bb156f3e47d8b3592f662349 Mon Sep 17 00:00:00 2001 From: Henrique Marques Date: Wed, 14 Dec 2022 17:24:20 -0300 Subject: [PATCH] Activity List desenvolvida --- .../FinanceApp.xcodeproj/project.pbxproj | 4 ++ .../Extensions/ViewCodePipeline.swift | 24 +++++++ .../Screens/Components/ActivityCellView.swift | 67 ++++++++++++++++- .../Screens/Components/ActivityListView.swift | 65 ++++++++++++++++- .../FinanceApp/Screens/Home/HomeView.swift | 1 + .../Screens/Home/HomeViewController.swift | 72 +++++++++++++++++-- 6 files changed, 227 insertions(+), 6 deletions(-) create mode 100644 solutions/devsprint-pedro-alvarez-2/FinanceApp/Extensions/ViewCodePipeline.swift diff --git a/solutions/devsprint-pedro-alvarez-2/FinanceApp.xcodeproj/project.pbxproj b/solutions/devsprint-pedro-alvarez-2/FinanceApp.xcodeproj/project.pbxproj index c80625f..8b7ff11 100644 --- a/solutions/devsprint-pedro-alvarez-2/FinanceApp.xcodeproj/project.pbxproj +++ b/solutions/devsprint-pedro-alvarez-2/FinanceApp.xcodeproj/project.pbxproj @@ -8,6 +8,7 @@ /* Begin PBXBuildFile section */ 1DBC0432294176F6000501FA /* TabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DBC0431294176F6000501FA /* TabBarController.swift */; }; + 1DFDAAE129453C5900EDA3A3 /* ViewCodePipeline.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DFDAAE029453C5900EDA3A3 /* ViewCodePipeline.swift */; }; 98584A6D277E32C30028DBEA /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98584A6C277E32C30028DBEA /* AppDelegate.swift */; }; 98584A6F277E32C30028DBEA /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98584A6E277E32C30028DBEA /* SceneDelegate.swift */; }; 98584A76277E32C50028DBEA /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 98584A75277E32C50028DBEA /* Assets.xcassets */; }; @@ -72,6 +73,7 @@ /* Begin PBXFileReference section */ 1DBC0431294176F6000501FA /* TabBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabBarController.swift; sourceTree = ""; }; + 1DFDAAE029453C5900EDA3A3 /* ViewCodePipeline.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewCodePipeline.swift; sourceTree = ""; }; 98584A69277E32C30028DBEA /* FinanceApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = FinanceApp.app; sourceTree = BUILT_PRODUCTS_DIR; }; 98584A6C277E32C30028DBEA /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 98584A6E277E32C30028DBEA /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; @@ -348,6 +350,7 @@ children = ( 98C8A4D827C8152200A630ED /* String+Extensions.swift */, 98C8A4DA27C815C000A630ED /* UITableViewCell+Extensions.swift */, + 1DFDAAE029453C5900EDA3A3 /* ViewCodePipeline.swift */, ); path = Extensions; sourceTree = ""; @@ -487,6 +490,7 @@ 98584B10277E605F0028DBEA /* ActivityDetailsViewController.swift in Sources */, 98584B20277E60740028DBEA /* ContactListViewController.swift in Sources */, 98584AF4277E50430028DBEA /* ConfirmationViewController.swift in Sources */, + 1DFDAAE129453C5900EDA3A3 /* ViewCodePipeline.swift in Sources */, 98C8A4DD27C818A800A630ED /* HomeData.swift in Sources */, 98C8A4D927C8152200A630ED /* String+Extensions.swift in Sources */, 98C8A4E727C81A9C00A630ED /* UserProfile.swift in Sources */, diff --git a/solutions/devsprint-pedro-alvarez-2/FinanceApp/Extensions/ViewCodePipeline.swift b/solutions/devsprint-pedro-alvarez-2/FinanceApp/Extensions/ViewCodePipeline.swift new file mode 100644 index 0000000..8960155 --- /dev/null +++ b/solutions/devsprint-pedro-alvarez-2/FinanceApp/Extensions/ViewCodePipeline.swift @@ -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() + } +} diff --git a/solutions/devsprint-pedro-alvarez-2/FinanceApp/Screens/Components/ActivityCellView.swift b/solutions/devsprint-pedro-alvarez-2/FinanceApp/Screens/Components/ActivityCellView.swift index 59f55fd..20250a8 100644 --- a/solutions/devsprint-pedro-alvarez-2/FinanceApp/Screens/Components/ActivityCellView.swift +++ b/solutions/devsprint-pedro-alvarez-2/FinanceApp/Screens/Components/ActivityCellView.swift @@ -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 = { + 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), + ]) + } + } diff --git a/solutions/devsprint-pedro-alvarez-2/FinanceApp/Screens/Components/ActivityListView.swift b/solutions/devsprint-pedro-alvarez-2/FinanceApp/Screens/Components/ActivityListView.swift index 56872a3..27def84 100644 --- a/solutions/devsprint-pedro-alvarez-2/FinanceApp/Screens/Components/ActivityListView.swift +++ b/solutions/devsprint-pedro-alvarez-2/FinanceApp/Screens/Components/ActivityListView.swift @@ -5,8 +5,71 @@ // Created by Rodrigo Soares on 01/12/22. // +import Foundation import UIKit -class ActivityListView { +class ActivityListView: UIView { + + lazy var activityListTableView: UITableView = { + let tableView = UITableView() + tableView.translatesAutoresizingMaskIntoConstraints = false + tableView.backgroundColor = .systemBackground + tableView.separatorStyle = .none + tableView.backgroundView = activity + tableView.register(ActivityCellView.self, forCellReuseIdentifier: ActivityCellView.identifier) + return tableView + }() + + lazy var activity: UIActivityIndicatorView = { + let activity = UIActivityIndicatorView() + activity.translatesAutoresizingMaskIntoConstraints = false + activity.style = UIActivityIndicatorView.Style.large + activity.startAnimating() + // activity.hidesWhenStopped = true + return activity + }() + + public func activityListTableViewProtocols(delegate: UITableViewDelegate, dataSource: UITableViewDataSource) { + self.activityListTableView.delegate = delegate + self.activityListTableView.dataSource = dataSource + } + + override init(frame: CGRect) { + super.init(frame: frame) + initView() + } + + required init?(coder: NSCoder) { + super.init(coder: coder) + } +} + + +extension ActivityListView: ViewCodePipeline { + + func setupView() { + self.backgroundColor = .systemBackground + } + + func configureSubviews() { + self.addSubview(self.activityListTableView) + self.addSubview(self.activity) + } + + func configureSubviewsConstraints() { + NSLayoutConstraint.activate([ + + + self.activityListTableView.topAnchor.constraint(equalTo: self.topAnchor), + self.activityListTableView.leadingAnchor.constraint(equalTo: self.leadingAnchor), + self.activityListTableView.trailingAnchor.constraint(equalTo: self.trailingAnchor), + self.activityListTableView.bottomAnchor.constraint(equalTo: self.safeAreaLayoutGuide.bottomAnchor), + + self.activity.centerXAnchor.constraint(equalTo: self.centerXAnchor), + self.activity.centerYAnchor.constraint(equalTo: self.centerYAnchor), + + ]) + } + } diff --git a/solutions/devsprint-pedro-alvarez-2/FinanceApp/Screens/Home/HomeView.swift b/solutions/devsprint-pedro-alvarez-2/FinanceApp/Screens/Home/HomeView.swift index 082b639..170b7a3 100644 --- a/solutions/devsprint-pedro-alvarez-2/FinanceApp/Screens/Home/HomeView.swift +++ b/solutions/devsprint-pedro-alvarez-2/FinanceApp/Screens/Home/HomeView.swift @@ -23,6 +23,7 @@ final class HomeView: UIView { let tableView = UITableView(frame: .zero) tableView.translatesAutoresizingMaskIntoConstraints = false tableView.register(UITableViewCell.self, forCellReuseIdentifier: self.listViewCellIdentifier) + tableView.backgroundColor = .systemBackground tableView.dataSource = self return tableView }() diff --git a/solutions/devsprint-pedro-alvarez-2/FinanceApp/Screens/Home/HomeViewController.swift b/solutions/devsprint-pedro-alvarez-2/FinanceApp/Screens/Home/HomeViewController.swift index add9766..e42cebe 100644 --- a/solutions/devsprint-pedro-alvarez-2/FinanceApp/Screens/Home/HomeViewController.swift +++ b/solutions/devsprint-pedro-alvarez-2/FinanceApp/Screens/Home/HomeViewController.swift @@ -10,7 +10,10 @@ import UIKit class HomeViewController: UIViewController { private let service = FinanceService() - + + var activityListView: ActivityListView? + var ActivityData: [Activity] = [] + private let homeView: HomeView = { let homeView = HomeView() @@ -18,10 +21,10 @@ class HomeViewController: UIViewController { }() 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 } + + }