forked from coding/Coding-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskActivityCell.m
More file actions
150 lines (131 loc) · 7.45 KB
/
TaskActivityCell.m
File metadata and controls
150 lines (131 loc) · 7.45 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
//
// TaskActivityCell.m
// Coding_iOS
//
// Created by Ease on 15/6/18.
// Copyright (c) 2015年 Coding. All rights reserved.
//
#define kTaskActivityCell_LeftContentPading (kPaddingLeftWidth + 40)
#define kTaskActivityCell_ContentWidth (kScreen_Width - kTaskActivityCell_LeftContentPading - kPaddingLeftWidth)
#import "TaskActivityCell.h"
@interface TaskActivityCell ()
@property (strong, nonatomic) UIImageView *tipIconView, *timeLineView;
@property (strong, nonatomic) UILabel *contentLabel;
@end
@implementation TaskActivityCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
self.selectionStyle = UITableViewCellSelectionStyleNone;
if (!_timeLineView) {
_timeLineView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 2, 1)];
[_timeLineView setImage:[UIImage imageNamed:@"timeline_line_read"]];
[self.contentView addSubview:_timeLineView];
}
if (!_tipIconView) {
CGFloat borderWidth = 2;
_tipIconView = [[UIImageView alloc] initWithFrame:CGRectMake(kPaddingLeftWidth - borderWidth, 10, 28 + 2*borderWidth, 28 + 2*borderWidth)];
_tipIconView.contentMode = UIViewContentModeCenter;
_tipIconView.layer.masksToBounds = YES;
_tipIconView.layer.cornerRadius = _tipIconView.frame.size.width/2;
_tipIconView.layer.borderWidth = borderWidth;
_tipIconView.layer.borderColor = kColorTableBG.CGColor;
[self.contentView addSubview:_tipIconView];
}
if (!_contentLabel) {
_contentLabel = [[UITTTAttributedLabel alloc] initWithFrame:CGRectMake(kTaskActivityCell_LeftContentPading, 13, kTaskActivityCell_ContentWidth, 15)];
_contentLabel.numberOfLines = 0;
[self.contentView addSubview:_contentLabel];
}
}
return self;
}
- (void)setCurActivity:(ProjectActivity *)curActivity{
_curActivity = curActivity;
if (!_curActivity) {
return;
}
NSString *tipIconImageName;
if ([curActivity.target_type isEqualToString:@"Task"]) {
tipIconImageName = [NSString stringWithFormat:@"task_activity_icon_%@", _curActivity.action];
}else if ([curActivity.target_type isEqualToString:@"ProjectFile"]){
tipIconImageName = [NSString stringWithFormat:@"file_activity_icon_%@", _curActivity.action];
}
_tipIconView.image = [UIImage imageNamed:tipIconImageName];
NSAttributedString *attrContent = [[self class] attrContentWithObj:_curActivity];
CGFloat contentHeight = [attrContent boundingRectWithSize:CGSizeMake(kTaskActivityCell_ContentWidth, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin context:nil].size.height;
[self.contentLabel setHeight:contentHeight];
self.contentLabel.attributedText = attrContent;
}
- (void)configTop:(BOOL)isTop andBottom:(BOOL)isBottom{
if (isTop && isBottom) {
_timeLineView.hidden = YES;
}else{
_timeLineView.hidden = NO;
[_timeLineView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(2.0);
make.centerX.equalTo(_tipIconView);
make.top.equalTo(isTop? _tipIconView.mas_centerY: self.contentView);
make.bottom.equalTo(isBottom? _tipIconView.mas_centerY: self.contentView);
}];
}
}
+ (NSAttributedString *)attrContentWithObj:(ProjectActivity *)curActivity{
if (![curActivity.target_type isEqualToString:@"Task"]) {
return nil;
}
NSString *userName, *contentStr;
userName = curActivity.user.name? curActivity.user.name: @"";
NSMutableAttributedString *attrContent;
if ([curActivity.action isEqualToString:@"create"]) {
contentStr = [NSString stringWithFormat:@"创建了任务 - %@", [curActivity.created_at stringDisplay_HHmm]];
}else if ([curActivity.action isEqualToString:@"update"]) {
contentStr = [NSString stringWithFormat:@"更新了任务 - %@", [curActivity.created_at stringDisplay_HHmm]];
}else if ([curActivity.action isEqualToString:@"update_priority"]) {
contentStr = [NSString stringWithFormat:@"更新了任务优先级为 「%@」 - %@", kTaskPrioritiesDisplay[curActivity.task.priority.intValue], [curActivity.created_at stringDisplay_HHmm]];
}else if ([curActivity.action isEqualToString:@"update_deadline"]) {
if (curActivity.task.deadline_date) {
contentStr = [NSString stringWithFormat:@"更新了任务截止日期为 「%@」 - %@", [NSDate convertStr_yyyy_MM_ddToDisplay:curActivity.task.deadline], [curActivity.created_at stringDisplay_HHmm]];
}else{
contentStr = [NSString stringWithFormat:@"移除了任务的截止日期 - %@", [curActivity.created_at stringDisplay_HHmm]];
}
}else if ([curActivity.action isEqualToString:@"update_description"]) {
contentStr = [NSString stringWithFormat:@"更新了任务描述 - %@", [curActivity.created_at stringDisplay_HHmm]];
}else if ([curActivity.action isEqualToString:@"reassign"]) {
contentStr = [NSString stringWithFormat:@"重新指派了任务给了 「%@」 - %@", curActivity.task.owner.name, [curActivity.created_at stringDisplay_HHmm]];
}else if ([curActivity.action isEqualToString:@"finish"]) {
contentStr = [NSString stringWithFormat:@"完成了任务 - %@", [curActivity.created_at stringDisplay_HHmm]];
}else if ([curActivity.action isEqualToString:@"restore"]) {
contentStr = [NSString stringWithFormat:@"重新开启了任务 - %@", [curActivity.created_at stringDisplay_HHmm]];
}else if ([curActivity.action isEqualToString:@"commit_refer"]) {
contentStr = [NSString stringWithFormat:@"在分支 %@ 中提交的代码提到了任务 - %@\n%@", curActivity.commit.ref, [curActivity.created_at stringDisplay_HHmm], curActivity.commit.contentStr];
}else{
contentStr = @"...";
}
attrContent = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@ %@", userName, contentStr]];
[attrContent addAttributes:@{NSFontAttributeName : [UIFont boldSystemFontOfSize:13],
NSForegroundColorAttributeName : [UIColor colorWithHexString:@"0x222222"]}
range:NSMakeRange(0, userName.length)];
[attrContent addAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:13],
NSForegroundColorAttributeName : [UIColor colorWithHexString:@"0x999999"]}
range:NSMakeRange(userName.length + 1, contentStr.length)];
NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];
paragraphStyle.minimumLineHeight = 18;
[attrContent addAttribute:NSParagraphStyleAttributeName
value:paragraphStyle
range:NSMakeRange(0, [attrContent length])];
return attrContent;
}
+ (CGFloat)cellHeightWithObj:(id)obj{
CGFloat cellHeight = 0;
if ([obj isKindOfClass:[ProjectActivity class]]) {
NSAttributedString *attrContent = [self attrContentWithObj:obj];
CGFloat contentHeight = [attrContent boundingRectWithSize:CGSizeMake(kTaskActivityCell_ContentWidth, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin context:nil].size.height;
cellHeight = ceilf(contentHeight + 26);
cellHeight = MAX(44, cellHeight);
}
return cellHeight;
}
@end