CNLiveVodLandscapeXuanjiView.swift 15.9 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412
//
//  CNLiveVodLandscapeXuanjiView.swift
//  metaCode
//
//  Created by zx on 2025/3/28.
//
//  横屏选集

import Foundation

//专辑选择某一集
typealias CNLiveVodPlayerLandscapeXuanjiUpdateBlock = (_ jishuIndex:Int,_ albumModel:CNLiveVodAlbumListModel)->Void
//看点选择某一集
typealias CNLiveVodPlayerLandscapeXuanjiKanDianSelectBlock = (_ kanDianIndex:Int,_ vodPlayBlockListListModel:CNLiveVodPlayBlockListListModel)->Void

class CNLiveVodLandscapeXuanjiView:UIView, UITableViewDataSource, UITableViewDelegate,UIGestureRecognizerDelegate{//, UICollectionViewDelegate, UICollectionViewDataSource{
    
    var currSeleIdx = 0
//    var selectBlock:CNLiveVodAlbumListCellSelectBlock?
    var xuanjiUpdateBlock:CNLiveVodPlayerLandscapeXuanjiUpdateBlock?
    var vodPlayerLandscapeXuanjiKanDianSelectBlock:CNLiveVodPlayerLandscapeXuanjiKanDianSelectBlock?
//    //实时热榜的列表
//    lazy var albumListArr: NSMutableArray = {
//        var albumListArr = NSMutableArray()
//        return albumListArr
//    }()
//    let kCNLiveVodAlbumListCollectionCellIdentifier = "kCNLiveVodAlbumListCollectionCellIdentifier"
//
//    lazy var realHotCollectionView: UICollectionView = {
//        let layout = UICollectionViewFlowLayout()
//        layout.scrollDirection = .horizontal
//        layout.itemSize = CGSizeMake(50, 50)
//        layout.sectionInset = .init(top: 0, left: 0, bottom: 0, right: 0)
//        layout.minimumLineSpacing = 13.5
//        let cv = UICollectionView(frame: .zero, collectionViewLayout: layout)
//        cv.delegate = self
//        cv.dataSource = self
//        cv.backgroundColor = .red//.clear
//        cv.showsHorizontalScrollIndicator = false
//        cv.register(CNLiveVodAlbumListCollectionCell.self, forCellWithReuseIdentifier: kCNLiveVodAlbumListCollectionCellIdentifier)
//        return cv
//    }()
    
    let kCNLiveVodXuanjiKandianCellIdentifier = "kCNLiveVodXuanjiKandianCellIdentifier"
    
    lazy var kandianTableView : UITableView = {
        let tableView = UITableView(frame: .zero, style: .plain)
        tableView.dataSource = self
        tableView.delegate = self
        tableView.separatorStyle = .none
        tableView.register(CNLiveVodXuanjiKandianCell.self, forCellReuseIdentifier: kCNLiveVodXuanjiKandianCellIdentifier)
        tableView.backgroundColor = .clear
        return tableView
    }()
    lazy var tableViewBgView :UIView = {
        let bottomNavView = UIView()
        bottomNavView.isUserInteractionEnabled = true
        return bottomNavView
    }()

    
    //
    var _vodAlbumListBaseModel : CNLiveVodAlbumListBaseModel?
    var vodAlbumListBaseModel : CNLiveVodAlbumListBaseModel? {
        get{
            _vodAlbumListBaseModel
        }
        set{
            _vodAlbumListBaseModel = newValue
            self.setupNewUI(model: vodAlbumListBaseModel)
        }
    }
    
    var _kanDianListArr : NSMutableArray?
    var kanDianListArr : NSMutableArray? {
        get{
            _kanDianListArr
        }
        set{
            _kanDianListArr = newValue!
            self.setupNewUI(kanDianListArr: _kanDianListArr!)
        }
    }


    //MARK: - 懒加载
    lazy var titleLabel: UILabel = {
        let titleLbl = UILabel()
        titleLbl.font = Font_14
        titleLbl.textColor = HexColor("#FFFFFF")
        titleLbl.text = "选集"
        return titleLbl
    }()
    
    lazy var bgScrollView :UIScrollView = {
        let bgScrollView = UIScrollView()
        bgScrollView.showsVerticalScrollIndicator = false
        bgScrollView.isScrollEnabled = true
        return bgScrollView
    }()

    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = HexColor("#000000", alpha: 0.7)
        self.isUserInteractionEnabled = true
        self.initUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
//    var footerRefreshView: MJRefreshAutoNormalFooter!
    var page = 1//当前页数
    
    func initUI(){
        
        self.addSubview(self.titleLabel)
        titleLabel.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(31)
            make.centerX.equalToSuperview()
        }
        
        let leftPadding:CGFloat = 158.0
        let topPadding:CGFloat = 25.0
        let WH:CGFloat = 50.0
        let padding:CGFloat = 13.5
        let maxH = max(KSreenHeight, KSreenWidth)
        var containerWidth: CGFloat = maxH-158.0*2
        // 计算不包括最后一个方块间距时一行能放置的方块数量
        let maxBlocksWithoutLastSpacing = Int(containerWidth / (WH + padding))
        let hangMaxNum = maxBlocksWithoutLastSpacing//一行几块
        containerWidth = CGFloat(hangMaxNum)*(WH+padding)-padding

        self.addSubview(self.bgScrollView)
        bgScrollView.snp.makeConstraints { make in
            make.top.equalTo(self.titleLabel.snp.bottom).offset(topPadding)
            make.centerX.equalToSuperview()
            make.width.equalTo(containerWidth)
            make.bottom.equalToSuperview().offset(-50)
        }
        bgScrollView.backgroundColor = .clear
        
        self.addSubview(self.tableViewBgView)
        tableViewBgView.snp.makeConstraints { make in
            make.top.bottom.left.right.equalToSuperview()
        }
        tableViewBgView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(tapAction)))
        
        tableViewBgView.addSubview(self.kandianTableView)
        kandianTableView.snp.makeConstraints { make in
            make.top.equalTo(self.titleLabel.snp.bottom).offset(topPadding)
            make.centerX.equalToSuperview()
            make.width.equalTo(containerWidth)
            make.bottom.equalToSuperview().offset(-50)
        }
        
        self.initGesture()
    }
    
    func initGesture(){
        self.isMultipleTouchEnabled = true

        // 双击手势
        var doubleTapGesture = UITapGestureRecognizer(target: self, action: #selector(doubleTapAction))
        doubleTapGesture.numberOfTapsRequired = 2 // 双击触发
        doubleTapGesture.delaysTouchesBegan = true
        doubleTapGesture.delaysTouchesEnded = true
        doubleTapGesture.numberOfTouchesRequired = 1

        var panGesture = UIPanGestureRecognizer(target: self, action: #selector(panAction))
        panGesture.delaysTouchesBegan = true
        panGesture.delaysTouchesEnded = true
        panGesture.maximumNumberOfTouches = 1
        panGesture.cancelsTouchesInView = true

        var tapGesture = UITapGestureRecognizer(target: self, action: #selector(tapAction))
        tapGesture.delaysTouchesBegan = true
        tapGesture.delaysTouchesEnded = true
        tapGesture.numberOfTouchesRequired = 1
        tapGesture.numberOfTapsRequired = 1
        tapGesture.require(toFail: doubleTapGesture)
        tapGesture.require(toFail: panGesture)
        self.addGestureRecognizer(tapGesture)
        self.addGestureRecognizer(doubleTapGesture)
        self.addGestureRecognizer(panGesture)

        var pinchGesture = UIPinchGestureRecognizer(target: self, action: #selector(pinchAction))
        pinchGesture.delaysTouchesBegan = true
        self.addGestureRecognizer(pinchGesture)

        // 长按手势
        var longGesture = UILongPressGestureRecognizer(target: self, action: #selector(longPressAction))
        longGesture.minimumPressDuration = 0.5// 长按触发时间(秒)
        self.addGestureRecognizer(longGesture)
    }
//    @objc func tapAction(){
////        self.isHidden = true
//        print("tapAction")
//    }
    @objc func pinchAction(){
//        self.isHidden = true
        print("pinchAction")
    }
    @objc func longPressAction(){
//        self.isHidden = true
        print("longPressAction")
    }
    @objc func doubleTapAction(){
//        self.isHidden = true
        print("doubleTapAction")
    }
    
    @objc func panAction(){
//        self.isHidden = true
        print("panAction")
    }
    
    //看点列表
    func setupNewUI(kanDianListArr:NSMutableArray){
//        CNLiveVodPlayblockListListModel
        self.bgScrollView.isHidden = true
        
        self.tableViewBgView.isHidden = false
        self.kandianTableView.isHidden = false
        self.kandianTableView.reloadData()
    }
    // MARK: - UITableViewDelegate
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.kanDianListArr?.count ?? 0
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        if let listModel = self.kanDianListArr?[indexPath.row] as? CNLiveVodPlayBlockListListModel{
            guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveVodXuanjiKandianCellIdentifier) as? CNLiveVodXuanjiKandianCell
            else {
                let cell = CNLiveVodXuanjiKandianCell()
                return cell
            }
            if self.currSeleIdx == indexPath.row{
                cell.isSelect = true
            }else{
                cell.isSelect = false
            }
            cell.vodPlayBlockListListModel = listModel
            //横屏看点-点击某集
            cell.vodXuanjiKandianCellClickBlock = {[weak self]   vodPlayBlockListListModel in
                guard let self = self else { return }
                self.vodPlayerLandscapeXuanjiKanDianSelectBlock?(indexPath.row,vodPlayBlockListListModel ?? CNLiveVodPlayBlockListListModel())
                self.currSeleIdx = indexPath.row
                self.kandianTableView.reloadData()
                self.isHidden = true
            }
            return cell
        }
        return UITableViewCell()
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        let imgH:CGFloat = 65.0
        return imgH+10.0
    }
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        if let listModel = self.kanDianListArr?[indexPath.row] as? CNLiveVodPlayBlockListListModel{
            self.vodPlayerLandscapeXuanjiKanDianSelectBlock?(indexPath.row,listModel)
        }
    }
    
    //专辑列表
    func setupNewUI(model:CNLiveVodAlbumListBaseModel?){
//        self.albumListArr = NSMutableArray(array: model.list)
//        self.realHotCollectionView.reloadData()
        self.bgScrollView.removeAllSubviews()
        self.bgScrollView.isHidden = false
        
        self.tableViewBgView.isHidden = true
        self.kandianTableView.isHidden = true
        
        let WH:CGFloat = 50.0
        let padding:CGFloat = 13.5
        let maxH = max(KSreenHeight, KSreenWidth)
        let minH = max(KSreenHeight, KSreenWidth)
        var containerWidth: CGFloat = maxH-158.0*2
        // 计算不包括最后一个方块间距时一行能放置的方块数量
        let maxBlocksWithoutLastSpacing = Int(containerWidth / (WH + padding))
        let hangMaxNum = maxBlocksWithoutLastSpacing//一行几块
        containerWidth = CGFloat(hangMaxNum)*(WH+padding)-padding
        //lieIndex 当前是contents的第0列还是第1列
        var lieIndex = 0
        //hangIndex 当前是第几行,1...n
        var hangIndex = 1

        
        var maxContentHeight:CGFloat = self.bgScrollView.height
        for i in 0..<(model?.list.count ?? 0){//60{//
            let listMdl = model?.list[i]//model?.list[0]//
            let rowH = WH+padding
            let imgX = CGFloat(lieIndex)*(WH+padding)
            let imgY = rowH*CGFloat(hangIndex-1)
            
            let imgBottom = imgY+WH
            if imgBottom > maxContentHeight{
                maxContentHeight = imgBottom
            }
            print("1111bgScrollView:containerWidth\(containerWidth),maxContentHeight\(maxContentHeight)")
            self.bgScrollView.contentSize = CGSize(width: containerWidth, height: maxContentHeight)
            let expandBtn = UIButton.init(type: .custom)
            expandBtn.frame = CGRect(x: imgX, y: imgY, width: WH, height: WH)
            
            if i == self.currSeleIdx{
                expandBtn.backgroundColor = HexColor("#D3E4FF")
                expandBtn.layer.borderWidth = 0.65
                expandBtn.layer.borderColor = HexColor("#478BFF")?.cgColor
                expandBtn.isSelected = true
            }else{
                expandBtn.backgroundColor = HexColor("#000000", alpha: 0.5)
                expandBtn.layer.borderWidth = 0
                expandBtn.layer.borderColor = HexColor("#000000")?.cgColor
                expandBtn.isSelected = false
            }
            expandBtn.setTitle("\(i+1)", for: .normal)
            expandBtn.setTitle("\(i+1)", for: .selected)
            expandBtn.setTitleColor(HexColor("#FFFFFF"), for: .normal)
            expandBtn.setTitleColor(HexColor("#478BFF"), for: .selected)
            expandBtn.titleLabel?.font = Font_18
            expandBtn.layer.cornerRadius = 12
            expandBtn.clipsToBounds = true
            expandBtn.tag = 100+i
            expandBtn.addTarget(self, action: #selector(xuanjiBtnAction), for: .touchUpInside)
            self.bgScrollView.addSubview(expandBtn)
            
            let layerView = UIImageView()
            layerView.image = UIImage(named: "home_player_pay")
            layerView.frame = CGRect(x: 0, y: 0, width: 26, height: 15)
            expandBtn.addSubview(layerView)
            
            let isPaid = CNLivePlayerTool.isShowPaidIcon(product: listMdl?.product)
            if isPaid{
                layerView.isHidden = false
            }else{
                layerView.isHidden = true
            }
//            if listMdl.product?.productType == "2" || listMdl.product?.productType == "5"{//付费
//                layerView.isHidden = false
//            }else{
//                if listMdl.product?.check == true {
//                    //免费或者付过费了
//                    layerView.isHidden = true
//                } else {
//                    if listMdl.product?.productType == "4" {
//                        //这里表示可以进行试听
//                        layerView.isHidden = true
//                    } else {
//                        layerView.isHidden = true
//                    }
//                }
//            }
            
            if lieIndex < hangMaxNum-1{
                lieIndex = lieIndex+1
            }else{
                lieIndex = 0
                hangIndex += 1
            }
        }
        
    }
    
//    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
//        self.albumListArr.count
//    }
//    
//    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
//        
//        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: kCNLiveVodAlbumListCollectionCellIdentifier, for: indexPath) as! CNLiveVodAlbumListCollectionCell
//        if self.currSeleIdx == indexPath.row{
//            //当前cell选中
//            cell.isJiShuSelected = true
//        }else{
//            //不选中
//            cell.isJiShuSelected = false
//        }
//        cell.num = indexPath.row
//        cell.vodAlbumListModel = self.albumListArr[indexPath.row] as? CNLiveVodAlbumListModel
//        return cell
//    }
//    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
//        if let vodAlbumListModel = self.albumListArr[indexPath.row] as? CNLiveVodAlbumListModel{
//            //点击某集,刷新页面
//            self.selectBlock?(vodAlbumListModel, indexPath.row, self.albumListArr)
//            self.currSeleIdx = indexPath.row
//            self.realHotCollectionView.reloadData()
//            
//        }
//    }

    ///专辑点击每个剧集按钮
    @objc func xuanjiBtnAction(btn:UIButton){
        let index = btn.tag-100
        if let listModel = self.vodAlbumListBaseModel?.list[index] as? CNLiveVodAlbumListModel{
            self.xuanjiUpdateBlock?(index,listModel)
        }
    }
    @objc func tapAction(){
        self.isHidden = true
    }
    
}