From 566e9244d822c660f5bbda9cd95f3adf33c23754 Mon Sep 17 00:00:00 2001 From: gme_2 Date: Thu, 27 Sep 2018 16:26:10 +0900 Subject: [PATCH] notification added --- .../Cell/HomeCollectionTableViewCell.swift | 61 +++++++++++++ .../View/HomeViewController.swift | 91 +++++++++++++++++-- GMERemittance/Utility/AppConstants.swift | 8 ++ GMERemittance/_Home/_HomeViewController.swift | 10 +- 4 files changed, 156 insertions(+), 14 deletions(-) diff --git a/GMERemittance/Module/Home/User Interface/View/Cell/HomeCollectionTableViewCell.swift b/GMERemittance/Module/Home/User Interface/View/Cell/HomeCollectionTableViewCell.swift index 362db278..7dcafa4d 100644 --- a/GMERemittance/Module/Home/User Interface/View/Cell/HomeCollectionTableViewCell.swift +++ b/GMERemittance/Module/Home/User Interface/View/Cell/HomeCollectionTableViewCell.swift @@ -8,10 +8,29 @@ import UIKit +struct MenuNotificationName { + static let sendMoney = "SendMoeny" + static let mobileRecharge = "mobileRecharge" + static let todaysRate = "todaysRate" + static let trackYourTransfer = "trackYourTransfer" + static let transactionStatement = "transactionStatement" + static let walletToWallet = "walletToWallet" +} + class HomeCollectionTableViewCell: UITableViewCell, UICollectionViewDelegateFlowLayout { + enum CollectionMenus: Int { + case sendMoney = 0 + case mobileRecharge + case todaysRate + case trackYourTransfer + case transationStatement + case walletToWallet + } + @IBOutlet weak var collectionView: UICollectionView! private var menus: [HomeCollectionModel]? + var parentViewController: HomeViewController? override func awakeFromNib() { super.awakeFromNib() // Initialization code @@ -72,7 +91,48 @@ class HomeCollectionTableViewCell: UITableViewCell, UICollectionViewDelegateFlow extension HomeCollectionTableViewCell: UICollectionViewDelegate { + func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + guard let index = self.menus?.elementAt(index: indexPath.row)?.index else {return} + guard let _index = CollectionMenus.init(rawValue: index) else {return } + let center = NotificationCenter.default + + switch _index { + + case .sendMoney: + center.post(name: self.getSendMoneyNotificationName(), object: nil) + case .mobileRecharge: + center.post(name: self.getMobileRechargeNotificationName(), object: nil) + case .todaysRate: + center.post(name: self.getTodaysRateNotificationName(), object: nil) + case .trackYourTransfer: + center.post(name: self.getTrackYourTransferNotificationName(), object: nil) + case .transationStatement: + center.post(name: self.getTransactionStatementNotificationName(), object: nil) + case .walletToWallet: + center.post(name: self.getWalletToWalletNotificationName(), object: nil) + } + } + + func getSendMoneyNotificationName() -> Notification.Name { + return Notification.Name.init(rawValue: MenuNotificationName.sendMoney) + } + func getMobileRechargeNotificationName() -> Notification.Name { + return Notification.Name.init(rawValue: MenuNotificationName.mobileRecharge) + } + + func getTodaysRateNotificationName() -> Notification.Name { + return Notification.Name.init(rawValue: MenuNotificationName.todaysRate) + } + func getTrackYourTransferNotificationName() -> Notification.Name { + return Notification.Name.init(rawValue: MenuNotificationName.trackYourTransfer) + } + func getTransactionStatementNotificationName() -> Notification.Name { + return Notification.Name.init(rawValue: MenuNotificationName.transactionStatement) + } + func getWalletToWalletNotificationName() -> Notification.Name { + return Notification.Name.init(rawValue: MenuNotificationName.walletToWallet) + } } extension HomeCollectionTableViewCell: UICollectionViewDataSource { @@ -91,3 +151,4 @@ extension HomeCollectionTableViewCell: UICollectionViewDataSource { } + diff --git a/GMERemittance/Module/Home/User Interface/View/HomeViewController.swift b/GMERemittance/Module/Home/User Interface/View/HomeViewController.swift index 25e99eec..fe169367 100644 --- a/GMERemittance/Module/Home/User Interface/View/HomeViewController.swift +++ b/GMERemittance/Module/Home/User Interface/View/HomeViewController.swift @@ -35,16 +35,35 @@ class HomeViewController: UIViewController, UICollectionViewDelegateFlowLayout { // MARK: IBActions + @IBAction func closeVerificationNotice(_ sender: UIButton) { + UIView.animate(withDuration: 0.33) { + self.verificationNoticeView.alpha = 0 + } + self.verificationNoticeView.isHidden = true + } + + // MARK: Other Functions private func setup() { // all setup should be done here setupDelegates() configureViews() + setupNotifications() self.setupPicturedNavBar() } + private func setupNotifications() { + let center = NotificationCenter.default + center.addObserver(self, selector: #selector(self.showSendMoney), name: self.getSendMoneyNotificationName(), object: nil) + center.addObserver(self, selector: #selector(self.showMobileRecharge), name: self.getMobileRechargeNotificationName(), object: nil) + center.addObserver(self, selector: #selector(self.showTodaysRate), name: self.getTodaysRateNotificationName(), object: nil) + center.addObserver(self, selector: #selector(self.showTrackYourTransfer), name: self.getTrackYourTransferNotificationName(), object: nil) + center.addObserver(self, selector: #selector(self.showTransactionStatement), name: self.getTransactionStatementNotificationName(), object: nil) + center.addObserver(self, selector: #selector(self.showWalletToWallet), name: self.getWalletToWalletNotificationName(), object: nil) + } + private func setupDelegates() { self.tableView.delegate = self self.tableView.dataSource = self @@ -65,19 +84,54 @@ class HomeViewController: UIViewController, UICollectionViewDelegateFlowLayout { showUnverifiedNotice() } - @IBAction func closeVerificationNotice(_ sender: UIButton) { - UIView.animate(withDuration: 0.33) { - self.verificationNoticeView.alpha = 0 - } - self.verificationNoticeView.isHidden = true - } + private func isUserVerified() -> Bool { return false let val = (UserDefaults.standard.object(forKey: UserKeys.verified) as? Bool ) ?? false print(val) return val } + + @objc private func showSendMoney() { + if !isVerifiedUser() { + let viewcontroller = UIStoryboard.init(name: + "RecipientListViewController", bundle: nil).instantiateViewController(withIdentifier: "RecipientListViewController") as! RecipientListViewController + self.navigationController?.pushViewController(viewcontroller, animated: true) + } else { + self.popUpMessage(value: 13) + } + } + + @objc private func showMobileRecharge() { + self.alert(message: "This feature is coming soon") + return + + if isUserVerified() { + self.performSegue(withIdentifier: "mobileRecharge", sender: nil) + }else { + self.popUpMessage(value: 13) + } + } + + @objc private func showTodaysRate() { + let exchangeRateWireFrame = ExchangeRatesWireframe() + if let navigation = self.navigationController { + exchangeRateWireFrame.pushMainView(in: navigation) + } + } + + @objc private func showTrackYourTransfer() { + self.performSegue(withIdentifier: "trackTransfer", sender: nil) + } + + @objc private func showTransactionStatement() { + self.performSegue(withIdentifier: "transactionStatement", sender: nil) + } + + @objc private func showWalletToWallet() { + self.alert(message: "This feature is coming soon") + } } // MARK: HomeViewInterface @@ -137,3 +191,28 @@ extension HomeViewController: UITableViewDataSource { } } + + +// notification Name +extension HomeViewController { + func getSendMoneyNotificationName() -> Notification.Name { + return Notification.Name.init(rawValue: MenuNotificationName.sendMoney) + } + + func getMobileRechargeNotificationName() -> Notification.Name { + return Notification.Name.init(rawValue: MenuNotificationName.mobileRecharge) + } + + func getTodaysRateNotificationName() -> Notification.Name { + return Notification.Name.init(rawValue: MenuNotificationName.todaysRate) + } + func getTrackYourTransferNotificationName() -> Notification.Name { + return Notification.Name.init(rawValue: MenuNotificationName.trackYourTransfer) + } + func getTransactionStatementNotificationName() -> Notification.Name { + return Notification.Name.init(rawValue: MenuNotificationName.transactionStatement) + } + func getWalletToWalletNotificationName() -> Notification.Name { + return Notification.Name.init(rawValue: MenuNotificationName.walletToWallet) + } +} diff --git a/GMERemittance/Utility/AppConstants.swift b/GMERemittance/Utility/AppConstants.swift index 947a8f6a..c54fda59 100644 --- a/GMERemittance/Utility/AppConstants.swift +++ b/GMERemittance/Utility/AppConstants.swift @@ -37,3 +37,11 @@ class Utility { return nil } } + +func isVerifiedUser() -> Bool { + return false + let val = (UserDefaults.standard.object(forKey: UserKeys.verified) as? Bool ) ?? false + print("value is") + print(val) + return val +} diff --git a/GMERemittance/_Home/_HomeViewController.swift b/GMERemittance/_Home/_HomeViewController.swift index 35ad5a87..a3993ffe 100644 --- a/GMERemittance/_Home/_HomeViewController.swift +++ b/GMERemittance/_Home/_HomeViewController.swift @@ -163,13 +163,7 @@ class _HomeViewController: UIViewController, TableViewCellDelegate, FBSDKSharin sideMenuController?.showLeftViewAnimated() } - func isVerifiedUser() -> Bool { - return false - let val = (UserDefaults.standard.object(forKey: UserKeys.verified) as? Bool ) ?? false - print("value is") - print(val) - return val - } + /** Update User data in view @@ -1370,7 +1364,7 @@ extension _HomeViewController: UICollectionViewDelegate, UICollectionViewDataSou switch collectionViewMenuIndexArray[indexPath.row] { case 0: - if self.isVerifiedUser() { + if isVerifiedUser() { // self.performSegue(withIdentifier: "recipientList", sender: nil) // RecipientListViewController // recipientList