-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathMRPRListCell.m
165 lines (155 loc) · 7.76 KB
/
MRPRListCell.m
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
//
// MRPRListCell.m
// Coding_iOS
//
// Created by Ease on 15/5/29.
// Copyright (c) 2015年 Coding. All rights reserved.
//
#import "MRPRListCell.h"
@interface MRPRListCell ()
@property (strong, nonatomic) UIImageView *statusIcon;
@property (strong, nonatomic) UILabel *titleL, *numL, *authorL, *timeL, *commentCountL;
@property (strong, nonatomic) UIImageView *timeIcon, *commentIcon, *arrowIcon;
@property (strong, nonatomic) UILabel *fromL, *toL;
@end
@implementation MRPRListCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
self.backgroundColor = kColorTableBG;
_statusIcon = [UIImageView new];
_titleL = [UILabel labelWithSystemFontSize:15 textColorHexString:@"0x323A45"];
_numL = [UILabel labelWithSystemFontSize:12 textColorHexString:@"0x76808E"];
_authorL = [UILabel labelWithSystemFontSize:12 textColorHexString:@"0x76808E"];
_timeL = [UILabel labelWithSystemFontSize:12 textColorHexString:@"0x76808E"];
_commentCountL = [UILabel labelWithSystemFontSize:12 textColorHexString:@"0x76808E"];
_timeIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"time_clock_icon"]];
_commentIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"topic_comment_icon"]];
_arrowIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"mrpr_icon_arrow"]];
_fromL = [UILabel labelWithSystemFontSize:12 textColorHexString:@"0x76808E"];
_fromL.backgroundColor = [UIColor colorWithHexString:@"0xF2F4F6"];
_fromL.cornerRadius = 2;
_fromL.masksToBounds = YES;
// [_fromL doBorderWidth:0.5 color:[UIColor colorWithHexString:@"0x76808E"] cornerRadius:2.0];
_toL = [UILabel labelWithSystemFontSize:12 textColorHexString:@"0x76808E"];
_toL.backgroundColor = [UIColor colorWithHexString:@"0xD8DDE4"];
_toL.cornerRadius = 2;
_toL.masksToBounds = YES;
// [_toL doBorderWidth:0.5 color:[UIColor colorWithHexString:@"0x76808E"] cornerRadius:2.0];
for (UIView *tempV in @[_statusIcon, _titleL, _numL, _authorL, _timeL, _commentCountL, _timeIcon, _commentIcon, _arrowIcon, _fromL, _toL]) {
[self.contentView addSubview:tempV];
}
[_statusIcon mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView).offset(kPaddingLeftWidth);
make.top.equalTo(self.contentView).offset(15);
make.size.mas_equalTo(CGSizeMake(24, 24));
}];
[_titleL mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(_statusIcon);
make.left.equalTo(_statusIcon.mas_right).offset(kPaddingLeftWidth);
make.right.equalTo(self.contentView).offset(-kPaddingLeftWidth);
make.height.mas_equalTo(21);
}];
[_fromL mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(_titleL.mas_bottom).offset(10);
make.height.mas_equalTo(22);
make.left.equalTo(_titleL);
}];
[_arrowIcon mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(_fromL.mas_right).offset(10);
make.centerY.equalTo(_fromL);
make.size.mas_equalTo(CGSizeMake(12, 12));
make.right.lessThanOrEqualTo(self.contentView).offset(-kPaddingLeftWidth);
}];
[_toL mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(_arrowIcon.mas_right).offset(10);
make.centerY.equalTo(_fromL);
make.height.mas_equalTo(22);
make.right.lessThanOrEqualTo(self.contentView).offset(-kPaddingLeftWidth);
}];
[_numL mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(_toL.mas_bottom).offset(10);
make.left.equalTo(_titleL);
make.height.mas_equalTo(17);
}];
[@[_authorL, _timeIcon, _timeL, _commentIcon, _commentCountL] mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(_numL);
}];
[_authorL mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(_numL.mas_right).offset(10);
make.right.equalTo(_timeIcon.mas_left).offset(-10);
}];
[_timeL mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(_timeIcon.mas_right).offset(5);
make.right.equalTo(_commentIcon.mas_left).offset(-10);
}];
[_commentCountL mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(_commentIcon.mas_right).offset(5);
}];
}
return self;
}
- (void)setCurMRPR:(MRPR *)curMRPR{
_curMRPR = curMRPR;
if (!_curMRPR) {
return;
}
_statusIcon.image = [UIImage imageNamed:[NSString stringWithFormat:@"mrpr_icon_status_%@", [_curMRPR.merge_status lowercaseString]]];
_titleL.text = _curMRPR.title;
_numL.text = [NSString stringWithFormat:@"#%@", _curMRPR.iid.stringValue ?: @""];
_authorL.text = _curMRPR.author.name;
_timeL.text = [_curMRPR.created_at stringDisplay_HHmm];
_commentCountL.text = _curMRPR.comment_count.stringValue;
_commentCountL.hidden = _commentIcon.hidden = (_curMRPR.comment_count == nil);
NSString *fromStr, *toStr;
if (_curMRPR.isMR) {
fromStr = [NSString stringWithFormat:@" %@ ", _curMRPR.srcBranch];
toStr = [NSString stringWithFormat:@" %@ ", _curMRPR.desBranch];
}else{
fromStr = [NSString stringWithFormat:@" %@ : %@ ", _curMRPR.src_owner_name ?: @"已删除项目", _curMRPR.srcBranch];
toStr = [NSString stringWithFormat:@" %@ : %@ ", _curMRPR.des_owner_name ?: @"已删除项目", _curMRPR.desBranch];
}
NSString *totalStr = [NSString stringWithFormat:@"%@%@", fromStr, toStr];
if ([totalStr getWidthWithFont:[UIFont systemFontOfSize:12] constrainedToSize:CGSizeMake(CGFLOAT_MAX, 20)] + 40 > kScreen_Width - (24 + 2* kPaddingLeftWidth) - kPaddingLeftWidth) {
[_toL mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(_titleL);
make.top.equalTo(_fromL.mas_bottom).offset(15);
make.height.mas_equalTo(22);
make.right.lessThanOrEqualTo(self.contentView).offset(-kPaddingLeftWidth);
}];
}else{
[_toL mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(_arrowIcon.mas_right).offset(10);
make.centerY.equalTo(_fromL);
make.height.mas_equalTo(22);
make.right.lessThanOrEqualTo(self.contentView).offset(-kPaddingLeftWidth);
}];
}
_fromL.text = fromStr;
_toL.text = toStr;
}
+ (CGFloat)cellHeight{
return 110.0;
}
+ (CGFloat)cellHeightWithObj:(id)obj{
CGFloat cellHeight = 110.0;
if ([obj isKindOfClass:[MRPR class]]) {
MRPR *curMRPR = (MRPR *)obj;
NSString *fromStr, *toStr;
if (curMRPR.isMR) {
fromStr = [NSString stringWithFormat:@" %@ ", curMRPR.srcBranch];
toStr = [NSString stringWithFormat:@" %@ ", curMRPR.desBranch];
}else{
fromStr = [NSString stringWithFormat:@" %@ : %@ ", curMRPR.src_owner_name ?: @"已删除项目", curMRPR.srcBranch];
toStr = [NSString stringWithFormat:@" %@ : %@ ", curMRPR.des_owner_name ?: @"已删除项目", curMRPR.desBranch];
}
NSString *totalStr = [NSString stringWithFormat:@"%@%@", fromStr, toStr];
if ([totalStr getWidthWithFont:[UIFont systemFontOfSize:12] constrainedToSize:CGSizeMake(CGFLOAT_MAX, 20)] + 40 > kScreen_Width - (24 + 2* kPaddingLeftWidth) - kPaddingLeftWidth) {
cellHeight += 15 + 22;
}
}
return cellHeight;
}
@end