CNLiveVodXuanjiKandianCell.swift
6.78 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
//
// CNLiveVodXuanjiKandianCell.swift
// metaCode
//
// Created by zx on 2025/4/9.
// 选集-看点列表
import Foundation
typealias CNLiveVodXuanjiKandianCellClickBlock = (_ model:CNLiveVodPlayBlockListListModel?)->Void
class CNLiveVodXuanjiKandianCell:UITableViewCell{
var isSelect:Bool = false
var vodXuanjiKandianCellClickBlock : CNLiveVodXuanjiKandianCellClickBlock?
//slideModel
var _vodPlayBlockListListModel : CNLiveVodPlayBlockListListModel?
var vodPlayBlockListListModel : CNLiveVodPlayBlockListListModel? {
get{
_vodPlayBlockListListModel
}
set{
_vodPlayBlockListListModel = newValue!
self.setupNewUI(model: _vodPlayBlockListListModel!)
}
}
//MARK: - 懒加载
lazy var totalBtn: UIButton = {
let expandBtn = UIButton(type: .custom)
expandBtn.backgroundColor = HexColor("#D3E4FF")//nor EEEEEE,sele #D3E4FF
expandBtn.setTitleColor(HexColor("#FFFFFF"), for: .normal)
expandBtn.setTitleColor(HexColor("#478BFF"), for: .selected)
expandBtn.layer.cornerRadius = 9
expandBtn.clipsToBounds = true
// expandBtn.isUserInteractionEnabled = false
expandBtn.addTarget(self, action: #selector(totalBtnAction), for: .touchUpInside)
return expandBtn
}()
lazy var titleLabel: UILabel = {
let titleLabel = UILabel.init()
titleLabel.textColor = .white
titleLabel.textAlignment = .left
titleLabel.font = Font_18
return titleLabel
}()
lazy var timeTitleLabel: UILabel = {
let titleLabel = UILabel.init()
titleLabel.textColor = .white
titleLabel.textAlignment = .left
titleLabel.font = Font_18
return titleLabel
}()
//付费角标
lazy var payIconView :UIImageView = {
let layerView = UIImageView()
layerView.image = UIImage(named: "home_player_pay")
layerView.frame = CGRect(x: 0, y: 0, width: 26, height: 15)
return layerView
}()
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.selectionStyle = .none
setupUI()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func setupUI() {
self.backgroundColor = .clear
contentView.backgroundColor = .clear
self.contentView.addSubview(self.totalBtn)
totalBtn.snp.makeConstraints { make in
make.left.right.equalToSuperview()
make.top.equalToSuperview()
make.bottom.equalToSuperview().offset(-10)
}
self.totalBtn.addSubview(self.timeTitleLabel)
timeTitleLabel.snp.makeConstraints { make in
make.centerY.equalToSuperview()
make.right.equalToSuperview().offset(-30)
}
self.totalBtn.addSubview(self.titleLabel)
titleLabel.snp.makeConstraints { make in
make.left.equalTo(25)
make.centerY.equalToSuperview()
make.right.lessThanOrEqualTo(self.timeTitleLabel.snp.left).offset(-10)
}
self.totalBtn.addSubview(self.payIconView)
payIconView.snp.makeConstraints { make in
make.top.equalToSuperview()
make.right.equalToSuperview()
make.width.equalTo(26)
make.height.equalTo(15)
}
}
func setupNewUI(model:CNLiveVodPlayBlockListListModel){
self.titleLabel.text = model.title
if let formattedTime = convertSecondsToFormattedTime(secondsString: model.duration) {
print(formattedTime) // 输出: "05:59"
self.timeTitleLabel.text = formattedTime
} else {
print("Invalid seconds string")
self.timeTitleLabel.text = "00:00"
}
self.totalBtn.isSelected = isSelect
if isSelect{
//当前选中
self.titleLabel.textColor = HexColor("#478BFF")
self.timeTitleLabel.textColor = HexColor("#478BFF")
self.totalBtn.backgroundColor = HexColor("#D3E4FF")
}else{
//未选中
self.titleLabel.textColor = HexColor("#FFFFFF")
self.timeTitleLabel.textColor = HexColor("#FFFFFF")
self.totalBtn.backgroundColor = HexColor("#000000", alpha: 0.5)
}
// if model.product?.albumProductType.count ?? 0 > 0{
// //专辑
// if model.product?.albumProductType == "2" || model.product?.albumProductType == "5"{
// //人民币 ,专辑付费
//
// }else{
// //免费
// }
// }else{
// //单集
// if model.product?.productType.count ?? 0 > 0{
// //单集
// if model.product?.productType == "2"{
// //人民币付费
//
// }else{
// //免费
//
// }
// }else{
// //免费
//
// }
// }
let isPaid = CNLivePlayerTool.isShowPaidIcon(product: model.product)
if isPaid{
payIconView.isHidden = false
}else{
payIconView.isHidden = true
}
// if model.product?.productType == "2" || model.product?.productType == "5"{//付费
// payIconView.isHidden = false
// }else{
// if model.product?.check == true {
// //免费或者付过费了
// payIconView.isHidden = true
// } else {
// if model.product?.productType == "4" {
// //这里表示可以进行试听
// payIconView.isHidden = true
// } else {
// payIconView.isHidden = true
// }
// }
// }
}
func convertSecondsToFormattedTime(secondsString: String) -> String? {
if let seconds = Int(secondsString) {
let hours = seconds / 3600
let minutes = (seconds % 3600) / 60
let secondsRemainder = seconds % 60
if hours == 0 {
// 如果小时为0,则返回mm:ss格式
return String(format: "%02d:%02d", minutes, secondsRemainder)
} else {
// 如果小时不为0,则返回hh:mm:ss格式
return String(format: "%02d:%02d:%02d", hours, minutes, secondsRemainder)
}
}
return nil // 如果字符串不能转换为整数,则返回nil
}
@objc func totalBtnAction(btn: UIButton){
self.vodXuanjiKandianCellClickBlock?(self.vodPlayBlockListListModel)
}
}