60 lines
1.6 KiB
Swift
60 lines
1.6 KiB
Swift
//
|
|
// P2PViewToken.swift
|
|
// Wallet
|
|
//
|
|
// Created by Igor on 03.03.2021.
|
|
// Copyright © 2021 AM. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
@IBDesignable
|
|
class P2PViewToken: UIView, CommonMenuSender {
|
|
|
|
@IBOutlet private weak var imgView: UIImageView!
|
|
@IBOutlet private weak var titleLbl: UILabel!
|
|
@IBOutlet private weak var textLbl: UILabel!
|
|
@IBOutlet private weak var badgeView: UIView!
|
|
|
|
var action: CommonMenuAction? {
|
|
didSet { update(animated: false) }
|
|
}
|
|
|
|
func update(animated: Bool) {
|
|
badgeView.isHidden = true
|
|
badgeView.layer.cornerRadius = 4
|
|
|
|
guard let menu = action?.menu else { return }
|
|
if let image = menu.image {
|
|
imgView.image = image
|
|
} else if let urls = menu.imageURLs {
|
|
downloadImage(urls: urls)
|
|
} else {
|
|
imgView.image = nil
|
|
}
|
|
|
|
if let _ = menu.badge {
|
|
badgeView.isHidden = false
|
|
}
|
|
|
|
titleLbl.attributedText = menu.title.attributed(style: .bold, size: 16, color: Asset.textCoal.color)
|
|
textLbl.attributedText = menu.text?.attributed(style: .regular, size: 10, color: Asset.textGranite.color)
|
|
}
|
|
|
|
private func downloadImage(urls: [URL]) {
|
|
if urls.isEmpty {
|
|
imgView.image = nil
|
|
} else {
|
|
imgView.af.setImage(withURL: urls.first!, completion: {
|
|
guard $0.error != nil else { return }
|
|
self.downloadImage(urls: Array(urls.dropFirst()))
|
|
})
|
|
}
|
|
}
|
|
|
|
@IBAction func onAction(_: AnyObject?) {
|
|
action?.perform(sender: self)
|
|
}
|
|
|
|
}
|