diff --git a/solutions/devsprint-ana-nogal-1/DeliveryApp.xcodeproj/project.pbxproj b/solutions/devsprint-ana-nogal-1/DeliveryApp.xcodeproj/project.pbxproj index bbff387..6530ba7 100644 --- a/solutions/devsprint-ana-nogal-1/DeliveryApp.xcodeproj/project.pbxproj +++ b/solutions/devsprint-ana-nogal-1/DeliveryApp.xcodeproj/project.pbxproj @@ -8,11 +8,14 @@ /* Begin PBXBuildFile section */ 870B56F8281993AE00A4D17A /* AddressCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 870B56F7281993AE00A4D17A /* AddressCell.swift */; }; - 873B6EEA2820715A003B4088 /* MenuItemCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 873B6EE92820715A003B4088 /* MenuItemCell.swift */; }; 87148A0228215E2B0058F5D2 /* Address.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87148A0128215E2B0058F5D2 /* Address.swift */; }; + 8734CB9F2822AAD400A38B61 /* CategoryCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8734CB9E2822AAD400A38B61 /* CategoryCell.swift */; }; + 8734CBA12822AF6700A38B61 /* CategoryListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8734CBA02822AF6700A38B61 /* CategoryListView.swift */; }; 873B6EE828205E3C003B4088 /* EmptyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 873B6EE728205E3C003B4088 /* EmptyView.swift */; }; + 873B6EEA2820715A003B4088 /* MenuItemCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 873B6EE92820715A003B4088 /* MenuItemCell.swift */; }; 877B5B2E28186170002C0B95 /* LoadingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 877B5B2D28186170002C0B95 /* LoadingView.swift */; }; 877B5B3328186467002C0B95 /* ViewConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 877B5B3228186467002C0B95 /* ViewConfiguration.swift */; }; + 87EA105D2822E486008B4116 /* Category.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87EA105C2822E486008B4116 /* Category.swift */; }; 87FACFE62819B3A500CDA67E /* RestaurantCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87FACFE52819B3A500CDA67E /* RestaurantCell.swift */; }; 983271C6272752B50010C63A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 983271C5272752B50010C63A /* Assets.xcassets */; }; 983271C9272752B50010C63A /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 983271C7272752B50010C63A /* LaunchScreen.storyboard */; }; @@ -50,11 +53,14 @@ /* Begin PBXFileReference section */ 870B56F7281993AE00A4D17A /* AddressCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddressCell.swift; sourceTree = ""; }; - 873B6EE92820715A003B4088 /* MenuItemCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuItemCell.swift; sourceTree = ""; }; 87148A0128215E2B0058F5D2 /* Address.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Address.swift; sourceTree = ""; }; + 8734CB9E2822AAD400A38B61 /* CategoryCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CategoryCell.swift; sourceTree = ""; }; + 8734CBA02822AF6700A38B61 /* CategoryListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CategoryListView.swift; sourceTree = ""; }; 873B6EE728205E3C003B4088 /* EmptyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyView.swift; sourceTree = ""; }; + 873B6EE92820715A003B4088 /* MenuItemCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuItemCell.swift; sourceTree = ""; }; 877B5B2D28186170002C0B95 /* LoadingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingView.swift; sourceTree = ""; }; 877B5B3228186467002C0B95 /* ViewConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewConfiguration.swift; sourceTree = ""; }; + 87EA105C2822E486008B4116 /* Category.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Category.swift; sourceTree = ""; }; 87FACFE52819B3A500CDA67E /* RestaurantCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RestaurantCell.swift; sourceTree = ""; }; 983271B9272752AF0010C63A /* DeliveryApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DeliveryApp.app; sourceTree = BUILT_PRODUCTS_DIR; }; 983271BC272752AF0010C63A /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; @@ -213,6 +219,7 @@ isa = PBXGroup; children = ( 98C4368627ADAEA500D9048A /* Restaurant.swift */, + 87EA105C2822E486008B4116 /* Category.swift */, 87148A0128215E2B0058F5D2 /* Address.swift */, ); path = Models; @@ -276,6 +283,8 @@ 98C4368027ADADC000D9048A /* SampleComponentView.swift */, 87FACFE52819B3A500CDA67E /* RestaurantCell.swift */, 870B56F7281993AE00A4D17A /* AddressCell.swift */, + 8734CB9E2822AAD400A38B61 /* CategoryCell.swift */, + 8734CBA02822AF6700A38B61 /* CategoryListView.swift */, ); path = Components; sourceTree = ""; @@ -403,6 +412,7 @@ 98AF572227ADB16E00339A66 /* AppDelegate.swift in Sources */, 98AF573627ADB34C00339A66 /* DebugViewController.swift in Sources */, 98AF572327ADB16E00339A66 /* SceneDelegate.swift in Sources */, + 8734CB9F2822AAD400A38B61 /* CategoryCell.swift in Sources */, 98AF572427ADB16E00339A66 /* SampleComponentView.swift in Sources */, 873B6EE828205E3C003B4088 /* EmptyView.swift in Sources */, 98AF572527ADB16E00339A66 /* HomeViewController.swift in Sources */, @@ -418,12 +428,14 @@ 98AF572C27ADB16E00339A66 /* RestaurantDetailsView.swift in Sources */, 873B6EEA2820715A003B4088 /* MenuItemCell.swift in Sources */, 98AF572D27ADB16E00339A66 /* MenuItemViewController.swift in Sources */, + 8734CBA12822AF6700A38B61 /* CategoryListView.swift in Sources */, 877B5B2E28186170002C0B95 /* LoadingView.swift in Sources */, 98AF572E27ADB16E00339A66 /* MenuItemView.swift in Sources */, 98AF572F27ADB16E00339A66 /* SettingsViewController.swift in Sources */, 98AF573027ADB16E00339A66 /* SettingsView.swift in Sources */, 98AF573127ADB16E00339A66 /* DeliveryApi.swift in Sources */, 98AF573227ADB16E00339A66 /* Restaurant.swift in Sources */, + 87EA105D2822E486008B4116 /* Category.swift in Sources */, 98AF573327ADB16E00339A66 /* String+Extensions.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/solutions/devsprint-ana-nogal-1/DeliveryApp/Models/Category.swift b/solutions/devsprint-ana-nogal-1/DeliveryApp/Models/Category.swift new file mode 100644 index 0000000..79c91bb --- /dev/null +++ b/solutions/devsprint-ana-nogal-1/DeliveryApp/Models/Category.swift @@ -0,0 +1,13 @@ +// +// Category.swift +// DeliveryApp +// +// Created by Anderson Oliveira on 04/05/22. +// + +import Foundation + +struct Category: Decodable { + let categoryName: String + let categoryImageLabel: String +} diff --git a/solutions/devsprint-ana-nogal-1/DeliveryApp/Screens/Components/AddressCell.swift b/solutions/devsprint-ana-nogal-1/DeliveryApp/Screens/Components/AddressCell.swift index 38c35a1..8ae09b0 100644 --- a/solutions/devsprint-ana-nogal-1/DeliveryApp/Screens/Components/AddressCell.swift +++ b/solutions/devsprint-ana-nogal-1/DeliveryApp/Screens/Components/AddressCell.swift @@ -2,7 +2,7 @@ // AddressCell.swift // DeliveryApp // -// Created by Cora on 27/04/22. +// Created by Anderson Oliveira on 27/04/22. // import UIKit diff --git a/solutions/devsprint-ana-nogal-1/DeliveryApp/Screens/Components/CategoryCell.swift b/solutions/devsprint-ana-nogal-1/DeliveryApp/Screens/Components/CategoryCell.swift new file mode 100644 index 0000000..622e16d --- /dev/null +++ b/solutions/devsprint-ana-nogal-1/DeliveryApp/Screens/Components/CategoryCell.swift @@ -0,0 +1,75 @@ +// +// CategoryCell.swift +// DeliveryApp +// +// Created by Anderson Oliveira on 04/05/22. +// + +import Foundation +import UIKit + +class CategoryCell: UICollectionViewCell, ViewConfiguration { + + static var identifier = "CategoryCell" + + private lazy var categoryStackView: UIStackView = { + let stackView = UIStackView() + stackView.spacing = 10 + stackView.axis = .vertical + stackView.distribution = .equalSpacing + return stackView + }() + + lazy var categoryImage: UIImageView = { + let catImage = UIImageView() + catImage.layer.masksToBounds = true + catImage.layer.cornerRadius = 14 + return catImage + }() + + lazy var categoryLabel: UILabel = { + let catLabel = UILabel() + catLabel.textAlignment = .center + catLabel.font = .systemFont(ofSize: 12) + catLabel.textColor = UIColor(red: 0.235, green: 0.235, blue: 0.263, alpha: 0.6) + return catLabel + }() + + override init(frame: CGRect){ + super.init(frame: frame) + setupViews() + } + @available(*, unavailable) + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + func updateCell(imageName: String, category: String){ + categoryImage.image = UIImage(named: imageName) + categoryLabel.text = category + } + + func configViews() { } + + func buildViews() { + [categoryImage,categoryLabel].forEach(addSubview) + } + + func setupConstraints() { + [categoryStackView,categoryLabel,categoryImage].forEach { + $0.translatesAutoresizingMaskIntoConstraints = false + } + NSLayoutConstraint.activate([ + categoryImage.topAnchor.constraint(equalTo: topAnchor), + categoryImage.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 2.5), + categoryImage.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -2.5), + + categoryLabel.topAnchor.constraint(equalTo: categoryImage.bottomAnchor, constant: 10), + categoryLabel.leadingAnchor.constraint(equalTo: leadingAnchor), + categoryLabel.trailingAnchor.constraint(equalTo: trailingAnchor), + categoryLabel.bottomAnchor.constraint(equalTo: bottomAnchor), + + categoryImage.heightAnchor.constraint(equalToConstant: 54), + ]) + } +} diff --git a/solutions/devsprint-ana-nogal-1/DeliveryApp/Screens/Components/CategoryListView.swift b/solutions/devsprint-ana-nogal-1/DeliveryApp/Screens/Components/CategoryListView.swift new file mode 100644 index 0000000..ca9b494 --- /dev/null +++ b/solutions/devsprint-ana-nogal-1/DeliveryApp/Screens/Components/CategoryListView.swift @@ -0,0 +1,77 @@ +// +// CollectionView.swift +// DeliveryApp +// +// Created by Anderson Oliveira on 04/05/22. +// + +import Foundation + + + +import UIKit + +final class CategoryListView: UIView, ViewConfiguration { + + private var categories: [Category] + + private lazy var collectionView: UICollectionView = { + let layout = UICollectionViewFlowLayout() + layout.scrollDirection = .horizontal + layout.itemSize = CGSize(width: 64, height: 80) + layout.sectionInset = UIEdgeInsets(top: 21.5, left: 18, bottom: 21.5, right: 18) + let collection = UICollectionView(frame: .zero, collectionViewLayout: layout) + collection.register(CategoryCell.self, forCellWithReuseIdentifier: CategoryCell.identifier) + collection.translatesAutoresizingMaskIntoConstraints = false + return collection + }() + + + init(categories: [Category]) { + self.categories = categories + super.init(frame: .zero) + collectionView.delegate = self + collectionView.dataSource = self + setupViews() + } + + @available(*, unavailable) + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + func configViews() { + backgroundColor = .white + } + + func buildViews() { + [collectionView].forEach(addSubview) + } + + func setupConstraints() { + NSLayoutConstraint.activate([ + collectionView.topAnchor.constraint(equalTo: topAnchor), + collectionView.leadingAnchor.constraint(equalTo: leadingAnchor), + collectionView.trailingAnchor.constraint(equalTo: trailingAnchor), + collectionView.bottomAnchor.constraint(equalTo: bottomAnchor), + ]) + } +} +extension CategoryListView: UICollectionViewDataSource { + + func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + return categories.count + } + + func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + let category = categories[indexPath.row] + let cell = collectionView.dequeueReusableCell(withReuseIdentifier: CategoryCell.identifier, for: indexPath) as! CategoryCell + + cell.updateCell(imageName: category.categoryImageLabel, category: category.categoryName) + return cell + } +} + +extension CategoryListView: UICollectionViewDelegate { + +}