-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathCommitContentCell.m
118 lines (108 loc) · 5.41 KB
/
CommitContentCell.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
//
// CommitContentCell.m
// Coding_iOS
//
// Created by Ease on 15/6/1.
// Copyright (c) 2015年 Coding. All rights reserved.
//
#define kCommitContentCell_FontTitle [UIFont boldSystemFontOfSize:18]
#import "CommitContentCell.h"
@interface CommitContentCell ()
@property (strong, nonatomic) UIImageView *userIconView;
@property (strong, nonatomic) UILabel *titleL, *timeL, *statusL;
@property (strong, nonatomic) UIView *lineView;
@end
@implementation CommitContentCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
self.selectionStyle = UITableViewCellSelectionStyleNone;
self.backgroundColor = kColorTableBG;
if (!_userIconView) {
_userIconView = [[YLImageView alloc] initWithFrame:CGRectMake(kPaddingLeftWidth, 0, 20, 20)];
[_userIconView doCircleFrame];
[self.contentView addSubview:_userIconView];
}
CGFloat curWidth = kScreen_Width - 2 * kPaddingLeftWidth;
if (!_titleL) {
_titleL = [[UILabel alloc] initWithFrame:CGRectMake(kPaddingLeftWidth, 15, curWidth, 30)];
_titleL.textColor = kColor222;
_titleL.font = kCommitContentCell_FontTitle;
[self.contentView addSubview:_titleL];
}
if (!_timeL) {
_timeL = [[UILabel alloc] initWithFrame:CGRectMake(kPaddingLeftWidth +25, 0, curWidth, 20)];
_timeL.textColor = kColor999;
_timeL.font = [UIFont systemFontOfSize:12];
[self.contentView addSubview:_timeL];
[_timeL mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(_userIconView.mas_right).offset(5);
make.centerY.equalTo(_userIconView);
make.height.mas_equalTo(20);
}];
}
if (!_statusL) {
_statusL = [[UILabel alloc] initWithFrame:CGRectMake(kPaddingLeftWidth +25, 0, curWidth, 20)];
_statusL.textColor = [UIColor colorWithHexString:@"0xFB3B30"];
_statusL.font = [UIFont systemFontOfSize:12];
_statusL.textAlignment = NSTextAlignmentRight;
[self.contentView addSubview:_statusL];
[_statusL mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(_timeL.mas_right).offset(10);
make.centerY.height.equalTo(_timeL);
make.right.equalTo(self.contentView).offset(-kPaddingLeftWidth);
make.width.mas_equalTo(80);
}];
}
if (!_lineView) {
_lineView = [UIView new];
_lineView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"dot_line"]];
[self.contentView addSubview:_lineView];
[_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView).offset(kPaddingLeftWidth);
make.right.equalTo(self.contentView).offset(-kPaddingLeftWidth);
make.bottom.equalTo(self.contentView).offset(-0.5);
make.height.mas_equalTo(0.5);
}];
}
}
return self;
}
- (void)setCurCommitInfo:(CommitInfo *)curCommitInfo{
_curCommitInfo = curCommitInfo;
if (!_curCommitInfo) {
return;
}
CGFloat curBottomY = 0;
CGFloat curWidth = kScreen_Width -2*kPaddingLeftWidth;
[_titleL setLongString:_curCommitInfo.commitDetail.fullMessage withFitWidth:curWidth];
curBottomY += CGRectGetMaxY(_titleL.frame) + 15;
[_userIconView sd_setImageWithURL:[_curCommitInfo.commitDetail.committer.avatar urlImageWithCodePathResizeToView:_userIconView] placeholderImage:kPlaceholderMonkeyRoundView(_userIconView)];
[_userIconView setY:curBottomY];
_timeL.attributedText = [self attributeTimeStr];
_statusL.text = _curCommitInfo.commitDetail.commitId.length > 10? [_curCommitInfo.commitDetail.commitId substringToIndex:10]: _curCommitInfo.commitDetail.commitId;
}
- (NSAttributedString *)attributeTimeStr{
NSString *nameStr = _curCommitInfo.commitDetail.committer.name? _curCommitInfo.commitDetail.committer.name: @"";
NSString *timeStr = _curCommitInfo.commitDetail.commitTime? [_curCommitInfo.commitDetail.commitTime stringDisplay_HHmm]: @"";
NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@ %@", nameStr, timeStr]];
[attrString addAttributes:@{NSFontAttributeName : [UIFont boldSystemFontOfSize:12],
NSForegroundColorAttributeName : kColor222}
range:NSMakeRange(0, nameStr.length)];
[attrString addAttributes:@{NSFontAttributeName : [UIFont boldSystemFontOfSize:12],
NSForegroundColorAttributeName : kColor999}
range:NSMakeRange(nameStr.length + 1, timeStr.length)];
return attrString;
}
+ (CGFloat)cellHeightWithObj:(id)obj{
CGFloat cellHeight = 0;
if ([obj isKindOfClass:[CommitInfo class]]) {
CommitInfo *curCommitInfo = (CommitInfo *)obj;
CGFloat curWidth = kScreen_Width -2*kPaddingLeftWidth;
cellHeight += 8 + [curCommitInfo.commitDetail.fullMessage getHeightWithFont:kCommitContentCell_FontTitle constrainedToSize:CGSizeMake(curWidth, CGFLOAT_MAX)];
cellHeight += 15 + 15 + 20 + 15;
}
return cellHeight;
}
@end