CNLiveVodIntroductionCell.swift
10.1 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
//
// CNLiveVodIntroductionCell.swift
// metaCode
//
// Created by zx on 2025/3/3.
// 简介,点赞等
import Foundation
import CNLiveShareToolKit
// type 1详情按钮 2点赞按钮 3收藏按钮 4分享按钮
typealias CNLiveVodIntroductionCellUpdateBlock = (_ isExpandDetail:Bool,_ isFavorite:Bool ,_ favoriteNum:Int,_ isCollection:Bool,_ type:String,_ model:CNLiveVodPlayBlockListListModel)->Void
class CNLiveVodIntroductionCell:UITableViewCell{
var updateCellBlock:CNLiveVodIntroductionCellUpdateBlock?
var _vodPlayBlockListModel : CNLiveVodPlayBlockListModel?
var vodPlayBlockListModel : CNLiveVodPlayBlockListModel? {
get{
_vodPlayBlockListModel
}
set{
_vodPlayBlockListModel = newValue!
self.setupNewUI(model: vodPlayBlockListModel!)
}
}
//MARK: - 懒加载
lazy var titleLabel: UILabel = {
let titleLbl = UILabel()
titleLbl.font = BoldFont_15
titleLbl.textColor = HexColor("#000102")
titleLbl.text = "标题"
return titleLbl
}()
//详情
lazy var detailBtn: UIButton = {
let expandBtn = UIButton.init(type: .custom)
expandBtn.backgroundColor = .clear
expandBtn.frame = CGRect(x: 0, y: 0, width: 60, height: 40)
expandBtn.setTitle("详情", for: .normal)
expandBtn.setTitle("详情", for: .selected)
expandBtn.setTitleColor(HexColor("#999999"), for: .normal)
expandBtn.setImage(UIImage(named: "home_player_expand"), for: .normal)
expandBtn.setImage(UIImage(named: "home_player_unexpand"), for: .selected)
expandBtn.titleLabel?.font = Font_10
expandBtn.setupButtonImageAndTitlePossitionWith(padding: 5, style: .right)
expandBtn.addTarget(self, action: #selector(detailBtnAction), for: .touchUpInside)
return expandBtn
}()
//点赞
lazy var likeBtn: UIButton = {
let expandBtn = UIButton.init(type: .custom)
expandBtn.backgroundColor = .clear
expandBtn.frame = CGRect(x: 0, y: 0, width: (KSreenWidth-40)/3.0, height: 40)
expandBtn.setTitle("0", for: .normal)
expandBtn.setTitle("0", for: .selected)
expandBtn.setTitleColor(HexColor("#333333"), for: .normal)
expandBtn.setImage(UIImage(named: "home_player_like"), for: .normal)
expandBtn.setImage(UIImage(named: "home_player_liked"), for: .selected)
expandBtn.titleLabel?.font = Font_10
expandBtn.setupButtonImageAndTitlePossitionWith(padding: 5, style: .left)
expandBtn.addTarget(self, action: #selector(likeBtnAction), for: .touchUpInside)
expandBtn.backgroundColor = HexColor("#F5F5F5")
expandBtn.clipsToBounds = true
expandBtn.layer.cornerRadius = 20
return expandBtn
}()
//评论
lazy var collectionBtn: UIButton = {
let expandBtn = UIButton.init(type: .custom)
expandBtn.backgroundColor = .clear
expandBtn.frame = CGRect(x: 0, y: 0, width: (KSreenWidth-40)/3.0, height: 40)
expandBtn.setTitle("收藏", for: .normal)
expandBtn.setTitle("已收藏", for: .selected)
expandBtn.setTitleColor(HexColor("#333333"), for: .normal)
expandBtn.setImage(UIImage(named: "home_player_uncollection"), for: .normal)
expandBtn.setImage(UIImage(named: "home_player_collection"), for: .selected)
expandBtn.titleLabel?.font = Font_10
expandBtn.backgroundColor = HexColor("#F5F5F5")
expandBtn.clipsToBounds = true
expandBtn.layer.cornerRadius = 20
expandBtn.setupButtonImageAndTitlePossitionWith(padding: 5, style: .left)
expandBtn.addTarget(self, action: #selector(collectionBtnAction), for: .touchUpInside)
return expandBtn
}()
//分享
lazy var shareBtn: UIButton = {
let expandBtn = UIButton.init(type: .custom)
expandBtn.backgroundColor = .clear
expandBtn.frame = CGRect(x: 0, y: 0, width: (KSreenWidth-40)/3.0, height: 40)
expandBtn.setTitle("分享", for: .normal)
expandBtn.setTitle("分享", for: .selected)
expandBtn.setTitleColor(HexColor("#333333"), for: .normal)
expandBtn.setImage(UIImage(named: "home_player_share"), for: .normal)
expandBtn.setImage(UIImage(named: "home_player_share"), for: .selected)
expandBtn.titleLabel?.font = Font_10
expandBtn.setupButtonImageAndTitlePossitionWith(padding: 5, style: .left)
expandBtn.backgroundColor = HexColor("#F5F5F5")
expandBtn.clipsToBounds = true
expandBtn.layer.cornerRadius = 20
expandBtn.addTarget(self, action: #selector(shareBtnAction), for: .touchUpInside)
return expandBtn
}()
//share gift
lazy var shareGiftBtn: UIButton = {
let expandBtn = UIButton.init(type: .custom)
expandBtn.backgroundColor = .clear
expandBtn.frame = CGRect(x: 0, y: 0, width: 64, height: 21)
expandBtn.setTitle("送礼", for: .normal)
expandBtn.setTitle("送礼", for: .selected)
expandBtn.setTitleColor(HexColor("#000102"), for: .normal)
expandBtn.setImage(UIImage(named: "home_shareGift"), for: .normal)
expandBtn.setImage(UIImage(named: "home_shareGift"), for: .selected)
expandBtn.titleLabel?.font = Font_12
expandBtn.setupButtonImageAndTitlePossitionWith(padding: 6, style: .left)
expandBtn.addTarget(self, action: #selector(shareGiftBtnAction), for: .touchUpInside)
expandBtn.backgroundColor = HexColor("#FFEFE9")
expandBtn.clipsToBounds = true
expandBtn.layer.cornerRadius = 10
return expandBtn
}()
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() {
contentView.backgroundColor = .white
self.contentView.addSubview(self.titleLabel)
titleLabel.snp.makeConstraints { make in
make.left.equalToSuperview().offset(10)
make.top.equalToSuperview().offset(15)
make.width.lessThanOrEqualTo(KSreenWidth-10-80)
}
self.contentView.addSubview(self.detailBtn)
detailBtn.snp.makeConstraints { make in
make.left.equalTo(self.titleLabel.snp.right).offset(10)
make.centerY.equalTo(self.titleLabel.snp.centerY)
make.width.equalTo(60)
make.height.equalTo(30)
}
self.contentView.addSubview(self.likeBtn)
likeBtn.snp.makeConstraints { make in
make.left.equalTo(10)
make.top.equalTo(self.titleLabel.snp.bottom).offset(19)
make.width.equalTo((KSreenWidth-40)/3.0)
make.height.equalTo(40)
}
if metaAppDelegate.isGift{
self.contentView.addSubview(shareGiftBtn)
shareGiftBtn.snp.makeConstraints { make in
make.right.equalToSuperview().offset(-10)
make.width.equalTo(64)
make.height.equalTo(21)
make.centerY.equalTo(self.titleLabel.snp.centerY)
}
}
self.contentView.addSubview(self.collectionBtn)
collectionBtn.snp.makeConstraints { make in
make.left.equalTo(self.likeBtn.snp.right).offset(10)
make.centerY.equalTo(self.likeBtn.snp.centerY)
make.width.equalTo((KSreenWidth-40)/3.0)
make.height.equalTo(40)
}
self.contentView.addSubview(self.shareBtn)
shareBtn.snp.makeConstraints { make in
make.left.equalTo(self.collectionBtn.snp.right).offset(10)
make.centerY.equalTo(self.likeBtn.snp.centerY)
make.width.equalTo((KSreenWidth-40)/3.0)
make.height.equalTo(40)
}
self.contentView.clipsToBounds = true
}
func setupNewUI(model:CNLiveVodPlayBlockListModel){
if model.list.count > 0{
if let vodMdl = model.list.first{
titleLabel.text = vodMdl.title
//处理转换成万
likeBtn.setTitle("\(vodMdl.likesNum)", for: .normal)
likeBtn.setTitle("\(vodMdl.likesNum)", for: .selected)
likeBtn.isSelected = vodMdl.liked
collectionBtn.isSelected = vodMdl.collectioned
}
}
}
@objc func detailBtnAction(){
self.updateCellBlock?(true, false,0, false, "1",self.vodPlayBlockListModel!.list.first!)
}
@objc func likeBtnAction(){
likeBtn.isSelected = likeBtn.isSelected ? false : true
let vodMdl = self.vodPlayBlockListModel!.list.first!
let num = likeBtn.isSelected ? 1 : -1
let likeNum = ((vodMdl.likesNum+num) == -1) ? 0 : vodMdl.likesNum+num
likeBtn.setTitle("\(likeNum)", for: .normal)
likeBtn.setTitle("\(likeNum)", for: .selected)
self.updateCellBlock?(false, likeBtn.isSelected,likeNum, false, "2",self.vodPlayBlockListModel!.list.first!)
}
@objc func collectionBtnAction(){
collectionBtn.isSelected = collectionBtn.isSelected ? false : true
self.updateCellBlock?(false, false,0, true, "3",self.vodPlayBlockListModel!.list.first!)
}
@objc func shareBtnAction(){
self.updateCellBlock?(false, false,0, false, "4",self.vodPlayBlockListModel!.list.first!)
}
@objc func shareGiftBtnAction(){
CNLiveShareManager.showShareViewWithParam(forShareTitle: "忽必烈电视剧", shareUrl: "http://wjjh5.cnlive.com/cnYmHbl.html?channelName=ymhbl", shareDesc: "邀你共赴大元史诗!点击加入追剧联盟", shareImage: UIImage(named: "shareAppIcon"), screenFull: false, hiddenWjj: true, hiddenQQ: true, hiddenWB: true, hiddenLifeCircle: true, hiddenWechatCircle: false, hiddenWechat: false, hiddenSafari: true, formVC: currentViewController(), topImage: [], topTitles: [], platformType: .all) { title in
} completerBlock: { resultType, platformType, typeString in
if resultType == .succ{
print("succ")
}
}
}
}