CNWitnessSearchVideoCell.m
7.73 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
//
// CNWitnessSearchVideoCell.m
// CNLiveVideoClassifyKit
//
// Created by CNLive on 2022/6/17.
//
#import "CNWitnessSearchVideoCell.h"
#import "CNWitnessSearchModel.h"
#import "CNWitnessSearchPresent.h"
@interface CNWitnessSearchVideoCell ()
@property (nonatomic, strong)UIView *bgView;
@property (nonatomic, strong)UIImageView *videoImage;
@property (nonatomic, strong)UIImageView *playImage;
@property (nonatomic, strong)UILabel *titleLabel;
@property (nonatomic, strong)UIImageView *logoImage;
@property (nonatomic, strong)UILabel *nameLabel;
@property (nonatomic, strong)QMUIButton *likeBtn;
@end
@implementation CNWitnessSearchVideoCell
- (instancetype)initWithFrame:(CGRect)frame{
if (self = [super initWithFrame:frame]) {
[self.contentView addSubview:self.bgView];
[self.bgView addSubview:self.videoImage];
[self.videoImage addSubview:self.playImage];
[self.bgView addSubview:self.titleLabel];
[self.bgView addSubview:self.logoImage];
[self.bgView addSubview:self.nameLabel];
[self.bgView addSubview:self.likeBtn];
[self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.bottom.left.right.equalTo(self.contentView);
}];
[self.videoImage mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.right.equalTo(self.contentView);
make.height.mas_equalTo(242);
}];
[self.playImage mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.contentView).offset(9);
make.right.equalTo(self.contentView).offset(-9);
make.width.height.mas_equalTo(21);
}];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView).offset(10);
make.right.equalTo(self.contentView).offset(-10);
make.top.equalTo(self.videoImage.mas_bottom).offset(9);
}];
[self.logoImage mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self.contentView).offset(-10);
make.left.equalTo(self.contentView).offset(10);
make.width.height.mas_equalTo(21);
}];
[self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.logoImage);
make.left.equalTo(self.logoImage.mas_right).offset(5);
make.right.equalTo(self.likeBtn.mas_left).offset(-5);
}];
[self.likeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.contentView).offset(-10);
make.centerY.equalTo(self.logoImage);
}];
}
return self;
}
#pragma mark - Action
- (void)likeBtnClick:(QMUIButton *)sender{
if (![CNUserShareManager isLogin]) {
#pragma mark -- TODO grp
[CNLiveClassifyJumpBridge showLoginViewWithString:@""];
return;
}
[QMUITips showLoadingInView:self.contentView];
weakself
[CNWitnessSearchPresent requestWitnessLikeMomentWithPid:self.model.pid ContentSid:self.model.icon.id support:sender.selected?@"0":@"1" contentTag:self.model.tagName responseBlock:^(BOOL succeed) {
[QMUITips hideAllTips];
if (succeed) {
if (sender.selected) {
sender.selected = NO;
weakSelf.model.tool.likesNum --;
}else{
sender.selected = YES;
weakSelf.model.tool.likesNum ++;
}
weakSelf.model.tool.liked = sender.selected;
[weakSelf.likeBtn setTitle:[NSString stringWithFormat:@"%ld",weakSelf.model.tool.likesNum] forState:UIControlStateNormal];
[weakSelf.likeBtn setTitle:[NSString stringWithFormat:@"%ld",weakSelf.model.tool.likesNum] forState:UIControlStateSelected];
[weakSelf notificationH5Update];
}
}];
}
- (void)notificationH5Update{
NSDictionary *dic = @{
@"contentId":self.model.contentId?self.model.contentId:@"",
@"selected":self.model.tool.liked?@"true":@"false",
@"model":self.model.model?self.model.model:@""
};
[CNLiveClassifyJumpBridge requestWittnessLikeNotification:dic];
}
#pragma mark - Setting
- (void)setModel:(CNWitnessSearchDetailModel *)model{
_model = model;
if (model.isHorizontalScreen == 1) {
[self.videoImage mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(121);
}];
}else{
[self.videoImage mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(242);
}];
}
[self.videoImage sd_setImageWithURL:[NSURL URLWithString:model.poster] placeholderImage:[UIImage loadBundleImage:@"moren"]];
self.titleLabel.text = model.title;
[self.logoImage sd_setImageWithURL:[NSURL URLWithString:model.icon.face] placeholderImage:[UIImage loadBundleImage:@"default _icon_bg"]];
self.nameLabel.text = model.icon.name;
[self.likeBtn setTitle:[NSString stringWithFormat:@"%ld",model.tool.likesNum] forState:UIControlStateNormal];
[self.likeBtn setTitle:[NSString stringWithFormat:@"%ld",model.tool.likesNum] forState:UIControlStateSelected];
self.likeBtn.selected = _model.tool.liked;
[self.likeBtn sizeToFit];
}
#pragma mark - Getting
- (UIView *)bgView{
if (!_bgView) {
_bgView = [[UIView alloc] init];
_bgView.backgroundColor = UIColorWhite;
_bgView.layer.cornerRadius = 8;
_bgView.clipsToBounds = YES;
}
return _bgView;
}
- (UIImageView *)videoImage{
if (!_videoImage) {
_videoImage = [[UIImageView alloc] init];
_videoImage.layer.cornerRadius = 8;
_videoImage.clipsToBounds = YES;
_videoImage.contentMode = UIViewContentModeScaleAspectFill;
}
return _videoImage;
}
- (UIImageView *)playImage {
if (!_playImage) {
_playImage = [[UIImageView alloc] init];
[_playImage setImage:[UIImage loadBundleImage:@"witness_search_play"]];
}
return _playImage;
}
- (UILabel *)titleLabel
{
if (!_titleLabel) {
_titleLabel = [[UILabel alloc] init];
_titleLabel.textColor = UIColorHex(#333333);
_titleLabel.font = UIFontMake(15);
_titleLabel.numberOfLines = 2;
_titleLabel.textAlignment = NSTextAlignmentLeft;
}
return _titleLabel;
}
- (UIImageView *)logoImage
{
if (!_logoImage) {
_logoImage = [[UIImageView alloc] init];
_logoImage.contentMode = UIViewContentModeScaleAspectFill;
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 20, 20) cornerRadius:10];
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.path = path.CGPath;
_logoImage.layer.mask = maskLayer;
}
return _logoImage;
}
- (UILabel *)nameLabel
{
if (!_nameLabel) {
_nameLabel = [[UILabel alloc] init];
_nameLabel.textColor = UIColorHex(#666666);
_nameLabel.font = UIFontMake(11);
_nameLabel.textAlignment = NSTextAlignmentLeft;
}
return _nameLabel;
}
- (QMUIButton *)likeBtn
{
if (!_likeBtn) {
_likeBtn = [QMUIButton buttonWithType:UIButtonTypeCustom];
[_likeBtn setImage:[UIImage loadBundleImage:@"witness_search_like"] forState:UIControlStateSelected];
[_likeBtn setImage:[UIImage loadBundleImage:@"witness_search_unLike"] forState:UIControlStateNormal];
_likeBtn.titleLabel.font = UIFontMake(13);
[_likeBtn setTitleColor:UIColorHex(#666666) forState:UIControlStateNormal];
[_likeBtn setTitleColor:UIColorHex(#666666) forState:UIControlStateSelected];
_likeBtn.spacingBetweenImageAndTitle = 5;
[_likeBtn addTarget:self action:@selector(likeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
}
return _likeBtn;
}
@end