Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // ArtistTVC.swift
- // hubble-ios
- //
- // Created by Chandan Chandan on 11/06/23.
- //
- import UIKit
- class ArtistTVC: UITableViewCell {
- private lazy var mainBgView: UIView = {
- let view = UIView()
- view.isUserInteractionEnabled = true
- view.backgroundColor = .clear
- view.corner(cornerRadius: 12)
- return view
- }()
- private lazy var bgImageView: UIImageView = {
- let imageView = UIImageView()
- imageView.image = UIImage(named: "cellbg")
- imageView.isUserInteractionEnabled = true
- imageView.backgroundColor = .clear
- return imageView
- }()
- private lazy var cellTypeNameLabel: UILabel = {
- let label = UILabel()
- label.text = "artist_home_artst".myLocalizedString
- label.textAlignment = .center
- label.isUserInteractionEnabled = true
- label.textColor = .white
- label.backgroundColor = .color111111Alpha6
- label.corner(cornerRadius: 8.0)
- label.font = .fontRegular16
- return label
- }()
- private lazy var cellTypeNameLabelBgView: UIView = {
- let view = UIView()
- view.isUserInteractionEnabled = true
- view.addSubview(cellTypeNameLabel)
- cellTypeNameLabel.snp.makeConstraints { make in
- make.center.equalTo(view)
- }
- return view
- }()
- lazy var bookmarkedImageView: UIImageView = {
- let imageView = UIImageView()
- imageView.tintColor = .white
- imageView.isUserInteractionEnabled = true
- let tap = UITapGestureRecognizer(target: self, action: #selector(saveStarButtonTapped(_:)))
- imageView.addGestureRecognizer(tap)
- return imageView
- }()
- private lazy var detailBgView: UIView = { // details
- let view = UIView()
- view.isUserInteractionEnabled = true
- view.corner(cornerRadius: 12)
- view.backgroundColor = .color111111Alpha6
- return view
- }()
- private lazy var reatingsStack: UIStackView = {
- let stack = UIStackView(arrangedSubviews: [ratingsTextlabel, reatingStarImageView])
- reatingStarImageView.snp.makeConstraints { make in
- make.width.equalTo(20)
- }
- stack.isUserInteractionEnabled = true
- stack.axis = .horizontal
- stack.spacing = 2
- stack.distribution = .fill
- stack.alignment = .fill
- return stack
- }()
- private lazy var ratingsTextlabel: UILabel = {
- let label = UILabel()
- label.textColor = .white
- label.isUserInteractionEnabled = true
- label.font = .fontLight14
- return label
- }()
- lazy var nameStack: UIStackView = {
- let stack = UIStackView(arrangedSubviews: [artistName, artistUserName])
- stack.axis = .vertical
- stack.spacing = 6
- stack.isUserInteractionEnabled = true
- stack.alignment = .fill
- stack.distribution = .fillEqually
- return stack
- }()
- private lazy var artistName: UILabel = {
- let label = UILabel()
- label.isUserInteractionEnabled = true
- label.font = .fontBold14
- return label
- }()
- private lazy var artistUserName: UILabel = {
- let label = UILabel()
- label.isUserInteractionEnabled = true
- label.font = .fontRegular14
- return label
- }()
- private lazy var priceLocationValueTextStack: UIStackView = {
- let stack = UIStackView(arrangedSubviews: [priceLocationTextStack, priceLocationValueStack])
- stack.axis = .horizontal
- stack.isUserInteractionEnabled = true
- stack.alignment = .leading
- stack.distribution = .fillEqually
- return stack
- }()
- private lazy var priceLocationTextStack: UIStackView = {
- let stack = UIStackView(arrangedSubviews: [priceText, locationText])
- stack.axis = .vertical
- stack.isUserInteractionEnabled = true
- stack.spacing = 6
- stack.alignment = .fill
- stack.distribution = .fillEqually
- return stack
- }()
- private lazy var priceLocationValueStack: UIStackView = {
- let stack = UIStackView(arrangedSubviews: [priceValue, locationValue])
- stack.axis = .vertical
- stack.isUserInteractionEnabled = true
- stack.spacing = 6
- stack.alignment = .fill
- stack.distribution = .fillEqually
- return stack
- }()
- private lazy var priceText: UILabel = {
- let label = UILabel()
- label.isUserInteractionEnabled = true
- label.text = "artist_home_price".myLocalizedString
- label.font = .fontRegular14
- return label
- }()
- private lazy var priceValue: UILabel = {
- let label = UILabel()
- label.isUserInteractionEnabled = true
- label.font = .fontBold14
- return label
- }()
- private lazy var locationText: UILabel = {
- let label = UILabel()
- label.isUserInteractionEnabled = true
- label.text = "artist_home_location".myLocalizedString
- label.font = .fontRegular14
- return label
- }()
- private lazy var locationValue: UILabel = {
- let label = UILabel()
- label.isUserInteractionEnabled = true
- label.font = .fontBold14
- return label
- }()
- private lazy var reatingStarImageView: UIImageView = {
- let imageView = UIImageView()
- imageView.image = .saveStarFill
- imageView.isUserInteractionEnabled = true
- imageView.tintColor = .yellow
- return imageView
- }()
- lazy var cellNextButton: UIButton = {
- let button = UIButton()
- button.isUserInteractionEnabled = true
- button.setImage(.arrowRight, for: .normal)
- button.tintColor = .white
- button.backgroundColor = .colorWhiteAlpha3
- button.corner(cornerRadius: 6.0)
- button.addTarget(self, action: #selector(nextButtonTapped), for: .touchUpInside)
- return button
- }()
- var starButtonHandler: ((_ index: Int) -> Void)?
- var cellNextButtonHandler: (() -> Void)?
- override func awakeFromNib() {
- super.awakeFromNib()
- // Initialization code
- }
- override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
- super.init(style: style, reuseIdentifier: reuseIdentifier)
- setupUi()
- }
- required init?(coder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
- override func setSelected(_ selected: Bool, animated: Bool) {
- super.setSelected(selected, animated: animated)
- // Configure the view for the selected state
- }
- func setupCell(data: HomeArtistModal, index: Int) {
- self.cellTypeNameLabel.text = data.userType
- self.bgImageView.image = .artistBgImage // download image with SD Web Image
- let fullName = data.showLastName ?? true ? "\(data.firstName ?? K.emptyString) \(data.lastName ?? K.emptyString)" : data.firstName ?? K.emptyString
- self.artistName.text = fullName
- self.cellNextButton.accessibilityElement(id: AccessIdentifier.artistHomeTVCNextButton + "\(index)", label: AccessLabel.artistHomeTVCNextButton.replaceString(with: fullName))
- self.bookmarkedImageView.image = data.isSaved ?? false ? UIImage.saveStarFill : UIImage.unSaveStar
- self.setAccessibilityOfSaveButton(data: data, index: index)
- self.bookmarkedImageView.tag = index
- self.artistName.accessibilityElement(id: AccessIdentifier.artistHomeTVCName + "\(index)", label: AccessLabel.artistHomeTVCName.replaceString(with: fullName ))
- self.artistUserName.text = data.userName
- self.artistUserName.accessibilityElement(id: AccessIdentifier.artistHomeTVCUserName + "\(index)", label: AccessLabel.artistHomeTVCUserName.replaceString(with: data.userName ?? K.emptyString))
- self.priceValue.text = "$\(data.price ?? .zero)"
- self.priceValue.accessibilityElement(id: AccessIdentifier.artistHomeTVCPrice + "\(index)", label: AccessLabel.artistHomeTVCPrice.replaceString(with: "$\(data.price ?? .zero)"))
- self.locationValue.text = data.primaryLocation?.address
- self.artistUserName.accessibilityElement(id: AccessIdentifier.artistHomeTVCLocation + "\(index)", label: AccessLabel.artistHomeTVCLocation.replaceString(with: data.primaryLocation?.address ?? K.emptyString))
- let ratingStar = data.rating ?? 0.0
- if ratingStar < 0.5 {
- self.reatingsStack.isHidden = true
- } else {
- self.ratingsTextlabel.text = String(data.rating ?? .zero)
- self.reatingsStack.isHidden = false
- }
- self.ratingsTextlabel.accessibilityElement(id: AccessIdentifier.artistHomeTVCReating + "\(index)", label: AccessLabel.artistHomeTVCReating.replaceString(with: data.rating ?? K.emptyString))
- }
- @objc func nextButtonTapped(_ sender: UIButton) {
- if let block = cellNextButtonHandler {
- block()
- }
- }
- func setAccessibilityOfSaveButton(data: HomeArtistModal, index: Int) {
- if !(data.isSaved ?? false) {
- bookmarkedImageView.accessibilityElement(id: AccessIdentifier.artistHomeTVCSaveButton + "\(index)", label: AccessLabel.artistHomeTVCSaveButton.replaceString(with: data.userName ?? K.emptyString))
- } else {
- bookmarkedImageView.accessibilityElement(id: AccessIdentifier.artistHomeTVCUnSaveButton + "\(index)", label: AccessLabel.artistHomeTVCUnSaveButton.replaceString(with: data.userName ?? K.emptyString))
- }
- }
- @objc func saveStarButtonTapped(_ tapGestureRecognizer: UITapGestureRecognizer) {
- guard let tappedImage = tapGestureRecognizer.view as? UIImageView else { return }
- if let block = starButtonHandler {
- block(tappedImage.tag)
- }
- }
- lazy var artistProfileImage: UIImageView = {
- let imageView = UIImageView(isImageViewerEnable: true)
- imageView.image = UIImage(named: "ratingDemoProfile")
- imageView.corner(cornerRadius: 30)
- imageView.accessibilityElement(id: AccessIdentifier.artistPersonalInfoProfileImage, label: AccessLabel.artistPersonalInfoProfileImage)
- imageView.contentMode = .scaleAspectFill
- return imageView
- }()
- private func setupUi() {
- self.contentView.isUserInteractionEnabled = true
- self.contentView.backgroundColor = .primaryColor
- self.contentView.addSubview(mainBgView)
- mainBgView.addSubview(bgImageView)
- bgImageView.addSubview(cellTypeNameLabel)
- bgImageView.addSubview(bookmarkedImageView)
- bgImageView.addSubview(detailBgView)
- detailBgView.addSubview(reatingsStack)
- detailBgView.addSubview(nameStack)
- detailBgView.addSubview(cellNextButton)
- detailBgView.addSubview(priceLocationValueTextStack)
- bgImageView.addSubview(artistProfileImage)
- mainBgView.snp.makeConstraints { make in
- make.top.equalTo(self.contentView.snp.top)
- make.bottom.equalTo(self.contentView.snp.bottom)
- make.left.equalTo(self.contentView.snp.left)
- make.right.equalTo(self.contentView.snp.right)
- }
- artistProfileImage.snp.makeConstraints { make in
- make.left.equalTo(bgImageView.left).offset(leftOffset)
- make.top.equalTo(bgImageView.top).offset(10)
- make.height.width.equalTo(60)
- }
- bgImageView.snp.makeConstraints { make in
- make.top.bottom.left.right.equalTo(mainBgView)
- }
- bookmarkedImageView.snp.makeConstraints { make in
- make.top.equalTo(bgImageView.snp.top).offset(14)
- make.right.equalTo(bgImageView.snp.right).inset(7)
- make.height.width.equalTo(24)
- }
- cellTypeNameLabel.snp.makeConstraints { make in
- make.right.equalTo(bookmarkedImageView.left).inset(-12)
- make.top.equalTo(bgImageView.snp.top).offset(10)
- make.width.equalTo(78)
- make.height.equalTo(28)
- }
- detailBgView.snp.makeConstraints { make in
- make.left.equalTo(bgImageView.snp.left).offset(16)
- make.right.equalTo(bgImageView.snp.right).inset(16)
- make.bottom.equalTo(bgImageView.snp.bottom).inset(10)
- make.height.equalTo(82)
- }
- reatingsStack.snp.makeConstraints { make in
- make.top.equalTo(detailBgView.snp.top).offset(4)
- make.left.equalTo(detailBgView.snp.left).offset(8)
- make.width.equalTo(60)
- make.height.equalTo(16)
- }
- nameStack.snp.makeConstraints { make in
- make.bottom.equalTo(detailBgView.snp.bottom).inset(12)
- make.left.equalTo(detailBgView.snp.left).offset(8)
- make.width.equalTo(96)
- }
- cellNextButton.snp.makeConstraints { make in
- make.height.width.equalTo(32)
- make.right.equalTo(detailBgView.snp.right).inset(10)
- make.centerY.equalTo(detailBgView)
- }
- priceLocationValueTextStack.snp.makeConstraints { make in
- make.left.equalTo(nameStack.snp.right).offset(20)
- make.bottom.equalTo(detailBgView.snp.bottom).inset(12)
- make.right.equalTo(cellNextButton.snp.left).inset(8)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement