From 557e8cb633b61099238b2b44b14b7540cc554b81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=A4=91=ED=98=84?= Date: Fri, 25 Jan 2019 11:32:00 +0900 Subject: [PATCH 1/4] mainVIew section 3 adjust --- .../firstItemView/ItemViewController.swift | 409 ++++++++++++++++++ 1 file changed, 409 insertions(+) create mode 100644 UberEats/UberEats/firstItemView/ItemViewController.swift diff --git a/UberEats/UberEats/firstItemView/ItemViewController.swift b/UberEats/UberEats/firstItemView/ItemViewController.swift new file mode 100644 index 0000000..104587f --- /dev/null +++ b/UberEats/UberEats/firstItemView/ItemViewController.swift @@ -0,0 +1,409 @@ + +// ItemViewController.swift +// uberEats +// +// Created by admin on 23/01/2019. +// Copyright © 2019 team-b1. All rights reserved. +// + +import UIKit + +class ItemViewController: UIViewController, UIScrollViewDelegate { + @IBOutlet var tableView: UITableView! + + @IBOutlet var scrollView: UIScrollView! + + private var images: [String] = ["1_1", "2_1", "3_1", "4_1", "5_1", "6_1"] + + private var frame = CGRect(x: 0, y: 0, width: 0, height: 0) + + private var labelString: [String] = ["추천요리", "가까운 인기 레스토랑", "예상 시간 30분 이하", "Uber Eats 신규 레스토랑", + "주문시 5천원 할인 받기", "가나다라", "마바사", "아자차카", "타파하", "아아아앙아", "집에", "가고", "싶다"] + private var gameTimer: Timer! + + private var collectionViewItems: [Int] = [] + + private var bannerImages: [String] = ["1_1", "2_1", "3_1", "4_1", "5_1", "6_1"] + + private var bannerTimer: Timer! + + private var isScrolledByUser: Bool! + + private lazy var pageControl: UIPageControl = { + let pageControl = UIPageControl(frame: CGRect(x: 50, y: scrollView.frame.height - 40, + width: scrollView.frame.width - 280, height: 37)) + pageControl.currentPage = 0 + return pageControl + }() + + private static let numberOfSection = 8 + + override func viewDidLoad() { + super.viewDidLoad() + + setupTableView() + setupScrollView() + + pageControl.currentPage = 0 + isScrolledByUser = false + + bannerTimer = Timer.scheduledTimer(timeInterval: 4, target: self, + selector: #selector(scrolledBanner), userInfo: nil, repeats: true) + } + + private func setupTableView() { + tableView.backgroundColor = .clear + tableView.showsVerticalScrollIndicator = false + tableView.addSubview(pageControl) + tableView.bringSubviewToFront(pageControl) + } + + @objc func scrolledBanner() { + /* guard로 false 처리 + guard isAutoScrollMode else { + return + } + */ + let nextPage = pageControl.currentPage + 1 + + let point = nextPage >= bannerImages.count ? + CGPoint(x: 0, y: 0) : + CGPoint(x: view.frame.width * CGFloat(nextPage), y: 0) + + scrollView.setContentOffset(point, animated: true) + } + + func setupScrollView() { + scrollView.showsHorizontalScrollIndicator = false + + var frame = CGRect(x: 0, y: 0, width: 0, height: 0) + + for index in 0..= view.frame.width * CGFloat(bannerImages.count - 1) { + scrollView.isScrollEnabled = false + scrollView.isScrollEnabled = true + } + + let page = scrollView.contentOffset.x / scrollView.frame.size.width + pageControl.currentPage = Int(page) + } + } +} + +extension ItemViewController: UITableViewDelegate, UITableViewDataSource { + func numberOfSections(in tableView: UITableView) -> Int { + return ItemViewController.numberOfSection + } + + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + let section = Section(rawValue: section)! + switch section { + case .bannerScroll: + return 0 + case .recommendFood, .nearestRest, .expectedTime, .newRest, .discount, .searchAndSee: + return 1 + case .moreRest: + return 10 + } + } + + func setupTableViewCell(indexPath: IndexPath) -> TableViewCell { + let tableNIB = UINib(nibName: "TableViewCell", bundle: nil) + tableView.register(tableNIB, forCellReuseIdentifier: "TableViewCellId") + guard let tablecell = tableView.dequeueReusableCell(withIdentifier: "TableViewCellId", + for: indexPath) as? TableViewCell else { + return .init() + } + tablecell.selectionStyle = .none + tablecell.collectionView.tag = indexPath.section + + return tablecell + } + + func setupCollectionViewCell(indexPath: IndexPath, nibName: String, tablecell: TableViewCell) { + let NIB = UINib(nibName: nibName, bundle: nil) + tablecell.addSubview(tablecell.collectionView) + tablecell.collectionView.register(NIB, forCellWithReuseIdentifier: nibName + "Id") + + tablecell.backgroundColor = UIColor(displayP3Red: 247 / 255, green: 247 / 255, blue: 247 / 255, alpha: 1.0) + tablecell.collectionView.backgroundColor = UIColor(displayP3Red: 247 / 255, green: 247 / 255, + blue: 247 / 255, alpha: 1.0) + + let section = Section(rawValue: indexPath.section)! + switch section { + case .recommendFood: + tablecell.recommendLabel.text = "추천 요리" + case .nearestRest: + tablecell.recommendLabel.text = "가까운 인기 레스토랑" + case .expectedTime: + tablecell.recommendLabel.text = "예상 시간 30분 이하" + case .newRest: + tablecell.recommendLabel.text = "새로운 레스토랑" + default: + tablecell.recommendLabel.text = "" + } + + tablecell.collectionView.translatesAutoresizingMaskIntoConstraints = false + NSLayoutConstraint.activate( + [ + tablecell.collectionView.bottomAnchor.constraint(equalTo: tablecell.bottomAnchor), + tablecell.collectionView.leadingAnchor.constraint(equalTo: tablecell.leadingAnchor), + tablecell.collectionView.trailingAnchor.constraint(equalTo: tablecell.trailingAnchor), + tablecell.collectionView.heightAnchor.constraint(equalTo: tablecell.heightAnchor, multiplier: 0.833) + ] + ) + + tablecell.collectionView.delegate = self + tablecell.collectionView.dataSource = self + tablecell.collectionView.reloadData() + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let section = Section(rawValue: indexPath.section)! + switch section { + case .bannerScroll: + let tablecell = setupTableViewCell(indexPath: indexPath) + NSLayoutConstraint.activate( + [ + scrollView.bottomAnchor.constraint(equalTo: tablecell.bottomAnchor), + scrollView.topAnchor.constraint(equalTo: tablecell.topAnchor), + scrollView.leadingAnchor.constraint(equalTo: tablecell.leadingAnchor), + scrollView.trailingAnchor.constraint(equalTo: tablecell.trailingAnchor) + ] + ) + case .recommendFood: + let tablecell = setupTableViewCell(indexPath: indexPath) + setupCollectionViewCell(indexPath: indexPath, nibName: "RecommendCollectionViewCell", tablecell: tablecell) + return tablecell + case .nearestRest: + let tablecell = setupTableViewCell(indexPath: indexPath) + setupCollectionViewCell(indexPath: indexPath, nibName: "NearestCollectionViewCell", tablecell: tablecell) + return tablecell + case .expectedTime: + let tablecell = setupTableViewCell(indexPath: indexPath) + setupCollectionViewCell(indexPath: indexPath, nibName: "ExpectTimeCollectionViewCell", tablecell: tablecell) + return tablecell + case .newRest: + let tablecell = setupTableViewCell(indexPath: indexPath) + setupCollectionViewCell(indexPath: indexPath, nibName: "NewRestCollectionViewCell", tablecell: tablecell) + return tablecell + case .discount: + let tablecell = setupTableViewCell(indexPath: indexPath) + tablecell.recommendLabel.text = "주문시 5천원 할인 받기" + tablecell.collectionView.removeFromSuperview() + case .moreRest: + if indexPath.row != 0 { + let seeMoreRestTableViewCellNIB = UINib(nibName: "SeeMoreRestTableViewCell", bundle: nil) + tableView.register(seeMoreRestTableViewCellNIB, forCellReuseIdentifier: "SeeMoreRestTableViewCellId") + guard let tablecellOfsixCell = tableView.dequeueReusableCell( + withIdentifier: "SeeMoreRestTableViewCellId", + for: indexPath) as? SeeMoreRestTableViewCell else { + return .init() + } + tablecellOfsixCell.selectionStyle = .none + return tablecellOfsixCell + } else { + return .init() + } + case .searchAndSee: + let tablecell = setupTableViewCell(indexPath: indexPath) + + tablecell.recommendLabel.text = "주문시 5천원 할인 받기" + tablecell.collectionView.removeFromSuperview() + return tablecell + } + return .init() + } + + func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { + let section = Section(rawValue: indexPath.section)! + switch section { + case .recommendFood: + return view.frame.height * 0.44 + case .nearestRest, .expectedTime, .newRest: + return view.frame.height * 0.5 + case .discount: + return view.frame.height * 0.14 + case .moreRest: + if indexPath.row == 0 { + return 80 + } else { + return view.frame.height * 0.5 + } + case .searchAndSee: + return view.frame.height * 0.2 + case .bannerScroll: + return 0 + } + // MARK: - 디바이스별 분기 나눠서 오토레이아웃 적용 방법 예시 + //return UIDevice.current.screenType.tableCellSize(for: Section.init(rawValue: indexPath.row) + + } + + func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { + return view.frame.height * (10/812) + } +} + +extension ItemViewController: UICollectionViewDelegate, UICollectionViewDataSource { + func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + + let section = Section(rawValue: collectionView.tag)! + switch section { + case .bannerScroll: + return 0 + case .recommendFood: + return 7 + case .nearestRest: + return 6 + case .expectedTime: + return 6 + case .newRest: + return 4 + case .discount, .moreRest, .searchAndSee: + return 0 + } + } + + func collectionView(_ collectionView: UICollectionView, + cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + + collectionView.showsHorizontalScrollIndicator = false + + let section = Section(rawValue: collectionView.tag)! + switch section { + case .bannerScroll: + collectionView.backgroundColor = .lightGray + case .recommendFood://추천요리 + guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "RecommendCollectionViewCellId", + for: indexPath) as? RecommendCollectionViewCell else { return .init()} + cell.layer.cornerRadius = 5 + return cell + case .nearestRest://가까운 인기 레스토랑 + guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "NearestCollectionViewCellId", + for: indexPath) as? NearestCollectionViewCell else {return .init()} + cell.layer.cornerRadius = 5 + return cell + case .expectedTime://예상 시간 + guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ExpectTimeCollectionViewCellId", + for: indexPath) as? ExpectTimeCollectionViewCell else {return .init()} + cell.backgroundColor = .lightGray + return cell + case .newRest://신규 레스토랑 + guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "NewRestCollectionViewCellId", + for: indexPath) as? NewRestCollectionViewCell else {return .init()} + cell.backgroundColor = .lightGray + return cell + default: + return .init() + } + return .init() + } + + func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + let storboard = UIStoryboard.init(name: "Main", bundle: nil) + let collectionViewController = storboard.instantiateViewController(withIdentifier: "CollectionViewController") + self.navigationController?.pushViewController(collectionViewController, animated: true) + } +} + +extension ItemViewController: UICollectionViewDelegateFlowLayout { + func collectionView(_ collectionView: UICollectionView, + layout collectionViewLayout: UICollectionViewLayout, + sizeForItemAt indexPath: IndexPath) -> CGSize { + + guard let section = Section(rawValue: collectionView.tag) else { + preconditionFailure("") + } + + switch section { + case .recommendFood: + return CGSize(width: tableView.frame.width * 0.6, height: tableView.frame.width * 0.61 * 0.92) + case .nearestRest, .expectedTime, .newRest : + return CGSize(width: tableView.frame.width * 0.76, height: tableView.frame.width * 0.76 * 0.868) + case .discount: + return CGSize(width: 0, height: 0) + default: + return CGSize(width: 400, height: 400) + } + } + + func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets { + switch collectionView.tag { + case 0: + return UIEdgeInsets(top: 30, left: 30, bottom: 0, right: 30) + case 1://추천요리 + return UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0) + case 2://가까운 인기 레스토랑 + return UIEdgeInsets(top: 30, left: 30, bottom: 30, right: 30) + case 3://예상 시간 + return UIEdgeInsets(top: 30, left: 30, bottom: 30, right: 30) + case 4://신규 레스토랑 + return UIEdgeInsets(top: 30, left: 30, bottom: 30, right: 30) + //case 5: 주문시 5천원 할인받기 + default: + return UIEdgeInsets(top: 30, left: 30, bottom: 30, right: 30) + } + } + + + func collectionView(_ collectionView: UICollectionView, + layout collectionViewLayout: UICollectionViewLayout, + insetForSectionAt section: Int) -> UIEdgeInsets { + let section = Section(rawValue: collectionView.tag)! + switch section { + case .bannerScroll: + return UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0) + case .recommendFood: + return UIEdgeInsets(top: 24, left: 24, bottom: 24, right: 24) + case .nearestRest: + return UIEdgeInsets(top: 30, left: 24, bottom: 24, right: 30) + case .expectedTime: + return UIEdgeInsets(top: 30, left: 30, bottom: 30, right: 30) + case .newRest: + return UIEdgeInsets(top: 30, left: 30, bottom: 30, right: 30) + default: + return UIEdgeInsets(top: 30, left: 30, bottom: 30, right: 30) + } + } +} + From aa53a7c087ab337a387a4c1f147c10d5a44a3716 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=A4=91=ED=98=84?= Date: Fri, 25 Jan 2019 15:56:12 +0900 Subject: [PATCH 2/4] =?UTF-8?q?=EB=A9=94=EC=9D=B8=EB=B7=B0=20=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EC=84=B9=EC=85=98=201,2,3,4=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #12 스크롤뷰(90%) , 섹션 --- UberEats/UberEats/firstItemView/ItemViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UberEats/UberEats/firstItemView/ItemViewController.swift b/UberEats/UberEats/firstItemView/ItemViewController.swift index 104587f..091b073 100644 --- a/UberEats/UberEats/firstItemView/ItemViewController.swift +++ b/UberEats/UberEats/firstItemView/ItemViewController.swift @@ -130,6 +130,7 @@ class ItemViewController: UIViewController, UIScrollViewDelegate { } extension ItemViewController: UITableViewDelegate, UITableViewDataSource { + // 섹션 7개 func numberOfSections(in tableView: UITableView) -> Int { return ItemViewController.numberOfSection } @@ -406,4 +407,3 @@ extension ItemViewController: UICollectionViewDelegateFlowLayout { } } } - From 3047917d948360e66a411acc0d56b188bae4dda7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=A4=91=ED=98=84?= Date: Mon, 28 Jan 2019 10:10:51 +0900 Subject: [PATCH 3/4] develop push move to feature/MainView branch --- UberEats/UberEats.xcodeproj/project.pbxproj | 9 +--- .../xcshareddata/xcschemes/UberEats.xcscheme | 2 +- UberEats/UberEats/AppDelegate.swift | 48 +++++++++++++++++++ .../firstItemView/ItemViewController.swift | 5 ++ 4 files changed, 56 insertions(+), 8 deletions(-) create mode 100644 UberEats/UberEats/AppDelegate.swift diff --git a/UberEats/UberEats.xcodeproj/project.pbxproj b/UberEats/UberEats.xcodeproj/project.pbxproj index d6fd98d..cc28a95 100644 --- a/UberEats/UberEats.xcodeproj/project.pbxproj +++ b/UberEats/UberEats.xcodeproj/project.pbxproj @@ -424,8 +424,6 @@ isa = PBXGroup; children = ( 99342CCC21FB13110029DB10 /* Utill */, - 99342CC321FB12CF0029DB10 /* UberEatsTests.swift */, - 99342CC521FB12CF0029DB10 /* Info.plist */, ); path = UberEatsTests; sourceTree = ""; @@ -443,7 +441,6 @@ 99342CCC21FB13110029DB10 /* Utill */ = { isa = PBXGroup; children = ( - 99342CCF21FB13790029DB10 /* ThrottlerTests.swift */, ); path = Utill; sourceTree = ""; @@ -463,7 +460,6 @@ isa = PBXGroup; children = ( 9956F7ED21F98468004E9854 /* UberEats.app */, - 99342CC121FB12CF0029DB10 /* UberEatsTests.xctest */, ); name = Products; sourceTree = ""; @@ -897,7 +893,6 @@ ); name = UberEatsTests; productName = UberEatsTests; - productReference = 99342CC121FB12CF0029DB10 /* UberEatsTests.xctest */; productType = "com.apple.product-type.bundle.unit-test"; }; 9956F7EC21F98468004E9854 /* UberEats */ = { @@ -1122,8 +1117,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 99342CD021FB13790029DB10 /* ThrottlerTests.swift in Sources */, - 99342CC421FB12CF0029DB10 /* UberEatsTests.swift in Sources */, + 99342CD021FB13790029DB10 /* (null) in Sources */, + 99342CC421FB12CF0029DB10 /* (null) in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/UberEats/UberEats.xcodeproj/xcshareddata/xcschemes/UberEats.xcscheme b/UberEats/UberEats.xcodeproj/xcshareddata/xcschemes/UberEats.xcscheme index 11a97ec..dcc4ba4 100644 --- a/UberEats/UberEats.xcodeproj/xcshareddata/xcschemes/UberEats.xcscheme +++ b/UberEats/UberEats.xcodeproj/xcshareddata/xcschemes/UberEats.xcscheme @@ -33,7 +33,7 @@ diff --git a/UberEats/UberEats/AppDelegate.swift b/UberEats/UberEats/AppDelegate.swift new file mode 100644 index 0000000..3247251 --- /dev/null +++ b/UberEats/UberEats/AppDelegate.swift @@ -0,0 +1,48 @@ +// +// AppDelegate.swift +// UberEats +// +// Created by 장공의 on 24/01/2019. +// Copyright © 2019 team-b1. All rights reserved. +// + +import UIKit + +@UIApplicationMain +class AppDelegate: UIResponder, UIApplicationDelegate { + + var window: UIWindow? + + func application(_ application: UIApplication, + didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { + // Override point for customization after application launch. + + //window = UIWindow(frame: UIScreen.main.bounds) + + //window?.rootViewController = TabBarVC() + + //window?.makeKeyAndVisible() + + return true + } + + func applicationWillResignActive(_ application: UIApplication) { + + } + + func applicationDidEnterBackground(_ application: UIApplication) { + } + + func applicationWillEnterForeground(_ application: UIApplication) { + + } + + func applicationDidBecomeActive(_ application: UIApplication) { + + } + + func applicationWillTerminate(_ application: UIApplication) { + + } + +} diff --git a/UberEats/UberEats/firstItemView/ItemViewController.swift b/UberEats/UberEats/firstItemView/ItemViewController.swift index 091b073..4dbfe81 100644 --- a/UberEats/UberEats/firstItemView/ItemViewController.swift +++ b/UberEats/UberEats/firstItemView/ItemViewController.swift @@ -12,6 +12,11 @@ class ItemViewController: UIViewController, UIScrollViewDelegate { @IBOutlet var tableView: UITableView! @IBOutlet var scrollView: UIScrollView! + private var images: [String] = ["1_1", "2_1", "3_1","4_1","5_1","6_1"] + private var frame = CGRect(x: 0, y: 0, width: 0, height: 0) + private var labelString: [String] = ["추천요리","가까운 인기 레스토랑","예상 시간 30분 이하","Uber Eats 신규 레스토랑","주문시 5천원 할인 받기", "가나다라", "마바사", "아자차카", "타파하", "아아아앙아", "집에", "가고", "싶다"] + private var gameTimer: Timer! + private var collectionViewItems:[Int] = [] private var images: [String] = ["1_1", "2_1", "3_1", "4_1", "5_1", "6_1"] From 99d1309066e8eca73fa6711277208d68ad4e4b20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=A4=91=ED=98=84?= Date: Tue, 19 Mar 2019 19:37:46 +0900 Subject: [PATCH 4/4] =?UTF-8?q?=ED=95=A8=EC=88=98=20=ED=81=AC=EA=B8=B0?= =?UTF-8?q?=EB=A5=BC=20=EC=B5=9C=EB=8C=80=ED=95=9C=20=EC=A4=84=EC=98=80?= =?UTF-8?q?=EC=8A=B5=EB=8B=88=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Common/HTTPURLResponse+StatusCode.swift | 3 - .../Common/Common/ImageNetworkManager.swift | 4 + .../DependencyContainer/DependencyPool.swift | 1 - UberEats/UberEats/AppDelegate.swift | 12 +- .../OrderCheckingCollectionReusableView.swift | 1 + .../FoodMarketViewController.swift | 235 +++++++----------- .../firstItemView/ItemViewController.swift | 68 +++-- 7 files changed, 127 insertions(+), 197 deletions(-) diff --git a/UberEats/Common/Common/HTTPURLResponse+StatusCode.swift b/UberEats/Common/Common/HTTPURLResponse+StatusCode.swift index 2a50d12..34ba778 100644 --- a/UberEats/Common/Common/HTTPURLResponse+StatusCode.swift +++ b/UberEats/Common/Common/HTTPURLResponse+StatusCode.swift @@ -12,13 +12,10 @@ public extension HTTPURLResponse { var httpStatusCode: HTTPStatusCode { get { - guard let code = HTTPStatusCode(rawValue: statusCode) else { return HTTPStatusCode.nil } - return code } } - } diff --git a/UberEats/Common/Common/ImageNetworkManager.swift b/UberEats/Common/Common/ImageNetworkManager.swift index fa8de53..0b03659 100644 --- a/UberEats/Common/Common/ImageNetworkManager.swift +++ b/UberEats/Common/Common/ImageNetworkManager.swift @@ -24,10 +24,13 @@ public class ImageNetworkManager { } private func downloadImage(imageURL: URL, complection: @escaping (UIImage?, Error?) -> Void) { + session.dataTask(with: imageURL) { [weak self] (data, _, error) in + if error != nil { return } + guard let data = data else { return } @@ -41,6 +44,7 @@ public class ImageNetworkManager { DispatchQueue.main.async { complection(image, nil) } + }.resume() } diff --git a/UberEats/DependencyContainer/DependencyContainer/DependencyPool.swift b/UberEats/DependencyContainer/DependencyContainer/DependencyPool.swift index 367f047..292f30d 100644 --- a/UberEats/DependencyContainer/DependencyContainer/DependencyPool.swift +++ b/UberEats/DependencyContainer/DependencyContainer/DependencyPool.swift @@ -33,7 +33,6 @@ class DependencyPool { return dependency as! T } - } enum DependencyPoolError: Error { diff --git a/UberEats/UberEats/AppDelegate.swift b/UberEats/UberEats/AppDelegate.swift index 3247251..9660c7c 100644 --- a/UberEats/UberEats/AppDelegate.swift +++ b/UberEats/UberEats/AppDelegate.swift @@ -16,33 +16,33 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. - + //window = UIWindow(frame: UIScreen.main.bounds) //window?.rootViewController = TabBarVC() //window?.makeKeyAndVisible() - + return true } func applicationWillResignActive(_ application: UIApplication) { - + } func applicationDidEnterBackground(_ application: UIApplication) { } func applicationWillEnterForeground(_ application: UIApplication) { - + } func applicationDidBecomeActive(_ application: UIApplication) { - + } func applicationWillTerminate(_ application: UIApplication) { - + } } diff --git a/UberEats/UberEats/Scene/DeliveryLocation/View/OrderCheckingCollectionReusableView.swift b/UberEats/UberEats/Scene/DeliveryLocation/View/OrderCheckingCollectionReusableView.swift index 78d3e67..5aa2296 100644 --- a/UberEats/UberEats/Scene/DeliveryLocation/View/OrderCheckingCollectionReusableView.swift +++ b/UberEats/UberEats/Scene/DeliveryLocation/View/OrderCheckingCollectionReusableView.swift @@ -23,6 +23,7 @@ class OrderCheckingCollectionReusableView: UICollectionReusableView { var progressStatus: ProgressStatus? { didSet { + guard let status = progressStatus else { return } diff --git a/UberEats/UberEats/Scene/FoodMarket/ViewController/FoodMarketViewController.swift b/UberEats/UberEats/Scene/FoodMarket/ViewController/FoodMarketViewController.swift index 0a6a10e..164fe11 100644 --- a/UberEats/UberEats/Scene/FoodMarket/ViewController/FoodMarketViewController.swift +++ b/UberEats/UberEats/Scene/FoodMarket/ViewController/FoodMarketViewController.swift @@ -168,6 +168,7 @@ class ItemViewController: UIViewController { if completeState.state { self.tableView.reloadData() } + } @IBAction func touchUpSettingLocation(_ sender: Any) { @@ -207,6 +208,7 @@ class ItemViewController: UIViewController { self?.tableView.reloadData() self?.indicator.removeFromSuperview() } + } private func setupTableView() { @@ -365,7 +367,6 @@ extension ItemViewController: UITableViewDelegate, UITableViewDataSource { switch tableViewSection { case .bannerScroll: - guard let completeState = completeState else { return 0 } @@ -395,13 +396,9 @@ extension ItemViewController: UITableViewDelegate, UITableViewDataSource { return tablecell } - func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - - guard let tableviewSection = TableViewSection(rawValue: indexPath.section) else { - return .init() - } - + private func setTableViewSectionCell(_ tableviewSection: TableViewSection, indexPath: IndexPath) -> UITableViewCell { switch tableviewSection { + case .bannerScroll: deliveryCompleteStaticTableCell.storeInfo = (state: true, storeName: "피자헛 강남 논현점 Pizza Hut GangNam Nonhyeon", storeImageURL: "gogossing") return deliveryCompleteStaticTableCell @@ -455,8 +452,8 @@ extension ItemViewController: UITableViewDelegate, UITableViewDataSource { } else { guard let moreRestTableViewCell = tableView.dequeueReusableCell(withIdentifier: "SeeMoreRestTableViewCellId", for: indexPath) - as? SeeMoreRestTableViewCell else { - return .init() + as? SeeMoreRestTableViewCell else { + return .init() } if moreRests.count > indexPath.row { @@ -483,12 +480,22 @@ extension ItemViewController: UITableViewDelegate, UITableViewDataSource { } } + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + + guard let tableviewSection = TableViewSection(rawValue: indexPath.section) else { + return .init() + } + + return setTableViewSectionCell(tableviewSection, indexPath: indexPath) + } + func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { guard let tableViewSection = TableViewSection(rawValue: indexPath.section) else { return 0 } switch tableViewSection { + case .moreRest: if indexPath.row == restMoreSeeTableViewRow { return heightOfMoreRestTitle @@ -523,175 +530,70 @@ extension ItemViewController: UICollectionViewDelegate, UICollectionViewDataSour guard let tableViewSection = TableViewSection(rawValue: collectionView.tag) else { return 0 } - if section == collectionViewDataSection { - switch tableViewSection { - case .recommendFood: - return recommendFood.count - case .nearestRest: - return nearestRests.count - case .expectedTime: - return expectTimeRests.count - case .newRest: - return newRests.count - default: - return 0 - } - } else { - switch tableViewSection { - case .nearestRest, .expectedTime, .newRest: - return moreSeeData - default: - return 0 - } - } + + return getCollectionViewSectionCount(section, tableViewSection: tableViewSection) } func numberOfSections(in collectionView: UICollectionView) -> Int { + guard let talbeViewSection = TableViewSection(rawValue: collectionView.tag) else { return 0 } + return talbeViewSection.numberOfCollectionViewSection } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - guard let tableViewSection = TableViewSection(rawValue: collectionView.tag) else { return .init() } + + return getCollectionViewCell(tableViewSection, indexPath: indexPath, collectionView: collectionView) + } + + func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + + guard let tableViewSection = TableViewSection(rawValue: collectionView.tag) else { + return + } + + if indexPath.section == collectionViewDataSection { + sendDataToStoreVC(tableViewSection: tableViewSection, indexPath: indexPath) + } + + setNavigationState(indexPath.section, tableViewSection: tableViewSection) + } + + func sendDataToStoreVC(tableViewSection: TableViewSection, indexPath: IndexPath) { + + guard let storeViewController = UIStoryboard.main.instantiateViewController(withIdentifier: "CollectionViewController") + as? StoreCollectionViewController else { + return + } switch tableViewSection { case .recommendFood: - guard let recommendCollectionViewCell = recommendFoodStaticTableCell.collectionView.dequeueReusableCell(withReuseIdentifier: recommendFoodStaticTableCell.collectionVIewCellId, for: indexPath) as? RecommendCollectionViewCell else { - return .init() - } - if recommendFood.count > indexPath.item { - recommendCollectionViewCell.recommendFood = recommendFood[indexPath.item] - recommendCollectionViewCell.dropShadow(color: .gray, - opacity: 0.2, - offSet: CGSize(width: 1, height: -1), - radius: 5.0, - scale: true) - guard let imageURL = URL(string: recommendFood[indexPath.item].foodImageURL) else { - return recommendCollectionViewCell - } - ImageNetworkManager.shared.getImageByCache(imageURL: imageURL) { [weak recommendCollectionViewCell] (downloadImage, _) in - guard recommendCollectionViewCell?.confirmURL?.absoluteString == imageURL.absoluteString else {return } - recommendCollectionViewCell?.image.image = downloadImage - } - } - return recommendCollectionViewCell + storeViewController.passingData(status: SelectState.food(foodId: recommendFood[indexPath.item].id, + storeId: recommendFood[indexPath.item].storeId)) case .nearestRest: - if indexPath.section == collectionViewDataSection { - guard let nearestRestCell = collectionView.dequeueReusableCell(withReuseIdentifier: tableViewSection.identifier, for: indexPath) as? NearestCollectionViewCell else { - return .init() - } - if newRests.count > indexPath.item { - nearestRestCell.nearestRest = nearestRests[indexPath.item] - nearestRestCell.dropShadow(color: .gray, - opacity: 0.2, - offSet: CGSize(width: 1, height: -1), - radius: 5.0, - scale: true) - guard let imageURL = URL(string: nearestRests[indexPath.item].mainImage) else { - return nearestRestCell - } - ImageNetworkManager.shared.getImageByCache(imageURL: imageURL) { [weak nearestRestCell] (downloadImage, _) in - guard nearestRestCell?.confirmURL?.absoluteString == imageURL.absoluteString else {return } - nearestRestCell?.mainImage.image = downloadImage - } - } - return nearestRestCell - } else { - guard let nearestRestCell = collectionView.dequeueReusableCell(withReuseIdentifier: tableViewSection.moreRestCellId, for: indexPath) as? RestaurtSeeMoreCollectionViewCell else { - return .init() - } - return nearestRestCell - } + storeViewController.passingData(status: SelectState.store(nearestRests[indexPath.item].id)) case .expectedTime: - if indexPath.section == collectionViewDataSection { - guard let exepectTimeRestCell = collectionView.dequeueReusableCell(withReuseIdentifier: tableViewSection.identifier, for: indexPath) as? ExpectTimeCollectionViewCell else { - return .init() - } - if expectTimeRests.count > indexPath.item { - exepectTimeRestCell.expectTimeRest = expectTimeRests[indexPath.item] - exepectTimeRestCell.dropShadow(color: .gray, - opacity: 0.2, - offSet: CGSize(width: 1, height: -1), - radius: 5.0, - scale: true) - guard let imageURL = URL(string: expectTimeRests[indexPath.item].mainImage) else { - return exepectTimeRestCell - } - ImageNetworkManager.shared.getImageByCache(imageURL: imageURL) {[weak exepectTimeRestCell] (image, _) in - guard exepectTimeRestCell?.confirmURL?.absoluteString == imageURL.absoluteString else {return } - exepectTimeRestCell?.mainImage.image = image - } - } - return exepectTimeRestCell - } else { - guard let exepectTimeRestCell = collectionView.dequeueReusableCell(withReuseIdentifier: tableViewSection.moreRestCellId, for: indexPath) as? RestaurtSeeMoreCollectionViewCell else { - return .init() - } - return exepectTimeRestCell - } - + storeViewController.passingData(status: SelectState.store(expectTimeRests[indexPath.item].id)) case .newRest: - if indexPath.section == collectionViewDataSection { - guard let newRestCell = collectionView.dequeueReusableCell(withReuseIdentifier: tableViewSection.identifier, for: indexPath) as? NewRestCollectionViewCell else { - return .init() - } - if newRests.count > indexPath.item { - newRestCell.newRest = newRests[indexPath.item] - newRestCell.dropShadow(color: .gray, - opacity: 0.2, - offSet: CGSize(width: 1, height: -1), - radius: 5.0, - scale: true) - - guard let imageURL = URL(string: newRests[indexPath.item].mainImage) else { - return newRestCell - } - ImageNetworkManager.shared.getImageByCache(imageURL: imageURL) {[weak newRestCell] (downloadImage, _) in - guard newRestCell?.confirmURL?.absoluteString == imageURL.absoluteString else {return } - newRestCell?.mainImage.image = downloadImage - } - } - return newRestCell - } else { - guard let newRestCell = collectionView.dequeueReusableCell(withReuseIdentifier: tableViewSection.moreRestCellId, for: indexPath) as? RestaurtSeeMoreCollectionViewCell else { - return .init() - } - return newRestCell - } - case .searchAndSee, .discount, .bannerScroll, .moreRest: - return .init() + storeViewController.passingData(status: SelectState.store(newRests[indexPath.item].id)) + default: + break } - } - func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + func setNavigationState(_ section: Int, tableViewSection: TableViewSection) { guard let storeViewController = UIStoryboard.main.instantiateViewController(withIdentifier: "CollectionViewController") as? StoreCollectionViewController else { - return - } - guard let tableViewSection = TableViewSection(rawValue: collectionView.tag) else { - return + return } - if indexPath.section == collectionViewDataSection { - switch tableViewSection { - case .recommendFood: - storeViewController.passingData(status: SelectState.food(foodId: recommendFood[indexPath.item].id, - storeId: recommendFood[indexPath.item].storeId)) - case .nearestRest: - storeViewController.passingData(status: SelectState.store(nearestRests[indexPath.item].id)) - case .expectedTime: - storeViewController.passingData(status: SelectState.store(expectTimeRests[indexPath.item].id)) - case .newRest: - storeViewController.passingData(status: SelectState.store(newRests[indexPath.item].id)) - default: - break - } + + if section == collectionViewDataSection { tabBarController?.tabBar.isHidden = true navigationController?.setNavigationBarHidden(true, animated: false) navigationController?.pushViewController(storeViewController, animated: true) @@ -703,6 +605,30 @@ extension ItemViewController: UICollectionViewDelegate, UICollectionViewDataSour navigationController?.pushViewController(SeeMoreRestVC, animated: true) } } + + func getCollectionViewSectionCount(_ section: Int, tableViewSection: TableViewSection) -> Int { + if section == collectionViewDataSection { + switch tableViewSection { + case .recommendFood: + return recommendFood.count + case .nearestRest: + return nearestRests.count + case .expectedTime: + return expectTimeRests.count + case .newRest: + return newRests.count + default: + return 0 + } + } else { + switch tableViewSection { + case .nearestRest, .expectedTime, .newRest: + return moreSeeData + default: + return 0 + } + } + } } extension ItemViewController: UICollectionViewDelegateFlowLayout { @@ -715,6 +641,7 @@ extension ItemViewController: UICollectionViewDelegateFlowLayout { } switch tableViewSection { + case .recommendFood: guard let recommendFoodCell = collectionView.dequeueReusableCell(withReuseIdentifier: tableViewSection.identifier, for: indexPath) as? RecommendCollectionViewCell else { @@ -729,9 +656,11 @@ extension ItemViewController: UICollectionViewDelegateFlowLayout { case .nearestRest: if indexPath.section == collectionViewDataSection { + guard let nearestRestCell = collectionView.dequeueReusableCell(withReuseIdentifier: tableViewSection.identifier, for: indexPath) as? NearestCollectionViewCell else { return .init() } + nearestRestCell.nearestRest = nearestRests[indexPath.item] let cellHeight = nearestRestCell.isExistPromotion() @@ -742,9 +671,11 @@ extension ItemViewController: UICollectionViewDelegateFlowLayout { } case .expectedTime: if indexPath.section == collectionViewDataSection { + guard let expectTimeCell = collectionView.dequeueReusableCell(withReuseIdentifier: tableViewSection.identifier, for: indexPath) as? ExpectTimeCollectionViewCell else { return .init() } + expectTimeCell.expectTimeRest = expectTimeRests[indexPath.item] let cellHeight = expectTimeCell.isExistPromotion() diff --git a/UberEats/UberEats/firstItemView/ItemViewController.swift b/UberEats/UberEats/firstItemView/ItemViewController.swift index 4dbfe81..7d06861 100644 --- a/UberEats/UberEats/firstItemView/ItemViewController.swift +++ b/UberEats/UberEats/firstItemView/ItemViewController.swift @@ -1,4 +1,3 @@ - // ItemViewController.swift // uberEats // @@ -10,39 +9,39 @@ import UIKit class ItemViewController: UIViewController, UIScrollViewDelegate { @IBOutlet var tableView: UITableView! - + @IBOutlet var scrollView: UIScrollView! - private var images: [String] = ["1_1", "2_1", "3_1","4_1","5_1","6_1"] + private var images: [String] = ["1_1", "2_1", "3_1", "4_1", "5_1", "6_1"] private var frame = CGRect(x: 0, y: 0, width: 0, height: 0) - private var labelString: [String] = ["추천요리","가까운 인기 레스토랑","예상 시간 30분 이하","Uber Eats 신규 레스토랑","주문시 5천원 할인 받기", "가나다라", "마바사", "아자차카", "타파하", "아아아앙아", "집에", "가고", "싶다"] + private var labelString: [String] = ["추천요리", "가까운 인기 레스토랑", "예상 시간 30분 이하", "Uber Eats 신규 레스토랑", "주문시 5천원 할인 받기", "가나다라", "마바사", "아자차카", "타파하", "아아아앙아", "집에", "가고", "싶다"] private var gameTimer: Timer! - private var collectionViewItems:[Int] = [] - + private var collectionViewItems: [Int] = [] + private var images: [String] = ["1_1", "2_1", "3_1", "4_1", "5_1", "6_1"] - + private var frame = CGRect(x: 0, y: 0, width: 0, height: 0) - + private var labelString: [String] = ["추천요리", "가까운 인기 레스토랑", "예상 시간 30분 이하", "Uber Eats 신규 레스토랑", "주문시 5천원 할인 받기", "가나다라", "마바사", "아자차카", "타파하", "아아아앙아", "집에", "가고", "싶다"] private var gameTimer: Timer! - + private var collectionViewItems: [Int] = [] - + private var bannerImages: [String] = ["1_1", "2_1", "3_1", "4_1", "5_1", "6_1"] - + private var bannerTimer: Timer! - + private var isScrolledByUser: Bool! - + private lazy var pageControl: UIPageControl = { let pageControl = UIPageControl(frame: CGRect(x: 50, y: scrollView.frame.height - 40, width: scrollView.frame.width - 280, height: 37)) pageControl.currentPage = 0 return pageControl }() - + private static let numberOfSection = 8 - + override func viewDidLoad() { super.viewDidLoad() @@ -110,11 +109,11 @@ class ItemViewController: UIViewController, UIScrollViewDelegate { scrollView.scrollRectToVisible(frame, animated: true) } - + func scrollViewWillBeginDragging(_ scrollView: UIScrollView) { bannerTimer.invalidate() } - + func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) { bannerTimer = Timer.scheduledTimer(timeInterval: 4, target: self, selector: #selector(scrolledBanner), userInfo: nil, repeats: true) @@ -151,7 +150,7 @@ extension ItemViewController: UITableViewDelegate, UITableViewDataSource { return 10 } } - + func setupTableViewCell(indexPath: IndexPath) -> TableViewCell { let tableNIB = UINib(nibName: "TableViewCell", bundle: nil) tableView.register(tableNIB, forCellReuseIdentifier: "TableViewCellId") @@ -161,19 +160,19 @@ extension ItemViewController: UITableViewDelegate, UITableViewDataSource { } tablecell.selectionStyle = .none tablecell.collectionView.tag = indexPath.section - + return tablecell } - + func setupCollectionViewCell(indexPath: IndexPath, nibName: String, tablecell: TableViewCell) { let NIB = UINib(nibName: nibName, bundle: nil) tablecell.addSubview(tablecell.collectionView) tablecell.collectionView.register(NIB, forCellWithReuseIdentifier: nibName + "Id") - + tablecell.backgroundColor = UIColor(displayP3Red: 247 / 255, green: 247 / 255, blue: 247 / 255, alpha: 1.0) tablecell.collectionView.backgroundColor = UIColor(displayP3Red: 247 / 255, green: 247 / 255, blue: 247 / 255, alpha: 1.0) - + let section = Section(rawValue: indexPath.section)! switch section { case .recommendFood: @@ -187,7 +186,7 @@ extension ItemViewController: UITableViewDelegate, UITableViewDataSource { default: tablecell.recommendLabel.text = "" } - + tablecell.collectionView.translatesAutoresizingMaskIntoConstraints = false NSLayoutConstraint.activate( [ @@ -197,12 +196,12 @@ extension ItemViewController: UITableViewDelegate, UITableViewDataSource { tablecell.collectionView.heightAnchor.constraint(equalTo: tablecell.heightAnchor, multiplier: 0.833) ] ) - + tablecell.collectionView.delegate = self tablecell.collectionView.dataSource = self tablecell.collectionView.reloadData() } - + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let section = Section(rawValue: indexPath.section)! switch section { @@ -252,7 +251,7 @@ extension ItemViewController: UITableViewDelegate, UITableViewDataSource { } case .searchAndSee: let tablecell = setupTableViewCell(indexPath: indexPath) - + tablecell.recommendLabel.text = "주문시 5천원 할인 받기" tablecell.collectionView.removeFromSuperview() return tablecell @@ -284,7 +283,7 @@ extension ItemViewController: UITableViewDelegate, UITableViewDataSource { //return UIDevice.current.screenType.tableCellSize(for: Section.init(rawValue: indexPath.row) } - + func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { return view.frame.height * (10/812) } @@ -292,7 +291,7 @@ extension ItemViewController: UITableViewDelegate, UITableViewDataSource { extension ItemViewController: UICollectionViewDelegate, UICollectionViewDataSource { func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { - + let section = Section(rawValue: collectionView.tag)! switch section { case .bannerScroll: @@ -309,12 +308,12 @@ extension ItemViewController: UICollectionViewDelegate, UICollectionViewDataSour return 0 } } - + func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - + collectionView.showsHorizontalScrollIndicator = false - + let section = Section(rawValue: collectionView.tag)! switch section { case .bannerScroll: @@ -356,11 +355,11 @@ extension ItemViewController: UICollectionViewDelegateFlowLayout { func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { - + guard let section = Section(rawValue: collectionView.tag) else { preconditionFailure("") } - + switch section { case .recommendFood: return CGSize(width: tableView.frame.width * 0.6, height: tableView.frame.width * 0.61 * 0.92) @@ -372,7 +371,7 @@ extension ItemViewController: UICollectionViewDelegateFlowLayout { return CGSize(width: 400, height: 400) } } - + func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets { switch collectionView.tag { case 0: @@ -391,7 +390,6 @@ extension ItemViewController: UICollectionViewDelegateFlowLayout { } } - func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {