CNLiveShortVideoContentListView.swift
9.54 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
//
// CNLiveShortVideoContentListView.swift
// metaCode
//
// Created by open on 2024/1/9.
//
import Foundation
typealias CloseVideoListResultBlock = (_ listModel: Any) ->Void
class CNLiveShortVideoContentListView: UIView, UITableViewDelegate, UITableViewDataSource {
lazy var grayMaskView: UIView = {
let grayMaskView = UIView()
grayMaskView.backgroundColor = UIColor.black.withAlphaComponent(0.2)
return grayMaskView
}()
lazy var contentView: UIView = {
let view = UIView.init()
view.backgroundColor = HexColor("#010101")
return view
}()
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
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 = 90
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
}()
lazy var dataSource: NSMutableArray = {
let array = NSMutableArray()
return array
}()
var resultBlock: CloseVideoListResultBlock!
override init(frame: CGRect) {
super.init(frame: frame)
addSubview(grayMaskView)
grayMaskView.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
grayMaskView.addSubview(contentView)
contentView.snp.makeConstraints { make in
make.top.equalTo(250)
make.right.left.bottom.equalToSuperview()
}
contentView.addSubview(closeButton)
closeButton.snp.makeConstraints { make in
make.right.equalToSuperview().offset(-15)
make.top.equalToSuperview().offset(15)
make.size.equalTo(30)
}
contentView.addSubview(titleLabel)
titleLabel.snp.makeConstraints { make in
make.top.left.equalToSuperview().offset(20)
make.right.equalTo(closeButton.snp.left).offset(-10)
}
contentView.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)
}
contentView.addSubview(tableView)
tableView.snp.makeConstraints { make in
make.bottom.left.right.equalToSuperview()
make.top.equalTo(lineLabel.snp.bottom).offset(10)
}
}
func setupWithDataSource(title: String,dataArray: NSMutableArray) {
dataSource = dataArray
titleLabel.text = title
self.tableView.reloadData()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
deinit {
print("弹出界面销毁")
}
@objc func closeMethod() {
removeFromSuperview()
}
static public func showVideoContentListView(title: String,dataArray: NSMutableArray,result: @escaping CloseVideoListResultBlock) {
let pickerView = CNLiveShortVideoContentListView.init(frame: CGRect.zero)
pickerView.resultBlock = result
pickerView.setupWithDataSource(title: title,dataArray: dataArray)
let delegate = UIApplication.shared.delegate as! AppDelegate
delegate.window?.addSubview(pickerView)
pickerView.snp.makeConstraints { make in
make.edges.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 dataSource.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: kVideoContentListViewCellIdentifier) as? CNLiveShortVideoContentListTableViewCell else {
return CNLiveShortVideoContentListTableViewCell()
}
cell.setupWithDataModel(listModel: dataSource[indexPath.row] as! CNLiveAlbumListModel)
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
self.resultBlock(dataSource[indexPath.row] as! CNLiveAlbumListModel)
closeMethod()
}
}
class CNLiveShortVideoContentListTableViewCell: UITableViewCell {
lazy var iconView: UIImageView = {
let imageView = UIImageView.init()
imageView.image = UIImage(named: "short_video_default")
imageView.contentMode = .scaleAspectFill
imageView.layer.cornerRadius = 5
imageView.layer.masksToBounds = true
imageView.clipsToBounds = true
return imageView
}()
lazy var tipView: UIImageView = {
let imageView = UIImageView.init()
imageView.contentMode = .scaleAspectFit
imageView.layer.cornerRadius = 5
imageView.layer.masksToBounds = true
imageView.clipsToBounds = true
imageView.isHidden = true
return imageView
}()
lazy var titleLabel: UILabel = {
let titleLabel = UILabel.init()
titleLabel.textColor = .white
titleLabel.lineBreakMode = .byTruncatingTail
titleLabel.numberOfLines = 2
titleLabel.font = medium_adapt_font(pointSize: 12)
return titleLabel
}()
lazy var timeLabel: UILabel = {
let timeLabel = UILabel.init()
timeLabel.textColor = .white
timeLabel.font = light_adapt_font(pointSize: 13)
return timeLabel
}()
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
contentView.backgroundColor = .clear
backgroundColor = .clear
selectionStyle = .none
contentView.addSubview(iconView)
iconView.snp.makeConstraints { make in
make.left.top.equalToSuperview().offset(20)
make.width.equalTo(50)
make.height.equalTo(70)
}
contentView.addSubview(tipView)
tipView.snp.makeConstraints { make in
make.left.top.equalToSuperview().offset(20)
make.height.equalTo(15)
}
contentView.addSubview(titleLabel)
titleLabel.snp.makeConstraints { make in
make.left.equalTo(iconView.snp.right).offset(10)
make.top.equalToSuperview().offset(20)
make.right.equalToSuperview().offset(-20)
}
contentView.addSubview(timeLabel)
timeLabel.snp.makeConstraints { make in
make.left.equalTo(iconView.snp.right).offset(10)
make.bottom.equalTo(iconView.snp.bottom)
make.right.equalToSuperview().offset(-20)
}
}
func setupWithDataModel(listModel: CNLiveAlbumListModel) {
iconView.kf.indicatorType = .activity
iconView.kf.setImage(with: URL(string: listModel.poster), placeholder: UIImage(named: "short_video_default"))
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineSpacing = 6
titleLabel.attributedText = NSAttributedString(string: listModel.title, attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle, ])
timeLabel.text = listModel.duration
if listModel.product?.check == true {
if listModel.product?.albumProductType != "0" {
tipView.isHidden = false
tipView.image = UIImage(named: "short_video_free")
}
} else {
if listModel.product?.productType == "4" {
//这里表示可以进行试听
tipView.isHidden = true
} else {
tipView.isHidden = false
tipView.image = UIImage(named: "short_video_pay")
}
}
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}