parent
24553624d0
commit
3b12f6e786
@ -0,0 +1,111 @@ |
||||
// Copyright © 2018 Stormbird PTE. LTD. |
||||
|
||||
import Foundation |
||||
import UIKit |
||||
import BigInt |
||||
|
||||
struct EthTokenViewCellViewModel { |
||||
private let shortFormatter = EtherNumberFormatter.short |
||||
private let token: TokenObject |
||||
let ticker: CoinTicker? |
||||
|
||||
init( |
||||
token: TokenObject, |
||||
ticker: CoinTicker? |
||||
) { |
||||
self.token = token |
||||
self.ticker = ticker |
||||
} |
||||
|
||||
var title: String { |
||||
return token.title |
||||
} |
||||
|
||||
var amount: String { |
||||
return shortFormatter.string(from: BigInt(token.value) ?? BigInt(), decimals: token.decimals) |
||||
} |
||||
|
||||
var issuer: String { |
||||
return "" |
||||
} |
||||
|
||||
var blockChainName: String { |
||||
return "Ethereum Blockchain" |
||||
} |
||||
|
||||
var backgroundColor: UIColor { |
||||
return Colors.appBackground |
||||
} |
||||
|
||||
var contentsBackgroundColor: UIColor { |
||||
return Colors.appWhite |
||||
} |
||||
|
||||
var titleColor: UIColor { |
||||
return Colors.appText |
||||
} |
||||
|
||||
var subtitleColor: UIColor { |
||||
return Colors.appBackground |
||||
} |
||||
|
||||
var borderColor: UIColor { |
||||
return UIColor(red: 236, green: 236, blue: 236) |
||||
} |
||||
|
||||
var titleFont: UIFont { |
||||
return Fonts.light(size: 25)! |
||||
} |
||||
|
||||
var subtitleFont: UIFont { |
||||
return Fonts.semibold(size: 10)! |
||||
} |
||||
|
||||
var textColor: UIColor { |
||||
return UIColor(red: 155, green: 155, blue: 155) |
||||
} |
||||
|
||||
var valuePercentageChangeColor: UIColor { |
||||
//TODO must have a different color when depreciate? |
||||
return Colors.appHighlightGreen |
||||
} |
||||
|
||||
var textValueFont: UIFont { |
||||
return Fonts.semibold(size: 15)! |
||||
} |
||||
|
||||
var textLabelFont: UIFont { |
||||
return Fonts.regular(size: 10)! |
||||
} |
||||
|
||||
var valuePercentageChangeValue: String { |
||||
//TODO read from model |
||||
return "+50%" |
||||
} |
||||
|
||||
var valuePercentageChangePeriod: String { |
||||
return R.string.localizable.aWalletContentsValuePeriodTitle() |
||||
} |
||||
|
||||
var valueChange: String { |
||||
//TODO read from model |
||||
return "$17,000" |
||||
} |
||||
|
||||
var valueChangeName: String { |
||||
return R.string.localizable.aWalletContentsValueAppreciationTitle() |
||||
} |
||||
|
||||
var value: String { |
||||
//TODO read from model |
||||
return "$51,000" |
||||
} |
||||
|
||||
var valueName: String { |
||||
return R.string.localizable.aWalletContentsValueDollarTitle() |
||||
} |
||||
|
||||
var cellHeight: CGFloat { |
||||
return 196 |
||||
} |
||||
} |
@ -0,0 +1,135 @@ |
||||
// Copyright © 2018 Stormbird PTE. LTD. |
||||
|
||||
import Foundation |
||||
import UIKit |
||||
import Kingfisher |
||||
|
||||
class EthTokenViewCell: UITableViewCell { |
||||
static let identifier = "EthTokenViewCell" |
||||
|
||||
let background = UIView() |
||||
let titleLabel = UILabel() |
||||
let blockchainLabel = UILabel() |
||||
let separator = UILabel() |
||||
let issuerLabel = UILabel() |
||||
|
||||
let middleBorder = UIView() |
||||
let valuePercentageChangeValueLabel = UILabel() |
||||
let valuePercentageChangePeriodLabel = UILabel() |
||||
let valueChangeLabel = UILabel() |
||||
let valueChangeNameLabel = UILabel() |
||||
let valueLabel = UILabel() |
||||
let valueNameLabel = UILabel() |
||||
|
||||
override init(style: UITableViewCellStyle, reuseIdentifier: String?) { |
||||
super.init(style: style, reuseIdentifier: reuseIdentifier) |
||||
|
||||
contentView.addSubview(background) |
||||
background.translatesAutoresizingMaskIntoConstraints = false |
||||
|
||||
valuePercentageChangeValueLabel.textAlignment = .center |
||||
valuePercentageChangePeriodLabel.textAlignment = .center |
||||
valueChangeLabel.textAlignment = .center |
||||
valueChangeNameLabel.textAlignment = .center |
||||
valueLabel.textAlignment = .center |
||||
valueNameLabel.textAlignment = .center |
||||
|
||||
let bottomRowStack = UIStackView(arrangedSubviews: [blockchainLabel, separator, issuerLabel]) |
||||
bottomRowStack.axis = .horizontal |
||||
bottomRowStack.spacing = 15 |
||||
bottomRowStack.distribution = .fill |
||||
|
||||
let footerValuesStack = UIStackView(arrangedSubviews: [valuePercentageChangeValueLabel, valueChangeLabel, valueLabel]) |
||||
footerValuesStack.axis = .horizontal |
||||
footerValuesStack.spacing = 15 |
||||
footerValuesStack.distribution = .fillEqually |
||||
|
||||
let footerNamesStack = UIStackView(arrangedSubviews: [valuePercentageChangePeriodLabel, valueChangeNameLabel, valueNameLabel]) |
||||
footerNamesStack.axis = .horizontal |
||||
footerNamesStack.spacing = 15 |
||||
footerNamesStack.distribution = .fillEqually |
||||
|
||||
let footerStackView = UIStackView(arrangedSubviews: [middleBorder, .spacer(height: 14), footerValuesStack, footerNamesStack]) |
||||
footerStackView.translatesAutoresizingMaskIntoConstraints = false |
||||
footerStackView.axis = .vertical |
||||
footerStackView.spacing = 0 |
||||
footerStackView.distribution = .fill |
||||
footerValuesStack.setContentHuggingPriority(.defaultLow, for: .horizontal) |
||||
|
||||
let stackView = UIStackView(arrangedSubviews: [titleLabel, bottomRowStack, footerStackView]) |
||||
stackView.translatesAutoresizingMaskIntoConstraints = false |
||||
stackView.axis = .vertical |
||||
stackView.spacing = 15 |
||||
stackView.distribution = .fill |
||||
background.addSubview(stackView) |
||||
|
||||
// TODO extract constant. Maybe StyleLayout.sideMargin |
||||
let xMargin = CGFloat(7) |
||||
let yMargin = CGFloat(20) |
||||
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), |
||||
|
||||
middleBorder.heightAnchor.constraint(equalToConstant: 1), |
||||
|
||||
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), |
||||
]) |
||||
} |
||||
|
||||
required init?(coder aDecoder: NSCoder) { |
||||
fatalError("init(coder:) has not been implemented") |
||||
} |
||||
|
||||
func configure(viewModel: EthTokenViewCellViewModel) { |
||||
selectionStyle = .none |
||||
backgroundColor = viewModel.backgroundColor |
||||
|
||||
background.backgroundColor = viewModel.contentsBackgroundColor |
||||
background.layer.cornerRadius = 20 |
||||
|
||||
contentView.backgroundColor = viewModel.backgroundColor |
||||
|
||||
titleLabel.textColor = viewModel.titleColor |
||||
titleLabel.font = viewModel.titleFont |
||||
titleLabel.text = "\(viewModel.amount) \(viewModel.title)" |
||||
|
||||
blockchainLabel.textColor = viewModel.subtitleColor |
||||
blockchainLabel.font = viewModel.subtitleFont |
||||
blockchainLabel.text = viewModel.blockChainName |
||||
|
||||
issuerLabel.textColor = viewModel.subtitleColor |
||||
issuerLabel.font = viewModel.subtitleFont |
||||
issuerLabel.text = viewModel.issuer |
||||
|
||||
separator.textColor = viewModel.subtitleColor |
||||
separator.font = viewModel.subtitleFont |
||||
separator.text = "" |
||||
|
||||
middleBorder.backgroundColor = viewModel.borderColor |
||||
|
||||
valuePercentageChangePeriodLabel.textColor = viewModel.textColor |
||||
valuePercentageChangePeriodLabel.font = viewModel.textLabelFont |
||||
valuePercentageChangePeriodLabel.text = viewModel.valuePercentageChangePeriod |
||||
valueChangeNameLabel.textColor = viewModel.textColor |
||||
valueChangeNameLabel.font = viewModel.textLabelFont |
||||
valueChangeNameLabel.text = viewModel.valueChangeName |
||||
valueNameLabel.textColor = viewModel.textColor |
||||
valueNameLabel.font = viewModel.textLabelFont |
||||
valueNameLabel.text = viewModel.valueName |
||||
|
||||
valuePercentageChangeValueLabel.textColor = viewModel.valuePercentageChangeColor |
||||
valuePercentageChangeValueLabel.font = viewModel.textValueFont |
||||
valuePercentageChangeValueLabel.text = viewModel.valuePercentageChangeValue |
||||
valueChangeLabel.textColor = viewModel.textColor |
||||
valueChangeLabel.font = viewModel.textValueFont |
||||
valueChangeLabel.text = viewModel.valueChange |
||||
valueLabel.textColor = viewModel.textColor |
||||
valueLabel.font = viewModel.textValueFont |
||||
valueLabel.text = viewModel.value |
||||
} |
||||
} |
Loading…
Reference in new issue