CNLiveShortVideoContentListView.swift 6.73 KB
//
//  CNLiveShortVideoContentListView.swift
//  metaCode
//
//  Created by open on 2024/1/9.
//

import Foundation

typealias CloseVideoListResultBlock = (_ videoId: Any) ->Void
class CNLiveShortVideoContentListView: UIView, UITableViewDelegate, UITableViewDataSource {
    
    lazy var closeButton: UIButton = {
        let button = UIButton(type: .custom)
        button.setImage(UIImage(named: "short_video_close"), for: .normal)
        button.backgroundColor = .clear
        button.addTarget(self, action: #selector(closeMethod), for: .touchUpInside)
        return button
    }()
    
    lazy var titleLabel: UILabel = {
        let label = UILabel()
        label.textColor = UIColor.white
        label.font = semibold_adapt_font(pointSize: 19)
        label.textAlignment = .left
        label.numberOfLines = 1
        label.lineBreakMode = .byTruncatingTail
        label.text = "爱得供养"
        return label
    }()
    
    lazy var lineLabel: UILabel = {
        let lineLabel = UILabel.init()
        lineLabel.backgroundColor = HexColor("#686868")
        return lineLabel
    }()
    
    let kVideoContentListViewCellIdentifier = "kVideoContentListViewCellIdentifier"
    lazy var tableView : UITableView = {
        let tableView = UITableView(frame: .zero, style: .plain)
        tableView.dataSource = self
        tableView.delegate = self
        tableView.rowHeight = 90
        tableView.estimatedRowHeight = 0
        tableView.estimatedSectionFooterHeight = 0
        tableView.estimatedSectionHeaderHeight = 0
        tableView.backgroundColor = HexColor("#010101")
        tableView.tableFooterView = UIView.init()
        tableView.separatorStyle = .none
        tableView.scrollsToTop = false
        tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: get_system_tabbar_ui_offsetHeight(), right: 0)
        tableView.contentInsetAdjustmentBehavior = .never;
        tableView.register(CNLiveShortVideoContentListTableViewCell.self, forCellReuseIdentifier: kVideoContentListViewCellIdentifier)
        return tableView
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)

        addSubview(closeButton)
        closeButton.snp.makeConstraints { make in
            make.right.equalToSuperview().offset(-15)
            make.top.equalToSuperview().offset(15)
            make.size.equalTo(30)
        }
        addSubview(titleLabel)
        titleLabel.snp.makeConstraints { make in
            make.top.left.equalToSuperview().offset(20)
            make.right.equalTo(closeButton.snp.left).offset(-10)
        }
        addSubview(lineLabel)
        lineLabel.snp.makeConstraints { make in
            make.top.equalTo(closeButton.snp.bottom).offset(15)
            make.centerX.equalToSuperview()
            make.left.equalToSuperview().offset(10)
            make.right.equalToSuperview().offset(-10)
            make.height.equalTo(1)
        }
        addSubview(tableView)
        tableView.snp.makeConstraints { make in
            make.bottom.left.right.equalToSuperview()
            make.top.equalTo(lineLabel.snp.bottom).offset(10)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    @objc func closeMethod() {
        removeFromSuperview()
    }
    
    static public func showVideoContentListView(result: @escaping CloseVideoListResultBlock) {
        
        let pickerView = CNLiveShortVideoContentListView.init(frame: CGRect.zero)
        pickerView.backgroundColor = HexColor("#010101")
        
        let delegate = UIApplication.shared.delegate as! AppDelegate
        delegate.window?.addSubview(pickerView)
        pickerView.snp.makeConstraints { make in
            make.top.equalTo(250)
            make.right.left.bottom.equalToSuperview()
        }
        delegate.window?.layoutIfNeeded()
        pickerView.alpha = 0
        UIView.animate(withDuration: 0.1) {
            pickerView.alpha = 1
        } completion: { _ in}
    }
    
}

extension CNLiveShortVideoContentListView {
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 20
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        guard let cell = tableView.dequeueReusableCell(withIdentifier: kVideoContentListViewCellIdentifier) as? CNLiveShortVideoContentListTableViewCell else {
            return CNLiveShortVideoContentListTableViewCell()
        }
        return cell
    }
    
}

class CNLiveShortVideoContentListTableViewCell: UITableViewCell {
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        contentView.backgroundColor = .clear
        backgroundColor = .clear
        selectionStyle = .none
        
        let imageView = UIImageView.init()
        imageView.image = UIImage(named: "mine_auth_result_header_failer")
        imageView.contentMode = .scaleAspectFill
        imageView.layer.cornerRadius = 5
        imageView.layer.masksToBounds = true
        imageView.clipsToBounds = true
        contentView.addSubview(imageView)
        imageView.snp.makeConstraints { make in
            make.left.top.equalToSuperview().offset(20)
            make.width.equalTo(50)
            make.height.equalTo(70)
        }
        
        let paragraphStyle = NSMutableParagraphStyle()
        paragraphStyle.lineSpacing = 6
        let titleLabel = UILabel.init()
        titleLabel.attributedText = NSAttributedString(string: "第四集 我们都不知道,所做的哪一个选择会让命运的齿轮开始转动", attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle])
        titleLabel.textColor = .white
        titleLabel.lineBreakMode = .byTruncatingTail
        titleLabel.numberOfLines = 2
        titleLabel.font = medium_adapt_font(pointSize: 12)
        contentView.addSubview(titleLabel)
        titleLabel.snp.makeConstraints { make in
            make.left.equalTo(imageView.snp.right).offset(10)
            make.top.equalToSuperview().offset(20)
            make.right.equalToSuperview().offset(-20)
        }
        
        let timeLabel = UILabel.init()
        timeLabel.text = "04:45"
        timeLabel.textColor = .white
        timeLabel.font = light_adapt_font(pointSize: 13)
        contentView.addSubview(timeLabel)
        timeLabel.snp.makeConstraints { make in
            make.left.equalTo(imageView.snp.right).offset(10)
            make.bottom.equalTo(imageView.snp.bottom)
            make.right.equalToSuperview().offset(-20)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}