From d5932a97a5e9d251c0f9c531fae0178660363702 Mon Sep 17 00:00:00 2001 From: gme_2 Date: Tue, 28 Aug 2018 18:53:01 +0900 Subject: [PATCH] collection view setup --- GMERemittance.xcodeproj/project.pbxproj | 12 ++++ ...ndMoenyPaymentModeCollectionViewCell.swift | 40 ++++++++++++ .../View/SendMoneyPaymentMode.storyboard | 21 ++---- .../SendMoneyPaymentModeViewController.swift | 65 ++++++++++++++++++- 4 files changed, 123 insertions(+), 15 deletions(-) create mode 100644 GMERemittance/Module/SendMoneyPaymentMode/User Interface/View/Cells/SendMoenyPaymentModeCollectionViewCell.swift diff --git a/GMERemittance.xcodeproj/project.pbxproj b/GMERemittance.xcodeproj/project.pbxproj index b8187f55..1e0c32e5 100644 --- a/GMERemittance.xcodeproj/project.pbxproj +++ b/GMERemittance.xcodeproj/project.pbxproj @@ -343,6 +343,7 @@ D9DAFE2521352F3300483E71 /* SenMoneyPaymentModeRecipientViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D9DAFE2421352F3300483E71 /* SenMoneyPaymentModeRecipientViewModel.swift */; }; D9DAFE27213530A800483E71 /* PaymentModeRecipientViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D9DAFE26213530A800483E71 /* PaymentModeRecipientViewModel.swift */; }; D9DAFE2921353D6C00483E71 /* SendMoneyPaymentModeModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D9DAFE2821353D6C00483E71 /* SendMoneyPaymentModeModel.swift */; }; + D9DAFE2C21354D8900483E71 /* SendMoenyPaymentModeCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D9DAFE2B21354D8900483E71 /* SendMoenyPaymentModeCollectionViewCell.swift */; }; D9E57945212E938D00D47AC0 /* ExchangeRateDetailModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D9E57944212E938D00D47AC0 /* ExchangeRateDetailModel.swift */; }; EBFC1719B80F43F88EB01F69 /* Pods_GMERemittanceTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0380AEB198AADC0BC4394515 /* Pods_GMERemittanceTests.framework */; }; FF29296C212B8DFE00FF5BAC /* ExchangeRateCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF29296B212B8DFE00FF5BAC /* ExchangeRateCollectionViewCell.swift */; }; @@ -718,6 +719,7 @@ D9DAFE2421352F3300483E71 /* SenMoneyPaymentModeRecipientViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SenMoneyPaymentModeRecipientViewModel.swift; sourceTree = ""; }; D9DAFE26213530A800483E71 /* PaymentModeRecipientViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaymentModeRecipientViewModel.swift; sourceTree = ""; }; D9DAFE2821353D6C00483E71 /* SendMoneyPaymentModeModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SendMoneyPaymentModeModel.swift; sourceTree = ""; }; + D9DAFE2B21354D8900483E71 /* SendMoenyPaymentModeCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SendMoenyPaymentModeCollectionViewCell.swift; sourceTree = ""; }; D9E57944212E938D00D47AC0 /* ExchangeRateDetailModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExchangeRateDetailModel.swift; sourceTree = ""; }; E4028C5A57499BB54764190C /* Pods_GMERemittanceUITests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_GMERemittanceUITests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; FF29296B212B8DFE00FF5BAC /* ExchangeRateCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExchangeRateCollectionViewCell.swift; sourceTree = ""; }; @@ -1524,6 +1526,7 @@ D922D93B2135124200D43053 /* View */ = { isa = PBXGroup; children = ( + D9DAFE2A21354D2D00483E71 /* Cells */, D922D93C2135124200D43053 /* SendMoneyPaymentModeViewController.swift */, D922D93D2135124200D43053 /* ViewModels */, D922D93E2135124200D43053 /* SendMoneyPaymentMode.storyboard */, @@ -2072,6 +2075,14 @@ path = ItemPickerView; sourceTree = ""; }; + D9DAFE2A21354D2D00483E71 /* Cells */ = { + isa = PBXGroup; + children = ( + D9DAFE2B21354D8900483E71 /* SendMoenyPaymentModeCollectionViewCell.swift */, + ); + path = Cells; + sourceTree = ""; + }; FF29296A212B8DE600FF5BAC /* Cell */ = { isa = PBXGroup; children = ( @@ -2610,6 +2621,7 @@ D90D55D521327CD600EEEE04 /* AddReciepientViewInterface.swift in Sources */, A2B6CF19201469C800151863 /* EditCommentViewController.swift in Sources */, D90D55CC21327CD600EEEE04 /* AddReciepientServiceType.swift in Sources */, + D9DAFE2C21354D8900483E71 /* SendMoenyPaymentModeCollectionViewCell.swift in Sources */, A25CF60920467BA40029BC12 /* InviteViewController.swift in Sources */, D922D9AD21351B7400D43053 /* SendMoneyVerificationPresenter.swift in Sources */, A25A6C092029ADA80024CDFB /* TranscationStatementViewController.swift in Sources */, diff --git a/GMERemittance/Module/SendMoneyPaymentMode/User Interface/View/Cells/SendMoenyPaymentModeCollectionViewCell.swift b/GMERemittance/Module/SendMoneyPaymentMode/User Interface/View/Cells/SendMoenyPaymentModeCollectionViewCell.swift new file mode 100644 index 00000000..86e5c1a8 --- /dev/null +++ b/GMERemittance/Module/SendMoneyPaymentMode/User Interface/View/Cells/SendMoenyPaymentModeCollectionViewCell.swift @@ -0,0 +1,40 @@ +// +// SendMoenyPaymentModeCollectionViewCell.swift +// GMERemittance +// +// Created by gme_2 on 28/08/2018. +// Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved. +// + +import UIKit + +class SendMoenyPaymentModeCollectionViewCell: UICollectionViewCell { + @IBOutlet weak var cellBackgroundview: UIView! + @IBOutlet weak var imageview: UIImageView! + @IBOutlet weak var paymentLabel: UILabel! + + var cellSelected = false + var image: UIImage? + + var paymentServiceMethod: SendMoneyPayoutMode? + + func setup() { + self.imageview.image = image + self.paymentLabel.text = paymentServiceMethod?.mode + + self.cellBackgroundview.layer.cornerRadius = 5 + self.paymentLabel.text = self.paymentServiceMethod?.mode + cellSelected ? showBorderColor() : hideBorderColor() + + } + + private func showBorderColor() { + self.cellBackgroundview.layer.borderWidth = 1 + self.cellBackgroundview.layer.borderColor = UIColor.red.cgColor + } + + private func hideBorderColor() { + cellBackgroundview.layer.borderWidth = 0 + cellBackgroundview.layer.borderColor = UIColor.clear.cgColor + } +} diff --git a/GMERemittance/Module/SendMoneyPaymentMode/User Interface/View/SendMoneyPaymentMode.storyboard b/GMERemittance/Module/SendMoneyPaymentMode/User Interface/View/SendMoneyPaymentMode.storyboard index 7e9acdb6..60a47184 100644 --- a/GMERemittance/Module/SendMoneyPaymentMode/User Interface/View/SendMoneyPaymentMode.storyboard +++ b/GMERemittance/Module/SendMoneyPaymentMode/User Interface/View/SendMoneyPaymentMode.storyboard @@ -55,7 +55,7 @@ - + @@ -79,23 +79,14 @@ - - - - @@ -109,10 +100,9 @@ - - - - + + + @@ -129,6 +119,9 @@ + + + diff --git a/GMERemittance/Module/SendMoneyPaymentMode/User Interface/View/SendMoneyPaymentModeViewController.swift b/GMERemittance/Module/SendMoneyPaymentMode/User Interface/View/SendMoneyPaymentModeViewController.swift index cf3f6f4e..de77d656 100644 --- a/GMERemittance/Module/SendMoneyPaymentMode/User Interface/View/SendMoneyPaymentModeViewController.swift +++ b/GMERemittance/Module/SendMoneyPaymentMode/User Interface/View/SendMoneyPaymentModeViewController.swift @@ -26,6 +26,7 @@ class SendMoneyPaymentModeViewController: UIViewController { } } + var selectedPaymentIndex: IndexPath = IndexPath.init(row: 0, section: 0) // MARK: VC's Life cycle override func viewDidLoad() { @@ -48,7 +49,69 @@ class SendMoneyPaymentModeViewController: UIViewController { private func setupDelegates() { // self.collectionView.delegate = self -// self.collectionView.dataSource = self + self.collectionView.dataSource = self + } +} + +extension SendMoneyPaymentModeViewController: UICollectionViewDataSource { + func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + return 3 + } + + func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + let paymentMode = self.payoutMode?.elementAt(index: indexPath.row) + guard let index = PaymentMode.init(rawValue: paymentMode?.id ?? "") else { + return UICollectionViewCell() + + } + switch index { + case .bankDeposite: + return configureBankDepositeCell(collectionView: collectionView, indexPath: indexPath) + case .cashDelivery: + return configureCashDeliveryCell(collectionView: collectionView, indexPath: indexPath) + case .homeDelivery: + return configureHomeDeliveryCell(collectionView: collectionView, indexPath: indexPath) + + case .mobileWallet: + return configureWalletDeliveryCell(collectionView: collectionView, indexPath: indexPath) + } + + } + + func configureBankDepositeCell(collectionView: UICollectionView, indexPath: IndexPath) -> UICollectionViewCell { + let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "SendMoenyPaymentModeCollectionViewCell", for: indexPath) as! SendMoenyPaymentModeCollectionViewCell + cell.cellSelected = self.selectedPaymentIndex == indexPath + cell.paymentServiceMethod = self.payoutMode?.elementAt(index: indexPath.row) + cell.image = #imageLiteral(resourceName: "ic_bank") + cell.setup() + return cell + } + + func configureWalletDeliveryCell(collectionView: UICollectionView, indexPath: IndexPath) -> UICollectionViewCell { + let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "SendMoenyPaymentModeCollectionViewCell", for: indexPath) as! SendMoenyPaymentModeCollectionViewCell + cell.cellSelected = self.selectedPaymentIndex == indexPath + cell.paymentServiceMethod = self.payoutMode?.elementAt(index: indexPath.row) + cell.image = #imageLiteral(resourceName: "wallet-transfer") + cell.setup() + return cell + } + + func configureCashDeliveryCell(collectionView: UICollectionView, indexPath: IndexPath) -> UICollectionViewCell { + let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "SendMoenyPaymentModeCollectionViewCell", for: indexPath) as! SendMoenyPaymentModeCollectionViewCell + cell.cellSelected = self.selectedPaymentIndex == indexPath + cell.paymentServiceMethod = self.payoutMode?.elementAt(index: indexPath.row) + cell.image = #imageLiteral(resourceName: "ic_cash") + cell.setup() + return cell + } + + func configureHomeDeliveryCell(collectionView: UICollectionView, indexPath: IndexPath) -> UICollectionViewCell { + let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "SendMoenyPaymentModeCollectionViewCell", for: indexPath) as! SendMoenyPaymentModeCollectionViewCell + cell.cellSelected = self.selectedPaymentIndex == indexPath + cell.paymentServiceMethod = self.payoutMode?.elementAt(index: indexPath.row) + cell.image = #imageLiteral(resourceName: "ic_homeDelivery") + cell.setup() + return cell } }