CNLiveTotalHotListController.swift 4.48 KB
//
//  CNLiveTotalHotListController.swift
//  metaCode
//
//  Created by zx on 2024/5/22.
//  实时热榜详情页

import Foundation

class CNLiveTotalHotListController:CNLiveBaseViewController, UICollectionViewDelegate, UICollectionViewDataSource{
    var slideModel:CNLiveDownSlideModel?

    //实时热榜的列表
    lazy var realHotArr: NSMutableArray = {
        var realHotArr = NSMutableArray()
        return realHotArr
    }()
    let kRealHotListCollectionViewCellIdentifier = "kRealHotListCollectionViewCellIdentifier"
    let kRealHotListCollectionViewImageCellIdentifier = "kRealHotListCollectionViewImageCellIdentifier"

    lazy var realHotCollectionView: UICollectionView = {
        let layout = UICollectionViewFlowLayout()
        layout.scrollDirection = .vertical
        layout.itemSize = CGSizeMake(KSreenWidth, 138+15)
        layout.sectionInset = .init(top: 0, left: 0, bottom: 0, right: 0)
        layout.minimumLineSpacing = 15
        let cv = UICollectionView(frame: .zero, collectionViewLayout: layout)
        cv.delegate = self
        cv.dataSource = self
        cv.backgroundColor = .white
        cv.register(CNLiveRealHotListDetailCell.self, forCellWithReuseIdentifier: kRealHotListCollectionViewCellIdentifier)
        cv.register(CNLiveRealHotListDetailImageCell.self, forCellWithReuseIdentifier: kRealHotListCollectionViewImageCellIdentifier)
        return cv
    }()
    
    lazy var closeBtn: UIButton = {
        let  closeBtn = UIButton(type: .custom)
        closeBtn.frame = CGRect(x: 0, y: KStatusBarHeight, width: 50, height: 30)
        closeBtn.centerY = self.titleLabel.centerY
        closeBtn.setImage(UIImage(named: "mine_header_icon_white_back"), for: .normal)
        closeBtn.addTarget(self, action: #selector(changeCancelAction), for: .touchUpInside)
        return closeBtn
    }()

    /// 初始化播放器,第多少集
    init(slideModel:CNLiveDownSlideModel?) {
        super.init(nibName:nil, bundle:nil)
        self.slideModel = slideModel
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = .white
                
        self.view.addSubview(self.realHotCollectionView)
        self.realHotCollectionView.frame = CGRect(x: 0, y: 0, width: KSreenWidth, height: KSreenHeight)
        self.realHotArr = NSMutableArray(array: self.slideModel!.contents)
        self.realHotCollectionView.reloadData()

        self.view.addSubview(self.closeBtn)
    }
    
    func initUI(){
        self.view.addSubview(self.realHotCollectionView)
    }
    
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        
        self.realHotArr.count+1
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        if indexPath.row == 0{
            let cell = collectionView.dequeueReusableCell(withReuseIdentifier: kRealHotListCollectionViewImageCellIdentifier, for: indexPath) as! CNLiveRealHotListDetailImageCell
            // 加载和设置图片到 cell.imageView
            cell.iconImgView.kf.setImage(with: URL(string: self.slideModel?.background ?? ""))
            return cell
        }else{
            let cell = collectionView.dequeueReusableCell(withReuseIdentifier: kRealHotListCollectionViewCellIdentifier, for: indexPath) as! CNLiveRealHotListDetailCell
            cell.num = indexPath.row
            // 加载和设置图片到 cell.imageView
            cell.contentsModel = self.realHotArr[indexPath.row-1] as? CNLiveDownSlideContentsModel
            return cell
        }
    }
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        if indexPath.row == 0{
        }else{
            if let contentMdl = self.realHotArr[indexPath.row-1] as? CNLiveDownSlideContentsModel{
                //实时热榜点击短剧
                CNLiveDownSlideTool.pushWebVCWithContentsMdl(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: self.slideModel)
            }
        }
    }

    
    @objc func changeCancelAction() {
        self.navigationController?.popViewController(animated: true)
    }
    
    deinit {
        
    }
}