CNLiveMinePlayHistoryCell.swift 10.4 KB
//
//  CNLiveMinePlayHistoryCell.swift
//  metaCode
//
//  Created by zx on 2025/3/15.
//  播放记录

import Foundation
class CNLiveMinePlayHistoryCell : UITableViewCell ,UICollectionViewDelegate, UICollectionViewDataSource {
    
    lazy var albumListArr: NSMutableArray = {
        var albumListArr = NSMutableArray()
        return albumListArr
    }()
    let kCNLiveMinePlayHistoryCollectionCellIdentifier = "kCNLiveMinePlayHistoryCollectionCellIdentifier"

    lazy var realHotCollectionView: UICollectionView = {
        let layout = UICollectionViewFlowLayout()
        layout.scrollDirection = .horizontal
        layout.itemSize = CGSizeMake(165, 93+76)
        layout.sectionInset = .init(top: 0, left: 0, bottom: 0, right: 0)
        layout.minimumLineSpacing = 5
        let cv = UICollectionView(frame: .zero, collectionViewLayout: layout)
        cv.delegate = self
        cv.dataSource = self
        cv.backgroundColor = .white
        cv.showsHorizontalScrollIndicator = false
        cv.register(CNLiveMinePlayHistoryCollectionCell.self, forCellWithReuseIdentifier: kCNLiveMinePlayHistoryCollectionCellIdentifier)
        return cv
    }()

    //CNLiveHomeFollowModel
    var _followModels : [CNLiveHomeFollowModel]?
    var followModels : [CNLiveHomeFollowModel]? {
        get{
            _followModels
        }
        set{
            _followModels = newValue!
            self.setupNewUI(model: _followModels!)
        }
    }

    lazy var mainView: UIView = {
        let mainView = UIView.init()
        mainView.backgroundColor = .white
        mainView.layer.cornerRadius = 15
        mainView.layer.masksToBounds = true
        return mainView
    }()
    lazy var playIconView: UIImageView = {
        let headerView = UIImageView.init()
        headerView.backgroundColor = .clear
        headerView.image = UIImage(named: "mine_playHistory")
        headerView.contentMode = .scaleToFill
        return headerView
    }()

    lazy var nameLabel: UILabel = {
        let nameLabel = UILabel.init()
        nameLabel.textColor = .black
        nameLabel.font = BoldFont_16_Fit
        nameLabel.text = "播放记录"
        nameLabel.backgroundColor = .clear
        return nameLabel
    }()
    lazy var moreBtn: UIButton = {
        let moreBtn = UIButton.init(type: .custom)
        moreBtn.setImage(UIImage(named: "mine_list_icon_right_more"), for: .normal)
        moreBtn.layer.masksToBounds = true
        moreBtn.layer.cornerRadius = 15
        moreBtn.isUserInteractionEnabled = false
        return moreBtn
    }()
    lazy var iconImgView1 :UIImageView = {
        let imageView = UIImageView()
        imageView.tag = 1000
        imageView.layer.cornerRadius = 9
        imageView.clipsToBounds = true
        imageView.contentMode = .scaleAspectFill
        imageView.isUserInteractionEnabled = true
        imageView.addGestureRecognizer(UITapGestureRecognizer.init(target: self, action: #selector(imgTapAction)))
        return imageView
    }()
    lazy var iconImgView2 :UIImageView = {
        let imageView = UIImageView()
        imageView.tag = 1001
        imageView.layer.cornerRadius = 9
        imageView.clipsToBounds = true
        imageView.contentMode = .scaleAspectFill
        imageView.isUserInteractionEnabled = true
        imageView.addGestureRecognizer(UITapGestureRecognizer.init(target: self, action: #selector(imgTapAction)))
        return imageView
    }()

    
    lazy var lineView :UIView = {
        let bottomNavView = UIView(frame: CGRect(x: 35, y: 0, width: KSreenWidth-35*2, height: 0.5))
        bottomNavView.backgroundColor = HexColor("#EAEAEA")
        return bottomNavView
    }()
    lazy var collectionIconView: UIImageView = {
        let headerView = UIImageView.init()
        headerView.backgroundColor = .clear
        headerView.image = UIImage(named: "mine_mineCollection")
        headerView.contentMode = .scaleToFill
        return headerView
    }()

    lazy var collectionNameLabel: UILabel = {
        let nameLabel = UILabel.init()
        nameLabel.textColor = .black
        nameLabel.font = BoldFont_16_Fit
        nameLabel.text = "我的收藏"
        nameLabel.backgroundColor = .clear
        return nameLabel
    }()
    lazy var collMoreBtn: UIButton = {
        let moreBtn = UIButton.init(type: .custom)
        moreBtn.setImage(UIImage(named: "mine_list_icon_right_more"), for: .normal)
        moreBtn.layer.masksToBounds = true
        moreBtn.layer.cornerRadius = 15
        moreBtn.isUserInteractionEnabled = false
        return moreBtn
    }()
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = .none
        self.backgroundColor = .clear
        contentView.backgroundColor = .clear
        
        addSubview(mainView)
        mainView.addSubview(playIconView)
        mainView.addSubview(nameLabel)
        mainView.addSubview(moreBtn)
        mainView.addSubview(iconImgView1)
        mainView.addSubview(self.realHotCollectionView)
        self.contentView.clipsToBounds = true
//        realHotCollectionView.isHidden = true
        
        mainView.addSubview(lineView)
        mainView.addSubview(collectionIconView)
        mainView.addSubview(collectionNameLabel)
        mainView.addSubview(collMoreBtn)
        mainView.addSubview(iconImgView2)

        setupConstraints()
        
    }
    
    private func setupConstraints() {
        mainView.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.left.equalToSuperview().offset(15)
            make.right.equalToSuperview().offset(-15)
            make.top.bottom.equalToSuperview()
        }
        playIconView.snp.makeConstraints { make in
            make.left.equalTo(15)
            make.top.equalTo(15)
            make.height.equalTo(19)
            make.width.equalTo(19)
        }
        nameLabel.snp.makeConstraints { make in
            make.centerY.equalTo(playIconView.snp.centerY)
            make.left.equalTo(playIconView.snp.right).offset(10)
        }
        moreBtn.snp.makeConstraints { make in
            make.top.equalTo(0)
            make.right.equalToSuperview()
            make.height.equalTo(12+30)
            make.width.equalTo(12+30)
        }
        iconImgView1.snp.makeConstraints { make in
            make.top.left.right.equalToSuperview()
            make.height.equalTo(50)
        }

        realHotCollectionView.snp.makeConstraints { make in
            make.top.equalTo(50)
            make.left.equalTo(15)
            make.height.equalTo(56+93)
            make.right.equalToSuperview()
        }
        
        lineView.snp.makeConstraints { make in
            make.top.equalTo(self.realHotCollectionView.snp.bottom).offset(10)
            make.right.equalToSuperview().offset(-15)
            make.height.equalTo(0.5)
            make.width.equalToSuperview().offset(-30)
        }
        
        collectionIconView.snp.makeConstraints { make in
            make.left.equalTo(self.playIconView.snp.left)
            make.top.equalTo(self.lineView.snp.bottom).offset(17)
            make.height.equalTo(19)
            make.width.equalTo(19)
        }
        collectionNameLabel.snp.makeConstraints { make in
            make.centerY.equalTo(collectionIconView.snp.centerY)
            make.left.equalTo(collectionIconView.snp.right).offset(10)
        }
        collMoreBtn.snp.makeConstraints { make in
            make.centerY.equalTo(collectionIconView.snp.centerY)
            make.right.equalToSuperview()
            make.height.equalTo(12+30)
            make.width.equalTo(12+30)
        }
        iconImgView2.snp.makeConstraints { make in
            make.top.equalTo(self.lineView.snp.bottom)
            make.left.right.bottom.equalToSuperview()
        }
    }
    
    func setupNewUI(model:[CNLiveHomeFollowModel]){
        if model.count > 0{
            
        }else{
            realHotCollectionView.snp.remakeConstraints({ make in
                make.top.equalTo(40)
                make.left.equalTo(15)
                make.height.equalTo(0)
                make.right.equalToSuperview()
            })
        }
        self.albumListArr = NSMutableArray(array: model)
        self.realHotCollectionView.reloadData()
        
    }
        
    @objc func imgTapAction(ges: UITapGestureRecognizer){
        let imageView = ges.view as! UIImageView
        let i = imageView.tag-1000
        if i == 0{
            //播放记录
            let vc = CNLiveHomeMoreController()
            vc.followModels = self.followModels
            currentViewController()?.navigationController?.pushViewController(vc, animated: true)
        }else if i == 1{
            //我的收藏
            if metaAppDelegate.isLogin{
                let vc = CNLiveHomeMoreController()
                currentViewController()?.navigationController?.pushViewController(vc, animated: true)
            }else{
                metaAppDelegate.pushLoginVC()
            }
        }
    }

    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        self.albumListArr.count
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: kCNLiveMinePlayHistoryCollectionCellIdentifier, for: indexPath) as! CNLiveMinePlayHistoryCollectionCell
        cell.layer.cornerRadius = 9
        cell.clipsToBounds = true
        cell.num = indexPath.row
        //获取当前选中集数
        if indexPath.row == 0{
            cell.isJiShuSelected = true
        }else{
            cell.isJiShuSelected = false
        }
        cell.followModel = self.albumListArr[indexPath.row] as? CNLiveHomeFollowModel
        return cell
    }
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        if let contentMdl = self.albumListArr[indexPath.row] 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)
        }

    }


    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}