Skip to content

Commit

Permalink
GH-30 Create base UICollectionView
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronan Nunes committed Oct 8, 2019
1 parent f31e3eb commit 8e25ec6
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 17 deletions.
51 changes: 51 additions & 0 deletions iOS/Sources/ListFood/ListFoodCollectionViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// ListFoodCollectionViewController.swift
// iOS
//
// Created by Ronan Nunes on 08/10/19.
// Copyright © 2019 Ronan Nunes. All rights reserved.
//

import UIKit

private let reuseIdentifier = "Cell"

class ListFoodCollectionViewController: UICollectionViewController {

private var cellIdentifier: String = String(describing: ListFoodCollectionViewController.self) + "Cell"
private let sectionInsets = UIEdgeInsets(top: 50.0, left: 20.0, bottom: 50.0, right: 20.0)
private var viewModel = ListFoodViewModel.empty
private var groupedFoodViewModels: [GroupedFoodViewModel] { return viewModel.groupedFoodViewModels }
@IBOutlet var dependency: ListFoodViewControllerDependency! {
didSet {
dependency.presenter.bindable = self
dependency.interactor.list()
}
}

override func numberOfSections(in collectionView: UICollectionView) -> Int {
return groupedFoodViewModels.count
}

override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
let group = groupedFoodViewModels[section]
return group.foods.count
}

override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellIdentifier, for: indexPath)
cell.backgroundColor = .orange
return cell
}
}

extension ListFoodCollectionViewController: ListFoodTableViewControllerBind {
func bind(viewModel: ListFoodViewModel) {
self.viewModel = viewModel
title = viewModel.title
collectionView.reloadData()
}

func bind(errorViewModel: ListFoodErrorViewModel) {
}
}
62 changes: 51 additions & 11 deletions iOS/Sources/ListFood/ListFoodStoryboard.storyboard
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14865.1" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="Jnn-f8-rtA">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="m4n-IW-w6j">
<device id="retina6_1" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14819.2"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.49"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand All @@ -12,20 +14,20 @@
<scene sceneID="7dt-FR-KW9">
<objects>
<tableViewController id="Jnn-f8-rtA" customClass="ListFoodTableViewController" customModule="SensazonaliOS" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="insetGrouped" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="18" sectionFooterHeight="18" id="sWP-Mu-iJB">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="18" sectionFooterHeight="18" id="sWP-Mu-iJB">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" systemColor="tertiarySystemGroupedBackgroundColor" red="0.94901960780000005" green="0.94901960780000005" blue="0.96862745100000003" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="backgroundColor" red="0.94901960780000005" green="0.94901960780000005" blue="0.96862745100000003" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="ListFoodTableViewController" textLabel="4ee-Yr-fUQ" style="IBUITableViewCellStyleDefault" id="dZi-sn-RG9">
<rect key="frame" x="20" y="55.5" width="374" height="43.5"/>
<rect key="frame" x="0.0" y="18" width="414" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="dZi-sn-RG9" id="bwP-di-Akb">
<rect key="frame" x="0.0" y="0.0" width="374" height="43.5"/>
<rect key="frame" x="0.0" y="0.0" width="414" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="4ee-Yr-fUQ">
<rect key="frame" x="20" y="0.0" width="334" height="43.5"/>
<rect key="frame" x="20" y="0.0" width="374" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
Expand All @@ -49,18 +51,56 @@
</connections>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="gXQ-BZ-TFt" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
<customObject id="MRi-N7-55a" customClass="ListFoodTableViewControllerDependency" customModule="SensazonaliOS" customModuleProvider="target"/>
<customObject id="MRi-N7-55a" customClass="ListFoodViewControllerDependency" customModule="SensazonaliOS" customModuleProvider="target"/>
</objects>
<point key="canvasLocation" x="2523.1884057971015" y="-50.223214285714285"/>
</scene>
<!--List Food Collection View Controller-->
<scene sceneID="ECt-mi-Qub">
<objects>
<collectionViewController id="m4n-IW-w6j" customClass="ListFoodCollectionViewController" customModule="SensazonaliOS" customModuleProvider="target" sceneMemberID="viewController">
<collectionView key="view" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" dataMode="prototypes" id="WpK-sd-8Zv">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<collectionViewFlowLayout key="collectionViewLayout" minimumLineSpacing="10" minimumInteritemSpacing="10" id="eN5-Kc-fb9">
<size key="itemSize" width="50" height="50"/>
<size key="headerReferenceSize" width="0.0" height="0.0"/>
<size key="footerReferenceSize" width="0.0" height="0.0"/>
<inset key="sectionInset" minX="0.0" minY="0.0" maxX="0.0" maxY="0.0"/>
</collectionViewFlowLayout>
<cells>
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="ListFoodCollectionViewControllerCell" id="uVa-ft-Ij4">
<rect key="frame" x="0.0" y="0.0" width="50" height="50"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO">
<rect key="frame" x="0.0" y="0.0" width="50" height="50"/>
<autoresizingMask key="autoresizingMask"/>
</view>
</collectionViewCell>
</cells>
<connections>
<outlet property="dataSource" destination="m4n-IW-w6j" id="CmW-u7-iHh"/>
<outlet property="delegate" destination="m4n-IW-w6j" id="QG1-Xo-Hw8"/>
</connections>
</collectionView>
<connections>
<outlet property="dependency" destination="Ubx-0I-yEn" id="bsP-yM-Toy"/>
</connections>
</collectionViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="lx2-CE-zsk" userLabel="First Responder" sceneMemberID="firstResponder"/>
<customObject id="Ubx-0I-yEn" customClass="ListFoodViewControllerDependency" customModule="SensazonaliOS" customModuleProvider="target"/>
</objects>
<point key="canvasLocation" x="2523" y="655"/>
</scene>
<!--Food Detail View Controller-->
<scene sceneID="Kcv-7m-Zgm">
<objects>
<viewController id="Opr-No-0A1" customClass="FoodDetailViewController" customModule="SensazonaliOS" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="2g4-6s-ucY">
<rect key="frame" x="0.0" y="0.0" width="414" height="842"/>
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<viewLayoutGuide key="safeArea" id="eF8-Ph-eiK"/>
</view>
<navigationItem key="navigationItem" id="tpg-oP-5GW"/>
Expand Down
2 changes: 1 addition & 1 deletion iOS/Sources/ListFood/ListFoodTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ protocol ListFoodTableViewControllerBind: AnyObject {

class ListFoodTableViewController: UITableViewController {

@IBOutlet var dependency: ListFoodTableViewControllerDependency! {
@IBOutlet var dependency: ListFoodViewControllerDependency! {
didSet {
dependency.presenter.bindable = self
dependency.interactor.list()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Core
import Foundation
import Share

class ListFoodTableViewControllerDependency: NSObject {
class ListFoodViewControllerDependency: NSObject {

let presenter = ListFoodPresenterViewController()
lazy var interactor = ListFoodInteractorFactory.make(presenter: presenter)
Expand Down
12 changes: 8 additions & 4 deletions iOS/iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
342F26C22327735800241D1F /* FoodDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 342F26C12327735800241D1F /* FoodDetailViewController.swift */; };
342F26C423277C4700241D1F /* PrepareSegueFoodDetail.swift in Sources */ = {isa = PBXBuildFile; fileRef = 342F26C323277C4700241D1F /* PrepareSegueFoodDetail.swift */; };
34515F48234C9B4F00950292 /* ListFoodCollectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34515F47234C9B4F00950292 /* ListFoodCollectionViewController.swift */; };
345B0FD62325470400D1C722 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 345B0FD52325470400D1C722 /* AppDelegate.swift */; };
345B0FDD2325470400D1C722 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 345B0FDB2325470400D1C722 /* Main.storyboard */; };
345B0FDF2325470500D1C722 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 345B0FDE2325470500D1C722 /* Assets.xcassets */; };
Expand All @@ -22,7 +23,7 @@
345B0FFD2325564A00D1C722 /* ListFoodPresenterViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 345B0FFC2325564A00D1C722 /* ListFoodPresenterViewController.swift */; };
345B0FFF2325567200D1C722 /* ListFoodViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 345B0FFE2325567200D1C722 /* ListFoodViewModel.swift */; };
345B10012325579A00D1C722 /* ListFoodErrorViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 345B10002325579A00D1C722 /* ListFoodErrorViewModel.swift */; };
3490D66E23263A2100F9146E /* ListFoodTableViewControllerDependency.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3490D66D23263A2100F9146E /* ListFoodTableViewControllerDependency.swift */; };
3490D66E23263A2100F9146E /* ListFoodViewControllerDependency.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3490D66D23263A2100F9146E /* ListFoodViewControllerDependency.swift */; };
34B5622623260CDF00F83D42 /* AutoMock.generated.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34B5622523260CDE00F83D42 /* AutoMock.generated.swift */; };
34B5622C23260E9900F83D42 /* Locale.strings in Resources */ = {isa = PBXBuildFile; fileRef = 34B5622A23260E9900F83D42 /* Locale.strings */; };
34B5622F2326101300F83D42 /* Locale.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34B5622E2326101300F83D42 /* Locale.swift */; };
Expand Down Expand Up @@ -57,6 +58,7 @@
/* Begin PBXFileReference section */
342F26C12327735800241D1F /* FoodDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FoodDetailViewController.swift; sourceTree = "<group>"; };
342F26C323277C4700241D1F /* PrepareSegueFoodDetail.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrepareSegueFoodDetail.swift; sourceTree = "<group>"; };
34515F47234C9B4F00950292 /* ListFoodCollectionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListFoodCollectionViewController.swift; sourceTree = "<group>"; };
345B0FD22325470400D1C722 /* Sensazonal.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Sensazonal.app; sourceTree = BUILT_PRODUCTS_DIR; };
345B0FD52325470400D1C722 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
345B0FDC2325470400D1C722 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
Expand All @@ -71,7 +73,7 @@
345B0FFC2325564A00D1C722 /* ListFoodPresenterViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListFoodPresenterViewController.swift; sourceTree = "<group>"; };
345B0FFE2325567200D1C722 /* ListFoodViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListFoodViewModel.swift; sourceTree = "<group>"; };
345B10002325579A00D1C722 /* ListFoodErrorViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListFoodErrorViewModel.swift; sourceTree = "<group>"; };
3490D66D23263A2100F9146E /* ListFoodTableViewControllerDependency.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListFoodTableViewControllerDependency.swift; sourceTree = "<group>"; };
3490D66D23263A2100F9146E /* ListFoodViewControllerDependency.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListFoodViewControllerDependency.swift; sourceTree = "<group>"; };
34B5621A23260C8500F83D42 /* iOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = iOSTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
34B5621E23260C8500F83D42 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
34B5622523260CDE00F83D42 /* AutoMock.generated.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AutoMock.generated.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -146,9 +148,10 @@
345B0FF923254F3200D1C722 /* ListFoodStoryboard.storyboard */,
345B0FE92325475500D1C722 /* ListFoodTableViewController.swift */,
345B0FFE2325567200D1C722 /* ListFoodViewModel.swift */,
3490D66D23263A2100F9146E /* ListFoodTableViewControllerDependency.swift */,
3490D66D23263A2100F9146E /* ListFoodViewControllerDependency.swift */,
342F26C12327735800241D1F /* FoodDetailViewController.swift */,
342F26C323277C4700241D1F /* PrepareSegueFoodDetail.swift */,
34515F47234C9B4F00950292 /* ListFoodCollectionViewController.swift */,
);
path = ListFood;
sourceTree = "<group>";
Expand Down Expand Up @@ -298,12 +301,13 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
34515F48234C9B4F00950292 /* ListFoodCollectionViewController.swift in Sources */,
345B0FD62325470400D1C722 /* AppDelegate.swift in Sources */,
345B0FFD2325564A00D1C722 /* ListFoodPresenterViewController.swift in Sources */,
345B0FFF2325567200D1C722 /* ListFoodViewModel.swift in Sources */,
342F26C22327735800241D1F /* FoodDetailViewController.swift in Sources */,
345B10012325579A00D1C722 /* ListFoodErrorViewModel.swift in Sources */,
3490D66E23263A2100F9146E /* ListFoodTableViewControllerDependency.swift in Sources */,
3490D66E23263A2100F9146E /* ListFoodViewControllerDependency.swift in Sources */,
342F26C423277C4700241D1F /* PrepareSegueFoodDetail.swift in Sources */,
34B5622F2326101300F83D42 /* Locale.swift in Sources */,
345B0FEA2325475500D1C722 /* ListFoodTableViewController.swift in Sources */,
Expand Down

0 comments on commit 8e25ec6

Please sign in to comment.