FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Coding-iOS/Coding_iOS/Controllers/CommitFilesViewController.m at master · 872409/Coding-iOS · GitHub
872409
/
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
/
Controllers
/
CommitFilesViewController.m
Copy path
More file actions
More file actions
Latest commit
History
History
History
368 lines (330 loc) · 15.3 KB
Breadcrumbs
Coding-iOS
/
Coding_iOS
/
Controllers
/
CommitFilesViewController.m
Copy path
File metadata and controls
368 lines (330 loc) · 15.3 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
//
//
CommitFilesViewController.m
//
Coding_iOS
//
//
Created by Ease on 15/6/1.
//
Copyright (c) 2015年 Coding. All rights reserved.
//
#
import
"
CommitFilesViewController.h
"
#
import
"
FileChangesIntroduceCell.h
"
#
import
"
FileChangeListCell.h
"
#
import
"
CommitContentCell.h
"
#
import
"
CommitCommentCell.h
"
#
import
"
AddCommentCell.h
"
#
import
"
CommitInfo.h
"
#
import
"
ODRefreshControl.h
"
#
import
"
Coding_NetAPIManager.h
"
#
import
"
FileChangeDetailViewController.h
"
#
import
"
AddMDCommentViewController.h
"
#
import
"
WebViewController.h
"
#
import
"
UIView+PressMenu.h
"
@interface
CommitFilesViewController
()<UITableViewDataSource, UITableViewDelegate, TTTAttributedLabelDelegate>
@property
(
strong
,
nonatomic
) CommitInfo *curCommitInfo;
@property
(
strong
,
nonatomic
)
NSMutableDictionary
*listGroups;
@property
(
strong
,
nonatomic
)
NSMutableArray
*listGroupKeys;
@property
(
strong
,
nonatomic
) UITableView *myTableView;
@property
(
nonatomic
,
strong
) ODRefreshControl *myRefreshControl;
@property
(
assign
,
nonatomic
)
BOOL
isLoading;
@end
@implementation
CommitFilesViewController
+ (CommitFilesViewController *)
vcWithPath
:
(
NSString
*)
path
{
NSArray
*pathComponents = [path
componentsSeparatedByString:
@"
/
"
];
if
(pathComponents.
count
!=
8
) {
return
nil
;
}
CommitFilesViewController *vc = [CommitFilesViewController
new
];
vc.
ownerGK
= pathComponents[
2
];
vc.
projectName
= pathComponents[
4
];
vc.
commitId
= pathComponents[
7
];
return
vc;
}
- (
void
)
viewDidLoad
{
[
super
viewDidLoad
];
self.
title
= _commitId.
length
>
10
? [_commitId
substringToIndex:
10
]: _commitId;
_myTableView = ({
UITableView *tableView = [[UITableView
alloc
]
initWithFrame:
self
.view.bounds
style:
UITableViewStylePlain];
tableView.
backgroundColor
=
kColorTableSectionBg
;
tableView.
dataSource
= self;
tableView.
delegate
= self;
tableView.
separatorStyle
= UITableViewCellSeparatorStyleNone;
[tableView
registerClass:
[FileChangesIntroduceCell
class
]
forCellReuseIdentifier:
kCellIdentifier_FileChangesIntroduceCell
];
[tableView
registerClass:
[FileChangeListCell
class
]
forCellReuseIdentifier:
kCellIdentifier_FileChangeListCell
];
[tableView
registerClass:
[CommitContentCell
class
]
forCellReuseIdentifier:
kCellIdentifier_CommitContentCell
];
[tableView
registerClass:
[CommitCommentCell
class
]
forCellReuseIdentifier:
kCellIdentifier_CommitCommentCell
];
[tableView
registerClass:
[CommitCommentCell
class
]
forCellReuseIdentifier:
kCellIdentifier_CommitCommentCell_Media
];
[tableView
registerClass:
[AddCommentCell
class
]
forCellReuseIdentifier:
kCellIdentifier_AddCommentCell
];
[
self
.view
addSubview:
tableView];
[tableView
mas_makeConstraints:
^(MASConstraintMaker *make) {
make.
edges
.
equalTo
(self.
view
);
}];
tableView;
});
_myRefreshControl = [[ODRefreshControl
alloc
]
initInScrollView:
self
.myTableView];
[_myRefreshControl
addTarget:
self
action:
@selector
(
refresh
)
forControlEvents:
UIControlEventValueChanged];
[
self
refresh
];
}
- (
void
)
refresh
{
if
(_isLoading) {
return
;
}
if
(!_curCommitInfo) {
[
self
.view
beginLoading
];
}
_isLoading =
YES
;
__weak
typeof
(self) weakSelf = self;
[[Coding_NetAPIManager
sharedManager
]
request_CommitInfo_WithUserGK:
_ownerGK
projectName:
_projectName
commitId:
_commitId
andBlock:
^(CommitInfo *data,
NSError
*error) {
weakSelf.
isLoading
=
NO
;
[weakSelf.view
endLoading
];
[weakSelf.myRefreshControl
endRefreshing
];
if
(data) {
weakSelf.
curCommitInfo
= data;
[weakSelf
configListGroups
];
[weakSelf.myTableView
performSelector:
@selector
(
reloadData
)
withObject:
nil
afterDelay:
0.5
];
}
[weakSelf.view
configBlankPage:
EaseBlankPageTypeView
hasData:
(weakSelf.curCommitInfo.commitDetail !=
nil
)
hasError:
(error !=
nil
)
reloadButtonBlock:
^(
id
sender) {
[weakSelf
refresh
];
}];
}];
//
推送过来的页面,可能 curProject 对象为空
if
(!_curProject) {
_curProject = [Project
new
];
_curProject.
owner_user_name
= _ownerGK;
_curProject.
name
= _projectName;
}
if
(![_curProject.
id
isKindOfClass:
[
NSNumber
class
]]) {
[[Coding_NetAPIManager
sharedManager
]
request_ProjectDetail_WithObj:
_curProject
andBlock:
^(
id
data,
NSError
*error) {
if
(data) {
weakSelf.
curProject
= data;
}
}];
}
}
- (
void
)
configListGroups
{
if
(_curCommitInfo && !_curCommitInfo.
commitDetail
) {
kTipAlert
(
@"
此 commit 改动太多,不宜在客户端上展示
"
);
return
;
}
if
(!_listGroupKeys) {
_listGroupKeys = [
NSMutableArray
new
];
}
if
(!_listGroups) {
_listGroups = [
NSMutableDictionary
new
];
}
[_listGroupKeys
removeAllObjects
];
[_listGroups
removeAllObjects
];
for
(FileChange *curFileChange in _curCommitInfo.
commitDetail
.
diffStat
.
paths
) {
NSString
*curKey = curFileChange.
displayFilePath
;
NSMutableArray
*curList = [_listGroups
objectForKey:
curKey];
if
(curList.
count
>
0
) {
[curList
addObject:
curFileChange];
}
else
{
[_listGroupKeys
addObject:
curKey];
curList = [
NSMutableArray
arrayWithObject:
curFileChange];
[_listGroups
setObject:
curList
forKey:
curKey];
}
}
[_listGroupKeys
sortUsingComparator:
^
NSComparisonResult
(
NSString
*obj1,
NSString
*obj2) {
return
[obj1
compare:
obj2];
}];
}
#
pragma mark
TableM Header
- (CGFloat)
tableView
:
(UITableView *)
tableView
heightForHeaderInSection
:
(
NSInteger
)
section
{
return
section ==
0
?
0
:
kScaleFrom_iPhone5_Desgin
(
24
);
}
- (UIView *)
tableView
:
(UITableView *)
tableView
viewForHeaderInSection
:
(
NSInteger
)
section
{
if
(section !=
0
) {
if
(section >
0
&& section < _listGroupKeys.
count
+
1
){
return
[tableView
getHeaderViewWithStr:
[_listGroupKeys
objectAtIndex:
section -
1
]
andBlock:
^(
id
obj) {
NSLog
(
@"
%@
"
, [_listGroupKeys
objectAtIndex:
section -
1
]);
}];
}
else
{
return
[tableView
getHeaderViewWithStr:
nil
andBlock:
^(
id
obj) {
}];
}
}
else
{
return
nil
;
}
}
#
pragma mark
Table
- (
NSInteger
)
numberOfSectionsInTableView
:
(UITableView *)
tableView
{
NSInteger
section =
0
;
if
(_curCommitInfo.
commitDetail
) {
section =
1
+ _listGroupKeys.
count
+
1
;
if
(_curCommitInfo.
commitComments
.
count
>
0
) {
section +=
1
;
}
}
return
section;
}
- (
NSInteger
)
tableView
:
(UITableView *)
tableView
numberOfRowsInSection
:
(
NSInteger
)
section
{
if
(section ==
0
) {
return
2
;
}
else
if
(section >
0
&& section < _listGroupKeys.
count
+
1
){
NSString
*curKey = [_listGroupKeys
objectAtIndex:
section -
1
];
NSArray
*curList = [_listGroups
objectForKey:
curKey];
return
curList.
count
;
}
else
if
(section == _listGroupKeys.
count
+
1
&& _curCommitInfo.
commitComments
.
count
>
0
){
return
_curCommitInfo.
commitComments
.
count
;
}
else
{
return
1
;
}
return
0
;
}
- (UITableViewCell *)
tableView
:
(UITableView *)
tableView
cellForRowAtIndexPath
:
(
NSIndexPath
*)
indexPath
{
if
(indexPath.
section
==
0
) {
if
(indexPath.
row
==
0
) {
CommitContentCell *cell = [tableView
dequeueReusableCellWithIdentifier:
kCellIdentifier_CommitContentCell
forIndexPath:
indexPath];
cell.
curCommitInfo
= _curCommitInfo;
return
cell;
}
else
{
FileChanges * curFileChanges = _curCommitInfo.
commitDetail
.
diffStat
;
FileChangesIntroduceCell *cell = [tableView
dequeueReusableCellWithIdentifier:
kCellIdentifier_FileChangesIntroduceCell
forIndexPath:
indexPath];
[cell
setFilesCount:
curFileChanges.paths.count
insertions:
curFileChanges.insertions.integerValue
deletions:
curFileChanges.deletions.integerValue];
return
cell;
}
}
else
if
(indexPath.
section
>
0
&& indexPath.
section
< _listGroupKeys.
count
+
1
){
NSString
*curKey = [_listGroupKeys
objectAtIndex:
indexPath.section -
1
];
NSArray
*curList = [_listGroups
objectForKey:
curKey];
FileChange *curFileChange = [curList
objectAtIndex:
indexPath.row];
FileChangeListCell *cell = [tableView
dequeueReusableCellWithIdentifier:
kCellIdentifier_FileChangeListCell
forIndexPath:
indexPath];
cell.
curFileChange
= curFileChange;
[tableView
addLineforPlainCell:
cell
forRowAtIndexPath:
indexPath
withLeftSpace:
50
];
return
cell;
}
else
if
(indexPath.
section
== _listGroupKeys.
count
+
1
&& _curCommitInfo.
commitComments
.
count
>
0
){
ProjectLineNote*curCommentItem = [_curCommitInfo.commitComments
objectAtIndex:
indexPath.row];
CommitCommentCell *cell = [tableView
dequeueReusableCellWithIdentifier:
curCommentItem.htmlMedia.imageItems.count>
0
?
kCellIdentifier_CommitCommentCell_Media:
kCellIdentifier_CommitCommentCell
forIndexPath:
indexPath];
cell.
curItem
= curCommentItem;
cell.
contentLabel
.
delegate
= self;
__weak
typeof
(self) weakSelf = self;
NSArray
*menuTitles;
if
([curCommentItem.author.global_key
isEqualToString:
[Login
curLoginUser
].global_key]) {
menuTitles = @[
@"
拷贝文字
"
,
@"
回复
"
,
@"
删除
"
];
}
else
{
menuTitles = @[
@"
拷贝文字
"
,
@"
回复
"
];
}
[cell.contentView
addPressMenuTitles:
menuTitles
menuClickedBlock:
^(
NSInteger
index,
NSString
*title) {
if
([title
hasPrefix:
@"
拷贝
"
]) {
[[UIPasteboard
generalPasteboard
]
setString:
curCommentItem.content];
}
else
if
([title
isEqualToString:
@"
删除
"
]){
[weakSelf
deleteComment:
curCommentItem];
}
else
if
([title
isEqualToString:
@"
回复
"
]){
[weakSelf
goToAddCommentVCToUser:
curCommentItem.author.name];
}
}];
[tableView
addLineforPlainCell:
cell
forRowAtIndexPath:
indexPath
withLeftSpace:
50
];
return
cell;
}
else
{
AddCommentCell *cell = [tableView
dequeueReusableCellWithIdentifier:
kCellIdentifier_AddCommentCell
forIndexPath:
indexPath];
[tableView
addLineforPlainCell:
cell
forRowAtIndexPath:
indexPath
withLeftSpace:
50
];
return
cell;
}
}
- (CGFloat)
tableView
:
(UITableView *)
tableView
heightForRowAtIndexPath
:
(
NSIndexPath
*)
indexPath
{
CGFloat cellHeight =
0
;
if
(indexPath.
section
==
0
) {
if
(indexPath.
row
==
0
) {
cellHeight = [CommitContentCell
cellHeightWithObj:
_curCommitInfo];
}
else
{
cellHeight = [FileChangesIntroduceCell
cellHeight
];
}
}
else
if
(indexPath.
section
>
0
&& indexPath.
section
< _listGroupKeys.
count
+
1
){
cellHeight = [FileChangeListCell
cellHeight
];
}
else
if
(indexPath.
section
== _listGroupKeys.
count
+
1
&& _curCommitInfo.
commitComments
.
count
>
0
){
ProjectLineNote*curCommentItem = [_curCommitInfo.commitComments
objectAtIndex:
indexPath.row];
cellHeight = [CommitCommentCell
cellHeightWithObj:
curCommentItem];
}
else
{
cellHeight = [AddCommentCell
cellHeight
];
}
return
cellHeight;
}
- (
void
)
tableView
:
(UITableView *)
tableView
didSelectRowAtIndexPath
:
(
NSIndexPath
*)
indexPath
{
[tableView
deselectRowAtIndexPath:
indexPath
animated:
YES
];
if
(indexPath.
section
==
0
) {
}
else
if
(indexPath.
section
>
0
&& indexPath.
section
< _listGroupKeys.
count
+
1
){
NSString
*curKey = [_listGroupKeys
objectAtIndex:
indexPath.section -
1
];
NSArray
*curList = [_listGroups
objectForKey:
curKey];
FileChange *curFileChange = [curList
objectAtIndex:
indexPath.row];
FileChangeDetailViewController *vc = [FileChangeDetailViewController
new
];
vc.
linkUrlStr
= [
NSString
stringWithFormat:
@"
api/user/
%@
/project/
%@
/git/commitDiffContent/
%@
"
, _ownerGK, _projectName, [
NSString
handelRef:
_commitId
path:
curFileChange.path]];
vc.
curProject
= _curProject;
vc.
commitId
= curFileChange.
commitId
;
vc.
filePath
= curFileChange.
path
;
vc.
noteable_id
=
nil
;
[
self
.navigationController
pushViewController:
vc
animated:
YES
];
}
else
if
(indexPath.
section
== _listGroupKeys.
count
+
1
&& _curCommitInfo.
commitComments
.
count
>
0
){
ProjectLineNote*curCommentItem = [_curCommitInfo.commitComments
objectAtIndex:
indexPath.row];
UITableViewCell *cell = [tableView
cellForRowAtIndexPath:
indexPath];
if
([cell.contentView
isMenuVCVisible
]) {
[cell.contentView
removePressMenu
];
return
;
}
NSArray
*menuTitles;
if
([curCommentItem.author.global_key
isEqualToString:
[Login
curLoginUser
].global_key]) {
menuTitles = @[
@"
拷贝文字
"
,
@"
删除
"
];
}
else
{
menuTitles = @[
@"
拷贝文字
"
,
@"
回复
"
];
}
__weak
typeof
(self) weakSelf = self;
[cell.contentView
showMenuTitles:
menuTitles
menuClickedBlock:
^(
NSInteger
index,
NSString
*title) {
if
([title
hasPrefix:
@"
拷贝
"
]) {
[[UIPasteboard
generalPasteboard
]
setString:
curCommentItem.content];
}
else
if
([title
isEqualToString:
@"
删除
"
]){
[weakSelf
deleteComment:
curCommentItem];
}
else
if
([title
isEqualToString:
@"
回复
"
]){
[weakSelf
goToAddCommentVCToUser:
curCommentItem.author.name];
}
}];
}
else
{
[
self
goToAddCommentVCToUser:
nil
];
}
}
#
pragma mark
Comment
- (
void
)
goToAddCommentVCToUser
:
(
NSString
*)
userName
{
DebugLog
(
@"
%@
"
, userName);
AddMDCommentViewController *vc = [AddMDCommentViewController
new
];
vc.
curProject
= _curProject;
vc.
requestPath
= [
NSString
stringWithFormat:
@"
api/user/
%@
/project/
%@
/git/line_notes
"
, _ownerGK, _projectName];
vc.
requestParams
= [@{
@"
noteable_type
"
:
@"
Commit
"
,
@"
commitId
"
: _commitId,
} mutableCopy];
vc.
contentStr
= userName.
length
>
0
? [
NSString
stringWithFormat:
@"
@
%@
"
, userName]:
nil
;
@
weakify
(self);
vc.
completeBlock
= ^(
id
data){
@
strongify
(self);
if
(data && [data
isKindOfClass:
[ProjectLineNote
class
]]) {
[
self
.curCommitInfo.commitComments
addObject:
data];
[
self
.myTableView
reloadData
];
}
};
[
self
.navigationController
pushViewController:
vc
animated:
YES
];
}
- (
void
)
deleteComment
:
(ProjectLineNote *)
lineNote
{
__weak
typeof
(self) weakSelf = self;
[[Coding_NetAPIManager
sharedManager
]
request_DeleteLineNote:
lineNote.
id
inProject:
_projectName
ofUser:
_ownerGK
andBlock:
^(
id
data,
NSError
*error) {
if
(data) {
[weakSelf.curCommitInfo.commitComments
removeObject:
lineNote];
[weakSelf.myTableView
reloadData
];
}
}];
}
#
pragma mark
TTTAttributedLabelDelegate
- (
void
)
attributedLabel
:
(TTTAttributedLabel *)
label
didSelectLinkWithTransitInformation
:
(
NSDictionary
*)
components
{
HtmlMediaItem *clickedItem = [components
objectForKey:
@"
value
"
];
[
self
analyseLinkStr:
clickedItem.href];
}
- (
void
)
analyseLinkStr
:
(
NSString
*)
linkStr
{
if
(linkStr.
length
<=
0
) {
return
;
}
UIViewController *vc = [BaseViewController
analyseVCFromLinkStr:
linkStr];
if
(vc) {
[
self
.navigationController
pushViewController:
vc
animated:
YES
];
}
else
{
//
跳转去网页
WebViewController *webVc = [WebViewController
webVCWithUrlStr:
linkStr];
[
self
.navigationController
pushViewController:
webVc
animated:
YES
];
}
}
@end
Back
|
FazBrowse Home
|
New Git URL