forked from coding/Coding-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPRMRSearchCell.m
More file actions
255 lines (221 loc) · 12.1 KB
/
PRMRSearchCell.m
File metadata and controls
255 lines (221 loc) · 12.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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
//
// PRMRSearchCell.m
// Coding_iOS
//
// Created by jwill on 15/11/24.
// Copyright © 2015年 Coding. All rights reserved.
//
#define kBaseCellHeight 110
#define kMRPRListCell_UserWidth 40.0
#define kDetialContentMaxHeight 36.0
#define kDetialContentWidth (kScreen_Width - 2*kPaddingLeftWidth - 12 - kMRPRListCell_UserWidth)
#import "PRMRSearchCell.h"
#import "NSString+Attribute.h"
@interface PRMRSearchCell ()
@property (strong, nonatomic) UIImageView *imgView,*arrowIcon,*timeClockIconView;
@property (strong, nonatomic) UILabel *titleLabel, *subTitleLabel,*fromL,*toL,*describeLab,*timeLabel,*statusLab;
@end
@implementation PRMRSearchCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
self.accessoryType = UITableViewCellAccessoryNone;
self.backgroundColor = [UIColor clearColor];
if (!_imgView) {
_imgView = [UIImageView new];
_imgView.layer.masksToBounds = YES;
_imgView.layer.cornerRadius = kMRPRListCell_UserWidth/2;
_imgView.layer.borderWidth = 0.5;
_imgView.layer.borderColor = [UIColor colorWithHexString:@"0xdddddd"].CGColor;
[self.contentView addSubview:_imgView];
[_imgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(kMRPRListCell_UserWidth, kMRPRListCell_UserWidth));
make.left.equalTo(self.contentView).offset(kPaddingLeftWidth);
make.top.equalTo(self.contentView).offset(18);
}];
}
if (!_titleLabel) {
_titleLabel = [UILabel new];
_titleLabel.textColor=[UIColor colorWithHexString:@"0x222222"];
_titleLabel.font=[UIFont boldSystemFontOfSize:16];
[self.contentView addSubview:_titleLabel];
[_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(_imgView.mas_right).offset(12);
make.right.equalTo(self.contentView);
make.top.equalTo(self.contentView).offset(13);
make.height.mas_equalTo(20);
}];
}
if (!_describeLab) {
_describeLab = [UILabel new];
_describeLab.textColor = [UIColor colorWithHexString:@"0x666666"];
_describeLab.font = [UIFont systemFontOfSize:15];
_describeLab.numberOfLines=2;
[self.contentView addSubview:_describeLab];
}
if (!_subTitleLabel) {
_subTitleLabel = [UILabel new];
_subTitleLabel.font=[UIFont boldSystemFontOfSize:12];
_subTitleLabel.textColor=[UIColor colorWithHexString:@"0x999999"];
[self.contentView addSubview:_subTitleLabel];
// [_subTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
// make.left.right.height.equalTo(_titleLabel);
// make.bottom.equalTo(self.contentView.mas_bottom).offset(-13);
// }];
}
if (!self.timeClockIconView) {
self.timeClockIconView = [UIImageView new];
self.timeClockIconView.image = [UIImage imageNamed:@"time_clock_icon"];
[self.contentView addSubview:self.timeClockIconView];
[self.timeClockIconView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(_subTitleLabel);
make.size.mas_equalTo(CGSizeMake(12, 12));
make.left.equalTo(_subTitleLabel.mas_right).offset(6);
}];
}
if (!self.timeLabel) {
self.timeLabel = [UILabel new];
self.timeLabel.font = [UIFont boldSystemFontOfSize:12];
self.timeLabel.textAlignment = NSTextAlignmentLeft;
self.timeLabel.textColor = [UIColor colorWithHexString:@"0x999999"];
[self.contentView addSubview:self.timeLabel];
}
if (!self.statusLab) {
self.statusLab = [UILabel new];
self.statusLab.font = [UIFont boldSystemFontOfSize:12];
self.statusLab.textAlignment = NSTextAlignmentLeft;
self.statusLab.textColor = [UIColor colorWithHexString:@"0xFB3B30"];
[self.contentView addSubview:self.statusLab];
[self.statusLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(_subTitleLabel);
make.height.equalTo(@(15));
make.left.equalTo(_timeLabel.mas_right).offset(6);
make.right.lessThanOrEqualTo(self.contentView).offset(-4);
}];
}
if (!_fromL) {
_fromL = [UILabel new];
[_fromL doBorderWidth:0.5 color:[UIColor colorWithHexString:@"0x4E90BF"] cornerRadius:2.0];
_fromL.font = [UIFont systemFontOfSize:12];
_fromL.textColor = [UIColor colorWithHexString:@"0x4E90BF"];
[self.contentView addSubview:_fromL];
}
if (!_arrowIcon) {
_arrowIcon = [UIImageView new];
_arrowIcon.image = [UIImage imageNamed:@"mrpr_icon_arrow"];
[self.contentView addSubview:_arrowIcon];
}
if (!_toL) {
_toL = [UILabel new];
[_toL doBorderWidth:0.5 color:[UIColor colorWithHexString:@"0x4E90BF"] cornerRadius:2.0];
_toL.font = [UIFont systemFontOfSize:12];
_toL.textColor = [UIColor colorWithHexString:@"0x4E90BF"];
[self.contentView addSubview:_toL];
}
[_fromL mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(_titleLabel);
make.top.equalTo(_titleLabel.mas_bottom).offset(10);
make.height.mas_equalTo(20);
}];
[_arrowIcon mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(_fromL.mas_right).offset(10);
make.centerY.equalTo(_fromL);
make.size.mas_equalTo(CGSizeMake(15, 15));
make.right.lessThanOrEqualTo(self.contentView).offset(-kPaddingLeftWidth);
}];
}
return self;
}
- (void)setCurMRPR:(MRPR *)curMRPR{
_curMRPR = curMRPR;
if (!_curMRPR) {
return;
}
[_imgView sd_setImageWithURL:[_curMRPR.author.avatar urlImageWithCodePathResize:2*kMRPRListCell_UserWidth] placeholderImage:kPlaceholderMonkeyRoundWidth(2*kMRPRListCell_UserWidth)];
_titleLabel.attributedText = [NSString getAttributeFromText:[_curMRPR.title stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] emphasizeTag:@"em" emphasizeColor:[UIColor colorWithHexString:@"0xE84D60"]];
// _subTitleLabel.attributedText = [self attributeTail];
_subTitleLabel.text=[NSString stringWithFormat:@"#%@ %@", [_curMRPR.iid stringValue], _curMRPR.author.name? _curMRPR.author.name: @""];
[_subTitleLabel setLongString:_subTitleLabel.text withVariableWidth:kScreen_Width / 2];
[_subTitleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(_titleLabel);
make.bottom.equalTo(self.contentView.mas_bottom).offset(-13);
}];
_timeLabel.text=_curMRPR.created_at? [_curMRPR.created_at stringDisplay_HHmm]: @"";
[_timeLabel setLongString:_timeLabel.text withVariableWidth:kScreen_Width / 2];
[_timeLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(_timeClockIconView.mas_right).offset(3);
make.bottom.equalTo(self.contentView.mas_bottom).offset(-13);
}];
_statusLab.text= _curMRPR.statusDisplay;
NSString *fromStr, *toStr;
if (_curMRPR.isMR) {
fromStr = [NSString stringWithFormat:@" %@ ", _curMRPR.source_branch];
toStr = [NSString stringWithFormat:@" %@ ", _curMRPR.target_branch];
}else{
fromStr = [NSString stringWithFormat:@" %@ : %@ ", _curMRPR.author.name, _curMRPR.source_branch];
toStr = [NSString stringWithFormat:@" %@ : %@ ", _curMRPR.des_owner_name, _curMRPR.target_branch];
}
NSString *totalStr = [NSString stringWithFormat:@"%@%@", fromStr, toStr];
if ([totalStr getWidthWithFont:[UIFont systemFontOfSize:12] constrainedToSize:CGSizeMake(CGFLOAT_MAX, 20)] + 40 > kScreen_Width - 2*kPaddingLeftWidth) {
[_toL mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(_titleLabel);
make.top.equalTo(_fromL.mas_bottom).offset(15);
make.height.equalTo(_fromL);
make.right.lessThanOrEqualTo(self.contentView).offset(-5);
}];
}else{
[_toL mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(_arrowIcon.mas_right).offset(10);
make.top.equalTo(_fromL);
make.height.top.equalTo(_fromL);
make.right.lessThanOrEqualTo(self.contentView).offset(-5);
}];
}
[_describeLab mas_updateConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(_titleLabel);
make.top.equalTo(_toL.mas_bottom).offset(8);
make.height.equalTo(@([PRMRSearchCell contentLabelHeightWithPRMR:_curMRPR]+2));
make.width.equalTo(@(kDetialContentWidth));
}];
// _fromL.attributedText = [NSString getAttributeFromText:[fromStr stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] emphasizeTag:@"em" emphasizeColor:[UIColor colorWithHexString:@"0xE84D60"]];
// _toL.attributedText = [NSString getAttributeFromText:[toStr stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] emphasizeTag:@"em" emphasizeColor:[UIColor colorWithHexString:@"0xE84D60"]];
_fromL.text = [NSString getStr:fromStr removeEmphasize:@"em"];
_toL.text = [NSString getStr:toStr removeEmphasize:@"em"];
_describeLab.attributedText=[NSString getAttributeFromText:[[_curMRPR.body firstObject] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] emphasizeTag:@"em" emphasizeColor:[UIColor colorWithHexString:@"0xE84D60"]];
}
- (NSAttributedString *)attributeTail{
NSString *numStr = [_curMRPR.iid stringValue];
NSString *nameStr = _curMRPR.author.name? _curMRPR.author.name: @"";
NSString *timeStr = _curMRPR.created_at? [_curMRPR.created_at stringDisplay_HHmm]: @"";
NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"#%@ %@ %@",numStr, nameStr, timeStr]];
// [attrString addAttributes:@{NSFontAttributeName : [UIFont boldSystemFontOfSize:12],
// NSForegroundColorAttributeName : [UIColor colorWithHexString:@"0x222222"]}
// range:NSMakeRange(0, nameStr.length)];
[attrString addAttributes:@{NSFontAttributeName : [UIFont boldSystemFontOfSize:12],
NSForegroundColorAttributeName : [UIColor colorWithHexString:@"0x999999"]}
range:NSMakeRange(0,numStr.length+timeStr.length+nameStr.length+3)];
return attrString;
}
+ (CGFloat)cellHeightWithObj:(id)obj {
MRPR *mrpr = (MRPR *)obj;
NSString *fromStr, *toStr;
if (mrpr.isMR) {
fromStr = [NSString stringWithFormat:@" %@ ", mrpr.source_branch];
toStr = [NSString stringWithFormat:@" %@ ", mrpr.target_branch];
}else{
fromStr = [NSString stringWithFormat:@" %@ : %@ ", mrpr.author.name, mrpr.source_branch];
toStr = [NSString stringWithFormat:@" %@ : %@ ", mrpr.des_owner_name, mrpr.target_branch];
}
NSString *totalStr = [NSString stringWithFormat:@"%@%@", fromStr, toStr];
float offset= ([totalStr getWidthWithFont:[UIFont systemFontOfSize:12] constrainedToSize:CGSizeMake(CGFLOAT_MAX, 20)] + 40 > kScreen_Width - 2*kPaddingLeftWidth)?(15+20):0;
return kBaseCellHeight+[PRMRSearchCell contentLabelHeightWithPRMR:mrpr]+offset;
}
+ (CGFloat)contentLabelHeightWithPRMR:(MRPR *)curMRPR{
NSString *content = [curMRPR.body firstObject];
NSString *realContent=[NSString getStr:content removeEmphasize:@"em"];
CGFloat realheight = [realContent getHeightWithFont:[UIFont systemFontOfSize:15] constrainedToSize:CGSizeMake(kDetialContentWidth, 1000)];
return MIN(realheight, kDetialContentMaxHeight);
}
@end