IVTMyFollowListTableViewCell.m
6.14 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
//
// IVTMyFollowListTableViewCell.m
// IVTMeLiveTwo
//
// Created by XRG on 16/8/25.
// Copyright © 2016年 QLQ. All rights reserved.
//
#import "IVTMyFollowListTableViewCell.h"
#import "NameSexLevelView.h"
@interface IVTMyFollowListTableViewCell ()
{
UIImageView *_headIcon;
NameSexLevelView *nameSexLevelView;
UILabel *_mark;
UIButton *_follow;
BOOL isFollowed;
}
@end
@implementation IVTMyFollowListTableViewCell
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self)
{
__unsafe_unretained typeof (self) wself = self;
self.selectionStyle = UITableViewCellSelectionStyleNone;
_headIcon = [[UIImageView alloc] init];
_headIcon.image = [UIImage imageNamed:@"占位头像"];
[self.contentView addSubview:_headIcon];
_headIcon.clipsToBounds = YES;
_headIcon.layer.cornerRadius = 40/2;
[_headIcon mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.equalTo(wself.contentView.mas_leading).with.offset(12);
make.centerY.equalTo(wself.contentView);
make.size.mas_equalTo(CGSizeMake(39.5, 39.5));
}];
nameSexLevelView = [[NameSexLevelView alloc]init];
nameSexLevelView.userNickNameColor = UIColorFromRGBAlphaHex(0x343434, 1.0);
[self.contentView addSubview:nameSexLevelView];
[nameSexLevelView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(wself.contentView.mas_top).offset(10);
make.left.equalTo(_headIcon.mas_right).offset(10);
make.width.mas_equalTo(50);
make.height.mas_equalTo(18);
}];
_mark = [[UILabel alloc]init];
[self.contentView addSubview:_mark];
_mark.backgroundColor = [UIColor clearColor];
_mark.textColor = [UIColor YXColorWithHexCode:@"#8d8d8d"];
_mark.font = [UIFont YXFontOfSize:11];
_mark.textAlignment = NSTextAlignmentLeft;
[_mark mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(_headIcon.mas_right).with.offset(10);
make.right.equalTo(wself.contentView.mas_right).with.offset(-50);
make.top.equalTo(nameSexLevelView.mas_bottom).offset(5);
make.height.mas_equalTo(15);
}];
_follow =[UIButton buttonWithType:UIButtonTypeCustom];
[_follow addTarget:self action:@selector(followClick:) forControlEvents:UIControlEventTouchUpInside];
[self.contentView addSubview:_follow];
[_follow mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(27.5, 27.5));
make.top.equalTo(wself.contentView.mas_top).with.offset(16);
make.trailing.equalTo(wself.contentView.mas_trailing).with.offset(-17);
}];
UIImageView *lineImageView = [[UIImageView alloc]init];
lineImageView.backgroundColor = UIColorFromRGBAlphaHex(0xdcdcdc, 1.0);
[self.contentView addSubview:lineImageView];
[lineImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(wself.contentView.mas_left).offset(62);
make.bottom.equalTo(wself.contentView.mas_bottom);
make.width.mas_equalTo(kScreenWidth-62);
make.height.mas_equalTo(0.4);
}];
}
return self;
}
- (void)setEntity:(NSDictionary *)entity{
_entity = entity;
if (![[_entity valueForKey:@"avatar"] isEqualToString:@"http://me.demo.bjivt.com/api/avatar.png"]){
[_headIcon sd_setImageWithURL:[NSURL URLWithString:[_entity valueForKey:@"avatar"]]];
}else{
_headIcon.image = [UIImage imageNamed:@"占位头像"];
}
nameSexLevelView.userNickName = _entity[@"name"];
nameSexLevelView.userSex = _entity[@"sex"];
nameSexLevelView.userLevel = _entity[@"level"];
_mark.text = [_entity[@"signature"] base64DecodedToString];
if ([_entity[@"id"] integerValue] == [[IVTAccountTool getUserId] integerValue]) {
_follow.hidden = YES;
}
else{
_follow.hidden = NO;
isFollowed = [IVTAccountTool isFollowedToUserId:[self.entity valueForKey:@"id"]];
if (isFollowed) {
[_follow setBackgroundImage:[UIImage imageNamed:@"已添加关注图标"] forState:UIControlStateNormal];
}
else{
[_follow setBackgroundImage:[UIImage imageNamed:@"添加关注图标"] forState:UIControlStateNormal];
}
}
}
-(void)followClick:(id)sender{
if (isFollowed == NO) {
[[IVTNetworkAPIClient sharedClient] doFollowUser:self.entity[@"id"] success:^(NSDictionary *successData) {
isFollowed = YES;
//添加到已关注列表
[IVTAccountTool insertToMyFollowListArrayWithUserDict:self.entity];
[_follow setBackgroundImage:[UIImage imageNamed:@"已添加关注图标"] forState:UIControlStateNormal];
[SVProgressHUD setMinimumDismissTimeInterval:2];
[SVProgressHUD showSuccessWithStatus:@"关注成功"];
} error:^(NSDictionary *successData) {
} failure:^(NSError *failureError) {
}];
}
else{
[[IVTNetworkAPIClient sharedClient] doCancelFollowUser:self.entity[@"id"] success:^(NSDictionary *successData) {
isFollowed = NO;
//取消关注,从列表删除
[IVTAccountTool deleteMyFollowToUserId:self.entity[@"id"]];
[_follow setBackgroundImage:[UIImage imageNamed:@"添加关注图标"] forState:UIControlStateNormal];
[SVProgressHUD setMinimumDismissTimeInterval:2];
[SVProgressHUD showSuccessWithStatus:@"取消关注"];
} error:^(NSDictionary *successData) {
} failure:^(NSError *failureError) {
}];
}
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end