Merge pull request #371 from James-Sangalli/extract-ticket-row-display-view-model

Extract ticket row view model code
pull/377/head
James Sangalli 7 years ago committed by GitHub
commit e20a81b36b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      Trust/Redeem/ViewControllers/RedeemTicketsQuantitySelectionViewController.swift
  2. 14
      Trust/Redeem/ViewControllers/TicketRedemptionViewController.swift
  3. 35
      Trust/Redeem/ViewModels/BaseTicketTableViewCellViewModel.swift
  4. 28
      Trust/Redeem/ViewModels/RedeemTicketsQuantitySelectionViewModel.swift
  5. 28
      Trust/Redeem/ViewModels/TicketRedemptionViewModel.swift
  6. 42
      Trust/Redeem/ViewModels/TicketRowViewModel.swift
  7. 16
      Trust/Redeem/Views/TicketRowView.swift
  8. 16
      Trust/Sell/ViewControllers/EnterSellTicketsPriceQuantityViewController.swift
  9. 28
      Trust/Sell/ViewModels/EnterSellTicketsPriceQuantityViewControllerViewModel.swift
  10. 20
      Trust/Tokens/ViewModels/TicketTableViewCellViewModel.swift
  11. 18
      Trust/Tokens/Views/BaseTicketTableViewCell.swift
  12. 16
      Trust/Transfer/ViewControllers/ChooseTicketTransferModeViewController.swift
  13. 16
      Trust/Transfer/ViewControllers/SetTransferTicketsExpiryDateViewController.swift
  14. 16
      Trust/Transfer/ViewControllers/TransferTicketsQuantitySelectionViewController.swift
  15. 16
      Trust/Transfer/ViewControllers/TransferTicketsViaWalletAddressViewController.swift
  16. 28
      Trust/Transfer/ViewModels/ChooseTicketTransferModeViewControllerViewModel.swift
  17. 28
      Trust/Transfer/ViewModels/SetTransferTicketsExpiryDateViewControllerViewModel.swift
  18. 28
      Trust/Transfer/ViewModels/TransferTicketsQuantitySelectionViewModel.swift
  19. 32
      Trust/Transfer/ViewModels/TransferTicketsViaWalletAddressViewControllerViewModel.swift

@ -129,7 +129,7 @@ class RedeemTicketsQuantitySelectionViewController: UIViewController {
subtitleLabel.font = viewModel.subtitleFont
subtitleLabel.text = viewModel.subtitleText
ticketView.configure(viewModel: .init())
ticketView.configure(viewModel: .init(ticketHolder: viewModel.ticketHolder))
quantityStepper.borderWidth = 1
quantityStepper.clipsToBounds = true
@ -138,20 +138,6 @@ class RedeemTicketsQuantitySelectionViewController: UIViewController {
ticketView.stateLabel.isHidden = true
ticketView.ticketCountLabel.text = viewModel.ticketCount
ticketView.venueLabel.text = viewModel.venue
ticketView.dateLabel.text = viewModel.date
ticketView.cityLabel.text = viewModel.city
ticketView.categoryLabel.text = viewModel.category
ticketView.teamsLabel.text = viewModel.teams
ticketView.matchLabel.text = viewModel.match
nextButton.setTitleColor(viewModel.buttonTitleColor, for: .normal)
nextButton.backgroundColor = viewModel.buttonBackgroundColor
nextButton.titleLabel?.font = viewModel.buttonFont

@ -149,20 +149,8 @@ class TicketRedemptionViewController: UIViewController {
configureUI()
ticketView.configure(viewModel: .init())
ticketView.configure(viewModel: .init(ticketHolder: viewModel.ticketHolder))
ticketView.stateLabel.isHidden = true
ticketView.ticketCountLabel.text = viewModel.ticketCount
ticketView.dateLabel.text = viewModel.date
ticketView.cityLabel.text = viewModel.city
ticketView.categoryLabel.text = viewModel.category
ticketView.teamsLabel.text = viewModel.teams
ticketView.matchLabel.text = viewModel.match
}
}

@ -3,7 +3,7 @@
import UIKit
struct BaseTicketTableViewCellViewModel {
private let ticketHolder: TicketHolder
let ticketHolder: TicketHolder
init(
ticketHolder: TicketHolder
@ -11,39 +11,6 @@ struct BaseTicketTableViewCellViewModel {
self.ticketHolder = ticketHolder
}
var ticketCount: String {
return "x\(ticketHolder.tickets.count)"
}
var city: String {
return ticketHolder.city
}
var category: String {
return String(ticketHolder.category)
}
var time: String {
//TODO Should format be localized?
return ticketHolder.date.format("h:mm a", overrideWithTimezoneIdentifier: ticketHolder.timeZoneIdentifier)
}
var teams: String {
return R.string.localizable.aWalletTicketTokenMatchVs(ticketHolder.countryA, ticketHolder.countryB)
}
var match: String {
return "M\(ticketHolder.match)"
}
var venue: String {
return ticketHolder.venue
}
var date: String {
return ticketHolder.date.formatAsShortDateString(overrideWithTimezoneIdentifier: ticketHolder.timeZoneIdentifier)
}
var backgroundColor: UIColor {
return Colors.appWhite
}

@ -50,35 +50,7 @@ struct RedeemTicketsQuantitySelectionViewModel {
return Colors.appBackground
}
var ticketCount: String {
return "x\(ticketHolder.tickets.count)"
}
var city: String {
return ticketHolder.city
}
var category: String {
return String(ticketHolder.category)
}
var teams: String {
return R.string.localizable.aWalletTicketTokenMatchVs(ticketHolder.countryA, ticketHolder.countryB)
}
var match: String {
return "M\(ticketHolder.match)"
}
var venue: String {
return ticketHolder.venue
}
var subtitleText: String {
return R.string.localizable.aWalletTicketTokenRedeemQuantityTitle()
}
var date: String {
return ticketHolder.date.formatAsShortDateString(overrideWithTimezoneIdentifier: ticketHolder.timeZoneIdentifier)
}
}

@ -28,32 +28,4 @@ struct TicketRedemptionViewModel {
var backgroundColor: UIColor {
return Colors.appBackground
}
var ticketCount: String {
return "x\(ticketHolder.tickets.count)"
}
var city: String {
return ticketHolder.city
}
var category: String {
return String(ticketHolder.category)
}
var teams: String {
return R.string.localizable.aWalletTicketTokenMatchVs(ticketHolder.countryA, ticketHolder.countryB)
}
var match: String {
return "M\(ticketHolder.match)"
}
var venue: String {
return ticketHolder.venue
}
var date: String {
return ticketHolder.date.formatAsShortDateString(overrideWithTimezoneIdentifier: ticketHolder.timeZoneIdentifier)
}
}

@ -3,6 +3,8 @@
import UIKit
struct TicketRowViewModel {
var ticketHolder: TicketHolder? = nil
var backgroundColor: UIColor {
return Colors.appWhite
}
@ -58,4 +60,44 @@ struct TicketRowViewModel {
var detailsFont: UIFont {
return Fonts.light(size: 16)!
}
var ticketCount: String {
guard let ticketHolder = ticketHolder else { return "" }
return "x\(ticketHolder.tickets.count)"
}
var city: String {
guard let ticketHolder = ticketHolder else { return "" }
return ", \(ticketHolder.city)"
}
var category: String {
guard let ticketHolder = ticketHolder else { return "" }
return String(ticketHolder.category)
}
var teams: String {
guard let ticketHolder = ticketHolder else { return "" }
return R.string.localizable.aWalletTicketTokenMatchVs(ticketHolder.countryA, ticketHolder.countryB)
}
var match: String {
guard let ticketHolder = ticketHolder else { return "" }
return "M\(ticketHolder.match)"
}
var venue: String {
guard let ticketHolder = ticketHolder else { return "" }
return ticketHolder.venue
}
var date: String {
guard let ticketHolder = ticketHolder else { return "" }
return ticketHolder.date.formatAsShortDateString(overrideWithTimezoneIdentifier: ticketHolder.timeZoneIdentifier)
}
var time: String {
guard let ticketHolder = ticketHolder else { return "" }
return ticketHolder.date.format("h:mm a", overrideWithTimezoneIdentifier: ticketHolder.timeZoneIdentifier)
}
}

@ -145,5 +145,21 @@ class TicketRowView: UIView {
teamsLabel.textColor = viewModel.subtitleColor
teamsLabel.font = viewModel.subtitleFont
ticketCountLabel.text = viewModel.ticketCount
venueLabel.text = viewModel.venue
dateLabel.text = viewModel.date
timeLabel.text = viewModel.time
cityLabel.text = viewModel.city
categoryLabel.text = viewModel.category
teamsLabel.text = viewModel.teams
matchLabel.text = viewModel.match
}
}

@ -253,7 +253,7 @@ class EnterSellTicketsPriceQuantityViewController: UIViewController {
header.configure(title: viewModel.headerTitle)
ticketView.configure(viewModel: .init())
ticketView.configure(viewModel: .init(ticketHolder: viewModel.ticketHolder))
pricePerTicketLabel.textAlignment = .center
pricePerTicketLabel.textColor = viewModel.choiceLabelColor
@ -296,20 +296,6 @@ class EnterSellTicketsPriceQuantityViewController: UIViewController {
ticketView.stateLabel.isHidden = true
ticketView.ticketCountLabel.text = viewModel.ticketCount
ticketView.venueLabel.text = viewModel.venue
ticketView.dateLabel.text = viewModel.date
ticketView.cityLabel.text = viewModel.city
ticketView.categoryLabel.text = viewModel.category
ticketView.teamsLabel.text = viewModel.teams
ticketView.matchLabel.text = viewModel.match
nextButton.setTitleColor(viewModel.buttonTitleColor, for: .normal)
nextButton.backgroundColor = viewModel.buttonBackgroundColor
nextButton.titleLabel?.font = viewModel.buttonFont

@ -46,38 +46,10 @@ struct EnterSellTicketsPriceQuantityViewControllerViewModel {
return Colors.appBackground
}
var ticketCount: String {
return "x\(ticketHolder.tickets.count)"
}
var city: String {
return ticketHolder.city
}
var category: String {
return String(ticketHolder.category)
}
var teams: String {
return R.string.localizable.aWalletTicketTokenMatchVs(ticketHolder.countryA, ticketHolder.countryB)
}
var match: String {
return "M\(ticketHolder.match)"
}
var venue: String {
return ticketHolder.venue
}
var quantityLabelText: String {
return R.string.localizable.aWalletTicketTokenSellQuantityTitle()
}
var date: String {
return ticketHolder.date.formatAsShortDateString(overrideWithTimezoneIdentifier: ticketHolder.timeZoneIdentifier)
}
var pricePerTicketLabelText: String {
return R.string.localizable.aWalletTicketTokenSellPricePerTicketTitle()
}

@ -11,26 +11,6 @@ struct TicketTableViewCellViewModel {
self.ticketHolder = ticketHolder
}
var ticketCount: String {
return "x\(ticketHolder.tickets.count)"
}
var title: String {
return ticketHolder.name
}
var seatRange: String {
return ticketHolder.seatRange
}
var city: String {
return ticketHolder.city
}
var venue: String {
return ticketHolder.venue
}
var backgroundColor: UIColor {
return Colors.appWhite
}

@ -32,7 +32,7 @@ class BaseTicketTableViewCell: UITableViewCell {
contentView.backgroundColor = viewModel.backgroundColor
rowView.configure(viewModel: .init())
rowView.configure(viewModel: .init(ticketHolder: viewModel.ticketHolder))
if showCheckbox() {
rowView.checkboxImageView.image = viewModel.checkboxImage
@ -41,22 +41,6 @@ class BaseTicketTableViewCell: UITableViewCell {
rowView.stateLabel.text = " \(viewModel.status) "
rowView.stateLabel.isHidden = viewModel.status.isEmpty
rowView.ticketCountLabel.text = viewModel.ticketCount
rowView.venueLabel.text = viewModel.venue
rowView.dateLabel.text = viewModel.date
rowView.cityLabel.text = ", \(viewModel.city)"
rowView.categoryLabel.text = viewModel.category
rowView.timeLabel.text = viewModel.time
rowView.teamsLabel.text = viewModel.teams
rowView.matchLabel.text = viewModel.match
rowView.areDetailsVisible = viewModel.areDetailsVisible
}

@ -118,24 +118,10 @@ class ChooseTicketTransferModeViewController: UIViewController {
header.configure(title: viewModel.headerTitle)
ticketView.configure(viewModel: .init())
ticketView.configure(viewModel: .init(ticketHolder: ticketHolder))
ticketView.stateLabel.isHidden = true
ticketView.ticketCountLabel.text = viewModel.ticketCount
ticketView.venueLabel.text = viewModel.venue
ticketView.dateLabel.text = viewModel.date
ticketView.cityLabel.text = viewModel.city
ticketView.categoryLabel.text = viewModel.category
ticketView.teamsLabel.text = viewModel.teams
ticketView.matchLabel.text = viewModel.match
generateMagicLinkButton.setTitleColor(viewModel.buttonTitleColor, for: .normal)
generateMagicLinkButton.backgroundColor = viewModel.buttonBackgroundColor
generateMagicLinkButton.titleLabel?.font = viewModel.buttonFont

@ -239,7 +239,7 @@ class SetTransferTicketsExpiryDateViewController: UIViewController {
header.configure(title: viewModel.headerTitle)
ticketView.configure(viewModel: .init())
ticketView.configure(viewModel: .init(ticketHolder: ticketHolder))
linkExpiryDateLabel.textAlignment = .center
linkExpiryDateLabel.textColor = viewModel.choiceLabelColor
@ -253,20 +253,6 @@ class SetTransferTicketsExpiryDateViewController: UIViewController {
ticketView.stateLabel.isHidden = true
ticketView.ticketCountLabel.text = viewModel.ticketCount
ticketView.venueLabel.text = viewModel.venue
ticketView.dateLabel.text = viewModel.date
ticketView.cityLabel.text = viewModel.city
ticketView.categoryLabel.text = viewModel.category
ticketView.teamsLabel.text = viewModel.teams
ticketView.matchLabel.text = viewModel.match
descriptionLabel.textAlignment = .center
descriptionLabel.numberOfLines = 0
descriptionLabel.textColor = viewModel.descriptionLabelColor

@ -125,7 +125,7 @@ class TransferTicketsQuantitySelectionViewController: UIViewController {
subtitleLabel.font = viewModel.subtitleFont
subtitleLabel.text = viewModel.subtitleText
ticketView.configure(viewModel: .init())
ticketView.configure(viewModel: .init(ticketHolder: viewModel.ticketHolder))
quantityStepper.borderWidth = 1
quantityStepper.clipsToBounds = true
@ -134,20 +134,6 @@ class TransferTicketsQuantitySelectionViewController: UIViewController {
ticketView.stateLabel.isHidden = true
ticketView.ticketCountLabel.text = viewModel.ticketCount
ticketView.venueLabel.text = viewModel.venue
ticketView.dateLabel.text = viewModel.date
ticketView.cityLabel.text = viewModel.city
ticketView.categoryLabel.text = viewModel.category
ticketView.teamsLabel.text = viewModel.teams
ticketView.matchLabel.text = viewModel.match
nextButton.setTitleColor(viewModel.buttonTitleColor, for: .normal)
nextButton.backgroundColor = viewModel.buttonBackgroundColor
nextButton.titleLabel?.font = viewModel.buttonFont

@ -113,24 +113,10 @@ class TransferTicketsViaWalletAddressViewController: UIViewController {
header.configure(title: viewModel.headerTitle)
ticketView.configure(viewModel: .init())
ticketView.configure(viewModel: .init(ticketHolder: ticketHolder))
ticketView.stateLabel.isHidden = true
ticketView.ticketCountLabel.text = viewModel.ticketCount
ticketView.venueLabel.text = viewModel.venue
ticketView.dateLabel.text = viewModel.date
ticketView.cityLabel.text = viewModel.city
ticketView.categoryLabel.text = viewModel.category
ticketView.teamsLabel.text = viewModel.teams
ticketView.matchLabel.text = viewModel.match
targetAddressTextField.label.text = R.string.localizable.aSendRecipientAddressTitle()
targetAddressTextField.configureOnce()

@ -31,32 +31,4 @@ struct ChooseTicketTransferModeViewControllerViewModel {
return Fonts.regular(size: 16)!
}
}
var ticketCount: String {
return "x\(ticketHolder.tickets.count)"
}
var city: String {
return ticketHolder.city
}
var category: String {
return String(ticketHolder.category)
}
var teams: String {
return R.string.localizable.aWalletTicketTokenMatchVs(ticketHolder.countryA, ticketHolder.countryB)
}
var match: String {
return "M\(ticketHolder.match)"
}
var venue: String {
return ticketHolder.venue
}
var date: String {
return ticketHolder.date.formatAsShortDateString(overrideWithTimezoneIdentifier: ticketHolder.timeZoneIdentifier)
}
}

@ -28,34 +28,6 @@ struct SetTransferTicketsExpiryDateViewControllerViewModel {
return Fonts.regular(size: 20)!
}
var ticketCount: String {
return "x\(ticketHolder.tickets.count)"
}
var city: String {
return ticketHolder.city
}
var category: String {
return String(ticketHolder.category)
}
var teams: String {
return R.string.localizable.aWalletTicketTokenMatchVs(ticketHolder.countryA, ticketHolder.countryB)
}
var match: String {
return "M\(ticketHolder.match)"
}
var venue: String {
return ticketHolder.venue
}
var date: String {
return ticketHolder.date.formatAsShortDateString(overrideWithTimezoneIdentifier: ticketHolder.timeZoneIdentifier)
}
var descriptionLabelText: String {
return R.string.localizable.aWalletTicketTokenTransferMagicLinkDescriptionTitle()
}

@ -44,35 +44,7 @@ struct TransferTicketsQuantitySelectionViewModel {
return Colors.appBackground
}
var ticketCount: String {
return "x\(ticketHolder.tickets.count)"
}
var city: String {
return ticketHolder.city
}
var category: String {
return String(ticketHolder.category)
}
var teams: String {
return R.string.localizable.aWalletTicketTokenMatchVs(ticketHolder.countryA, ticketHolder.countryB)
}
var match: String {
return "M\(ticketHolder.match)"
}
var venue: String {
return ticketHolder.venue
}
var subtitleText: String {
return R.string.localizable.aWalletTicketTokenTransferQuantityTitle()
}
var date: String {
return ticketHolder.date.formatAsShortDateString(overrideWithTimezoneIdentifier: ticketHolder.timeZoneIdentifier)
}
}

@ -27,36 +27,4 @@ struct TransferTicketsViaWalletAddressViewControllerViewModel {
var buttonFont: UIFont {
return Fonts.regular(size: 20)!
}
var ticketCount: String {
return "x\(ticketHolder.tickets.count)"
}
var seatRange: String {
return ticketHolder.seatRange
}
var city: String {
return ticketHolder.city
}
var category: String {
return String(ticketHolder.category)
}
var teams: String {
return R.string.localizable.aWalletTicketTokenMatchVs(ticketHolder.countryA, ticketHolder.countryB)
}
var match: String {
return "M\(ticketHolder.match)"
}
var venue: String {
return ticketHolder.venue
}
var date: String {
return ticketHolder.date.formatAsShortDateString(overrideWithTimezoneIdentifier: ticketHolder.timeZoneIdentifier)
}
}

Loading…
Cancel
Save