diff --git a/Trust.xcodeproj/project.pbxproj b/Trust.xcodeproj/project.pbxproj index 17d2c1336..882d784fb 100644 --- a/Trust.xcodeproj/project.pbxproj +++ b/Trust.xcodeproj/project.pbxproj @@ -307,6 +307,7 @@ 5E7C75F80A7E178B49830BCD /* TicketsViewControllerHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C796039C0F47CDCA236C0 /* TicketsViewControllerHeader.swift */; }; 5E7C760C7D55C97424F55138 /* TicketTableViewCellViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C75F877B2F2E24C7EF258 /* TicketTableViewCellViewModel.swift */; }; 5E7C76A0365D128B7F19A0C2 /* ProtectionCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C74BEC095303B66FB4B1E /* ProtectionCoordinator.swift */; }; + 5E7C76A65C14D0F11AF7848F /* TicketRowViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C7742709724B3BD0C2A0D /* TicketRowViewModel.swift */; }; 5E7C76B917517C93D1E26B0A /* LockEnterPasscodeCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C7981AB6584B25C72D46B /* LockEnterPasscodeCoordinator.swift */; }; 5E7C76F8CB67466725C590CE /* TokenViewCellViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C79ED9F842D3FC102AC54 /* TokenViewCellViewModel.swift */; }; 5E7C7700014B93A966BBA463 /* RedeemTicketTableViewCellViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C77061BEF269BCE358086 /* RedeemTicketTableViewCellViewModel.swift */; }; @@ -317,6 +318,7 @@ 5E7C78B3FD5CA87E395E1861 /* OnboardingPageStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C7AF9A592D7224ED58016 /* OnboardingPageStyle.swift */; }; 5E7C78D6C94739B1ADDFBB5B /* WhyUseEthereumInfoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C74FABE14B7B1BEEC4F5E /* WhyUseEthereumInfoViewController.swift */; }; 5E7C797BE2C8DB7EF6F217B3 /* OnboardingPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C7103135DCCCAB96EE5FC /* OnboardingPage.swift */; }; + 5E7C798E5F5EE00D405B91AE /* TicketRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C7ACB94CEE493AC37487F /* TicketRowView.swift */; }; 5E7C7AB2ECFB589632F2A26C /* WalletFilter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C7E2DCCE0D775ECF83088 /* WalletFilter.swift */; }; 5E7C7AB6950E43BD6E8D0CBE /* TokensViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C7B3302309706CA0F972A /* TokensViewController.swift */; }; 5E7C7B3E08EEA63C5B68B9C4 /* TicketRedemptionInfoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C778F20D32B70D7FF2135 /* TicketRedemptionInfoViewController.swift */; }; @@ -785,6 +787,7 @@ 5E7C767497AD8DEE83F384D7 /* RequestViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RequestViewModel.swift; sourceTree = ""; }; 5E7C77061BEF269BCE358086 /* RedeemTicketTableViewCellViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RedeemTicketTableViewCellViewModel.swift; sourceTree = ""; }; 5E7C77316522DF2B256F1F92 /* TicketsViewControllerHeaderViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TicketsViewControllerHeaderViewModel.swift; sourceTree = ""; }; + 5E7C7742709724B3BD0C2A0D /* TicketRowViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TicketRowViewModel.swift; sourceTree = ""; }; 5E7C774BCA281E4B077DBBFA /* WhatIsEthereumInfoViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WhatIsEthereumInfoViewController.swift; sourceTree = ""; }; 5E7C778F20D32B70D7FF2135 /* TicketRedemptionInfoViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TicketRedemptionInfoViewController.swift; sourceTree = ""; }; 5E7C7821694C489D5114DB18 /* TicketsViewControllerTitleHeader.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TicketsViewControllerTitleHeader.swift; sourceTree = ""; }; @@ -798,6 +801,7 @@ 5E7C79D674D45A07E694CE31 /* LockView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LockView.swift; sourceTree = ""; }; 5E7C79ED9F842D3FC102AC54 /* TokenViewCellViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TokenViewCellViewModel.swift; sourceTree = ""; }; 5E7C7AB3440C01136DF4F3E9 /* LockCreatePasscodeCoordinator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LockCreatePasscodeCoordinator.swift; sourceTree = ""; }; + 5E7C7ACB94CEE493AC37487F /* TicketRowView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TicketRowView.swift; sourceTree = ""; }; 5E7C7AE6FAE0DF969B4F52E9 /* ContactUsBannerView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContactUsBannerView.swift; sourceTree = ""; }; 5E7C7AF9A592D7224ED58016 /* OnboardingPageStyle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OnboardingPageStyle.swift; sourceTree = ""; }; 5E7C7AFE9AF9FE6B58C925D4 /* SettingsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsViewController.swift; sourceTree = ""; }; @@ -2131,6 +2135,7 @@ children = ( 442FCD4311FCAFE6FB288A5E /* RedeemTicketTableViewCell.swift */, 5E7C7821694C489D5114DB18 /* TicketsViewControllerTitleHeader.swift */, + 5E7C7ACB94CEE493AC37487F /* TicketRowView.swift */, ); path = Views; sourceTree = ""; @@ -2142,6 +2147,7 @@ 442FC54DA900FA2F9BB73A63 /* QuantitySelectionViewModel.swift */, 442FCBDB86579889BC773540 /* TicketRedemptionViewModel.swift */, 5E7C77061BEF269BCE358086 /* RedeemTicketTableViewCellViewModel.swift */, + 5E7C7742709724B3BD0C2A0D /* TicketRowViewModel.swift */, ); path = ViewModels; sourceTree = ""; @@ -3376,6 +3382,8 @@ 5E7C728CDF33FBDBA47F71A6 /* MarketplaceViewController.swift in Sources */, 5E7C7CDB837DCD57E0594CBA /* TicketsViewControllerTitleHeader.swift in Sources */, 5E7C7700014B93A966BBA463 /* RedeemTicketTableViewCellViewModel.swift in Sources */, + 5E7C798E5F5EE00D405B91AE /* TicketRowView.swift in Sources */, + 5E7C76A65C14D0F11AF7848F /* TicketRowViewModel.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Trust/Redeem/ViewModels/RedeemTicketTableViewCellViewModel.swift b/Trust/Redeem/ViewModels/RedeemTicketTableViewCellViewModel.swift index 481f462c8..b1a309b10 100644 --- a/Trust/Redeem/ViewModels/RedeemTicketTableViewCellViewModel.swift +++ b/Trust/Redeem/ViewModels/RedeemTicketTableViewCellViewModel.swift @@ -39,54 +39,10 @@ struct RedeemTicketTableViewCellViewModel { return Colors.appWhite } - var contentsBackgroundColor: UIColor { - return Colors.appWhite - } - - var titleColor: UIColor { - return Colors.appText - } - - var countColor: UIColor { - return Colors.appHighlightGreen - } - - var subtitleColor: UIColor { - return UIColor(red: 112, green: 112, blue: 112) - } - - var iconsColor: UIColor { - return Colors.appBackground - } - - var ticketCountFont: UIFont { - return Fonts.bold(size: 21)! - } - - var titleFont: UIFont { - return Fonts.light(size: 21)! - } - - var venueFont: UIFont { - return Fonts.light(size: 18)! - } - - var subtitleFont: UIFont { - return Fonts.semibold(size: 15)! - } - var status: String { return "" } - var stateBackgroundColor: UIColor { - return UIColor(red: 151, green: 151, blue: 151) - } - - var stateColor: UIColor { - return .white - } - var cellHeight: CGFloat { return 113 } diff --git a/Trust/Redeem/ViewModels/TicketRowViewModel.swift b/Trust/Redeem/ViewModels/TicketRowViewModel.swift new file mode 100644 index 000000000..0bbb1ce79 --- /dev/null +++ b/Trust/Redeem/ViewModels/TicketRowViewModel.swift @@ -0,0 +1,53 @@ +// Copyright © 2018 Stormbird PTE. LTD. + +import UIKit + +struct TicketRowViewModel { + var backgroundColor: UIColor { + return Colors.appWhite + } + + var contentsBackgroundColor: UIColor { + return Colors.appWhite + } + + var titleColor: UIColor { + return Colors.appText + } + + var countColor: UIColor { + return Colors.appHighlightGreen + } + + var subtitleColor: UIColor { + return UIColor(red: 112, green: 112, blue: 112) + } + + var iconsColor: UIColor { + return Colors.appBackground + } + + var ticketCountFont: UIFont { + return Fonts.bold(size: 21)! + } + + var titleFont: UIFont { + return Fonts.light(size: 21)! + } + + var venueFont: UIFont { + return Fonts.light(size: 18)! + } + + var stateBackgroundColor: UIColor { + return UIColor(red: 151, green: 151, blue: 151) + } + + var stateColor: UIColor { + return .white + } + + var subtitleFont: UIFont { + return Fonts.semibold(size: 15)! + } +} diff --git a/Trust/Redeem/Views/RedeemTicketTableViewCell.swift b/Trust/Redeem/Views/RedeemTicketTableViewCell.swift index f211bbf03..706c61b45 100644 --- a/Trust/Redeem/Views/RedeemTicketTableViewCell.swift +++ b/Trust/Redeem/Views/RedeemTicketTableViewCell.swift @@ -8,94 +8,22 @@ import UIKit -//TODO Can probably merge with TicketTableViewCell and just have an flag to show/hide the checkbox class RedeemTicketTableViewCell: UITableViewCell { static let identifier = "RedeemTicketTableViewCell" - let checkboxImageView = UIImageView(image: R.image.ticket_bundle_unchecked()) - let background = UIView() - let stateLabel = UILabel() - let ticketCountLabel = UILabel() - let titleLabel = UILabel() - let venueLabel = UILabel() - let dateLabel = UILabel() - let seatRangeLabel = UILabel() - let zoneNameLabel = UILabel() - let dateImageView = UIImageView() - let seatRangeImageView = UIImageView() - let zoneNameImageView = UIImageView() + let rowView = TicketRowView(showCheckbox: true) override init(style: UITableViewCellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) - contentView.addSubview(checkboxImageView) - checkboxImageView.translatesAutoresizingMaskIntoConstraints = false - - contentView.addSubview(background) - background.translatesAutoresizingMaskIntoConstraints = false - - venueLabel.setContentHuggingPriority(.defaultLow, for: .horizontal) - - //A spacer view to take up empty horizontal space so venueLabel can be right aligned while the rest is left aligned in topRowStack - let topRowStack = UIStackView(arrangedSubviews: [ - ticketCountLabel, - titleLabel, - .spacer(), - venueLabel]) - topRowStack.axis = .horizontal - topRowStack.spacing = 15 - topRowStack.distribution = .fill - topRowStack.alignment = .center - topRowStack.setContentHuggingPriority(UILayoutPriority.required, for: .horizontal) - - let bottomRowStack = UIStackView(arrangedSubviews: [ - dateImageView, - dateLabel, - .spacerWidth(7), - seatRangeImageView, - seatRangeLabel, - .spacerWidth(7), - zoneNameImageView, - zoneNameLabel - ]) - bottomRowStack.axis = .horizontal - bottomRowStack.spacing = 7 - bottomRowStack.distribution = .fill - bottomRowStack.setContentHuggingPriority(UILayoutPriority.required, for: .horizontal) - - let stackView = UIStackView(arrangedSubviews: [ - stateLabel, - topRowStack, - bottomRowStack - ]) - stackView.translatesAutoresizingMaskIntoConstraints = false - stackView.axis = .vertical - stackView.alignment = .leading - stackView.spacing = 10 - stackView.distribution = .fill - stackView.setContentHuggingPriority(UILayoutPriority.required, for: .vertical) - background.addSubview(stackView) - - // TODO extract constant. Maybe StyleLayout.sideMargin - let xMargin = CGFloat(7) - let yMargin = CGFloat(5) - NSLayoutConstraint.activate([ - topRowStack.trailingAnchor.constraint(equalTo: stackView.trailingAnchor), - - stackView.leadingAnchor.constraint(equalTo: background.leadingAnchor, constant: 21), - stackView.trailingAnchor.constraint(equalTo: background.trailingAnchor, constant: -21), - stackView.topAnchor.constraint(equalTo: background.topAnchor, constant: 16), - stackView.bottomAnchor.constraint(lessThanOrEqualTo: background.bottomAnchor, constant: -16), + rowView.translatesAutoresizingMaskIntoConstraints = false + contentView.addSubview(rowView) - checkboxImageView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: xMargin), - checkboxImageView.centerYAnchor.constraint(equalTo: centerYAnchor), - - background.leadingAnchor.constraint(equalTo: checkboxImageView.trailingAnchor, constant: xMargin), - background.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -xMargin), - background.topAnchor.constraint(equalTo: topAnchor, constant: yMargin), - background.bottomAnchor.constraint(lessThanOrEqualTo: bottomAnchor, constant: -yMargin), - - stateLabel.heightAnchor.constraint(equalToConstant: 22), + NSLayoutConstraint.activate([ + rowView.leadingAnchor.constraint(equalTo: leadingAnchor), + rowView.trailingAnchor.constraint(equalTo: trailingAnchor), + rowView.topAnchor.constraint(equalTo: topAnchor), + rowView.bottomAnchor.constraint(equalTo:bottomAnchor), ]) } @@ -107,57 +35,25 @@ class RedeemTicketTableViewCell: UITableViewCell { selectionStyle = .none backgroundColor = viewModel.backgroundColor - checkboxImageView.image = viewModel.checkboxImage - - background.backgroundColor = viewModel.contentsBackgroundColor - background.layer.cornerRadius = 20 - background.layer.shadowRadius = 3 - background.layer.shadowColor = UIColor.black.cgColor - background.layer.shadowOffset = CGSize(width: 0, height: 0) - background.layer.shadowOpacity = 0.14 - background.layer.borderColor = UIColor.black.cgColor - - contentView.backgroundColor = viewModel.backgroundColor - - stateLabel.backgroundColor = viewModel.stateBackgroundColor - stateLabel.layer.cornerRadius = 8 - stateLabel.clipsToBounds = true - stateLabel.textColor = viewModel.stateColor - stateLabel.font = viewModel.subtitleFont - stateLabel.text = " \(viewModel.status) " - stateLabel.isHidden = viewModel.status.isEmpty - - ticketCountLabel.textColor = viewModel.countColor - ticketCountLabel.font = viewModel.ticketCountFont - ticketCountLabel.text = viewModel.ticketCount - - titleLabel.textColor = viewModel.titleColor - titleLabel.font = viewModel.titleFont - titleLabel.text = viewModel.title - - venueLabel.textColor = viewModel.titleColor - venueLabel.font = viewModel.venueFont - venueLabel.text = viewModel.venue - venueLabel.textAlignment = .right - - dateLabel.textColor = viewModel.subtitleColor - dateLabel.font = viewModel.subtitleFont - dateLabel.text = viewModel.date - - seatRangeLabel.textColor = viewModel.subtitleColor - seatRangeLabel.font = viewModel.subtitleFont - seatRangeLabel.text = viewModel.seatRange - - zoneNameLabel.textColor = viewModel.subtitleColor - zoneNameLabel.font = viewModel.subtitleFont - zoneNameLabel.text = viewModel.zoneName - - dateImageView.image = R.image.calendar()?.withRenderingMode(.alwaysTemplate) - seatRangeImageView.image = R.image.ticket()?.withRenderingMode(.alwaysTemplate) - zoneNameImageView.image = R.image.category()?.withRenderingMode(.alwaysTemplate) - - dateImageView.tintColor = viewModel.iconsColor - seatRangeImageView.tintColor = viewModel.iconsColor - zoneNameImageView.tintColor = viewModel.iconsColor + contentView.backgroundColor = viewModel.backgroundColor + + rowView.configure(viewModel: .init()) + + rowView.checkboxImageView.image = viewModel.checkboxImage + + rowView.stateLabel.text = " \(viewModel.status) " + rowView.stateLabel.isHidden = viewModel.status.isEmpty + + rowView.ticketCountLabel.text = viewModel.ticketCount + + rowView.titleLabel.text = viewModel.title + + rowView.venueLabel.text = viewModel.venue + + rowView.dateLabel.text = viewModel.date + + rowView.seatRangeLabel.text = viewModel.seatRange + + rowView.zoneNameLabel.text = viewModel.zoneName } } diff --git a/Trust/Redeem/Views/TicketRowView.swift b/Trust/Redeem/Views/TicketRowView.swift new file mode 100644 index 000000000..d2e0359a5 --- /dev/null +++ b/Trust/Redeem/Views/TicketRowView.swift @@ -0,0 +1,150 @@ +// Copyright © 2018 Stormbird PTE. LTD. + +import UIKit + +class TicketRowView: UIView { + let checkboxImageView = UIImageView(image: R.image.ticket_bundle_unchecked()) + let background = UIView() + let stateLabel = UILabel() + let ticketCountLabel = UILabel() + let titleLabel = UILabel() + let venueLabel = UILabel() + let dateLabel = UILabel() + let seatRangeLabel = UILabel() + let zoneNameLabel = UILabel() + let dateImageView = UIImageView() + let seatRangeImageView = UIImageView() + let zoneNameImageView = UIImageView() + let showCheckbox: Bool + + init(showCheckbox: Bool = false) { + self.showCheckbox = showCheckbox + + super.init(frame: .zero) + + checkboxImageView.translatesAutoresizingMaskIntoConstraints = false + if showCheckbox { + addSubview(checkboxImageView) + } + + background.translatesAutoresizingMaskIntoConstraints = false + addSubview(background) + + venueLabel.setContentHuggingPriority(.defaultLow, for: .horizontal) + + //A spacer view to take up empty horizontal space so venueLabel can be right aligned while the rest is left aligned in topRowStack + let topRowStack = UIStackView(arrangedSubviews: [ + ticketCountLabel, + titleLabel, + .spacer(), + venueLabel]) + topRowStack.axis = .horizontal + topRowStack.spacing = 15 + topRowStack.distribution = .fill + topRowStack.alignment = .center + topRowStack.setContentHuggingPriority(UILayoutPriority.required, for: .horizontal) + + let bottomRowStack = UIStackView(arrangedSubviews: [ + dateImageView, + dateLabel, + .spacerWidth(7), + seatRangeImageView, + seatRangeLabel, + .spacerWidth(7), + zoneNameImageView, + zoneNameLabel + ]) + bottomRowStack.axis = .horizontal + bottomRowStack.spacing = 7 + bottomRowStack.distribution = .fill + bottomRowStack.setContentHuggingPriority(UILayoutPriority.required, for: .horizontal) + + let stackView = UIStackView(arrangedSubviews: [ + stateLabel, + topRowStack, + bottomRowStack + ]) + stackView.translatesAutoresizingMaskIntoConstraints = false + stackView.axis = .vertical + stackView.alignment = .leading + stackView.spacing = 10 + stackView.distribution = .fill + stackView.setContentHuggingPriority(UILayoutPriority.required, for: .vertical) + background.addSubview(stackView) + + // TODO extract constant. Maybe StyleLayout.sideMargin + let xMargin = CGFloat(7) + let yMargin = CGFloat(5) + var checkboxRelatedConstraints = [NSLayoutConstraint]() + if showCheckbox { + checkboxRelatedConstraints.append(checkboxImageView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: xMargin)) + checkboxRelatedConstraints.append(checkboxImageView.centerYAnchor.constraint(equalTo: centerYAnchor)) + checkboxRelatedConstraints.append(background.leadingAnchor.constraint(equalTo: checkboxImageView.trailingAnchor, constant: xMargin)) + } else { + checkboxRelatedConstraints.append(background.leadingAnchor.constraint(equalTo: leadingAnchor, constant: xMargin)) + } + + NSLayoutConstraint.activate([ + topRowStack.trailingAnchor.constraint(equalTo: stackView.trailingAnchor), + + stackView.leadingAnchor.constraint(equalTo: background.leadingAnchor, constant: 21), + stackView.trailingAnchor.constraint(equalTo: background.trailingAnchor, constant: -21), + stackView.topAnchor.constraint(equalTo: background.topAnchor, constant: 16), + stackView.bottomAnchor.constraint(lessThanOrEqualTo: background.bottomAnchor, constant: -16), + + + background.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -xMargin), + background.topAnchor.constraint(equalTo: topAnchor, constant: yMargin), + background.bottomAnchor.constraint(lessThanOrEqualTo: bottomAnchor, constant: -yMargin), + + stateLabel.heightAnchor.constraint(equalToConstant: 22), + ] + checkboxRelatedConstraints) + } + + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + func configure(viewModel: TicketRowViewModel) { + background.backgroundColor = viewModel.contentsBackgroundColor + background.layer.cornerRadius = 20 + background.layer.shadowRadius = 3 + background.layer.shadowColor = UIColor.black.cgColor + background.layer.shadowOffset = CGSize(width: 0, height: 0) + background.layer.shadowOpacity = 0.14 + background.layer.borderColor = UIColor.black.cgColor + + stateLabel.backgroundColor = viewModel.stateBackgroundColor + stateLabel.layer.cornerRadius = 8 + stateLabel.clipsToBounds = true + stateLabel.textColor = viewModel.stateColor + stateLabel.font = viewModel.subtitleFont + + ticketCountLabel.textColor = viewModel.countColor + ticketCountLabel.font = viewModel.ticketCountFont + + titleLabel.textColor = viewModel.titleColor + titleLabel.font = viewModel.titleFont + + venueLabel.textColor = viewModel.titleColor + venueLabel.font = viewModel.venueFont + venueLabel.textAlignment = .right + + dateLabel.textColor = viewModel.subtitleColor + dateLabel.font = viewModel.subtitleFont + + seatRangeLabel.textColor = viewModel.subtitleColor + seatRangeLabel.font = viewModel.subtitleFont + + zoneNameLabel.textColor = viewModel.subtitleColor + zoneNameLabel.font = viewModel.subtitleFont + + dateImageView.image = R.image.calendar()?.withRenderingMode(.alwaysTemplate) + seatRangeImageView.image = R.image.ticket()?.withRenderingMode(.alwaysTemplate) + zoneNameImageView.image = R.image.category()?.withRenderingMode(.alwaysTemplate) + + dateImageView.tintColor = viewModel.iconsColor + seatRangeImageView.tintColor = viewModel.iconsColor + zoneNameImageView.tintColor = viewModel.iconsColor + } +} diff --git a/Trust/Tokens/ViewModels/TicketTableViewCellViewModel.swift b/Trust/Tokens/ViewModels/TicketTableViewCellViewModel.swift index 3a7ea87ae..78a052a0d 100644 --- a/Trust/Tokens/ViewModels/TicketTableViewCellViewModel.swift +++ b/Trust/Tokens/ViewModels/TicketTableViewCellViewModel.swift @@ -36,46 +36,6 @@ struct TicketTableViewCellViewModel { return Colors.appWhite } - var contentsBackgroundColor: UIColor { - return Colors.appWhite - } - - var titleColor: UIColor { - return Colors.appText - } - - var countColor: UIColor { - if ticketHolder.status == .available { - return Colors.appHighlightGreen - } else { - return UIColor(red: 155, green: 155, blue: 155) - } - } - - var subtitleColor: UIColor { - return UIColor(red: 112, green: 112, blue: 112) - } - - var iconsColor: UIColor { - if ticketHolder.status == .available { - return Colors.appBackground - } else { - return UIColor(red: 151, green: 151, blue: 151) - } - } - - var ticketCountFont: UIFont { - return Fonts.bold(size: 21)! - } - - var titleFont: UIFont { - return Fonts.light(size: 21)! - } - - var subtitleFont: UIFont { - return Fonts.semibold(size: 15)! - } - var status: String { switch ticketHolder.status { case .available: @@ -91,14 +51,6 @@ struct TicketTableViewCellViewModel { } } - var stateBackgroundColor: UIColor { - return UIColor(red: 151, green: 151, blue: 151) - } - - var stateColor: UIColor { - return .white - } - var cellHeight: CGFloat { if status.isEmpty { return 113 diff --git a/Trust/Tokens/Views/TicketTableViewCell.swift b/Trust/Tokens/Views/TicketTableViewCell.swift index b4f2e0942..71eb839f0 100644 --- a/Trust/Tokens/Views/TicketTableViewCell.swift +++ b/Trust/Tokens/Views/TicketTableViewCell.swift @@ -11,72 +11,19 @@ import UIKit class TicketTableViewCell: UITableViewCell { static let identifier = "TicketTableViewCell" - let background = UIView() - let stateLabel = UILabel() - let ticketCountLabel = UILabel() - let titleLabel = UILabel() - let dateLabel = UILabel() - let seatRangeLabel = UILabel() - let zoneNameLabel = UILabel() - let dateImageView = UIImageView() - let seatRangeImageView = UIImageView() - let zoneNameImageView = UIImageView() + let rowView = TicketRowView() override init(style: UITableViewCellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) - contentView.addSubview(background) - background.translatesAutoresizingMaskIntoConstraints = false + rowView.translatesAutoresizingMaskIntoConstraints = false + contentView.addSubview(rowView) - let topRowStack = UIStackView(arrangedSubviews: [ticketCountLabel, titleLabel]) - topRowStack.axis = .horizontal - topRowStack.spacing = 15 - topRowStack.distribution = .fill - topRowStack.setContentHuggingPriority(UILayoutPriority.required, for: .horizontal) - - let bottomRowStack = UIStackView(arrangedSubviews: [ - dateImageView, - dateLabel, - .spacerWidth(7), - seatRangeImageView, - seatRangeLabel, - .spacerWidth(7), - zoneNameImageView, - zoneNameLabel - ]) - bottomRowStack.axis = .horizontal - bottomRowStack.spacing = 7 - bottomRowStack.distribution = .fill - bottomRowStack.setContentHuggingPriority(UILayoutPriority.required, for: .horizontal) - - let stackView = UIStackView(arrangedSubviews: [ - stateLabel, - topRowStack, - bottomRowStack - ]) - stackView.translatesAutoresizingMaskIntoConstraints = false - stackView.axis = .vertical - stackView.alignment = .leading - stackView.spacing = 10 - stackView.distribution = .fill - stackView.setContentHuggingPriority(UILayoutPriority.required, for: .vertical) - background.addSubview(stackView) - - // TODO extract constant. Maybe StyleLayout.sideMargin - let xMargin = CGFloat(7) - let yMargin = CGFloat(5) NSLayoutConstraint.activate([ - stackView.leadingAnchor.constraint(equalTo: background.leadingAnchor, constant: 21), - stackView.trailingAnchor.constraint(equalTo: background.trailingAnchor, constant: -21), - stackView.topAnchor.constraint(equalTo: background.topAnchor, constant: 16), - stackView.bottomAnchor.constraint(lessThanOrEqualTo: background.bottomAnchor, constant: -16), - - background.leadingAnchor.constraint(equalTo: leadingAnchor, constant: xMargin), - background.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -xMargin), - background.topAnchor.constraint(equalTo: topAnchor, constant: yMargin), - background.bottomAnchor.constraint(lessThanOrEqualTo: bottomAnchor, constant: -yMargin), - - stateLabel.heightAnchor.constraint(equalToConstant: 22), + rowView.leadingAnchor.constraint(equalTo: leadingAnchor), + rowView.trailingAnchor.constraint(equalTo: trailingAnchor), + rowView.topAnchor.constraint(equalTo: topAnchor), + rowView.bottomAnchor.constraint(equalTo:bottomAnchor), ]) } @@ -87,51 +34,21 @@ class TicketTableViewCell: UITableViewCell { func configure(viewModel: TicketTableViewCellViewModel) { selectionStyle = .none backgroundColor = viewModel.backgroundColor + contentView.backgroundColor = viewModel.backgroundColor - background.backgroundColor = viewModel.contentsBackgroundColor - background.layer.cornerRadius = 20 - background.layer.shadowRadius = 3 - background.layer.shadowColor = UIColor.black.cgColor - background.layer.shadowOffset = CGSize(width: 0, height: 0) - background.layer.shadowOpacity = 0.14 - background.layer.borderColor = UIColor.black.cgColor - - contentView.backgroundColor = viewModel.backgroundColor - - stateLabel.backgroundColor = viewModel.stateBackgroundColor - stateLabel.layer.cornerRadius = 8 - stateLabel.clipsToBounds = true - stateLabel.textColor = viewModel.stateColor - stateLabel.font = viewModel.subtitleFont - stateLabel.text = " \(viewModel.status) " - stateLabel.isHidden = viewModel.status.isEmpty - - ticketCountLabel.textColor = viewModel.countColor - ticketCountLabel.font = viewModel.ticketCountFont - ticketCountLabel.text = viewModel.ticketCount + rowView.configure(viewModel: .init()) - titleLabel.textColor = viewModel.titleColor - titleLabel.font = viewModel.titleFont - titleLabel.text = viewModel.title + rowView.stateLabel.text = " \(viewModel.status) " + rowView.stateLabel.isHidden = viewModel.status.isEmpty - dateLabel.textColor = viewModel.subtitleColor - dateLabel.font = viewModel.subtitleFont - dateLabel.text = viewModel.date + rowView.ticketCountLabel.text = viewModel.ticketCount - seatRangeLabel.textColor = viewModel.subtitleColor - seatRangeLabel.font = viewModel.subtitleFont - seatRangeLabel.text = viewModel.seatRange + rowView.titleLabel.text = viewModel.title - zoneNameLabel.textColor = viewModel.subtitleColor - zoneNameLabel.font = viewModel.subtitleFont - zoneNameLabel.text = viewModel.zoneName + rowView.dateLabel.text = viewModel.date - dateImageView.image = R.image.calendar()?.withRenderingMode(.alwaysTemplate) - seatRangeImageView.image = R.image.ticket()?.withRenderingMode(.alwaysTemplate) - zoneNameImageView.image = R.image.category()?.withRenderingMode(.alwaysTemplate) + rowView.seatRangeLabel.text = viewModel.seatRange - dateImageView.tintColor = viewModel.iconsColor - seatRangeImageView.tintColor = viewModel.iconsColor - zoneNameImageView.tintColor = viewModel.iconsColor + rowView.zoneNameLabel.text = viewModel.zoneName } }