FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Coding-iOS/Coding_iOS/Views/DynamicActivityCell.m at master · flattech/Coding-iOS · GitHub
flattech
/
Coding-iOS
Public
forked from
coding/Coding-iOS
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
Coding-iOS
/
Coding_iOS
/
Views
/
DynamicActivityCell.m
Copy path
More file actions
More file actions
Latest commit
History
History
History
161 lines (148 loc) · 8.38 KB
Breadcrumbs
Coding-iOS
/
Coding_iOS
/
Views
/
DynamicActivityCell.m
Copy path
File metadata and controls
161 lines (148 loc) · 8.38 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
//
//
NSObject+DynamicActivityCell.m
//
Coding_iOS
//
//
Created by hardac on 16/3/27.
//
Copyright © 2016年 Coding. All rights reserved.
//
#
define
kTaskActivityCell_LeftContentPading
(
kPaddingLeftWidth
+
40
)
#
define
kTaskActivityCell_ContentWidth
(
kScreen_Width
-
kTaskActivityCell_LeftContentPading
-
kPaddingLeftWidth
)
#
import
"
DynamicActivityCell.h
"
@interface
DynamicActivityCell
()
@property
(
strong
,
nonatomic
) UIImageView *tipIconView;
@property
(
strong
,
nonatomic
) UIImageView *timeLineView;
@property
(
strong
,
nonatomic
) UILabel *contentLabel;
@property
(
strong
,
nonatomic
) UILabel *tipLabel;
@end
@implementation
DynamicActivityCell
- (
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];
}
if
(!_tipLabel) {
_tipLabel = [[UITTTAttributedLabel
alloc
]
initWithFrame:
CGRectMake
(
kTaskActivityCell_LeftContentPading
,
50
,
kTaskActivityCell_ContentWidth
,
35
)];
_contentLabel.
numberOfLines
=
0
;
[
self
.contentView
addSubview:
_tipLabel];
}
[_tipLabel
mas_makeConstraints:
^(MASConstraintMaker *make) {
make.
edges
.
equalTo
(self.
contentView
).
insets
(
UIEdgeInsetsMake
(
50
,
60
,
5
,
20
));
}];
[_tipLabel
setBackgroundColor:
[UIColor
colorWithHexString:
@"
0xF0F0F0
"
]];
[_tipLabel
setTextColor:
[UIColor
colorWithHexString:
@"
0x3BBD79
"
]];
_tipLabel.
font
= [UIFont
fontWithName:
@"
Helvetica
"
size:
12
];
}
return
self;
}
- (
void
)
setCurActivity
:
(ProjectLineNote *)
curActivity
{
_curActivity = curActivity;
if
(!_curActivity) {
return
;
}
NSString
*tipIconImageName= [
NSString
stringWithFormat:
@"
PR_
%@
"
, _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
([
self
.curActivity.action
isEqualToString:
@"
mergeChanges
"
]) {
_tipLabel.
hidden
=
NO
;
_tipLabel.
text
=
@"
点击查看详情
"
;
}
else
{
_tipLabel.
hidden
=
YES
;
}
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
:
(ProjectLineNote*)
curActivity
{
NSString
*userName, *contentStr;
userName = curActivity.
author
.
name
? curActivity.
author
.
name
:
@"
"
;
NSMutableAttributedString
*attrContent;
if
([curActivity.action
isEqualToString:
@"
create
"
]) {
contentStr = [
NSString
stringWithFormat:
@"
创建了合并请求 -
%@
"
, [curActivity.created_at
stringDisplay_HHmm
]];
}
else
if
([curActivity.action
isEqualToString:
@"
merge
"
]) {
contentStr = [
NSString
stringWithFormat:
@"
合并了合并请求 -
%@
"
, [curActivity.created_at
stringDisplay_HHmm
]];
}
else
if
([curActivity.action
isEqualToString:
@"
review_undo
"
]) {
contentStr = [
NSString
stringWithFormat:
@"
撤销了对此合并请求评审+1 -
%@
"
,[curActivity.created_at
stringDisplay_HHmm
]];
}
else
if
([curActivity.action
isEqualToString:
@"
review
"
]) {
contentStr = [
NSString
stringWithFormat:
@"
对此合并请求评审+1 -
%@
"
,[curActivity.created_at
stringDisplay_HHmm
]];
}
else
if
([curActivity.action
isEqualToString:
@"
mergeChanges
"
]) {
contentStr = [
NSString
stringWithFormat:
@"
对文件改动发起了讨论 -
%@
"
, [curActivity.created_at
stringDisplay_HHmm
]];
}
else
if
([curActivity.action
isEqualToString:
@"
grant
"
]) {
contentStr = [
NSString
stringWithFormat:
@"
对此合并请求授权了合并权限 -
%@
"
, [curActivity.created_at
stringDisplay_HHmm
]];
}
else
if
([curActivity.action
isEqualToString:
@"
grant_undo
"
]) {
contentStr = [
NSString
stringWithFormat:
@"
取消了此合并请求授权了合并权限 -
%@
"
, [curActivity.created_at
stringDisplay_HHmm
]];
}
else
if
([curActivity.action
isEqualToString:
@"
refuse
"
]) {
contentStr = [
NSString
stringWithFormat:
@"
拒绝了合并请求 -
%@
"
, [curActivity.created_at
stringDisplay_HHmm
]];
}
else
if
([curActivity.action
isEqualToString:
@"
push
"
]) {
contentStr = [
NSString
stringWithFormat:
@"
推送了新的提交,更新了合并请求 -
%@
"
, [curActivity.created_at
stringDisplay_HHmm
]];
}
else
if
([curActivity.action
isEqualToString:
@"
update_content
"
]) {
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_title
"
]) {
contentStr = [
NSString
stringWithFormat:
@"
编辑了标题 -
%@
"
, [curActivity.created_at
stringDisplay_HHmm
]];
}
contentStr = contentStr? 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
contentHeight
:
(CGFloat)
height
{
CGFloat cellHeight =
0
;
ProjectLineNote *tmpProject = (ProjectLineNote*)obj;
if
([obj
isKindOfClass:
[ProjectLineNote
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
(
50
, cellHeight);
}
if
([tmpProject.action
isEqual:
@"
mergeChanges
"
]) {
cellHeight +=
44
;
}
return
cellHeight + height;
}
@end
Back
|
FazBrowse Home
|
New Git URL