Files
raspberry/iOS/Wallet/Sources/P2P/View/DealOrderOwnerView.swift

129 lines
5.4 KiB
Swift

//
// OrderOwnerView.swift
// Wallet
//
// Created by grigori on 3.11.2021.
// Copyright © 2021 AM. All rights reserved.
//
import Foundation
import UIKit
class OrderOvnewView: UIView {
let topImageView = UIImageView()
let ownerTextLbl = UILabel()
let ratingLbl = UILabel()
let chatImage = UIButton()
let chatLabel = UILabel()
let dateLabel = UILabel()
let dateValue = UILabel()
let numberLabel = UILabel()
let numberValue = UILabel()
var openChat: (() -> Void)?
override init(frame: CGRect) {
super.init(frame: frame)
setupViews()
}
required init?(coder: NSCoder) {
super.init(coder: coder)
setupViews()
chatImage.addAction(for: .touchUpInside) { [weak self] in
self?.openChat?()
}
let tap = UITapGestureRecognizer(target: self, action: #selector(chat))
chatLabel.isUserInteractionEnabled = true
chatLabel.addGestureRecognizer(tap)
}
private func setupViews() {
addSubview(topImageView)
addSubview(ownerTextLbl)
addSubview(ratingLbl)
addSubview(chatLabel)
addSubview(chatImage)
addSubview(dateLabel)
addSubview(dateValue)
addSubview(numberLabel)
addSubview(numberValue)
topImageView.layer.cornerRadius = 11
layer.masksToBounds = false
layer.cornerRadius = 16
layer.shadowColor = UIColor.black.cgColor
layer.shadowOpacity = 0.10
layer.shadowRadius = 4.0
layer.shadowOffset = CGSize(width: 0, height: 0)
let line = UIView()
line.backgroundColor = Asset.fog.color
addSubview(line)
subviews.forEach { $0.translatesAutoresizingMaskIntoConstraints = false }
UIView.activate(constraints: [
heightAnchor.constraint(equalToConstant: 100),
topImageView.topAnchor.constraint(equalTo: topAnchor, constant: 16),
topImageView.leftAnchor.constraint(equalTo: leftAnchor, constant: 14),
topImageView.heightAnchor.constraint(equalToConstant: 22),
topImageView.widthAnchor.constraint(equalToConstant: 22),
ownerTextLbl.topAnchor.constraint(equalTo: topAnchor, constant: 12),
ownerTextLbl.leftAnchor.constraint(equalTo: topImageView.rightAnchor, constant: 8),
ratingLbl.topAnchor.constraint(equalTo: topAnchor, constant: 28),
ratingLbl.leftAnchor.constraint(equalTo: topImageView.rightAnchor, constant: 8),
chatLabel.topAnchor.constraint(equalTo: topAnchor, constant: 18),
chatLabel.rightAnchor.constraint(equalTo: rightAnchor, constant: -15),
chatLabel.heightAnchor.constraint(equalToConstant: 20),
chatImage.topAnchor.constraint(equalTo: topAnchor, constant: 22),
chatImage.rightAnchor.constraint(equalTo: chatLabel.leftAnchor, constant: -3),
chatImage.heightAnchor.constraint(equalToConstant: 16),
chatImage.widthAnchor.constraint(equalToConstant: 16),
line.heightAnchor.constraint(equalToConstant: 1),
line.topAnchor.constraint(equalTo: topAnchor, constant: 52),
line.leftAnchor.constraint(equalTo: leftAnchor, constant: 14),
line.rightAnchor.constraint(equalTo: rightAnchor, constant: -14),
dateLabel.topAnchor.constraint(equalTo: topAnchor, constant: 62),
dateLabel.leftAnchor.constraint(equalTo: leftAnchor, constant: 14),
dateValue.topAnchor.constraint(equalTo: topAnchor, constant: 60),
dateValue.leftAnchor.constraint(equalTo: dateLabel.rightAnchor, constant: 8),
numberLabel.topAnchor.constraint(equalTo: topAnchor, constant: 78),
numberLabel.leftAnchor.constraint(equalTo: leftAnchor, constant: 14),
numberValue.topAnchor.constraint(equalTo: topAnchor, constant: 76),
numberValue.leftAnchor.constraint(equalTo: numberLabel.rightAnchor, constant: 8)
])
}
@objc func chat() {
self.openChat?()
}
func update(order: P2POrder) {
topImageView.image = Asset.p2pUser.image
ownerTextLbl.attributedText = order.owner.attributed(named: "bold_12", color: Asset.deepWater.color)
if let requests = order.rating?.requests {
let rating = ((order.rating?.rating ?? 0) * 100.0).toReadebleString(precisionMax: 0)
ratingLbl.attributedText = L10n.P2p.Dashboard.Order.rating("\(requests)", "\(rating)").attributed(named: "regular_10", color: Asset.textDryGranite.color)
} else {
ratingLbl.lzText = " "
}
chatImage.setImage(Asset.p2pChat.image, for: .normal)
chatLabel.attributedText = L10n.P2p.Dashboard.Order.Action.chat.attributed(style: .medium, size: 14, color: Asset.deepWater.color)
dateLabel.attributedText = L10n.P2p.Dashboard.Order.date.attributed(named: "regular_10", color: Asset.textDryGranite.color)
numberLabel.attributedText = L10n.P2p.Dashboard.Order.number.attributed(named: "regular_10", color: Asset.textDryGranite.color)
dateValue.attributedText = order.createdAt.string(date: .medium, time: .short).attributed(named: "medium_12", color: Asset.textDryGranite.color)
numberValue.attributedText = "# \(order.id)".attributed(named: "medium_12", color: Asset.textDryGranite.color)
}
}