// // ChatBaseCell.swift // yinmeng-ios // // Created by MaiMang on 2024/2/27. // import UIKit import Reusable protocol ChatBaseCellProtocol: NSObjectProtocol { func cell(_ cell: ChatBaseCell, didTapAvatarAt model: ChatBaseObject) } class ChatBaseCell: UITableViewCell, Reusable{ weak var delegate: ChatBaseCellProtocol? var model:ChatBaseObject? { didSet { guard let _ = model else {return} layoutMessageCell() } } /// 提供子类调用 open func layoutMessageCell() { } /// 执行加载动画 open func activityStartAnimating() { guard let sendType = model?.type, sendType.rawValue == 0 else { return } guard let sendDate = model?.msg?.timestamp as? Int else { return } let nowDate = Date.getNowTimeStamp() if ((nowDate - sendDate) <= 1) { self.activityIndicatorView.isHidden = false self.activityIndicatorView.startAnimating() DispatchQueue.main.asyncAfter(deadline: .now() + 1.25) { self.activityIndicatorView.startAnimating() self.activityIndicatorView.isHidden = true } } } override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) selectionStyle = .none backgroundColor = .clear contentView.addSubview(avatarImgView) contentView.addSubview(bubbleView) contentView.addSubview(activityIndicatorView) } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } lazy var avatarImgView: UIImageView = { let imageView = UIImageView() imageView.isUserInteractionEnabled = true imageView.layer.masksToBounds = true imageView.contentMode = .scaleAspectFill return imageView }() lazy var bubbleView: UIImageView = { let imageView = UIImageView() return imageView }() lazy var activityIndicatorView: UIActivityIndicatorView = { let activityView = UIActivityIndicatorView(style: UIActivityIndicatorView.Style.medium) activityView.backgroundColor = .clear activityView.isHidden = true return activityView }() }