CNLiveHomeTwoHengTuCell.swift 11.5 KB
//
//  CNLiveHomeTwoHengTuCell.swift
//  metaCode
//
//  Created by zx on 2025/3/14.
//  一行2横图,title subTitle
import Foundation

class CNLiveHomeTwoHengTuCell: UITableViewCell {

    //我的收藏
    var _collectionModel : [CNLiveCollectionListModel]?
    var collectionModel : [CNLiveCollectionListModel]? {
        get{
            _collectionModel
        }
        set{
            _collectionModel = newValue!
            for obj in contentView.subviews{
                obj.removeFromSuperview()
            }
            self.setupNewCollectionUI(model: _collectionModel!)
        }
    }

    //播放记录
    var _followModel : [CNLiveHomeFollowModel]?
    var followModel : [CNLiveHomeFollowModel]? {
        get{
            _followModel
        }
        set{
            _followModel = newValue!
            for obj in contentView.subviews{
                obj.removeFromSuperview()
            }
            self.setupNewFollowUI(model: _followModel!)
        }
    }

    //slideModel
    var _slideModel : [CNLiveAlbumModel]?
    var slideModel : [CNLiveAlbumModel]? {
        get{
            _slideModel
        }
        set{
            _slideModel = newValue!
            for obj in contentView.subviews{
                obj.removeFromSuperview()
            }
            setupNewUI(model: _slideModel!)
        }
    }
    

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = .none
        contentView.backgroundColor = .clear
        self.backgroundColor = .clear
        contentView.clipsToBounds = true
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupNewCollectionUI(model:[CNLiveCollectionListModel]){
        //创建cell 1-2个横版图
        for (idx,mdl) in model.enumerated(){
            let leftPadding:CGFloat = 15.0
            let imgW:CGFloat = (KSreenWidth-45.0)/2.0
            let imgH:CGFloat = imgW*93.0/165.0
            let x:CGFloat = leftPadding+(imgW+15.0)*CGFloat(idx)
            let y:CGFloat = 10.0
            let imageView = UIImageView(frame: CGRectMake(x, y, imgW, imgH))
            imageView.kf.setImage(with: URL(string:mdl.poster))
            imageView.tag = idx
            imageView.addCorner(conrners:[.topLeft,.topRight], radius: 9)
            imageView.clipsToBounds = true
            imageView.contentMode = .scaleAspectFill
            imageView.isUserInteractionEnabled = true
            imageView.addGestureRecognizer(UITapGestureRecognizer.init(target: self, action: #selector(imgTapAction)))
            contentView.addSubview(imageView)

            let payIconView = UIImageView()
            payIconView.image = UIImage(named: "home_player_pay")
            payIconView.frame = CGRect(x: 0, y: 0, width: 26, height: 15)
            imageView.addSubview(payIconView)
            payIconView.isHidden = true
            
            let grayBgView = UIView(frame: CGRect(x: imageView.left, y: imageView.bottom, width: imageView.width, height: grayH))
            grayBgView.backgroundColor = HexColor("#FAFAFA")
            grayBgView.addCorner(conrners:[.bottomLeft,.bottomRight], radius: 9)
            grayBgView.clipsToBounds = true
            contentView.addSubview(grayBgView)
            
            let titleLbl = UILabel(frame: CGRect(x: imageView.left, y: imageView.bottom+10, width: imageView.width, height: 20))
            titleLbl.font = BoldFont_14
            titleLbl.textColor = HexColor("#333333")
            titleLbl.text = mdl.title
            contentView.addSubview(titleLbl)

            let subTitleLbl = UILabel(frame: CGRect(x: titleLbl.left, y: titleLbl.bottom+3, width: titleLbl.width, height: 34))
            subTitleLbl.font = Font_12
            subTitleLbl.textColor = HexColor("#999999")
            subTitleLbl.numberOfLines = 2
            subTitleLbl.text = mdl.subTitle
            contentView.addSubview(subTitleLbl)
        }

    }

    func setupNewFollowUI(model:[CNLiveHomeFollowModel]){
        //创建cell 1-2个横版图
        for (idx,mdl) in model.enumerated(){
            let leftPadding:CGFloat = 15.0
            let imgW:CGFloat = (KSreenWidth-45.0)/2.0
            let imgH:CGFloat = imgW*93.0/165.0
            let x:CGFloat = leftPadding+(imgW+15.0)*CGFloat(idx)
            let y:CGFloat = 10.0
            let imageView = UIImageView(frame: CGRectMake(x, y, imgW, imgH))
            imageView.kf.setImage(with: URL(string:mdl.poster))
            imageView.tag = idx
            imageView.addCorner(conrners:[.topLeft,.topRight], radius: 9)
            imageView.clipsToBounds = true
            imageView.contentMode = .scaleAspectFill
            imageView.isUserInteractionEnabled = true
            imageView.addGestureRecognizer(UITapGestureRecognizer.init(target: self, action: #selector(imgTapAction)))
            contentView.addSubview(imageView)

            let payIconView = UIImageView()
            payIconView.image = UIImage(named: "home_player_pay")
            payIconView.frame = CGRect(x: 0, y: 0, width: 26, height: 15)
            imageView.addSubview(payIconView)
            
            let isPaid = CNLivePlayerTool.isShowPaidIcon(product: mdl.product)
            if isPaid{
                payIconView.isHidden = false
            }else{
                payIconView.isHidden = true
            }
            
//            if mdl.product?.productType == "2" || mdl.product?.productType == "5"{//付费
//                payIconView.isHidden = false
//            }else{
//                if mdl.product?.check == true {
//                    //免费或者付过费了
//                    payIconView.isHidden = true
//                } else {
//                    if mdl.product?.productType == "4" {
//                        //这里表示可以进行试听
//                        payIconView.isHidden = true
//                    } else {
//                        payIconView.isHidden = true
//                    }
//                }
//            }

            let grayBgView = UIView(frame: CGRect(x: imageView.left, y: imageView.bottom, width: imageView.width, height: grayH))
            grayBgView.backgroundColor = HexColor("#FAFAFA")
            grayBgView.addCorner(conrners:[.bottomLeft,.bottomRight], radius: 9)
            grayBgView.clipsToBounds = true
            contentView.addSubview(grayBgView)
            
            let titleLbl = UILabel(frame: CGRect(x: imageView.left, y: imageView.bottom+10, width: imageView.width, height: 20))
            titleLbl.font = BoldFont_14
            titleLbl.textColor = HexColor("#333333")
            titleLbl.text = mdl.title
            contentView.addSubview(titleLbl)

            let subTitleLbl = UILabel(frame: CGRect(x: titleLbl.left, y: titleLbl.bottom+3, width: titleLbl.width, height: 34))
            subTitleLbl.font = Font_12
            subTitleLbl.textColor = HexColor("#999999")
            subTitleLbl.numberOfLines = 2
            subTitleLbl.text = mdl.description
            contentView.addSubview(subTitleLbl)
        }

    }
    func setupNewUI(model:[CNLiveAlbumModel]){
        //创建cell 1-2个横版图
        for (idx,mdl) in model.enumerated(){
            let leftPadding:CGFloat = 15.0
            let imgW:CGFloat = (KSreenWidth-45.0)/2.0
            let imgH:CGFloat = imgW*93.0/165.0
            let x:CGFloat = leftPadding+(imgW+15.0)*CGFloat(idx)
            let y:CGFloat = 10.0
            let imageView = UIImageView(frame: CGRectMake(x, y, imgW, imgH))
            imageView.kf.setImage(with: URL(string:mdl.poster))
            imageView.tag = idx
            imageView.addCorner(conrners:[.topLeft,.topRight], radius: 9)
            imageView.clipsToBounds = true
            imageView.contentMode = .scaleAspectFill
            imageView.isUserInteractionEnabled = true
            imageView.addGestureRecognizer(UITapGestureRecognizer.init(target: self, action: #selector(imgTapAction)))
            contentView.addSubview(imageView)

            let payIconView = UIImageView()
            payIconView.image = UIImage(named: "home_player_pay")
            payIconView.frame = CGRect(x: 0, y: 0, width: 26, height: 15)
            imageView.addSubview(payIconView)
            
            let isPaid = CNLivePlayerTool.isShowPaidIcon(product: mdl.product)
            if isPaid{
                payIconView.isHidden = false
            }else{
                payIconView.isHidden = true
            }
            
//            if mdl.product?.productType == "2" || mdl.product?.productType == "5"{//付费
//                payIconView.isHidden = false
//            }else{
//                if mdl.product?.check == true {
//                    //免费或者付过费了
//                    payIconView.isHidden = true
//                } else {
//                    if mdl.product?.productType == "4" {
//                        //这里表示可以进行试听
//                        payIconView.isHidden = true
//                    } else {
//                        payIconView.isHidden = true
//                    }
//                }
//            }

            let grayBgView = UIView(frame: CGRect(x: imageView.left, y: imageView.bottom, width: imageView.width, height: grayH))
            grayBgView.backgroundColor = HexColor("#FAFAFA")
            grayBgView.addCorner(conrners:[.bottomLeft,.bottomRight], radius: 9)
            grayBgView.clipsToBounds = true
            contentView.addSubview(grayBgView)
            
            let titleLbl = UILabel(frame: CGRect(x: imageView.left, y: imageView.bottom+10, width: imageView.width, height: 20))
            titleLbl.font = BoldFont_14
            titleLbl.textColor = HexColor("#333333")
            titleLbl.text = mdl.title
            contentView.addSubview(titleLbl)

            let subTitleLbl = UILabel(frame: CGRect(x: titleLbl.left, y: titleLbl.bottom+3, width: titleLbl.width, height: 34))
            subTitleLbl.font = Font_12
            subTitleLbl.textColor = HexColor("#999999")
            subTitleLbl.numberOfLines = 2
            subTitleLbl.text = mdl.subTitle
            contentView.addSubview(subTitleLbl)

        }
        
    }
    
    @objc func imgTapAction(ges: UITapGestureRecognizer){
        let imageView = ges.view as! UIImageView
        let i = imageView.tag
        if let contentMdl = self.slideModel?[i]{
            CNLiveDownSlideTool.pushWebAndVodVCWithContentsMdl(model: contentMdl.model , contentId: contentMdl.contentId , pid: contentMdl.pid , shareUrl: contentMdl.shareUrl , thirdUrl: contentMdl.thirdUrl , title: contentMdl.title , s_to: contentMdl.s_to ,trailerId: contentMdl.trailerId , controller: nil, slideModel: nil)
        }else if let contentMdl = self.followModel?[i] as? CNLiveHomeFollowModel{
            CNLiveDownSlideTool.pushWebAndVodVCWithContentsMdl(model: contentMdl.modelId , contentId: contentMdl.contentId , pid: contentMdl.activeId , shareUrl: contentMdl.shareUrl , thirdUrl: contentMdl.shareUrl , title: contentMdl.title , s_to: "" ,trailerId: "" , controller: nil, slideModel: nil)
        }else if let contentMdl = self.collectionModel?[i] as? CNLiveCollectionListModel{//我的收藏
            if contentMdl.model == kCNDownSlideContentsModelModelAlbum_video{
                //专辑
                CNLiveDownSlideTool.pushVodController(albumId: contentMdl.albumId, navigationVC: navigationViewController())
            }else{
                //点播
                CNLiveDownSlideTool.pushVodController(contentId: contentMdl.contentId, navigationVC: navigationViewController(), isAblumVideo: false)

            }
        }

    }
    
}