Skip to content

Instantly share code, notes, and snippets.

@FabiolaRamirez
Created June 5, 2019 18:26
Show Gist options
  • Save FabiolaRamirez/c28577d712d12feabd52d1eddfe67cc5 to your computer and use it in GitHub Desktop.
Save FabiolaRamirez/c28577d712d12feabd52d1eddfe67cc5 to your computer and use it in GitHub Desktop.
//
// OffersViewController.swift
// finance
//
// Created by David Yanez on 4/4/18.
// Copyright © 2018 creditsesame. All rights reserved.
//
import UIKit
enum CreditCardOfferType: Int {
case simple
case estimatedCreditLimit
}
enum PersonalLoanOfferType: Int {
case simple
case table
case bullets
}
class OffersViewController: ViewController {
@IBOutlet weak var tableView: UITableView!
var previousVisibleCells: [UITableViewCell] = []
override func viewDidLoad() {
super.viewDidLoad()
tableView.register(UINib(nibName: CreditCardClickApplyCell.identifier, bundle: nil), forCellReuseIdentifier: CreditCardClickApplyCell.identifier)
tableView.register(UINib(nibName: CreditCardClickApplyCreditLimitCell.identifier, bundle: nil), forCellReuseIdentifier: CreditCardClickApplyCreditLimitCell.identifier)
tableView.register(UINib(nibName: PersonalLoanClickApplyCell.identifier, bundle: nil), forCellReuseIdentifier: PersonalLoanClickApplyCell.identifier)
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
for offerCell in previousVisibleCells {
trackViewOffer(offerCell: offerCell)
}
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
previousVisibleCells = tableView.visibleCells
}
func trackViewOffer(offerCell: UITableViewCell?) {
if let offerCell = offerCell as? ClickApplyCell, let offer = offerCell.offer as? CreditCard {
trackViewOfferCreditCard(creditCard: offer, pagePosition: offerCell.pagePosition, pageLocation: offerCell.pageLocation, offerPosition: offerCell.cellPosition)
}
else if let offerCell = offerCell as? ClickApplyCell, let offer = offerCell.offer as? PersonalLoan {
// track Personal Loan
print("Loan tracking")
}
}
func cellForCreditCard(creditCard: CreditCard, offerType: CreditCardOfferType) -> ClickApplyCell {
var creditCardClickApplyView: CreditCardClickApplyView? = nil
var creditCardCell: ClickApplyCell? = nil
switch offerType {
case .simple:
let cell = tableView.dequeueReusableCell(withIdentifier: CreditCardClickApplyCell.identifier) as! CreditCardClickApplyCell
cell.creditCardClickApplyView.configureCreditCard(creditCard: creditCard)
creditCardClickApplyView = cell.creditCardClickApplyView
creditCardCell = cell
case .estimatedCreditLimit:
let cell = tableView.dequeueReusableCell(withIdentifier: CreditCardClickApplyCreditLimitCell.identifier) as! CreditCardClickApplyCreditLimitCell
cell.creditCardClickApplyCreditLimitView.configureCreditCard(creditCard: creditCard)
creditCardClickApplyView = cell.creditCardClickApplyCreditLimitView.creditCardClickApplyView
creditCardCell = cell
cell.creditCardClickApplyCreditLimitView.creditLimitToolTipPressed = { creditCard in
self.showCreditLimitTooltip()
}
}
creditCardClickApplyView?.ratesPressed = { applyCreditCard in
self.openRatesFess(creditCard: applyCreditCard)
}
creditCardClickApplyView?.approvalOddsTooltipPressed = {
self.showApprovalOddsTooltip()
}
creditCardClickApplyView?.preFillTooltipPressed = {
self.showPreFillTooltip()
}
creditCardClickApplyView?.reviewsTooltipPressed = {
self.showReviewsTooltip()
}
creditCardClickApplyView?.applyPressed = { applyCreditCard in
self.apply(creditCard: applyCreditCard, pagePosition: creditCardCell?.pagePosition, pageLocation: nil, offerPosition: creditCardCell?.cellPosition!)
}
creditCardClickApplyView?.reviewPressed = { applyCreditCard in
self.showCardDetails(creditCard: applyCreditCard, pagePosition: creditCardCell?.pagePosition, pageLocation: nil, offerPosition: creditCardCell?.cellPosition!)
}
creditCardClickApplyView?.detailsPressed = { applyCreditCard in
self.showCardDetails(creditCard: applyCreditCard, pagePosition: creditCardCell?.pagePosition, pageLocation: nil, offerPosition: creditCardCell?.cellPosition!)
}
creditCardClickApplyView?.preQualPressed = { applyCreditCard in
self.showPreQual(creditCard: applyCreditCard, pagePosition: creditCardCell?.pagePosition, pageLocation: nil, offerPosition: creditCardCell?.cellPosition!)
}
return creditCardCell!
}
func cellForPersonalLoan(pL: PersonalLoan, offerType: PersonalLoanOfferType) -> ClickApplyCell {
var pLClickApplyView: PersonalLoanClickApplyView? = nil
var pLCell: ClickApplyCell? = nil
let cell = tableView.dequeueReusableCell(withIdentifier: PersonalLoanClickApplyCell.identifier) as! PersonalLoanClickApplyCell
cell.personalLoanClickApplyView.configurePersonaLoan(personalLoan: pL, offerType: offerType)
pLClickApplyView = cell.personalLoanClickApplyView
pLCell = cell
pLClickApplyView?.approvalOddsTooltipPressed = {
self.showApprovalOddsTooltip()
}
pLClickApplyView?.reviewsTooltipPressed = {
self.showReviewsTooltip()
}
pLClickApplyView?.applyPressed = { applyPL in
self.apply(personalLoan: applyPL, pagePosition: pLCell?.pagePosition, pageLocation: pLCell?.pageLocation, offerPosition: pLCell?.cellPosition)
}
pLClickApplyView?.detailsPressed = { applyPL in
self.showPLDetails(loan: applyPL, pagePosition: pLCell?.pagePosition, pageLocation: pLCell?.pageLocation, offerPosition: pLCell?.cellPosition)
}
pLClickApplyView?.reviewPressed = { applyPL in
self.showPLReviews(loan: applyPL, pagePosition: pLCell?.pagePosition, pageLocation: pLCell?.pageLocation, offerPosition: pLCell?.cellPosition)
}
pLClickApplyView?.preQualifiedPressed = { applyPL in
//TODO
}
pLClickApplyView?.disclaimerPressed = { applyPL in
self.showPLDisclaimerTooltip(message: applyPL.disclaimer?.htmlToAttributedString(font: UIFont.lato(12), textColor: UIColor.creditSesameGrayTextColor, boldFont: UIFont.latoBold(12), italicFont: UIFont.latoItalic(12)) ?? NSAttributedString.init(string: ""))
}
pLCell?.selectionStyle = .none
return pLCell!
}
func numberOfOffersTill(section: Int, tableView: UITableView) -> Int {
var count = 0
for i in 0..<section {
count += tableView.numberOfRows(inSection: i)
}
return count
}
func openCreditCards(screen: OfferPage, creditCards: [CreditCard], creditCardOfferType: CreditCardOfferType? = nil) {
let vc: CreditCardsViewController! = UIViewController.instantiateViewController(storyBoard: "Offers", identifier: "CreditCardsViewController") as! CreditCardsViewController
vc.creditCards = creditCards
if let creditCardOfferType = creditCardOfferType {
vc.creditCardOfferType = creditCardOfferType
}
vc.offerPage = screen
creditSesameNavigationController?.pushViewController(vc, animated: true)
}
@objc func openCreditCardsMarketplace() {
let vc = UIViewController.instantiateViewController(storyBoard: "Offers", identifier: "CreditCardsMarketplaceViewController") as! CreditCardsMarketplaceViewController
vc.creditCards = CreditSesameRestClient.shared.bestCards
creditSesameNavigationController?.pushViewController(vc, animated: true)
trackClickNavigation(navigationLocation: AnalyticsNavLocation.ccMarketplace)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment