forked from coding/Coding-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectActivityListCell.m
More file actions
executable file
·180 lines (164 loc) · 8.88 KB
/
ProjectActivityListCell.m
File metadata and controls
executable file
·180 lines (164 loc) · 8.88 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
//
// ProjectActivityListCell.m
// Coding_iOS
//
// Created by 王 原闯 on 14-8-14.
// Copyright (c) 2014年 Coding. All rights reserved.
//
#define kProjectActivityListCell_IconHeight 33.0
#define kProjectActivityListCell_TimeIconWidth 13.0
#define kProjectActivityListCell_TimeLineWidth 2.0
#define kProjectActivityListCell_LeftPading 85
#define kProjectActivityListCell_RightPading kPaddingLeftWidth
#define kProjectActivityListCell_UpDownPading kScaleFrom_iPhone5_Desgin(10)
#define kProjectActivityListCell_TextPading 5.0
//#define kProjectActivityListCell_MaxActionHeight (40.0+kNotHigher_iOS_6_1_DIS(0))
//#define kProjectActivityListCell_MaxContentHeight (32.0+kNotHigher_iOS_6_1_DIS(0))
#define kProjectActivityListCell_MaxActionHeight 80.0
#define kProjectActivityListCell_MaxContentHeight 64.0
#define kProjectActivityListCell_TimeHeight 12.0
#define kProjectActivityListCell_ContentWidth (kScreen_Width - kProjectActivityListCell_LeftPading - kProjectActivityListCell_RightPading)
#define kProjectActivityListCell_ActionFont [UIFont systemFontOfSize:15]
#define kProjectActivityListCell_ContentFont [UIFont systemFontOfSize:13]
#define kProjectActivityListCell_TimeFont [UIFont systemFontOfSize:11]
#import "ProjectActivityListCell.h"
@interface ProjectActivityListCell ()<TTTAttributedLabelDelegate>
@property (nonatomic, strong) ProjectActivity *proAct;
@property (nonatomic, assign) BOOL haveRead, top, bottom;
@property (nonatomic, strong) UIImageView *timeIconView, *timeLineView;
@property (nonatomic, strong) UILabel *timeLabel;
@end
@implementation ProjectActivityListCell
- (void)configWithProAct:(ProjectActivity *)proAct haveRead:(BOOL)haveRead isTop:(BOOL)top isBottom:(BOOL)bottom{
self.proAct = proAct;
_haveRead = haveRead;
_top = top;
_bottom = bottom;
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
self.backgroundColor = [UIColor clearColor];
if (!_userIconView) {
_userIconView = [[UITapImageView alloc] initWithFrame:CGRectMake(kPaddingLeftWidth, kProjectActivityListCell_UpDownPading, kProjectActivityListCell_IconHeight, kProjectActivityListCell_IconHeight)];
[_userIconView doCircleFrame];
[self.contentView addSubview:_userIconView];
}
CGFloat imgRightX = CGRectGetMaxX(_userIconView.frame);
CGFloat timeLineCenterX = imgRightX + (kProjectActivityListCell_LeftPading-imgRightX)/2;
;
if (!_timeLineView) {
_timeLineView = [[UIImageView alloc] initWithFrame:CGRectMake(timeLineCenterX - kProjectActivityListCell_TimeLineWidth/2, 0, kProjectActivityListCell_TimeLineWidth, 1)];
// _timeLineView.contentMode = UIViewContentModeScaleToFill;
[self.contentView addSubview:_timeLineView];
}
if (!_timeIconView) {
_timeIconView = [[UIImageView alloc] initWithFrame:CGRectMake(timeLineCenterX - kProjectActivityListCell_TimeIconWidth/2, 10+(kProjectActivityListCell_IconHeight- kProjectActivityListCell_TimeIconWidth)/2 , kProjectActivityListCell_TimeIconWidth, kProjectActivityListCell_TimeIconWidth)];
[self.contentView addSubview:_timeIconView];
}
if (!_actionLabel) {
_actionLabel = [[UITTTAttributedLabel alloc] initWithFrame:CGRectMake(kProjectActivityListCell_LeftPading, kProjectActivityListCell_UpDownPading, kProjectActivityListCell_ContentWidth, 20)];
_actionLabel.backgroundColor = [UIColor clearColor];
_actionLabel.textColor = [UIColor colorWithHexString:@"0x222222"];
_actionLabel.font = kProjectActivityListCell_ActionFont;
_actionLabel.linkAttributes = kLinkAttributes;
_actionLabel.activeLinkAttributes = kLinkAttributesActive;
_actionLabel.delegate = self;
[self.contentView addSubview:_actionLabel];
}
if (!_contentLabel) {
_contentLabel = [[UITTTAttributedLabel alloc] initWithFrame:CGRectMake(kProjectActivityListCell_LeftPading, 0, kProjectActivityListCell_ContentWidth, 20)];
_contentLabel.backgroundColor = [UIColor clearColor];
_contentLabel.textColor = [UIColor colorWithHexString:@"0x555555"];
_contentLabel.font = kProjectActivityListCell_ContentFont;
// _contentLabel.linkAttributes = kLinkAttributes;
// _contentLabel.activeLinkAttributes = kLinkAttributesActive;
_contentLabel.delegate = self;
[self.contentView addSubview:_contentLabel];
}
if (!_timeLabel) {
_timeLabel = [[UITTTAttributedLabel alloc] initWithFrame:CGRectMake(kProjectActivityListCell_LeftPading, 0, kProjectActivityListCell_ContentWidth, kProjectActivityListCell_TimeHeight)];
_timeLabel.backgroundColor = [UIColor clearColor];
_timeLabel.font = kProjectActivityListCell_TimeFont;
_timeLabel.textColor = [UIColor colorWithHexString:@"0x999999"];
[self.contentView addSubview:_timeLabel];
}
}
return self;
}
- (void)layoutSubviews{
[super layoutSubviews];
if (!_proAct) {
return;
}
// 头像
CGFloat cellHeight = [ProjectActivityListCell cellHeightWithObj:_proAct];
[_userIconView sd_setImageWithURL:[_proAct.user.avatar urlImageWithCodePathResizeToView:_userIconView] placeholderImage:kPlaceholderMonkeyRoundView(_userIconView)];
// 时间轴Line
CGRect frame = _timeLineView.frame;
if (_top) {
frame.origin.y = 10+kProjectActivityListCell_IconHeight/2;
if (_bottom) {
frame.size.height = 0;
}else{
frame.size.height = cellHeight -frame.origin.y;
}
}else{
frame.origin.y = 0;
if (_bottom) {
frame.size.height = 10+kProjectActivityListCell_IconHeight/2;
}else{
frame.size.height = cellHeight;
}
}
_timeLineView.frame = frame;
// [_timeLineView setHeight:cellHeight];
[_timeLineView setImage:[UIImage imageNamed:(_haveRead? @"timeline_line_read" : @"timeline_line_unread")]];
// 时间轴Icon
[_timeIconView setImage:[UIImage imageNamed:(_haveRead? @"timeline_icon_read" : @"timeline_icon_unread")]];
// 行为
CGFloat curBottomY = kProjectActivityListCell_UpDownPading;
[_actionLabel setLongString:_proAct.actionStr withFitWidth:kProjectActivityListCell_ContentWidth maxHeight:kProjectActivityListCell_MaxActionHeight];
for (HtmlMediaItem *item in _proAct.actionMediaItems) {
if (item.displayStr.length > 0) {
[self.actionLabel addLinkToTransitInformation:[NSDictionary dictionaryWithObject:item forKey:@"value"] withRange:item.range];
}
}
curBottomY += [_proAct.actionStr getHeightWithFont:kProjectActivityListCell_ActionFont constrainedToSize:CGSizeMake(kProjectActivityListCell_ContentWidth, kProjectActivityListCell_MaxActionHeight)];
curBottomY += kProjectActivityListCell_TextPading;
// 内容
[_contentLabel setLongString:_proAct.contentStr withFitWidth:kProjectActivityListCell_ContentWidth maxHeight:kProjectActivityListCell_MaxContentHeight];
[_contentLabel setY:curBottomY];
curBottomY += [_proAct.contentStr getHeightWithFont:kProjectActivityListCell_ContentFont constrainedToSize:CGSizeMake(kProjectActivityListCell_ContentWidth, kProjectActivityListCell_MaxContentHeight)];
curBottomY += kProjectActivityListCell_TextPading;
// 时间
curBottomY +=5;
if (_proAct.created_at) {
_timeLabel.text = [_proAct.created_at stringWithFormat:@"HH:mm"];
}else{
_timeLabel.text = @"";
}
[_timeLabel setY:curBottomY];
}
+ (CGFloat)cellHeightWithObj:(id)obj{
ProjectActivity *proAct = (ProjectActivity *)obj;
CGFloat cellHeight = 0;
cellHeight += kProjectActivityListCell_UpDownPading *2;
cellHeight += MIN(kProjectActivityListCell_MaxActionHeight, [proAct.actionStr getHeightWithFont:kProjectActivityListCell_ActionFont constrainedToSize:CGSizeMake(kProjectActivityListCell_ContentWidth, kProjectActivityListCell_MaxActionHeight)]);
cellHeight += kProjectActivityListCell_TextPading*2;
cellHeight += MIN(kProjectActivityListCell_MaxContentHeight, [proAct.contentStr getHeightWithFont:kProjectActivityListCell_ContentFont constrainedToSize:CGSizeMake(kProjectActivityListCell_ContentWidth, kProjectActivityListCell_MaxContentHeight)]);
cellHeight += 5+ kProjectActivityListCell_TimeHeight;
return cellHeight;
}
#pragma mark TTTAttributedLabelDelegate M
- (void)attributedLabel:(TTTAttributedLabel *)label didSelectLinkWithTransitInformation:(NSDictionary *)components{
HtmlMediaItem *item = [components objectForKey:@"value"];
if (item) {
if (_htmlItemClickedBlock) {
_htmlItemClickedBlock(item, _proAct, (_contentLabel == label));
}
}
}
@end