SHARE
TWEET

Untitled

a guest Jun 16th, 2019 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  OffersViewController.swift
  3. //  finance
  4. //
  5. //  Created by David Yanez on 4/4/18.
  6. //  Copyright © 2018 creditsesame. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10.  
  11. enum CreditCardOfferType: Int {
  12.     case simple
  13.     case estimatedCreditLimit
  14. }
  15.  
  16. enum PersonalLoanOfferType: Int {
  17.     case simple
  18.     case table
  19.     case bullets
  20. }
  21.  
  22. class OffersViewController: ViewController {
  23.    
  24.     @IBOutlet weak var tableView: UITableView!
  25.     var previousVisibleCells: [UITableViewCell] = []
  26.    
  27.     override func viewDidLoad() {
  28.         super.viewDidLoad()
  29.  
  30.         tableView.register(UINib(nibName: CreditCardClickApplyCell.identifier, bundle: nil), forCellReuseIdentifier: CreditCardClickApplyCell.identifier)
  31.         tableView.register(UINib(nibName: CreditCardClickApplyCreditLimitCell.identifier, bundle: nil), forCellReuseIdentifier: CreditCardClickApplyCreditLimitCell.identifier)
  32.         tableView.register(UINib(nibName: PersonalLoanClickApplyCell.identifier, bundle: nil), forCellReuseIdentifier: PersonalLoanClickApplyCell.identifier)
  33.     }
  34.    
  35.     override func viewWillAppear(_ animated: Bool) {
  36.         super.viewWillAppear(animated)
  37.        
  38.         for offerCell in previousVisibleCells {
  39.             trackViewOffer(offerCell: offerCell)
  40.         }
  41.     }
  42.    
  43.     override func viewWillDisappear(_ animated: Bool) {
  44.         super.viewWillDisappear(animated)
  45.        
  46.         previousVisibleCells = tableView.visibleCells
  47.     }
  48.    
  49.     func trackViewOffer(offerCell: UITableViewCell?) {
  50.         if let offerCell = offerCell as? ClickApplyCell, let offer = offerCell.offer as? CreditCard {
  51.             trackViewOfferCreditCard(creditCard: offer, pagePosition: offerCell.pagePosition, pageLocation: offerCell.pageLocation, offerPosition: offerCell.cellPosition)
  52.         }
  53.         else if let offerCell = offerCell as? ClickApplyCell, let offer = offerCell.offer as? PersonalLoan {
  54.             // track Personal Loan
  55.             print("Loan tracking")
  56.         }
  57.     }
  58.    
  59.     func cellForCreditCard(creditCard: CreditCard, offerType: CreditCardOfferType) -> ClickApplyCell {
  60.  
  61.         var creditCardClickApplyView: CreditCardClickApplyView? = nil
  62.         var creditCardCell: ClickApplyCell? = nil
  63.        
  64.         switch offerType {
  65.         case .simple:
  66.            
  67.             let cell = tableView.dequeueReusableCell(withIdentifier: CreditCardClickApplyCell.identifier) as! CreditCardClickApplyCell
  68.             cell.creditCardClickApplyView.configureCreditCard(creditCard: creditCard)
  69.             creditCardClickApplyView = cell.creditCardClickApplyView
  70.             creditCardCell = cell
  71.            
  72.         case .estimatedCreditLimit:
  73.             let cell = tableView.dequeueReusableCell(withIdentifier: CreditCardClickApplyCreditLimitCell.identifier) as! CreditCardClickApplyCreditLimitCell
  74.             cell.creditCardClickApplyCreditLimitView.configureCreditCard(creditCard: creditCard)
  75.             creditCardClickApplyView = cell.creditCardClickApplyCreditLimitView.creditCardClickApplyView
  76.             creditCardCell = cell
  77.            
  78.             cell.creditCardClickApplyCreditLimitView.creditLimitToolTipPressed = { creditCard in
  79.                 self.showCreditLimitTooltip()
  80.             }
  81.         }
  82.        
  83.         creditCardClickApplyView?.ratesPressed = { applyCreditCard in
  84.             self.openRatesFess(creditCard: applyCreditCard)
  85.         }
  86.        
  87.         creditCardClickApplyView?.approvalOddsTooltipPressed = {
  88.             self.showApprovalOddsTooltip()
  89.         }
  90.         creditCardClickApplyView?.preFillTooltipPressed = {
  91.             self.showPreFillTooltip()
  92.         }
  93.            
  94.         creditCardClickApplyView?.reviewsTooltipPressed = {
  95.             self.showReviewsTooltip()
  96.         }
  97.            
  98.         creditCardClickApplyView?.applyPressed = { applyCreditCard in
  99.             self.apply(creditCard: applyCreditCard, pagePosition: creditCardCell?.pagePosition, pageLocation: nil, offerPosition: creditCardCell?.cellPosition!)
  100.         }
  101.        
  102.         creditCardClickApplyView?.reviewPressed = { applyCreditCard in
  103.             self.showCardDetails(creditCard: applyCreditCard, pagePosition: creditCardCell?.pagePosition, pageLocation: nil, offerPosition: creditCardCell?.cellPosition!)
  104.         }
  105.        
  106.         creditCardClickApplyView?.detailsPressed = { applyCreditCard in
  107.             self.showCardDetails(creditCard: applyCreditCard, pagePosition: creditCardCell?.pagePosition, pageLocation: nil, offerPosition: creditCardCell?.cellPosition!)
  108.         }
  109.        
  110.         creditCardClickApplyView?.preQualPressed = { applyCreditCard in
  111.             self.showPreQual(creditCard: applyCreditCard, pagePosition: creditCardCell?.pagePosition, pageLocation: nil, offerPosition: creditCardCell?.cellPosition!)
  112.         }
  113.        
  114.         return creditCardCell!
  115.     }
  116.    
  117.     func cellForPersonalLoan(pL: PersonalLoan, offerType: PersonalLoanOfferType) -> ClickApplyCell {
  118.        
  119.         var pLClickApplyView: PersonalLoanClickApplyView? = nil
  120.         var pLCell: ClickApplyCell? = nil
  121.        
  122.         let cell = tableView.dequeueReusableCell(withIdentifier: PersonalLoanClickApplyCell.identifier) as! PersonalLoanClickApplyCell
  123.         cell.personalLoanClickApplyView.configurePersonaLoan(personalLoan: pL, offerType: offerType)
  124.        
  125.         pLClickApplyView = cell.personalLoanClickApplyView
  126.         pLCell = cell
  127.        
  128.         pLClickApplyView?.approvalOddsTooltipPressed = {
  129.             self.showApprovalOddsTooltip()
  130.         }
  131.        
  132.         pLClickApplyView?.reviewsTooltipPressed = {
  133.             self.showReviewsTooltip()
  134.         }
  135.        
  136.         pLClickApplyView?.applyPressed = { applyPL in
  137.             self.apply(personalLoan: applyPL, pagePosition: pLCell?.pagePosition, pageLocation: pLCell?.pageLocation, offerPosition: pLCell?.cellPosition)
  138.         }
  139.        
  140.         pLClickApplyView?.detailsPressed = { applyPL in
  141.             self.showPLDetails(loan: applyPL, pagePosition: pLCell?.pagePosition, pageLocation: pLCell?.pageLocation, offerPosition: pLCell?.cellPosition)
  142.         }
  143.        
  144.         pLClickApplyView?.reviewPressed = { applyPL in
  145.             self.showPLReviews(loan: applyPL, pagePosition: pLCell?.pagePosition, pageLocation: pLCell?.pageLocation, offerPosition: pLCell?.cellPosition)
  146.         }
  147.        
  148.         pLClickApplyView?.preQualifiedPressed = { applyPL in
  149.             //TODO
  150.         }
  151.        
  152.         pLClickApplyView?.disclaimerPressed = { applyPL in
  153.             self.showPLDisclaimerTooltip(message: applyPL.disclaimer?.htmlToAttributedString(font: UIFont.lato(12), textColor: UIColor.creditSesameGrayTextColor, boldFont: UIFont.latoBold(12), italicFont: UIFont.latoItalic(12)) ?? NSAttributedString.init(string: ""))
  154.         }
  155.        
  156.         pLCell?.selectionStyle = .none
  157.         return pLCell!
  158.     }
  159.    
  160.     func numberOfOffersTill(section: Int, tableView: UITableView) -> Int {
  161.         var count = 0
  162.         for i in 0..<section {
  163.             count += tableView.numberOfRows(inSection: i)
  164.         }
  165.         return count
  166.     }
  167.    
  168.     func openCreditCards(screen: OfferPage, creditCards: [CreditCard], creditCardOfferType: CreditCardOfferType? = nil) {
  169.         let vc: CreditCardsViewController! = UIViewController.instantiateViewController(storyBoard: "Offers", identifier: "CreditCardsViewController") as! CreditCardsViewController
  170.         vc.creditCards = creditCards
  171.         if let creditCardOfferType = creditCardOfferType {
  172.             vc.creditCardOfferType = creditCardOfferType
  173.         }
  174.        
  175.         vc.offerPage = screen
  176.         creditSesameNavigationController?.pushViewController(vc, animated: true)
  177.     }
  178.    
  179.     @objc func openCreditCardsMarketplace() {
  180.         let vc = UIViewController.instantiateViewController(storyBoard: "Offers", identifier: "CreditCardsMarketplaceViewController") as! CreditCardsMarketplaceViewController
  181.         vc.creditCards = CreditSesameRestClient.shared.bestCards
  182.         creditSesameNavigationController?.pushViewController(vc, animated: true)
  183.         trackClickNavigation(navigationLocation: AnalyticsNavLocation.ccMarketplace)
  184.     }
  185.    
  186. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top