forked from coding/Coding-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectPublicListCell.m
More file actions
236 lines (201 loc) · 9.57 KB
/
ProjectPublicListCell.m
File metadata and controls
236 lines (201 loc) · 9.57 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
//
// ProjectPublicListCell.m
// Coding_iOS
//
// Created by jwill on 15/11/16.
// Copyright © 2015年 Coding. All rights reserved.
//
#define kIconSize 90
#define kSwapBtnWidth 135
#define kLeftOffset 20
#define kPinSize 22
#import "ProjectPublicListCell.h"
#import "NSString+Attribute.h"
@interface ProjectPublicListCell ()
@property (nonatomic, strong) Project *project;
@property (nonatomic, strong) UIImageView *projectIconView, *privateIconView, *pinIconView;
@property (nonatomic, strong) UILabel *projectTitleLabel;
@property (nonatomic, strong) UILabel *ownerTitleLabel;
@property (nonatomic, strong) UILabel *describeLabel;
@property (nonatomic, strong) UIImageView *starV, *watchV, *forkV;
@property (strong, nonatomic) UILabel *desL, *starL, *watchL, *forkL;
@end
@implementation ProjectPublicListCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
self.backgroundColor = [UIColor clearColor];
if (!_projectIconView) {
_projectIconView = [[UIImageView alloc] initWithFrame:CGRectMake(12, 12, kIconSize, kIconSize)];
_projectIconView.layer.masksToBounds = YES;
_projectIconView.layer.cornerRadius = 2.0;
[self.contentView addSubview:_projectIconView];
}
if (!_projectTitleLabel) {
_projectTitleLabel = [UILabel new];
_projectTitleLabel.textColor = [UIColor colorWithHexString:@"0x222222"];
_projectTitleLabel.font = [UIFont systemFontOfSize:17];
[self.contentView addSubview:_projectTitleLabel];
}
if (!_describeLabel) {
_describeLabel = [UILabel new];
_describeLabel.textColor = [UIColor colorWithHexString:@"0x666666"];
_describeLabel.font = [UIFont systemFontOfSize:14];
_describeLabel.numberOfLines=1;
[self.contentView addSubview:_describeLabel];
}
if (!_privateIconView) {
_privateIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_project_private"]];
_privateIconView.hidden = YES;
[self.contentView addSubview:_privateIconView];
}
if (!_ownerTitleLabel) {
_ownerTitleLabel = [UILabel new];
_ownerTitleLabel.textColor = [UIColor colorWithHexString:@"0x999999"];
_ownerTitleLabel.font = [UIFont systemFontOfSize:11];
[self.contentView addSubview:_ownerTitleLabel];
}
[_ownerTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.equalTo(@(14));
make.width.equalTo(@(200));
make.left.equalTo(self.privateIconView);
make.bottom.equalTo(_projectIconView.mas_bottom);
}];
if (!_pinIconView) {
_pinIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_project_cell_setNormal"]];
_pinIconView.hidden = YES;
[self.contentView addSubview:_pinIconView];
[_pinIconView mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(kPinSize, kPinSize));
make.left.equalTo(self.projectIconView).offset(5);
make.top.equalTo(self.projectIconView).offset(6);
}];
}
if (!_starV) {
_starV = [[UIImageView alloc] init];
[self.contentView addSubview:_starV];
}
if (!_watchV) {
_watchV = [[UIImageView alloc] init];
[self.contentView addSubview:_watchV];
}
if (!_forkV) {
_forkV = [[UIImageView alloc] init];
[self.contentView addSubview:_forkV];
}
if (!_starL) {
_starL = [[UILabel alloc] init];
_starL.textColor = [UIColor colorWithHexString:@"0x999999"];
_starL.font = [UIFont systemFontOfSize:10];
[self.contentView addSubview:_starL];
}
if (!_watchL) {
_watchL = [[UILabel alloc] init];
_watchL.textColor = [UIColor colorWithHexString:@"0x999999"];
_watchL.font = [UIFont systemFontOfSize:10];
[self.contentView addSubview:_watchL];
}
if (!_forkL) {
_forkL = [[UILabel alloc] init];
_forkL.textColor = [UIColor colorWithHexString:@"0x999999"];
_forkL.font = [UIFont systemFontOfSize:10];
[self.contentView addSubview:_forkL];
}
_starV.image = [UIImage imageNamed:@"git_icon_star"];
_watchV.image = [UIImage imageNamed:@"git_icon_watch"];
_forkV.image = [UIImage imageNamed:@"git_icon_fork"];
[_starV mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(_ownerTitleLabel.mas_top).offset(-3);
make.left.equalTo(_privateIconView);
make.centerY.equalTo(@[_starL, _watchV, _watchL, _forkV, _forkL]);
make.width.height.equalTo(@[_watchV, _forkV, @12]);
}];
[_starL mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(_starV.mas_right).offset(2);
make.height.equalTo(@[_starV, _watchL, _forkL]);
}];
[_watchV mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(_starL.mas_right).offset(10);
}];
[_watchL mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(_watchV.mas_right).offset(2);
}];
[_forkV mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(_watchL.mas_right).offset(10);
}];
[_forkL mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(_forkV.mas_right).offset(2);
}];
}
return self;
}
- (void)setProject:(Project *)project hasSWButtons:(BOOL)hasSWButtons hasBadgeTip:(BOOL)hasBadgeTip hasIndicator:(BOOL)hasIndicator{
_project = project;
if (!_project) {
return;
}
//Icon
[_projectIconView sd_setImageWithURL:[_project.icon urlImageWithCodePathResizeToView:_projectIconView] placeholderImage:kPlaceholderCodingSquareWidth(55.0)];
_privateIconView.hidden = _project.is_public.boolValue;
[_privateIconView mas_updateConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(_privateIconView.hidden?CGSizeZero:CGSizeMake(12, 9));
make.centerY.equalTo(_projectTitleLabel.mas_centerY);
make.left.equalTo(_projectIconView.mas_right).offset(kLeftOffset);
}];
[_projectTitleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(_projectIconView.mas_top);
make.height.equalTo(@(20));
make.left.equalTo(_privateIconView.mas_right).offset(_privateIconView.hidden?0:8);
make.right.lessThanOrEqualTo(self.mas_right).offset(-12);
}];
[_describeLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.privateIconView);
make.height.equalTo(@(38));
make.width.equalTo(@(kScreen_Width-kLeftOffset-kIconSize-20));
make.top.equalTo(_projectTitleLabel.mas_bottom);
}];
//Title & description & star & watch &fork &owner+update_time
_projectTitleLabel.text = _project.name;
_describeLabel.text=_project.description_mine;
_starL.text = _project.star_count.stringValue;
_watchL.text = _project.watch_count.stringValue;
_forkL.text = _project.fork_count.stringValue;
NSString *titleStr=[NSString stringWithFormat:@"%@ 最后更新于 %@",_project.owner_user_name,[_project.updated_at stringDisplay_HHmm]];
_ownerTitleLabel.attributedText = [NSString getAttributeFromText:titleStr emphasize:_project.owner_user_name emphasizeColor:[UIColor colorWithHexString:@"0x3bbd79"]];
//hasSWButtons
[self setRightUtilityButtons:hasSWButtons? [self rightButtons]: nil
WithButtonWidth:kSwapBtnWidth];
//hasBadgeTip
if (hasBadgeTip) {
NSString *badgeTip = @"";
if (_project.un_read_activities_count && _project.un_read_activities_count.integerValue > 0) {
if (_project.un_read_activities_count.integerValue > 99) {
badgeTip = @"99+";
}else{
badgeTip = _project.un_read_activities_count.stringValue;
}
}
[self.contentView addBadgeTip:badgeTip withCenterPosition:CGPointMake(10+kIconSize, 15)];
}else{
[self.contentView removeBadgeTips];
}
//hasIndicator
self.accessoryType = hasIndicator? UITableViewCellAccessoryDisclosureIndicator: UITableViewCellAccessoryNone;
_pinIconView.hidden=!_project.pin.boolValue;
}
- (NSArray *)rightButtons{
NSMutableArray *rightUtilityButtons = [NSMutableArray new];
// [rightUtilityButtons sw_addUtilityButtonWithColor:[UIColor colorWithHexString:_project.pin.boolValue? @"0xe6e6e6": @"0x3bbd79"]
// icon:[UIImage imageNamed:_project.pin.boolValue? @"icon_project_cell_pin": @"icon_project_cell_nopin"]];
[rightUtilityButtons sw_addUtilityButtonWithColor:[UIColor colorWithHexString:_project.pin.boolValue? @"0xeeeeee": @"0x3bbd79"]
title:_project.pin.boolValue?@"取消常用":@"设置常用" titleColor:[UIColor colorWithHexString:_project.pin.boolValue?@"0x3bbd79":@"0xffffff"]];
return rightUtilityButtons;
}
-(void)showSliderAction
{
NSLog(@"tap");
[self showRightUtilityButtonsAnimated:TRUE];
}
@end