Skip to content
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
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -72,6 +73,7 @@

/* Begin PBXFileReference section */
1DBC0431294176F6000501FA /* TabBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabBarController.swift; sourceTree = "<group>"; };
1DFDAAE029453C5900EDA3A3 /* ViewCodePipeline.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewCodePipeline.swift; sourceTree = "<group>"; };
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 = "<group>"; };
98584A6E277E32C30028DBEA /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -348,6 +350,7 @@
children = (
98C8A4D827C8152200A630ED /* String+Extensions.swift */,
98C8A4DA27C815C000A630ED /* UITableViewCell+Extensions.swift */,
1DFDAAE029453C5900EDA3A3 /* ViewCodePipeline.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down
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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

intrinsicContentSize

return imageView
}()

lazy var storeLabel: UILabel = {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Colocar como private

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),
])
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -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),

])
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nunca usem este método

}


}