Skip to content

Commit 511eb7f

Browse files
committed
MRPRDetailViewController
1 parent eedb066 commit 511eb7f

18 files changed

Lines changed: 359 additions & 59 deletions

Coding_iOS/Controllers/AddMDCommentViewController.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,9 @@
99
#import "BaseViewController.h"
1010

1111
@interface AddMDCommentViewController : BaseViewController
12+
@property (strong, nonatomic) void (^completeBlock)(id data, NSError *error);
13+
@property (strong, nonatomic) id relatedObj, commentToObj;
14+
+ (AddMDCommentViewController *)vcWithRelatedObj:(id)relatedObj CommentToObj:(id)commentToObj andCompleteBlock:(void (^)(id data, NSError *error))completeBlock;
15+
1216

1317
@end

Coding_iOS/Controllers/AddMDCommentViewController.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,12 @@
99
#import "AddMDCommentViewController.h"
1010

1111
@implementation AddMDCommentViewController
12+
+ (AddMDCommentViewController *)vcWithRelatedObj:(id)relatedObj CommentToObj:(id)commentToObj andCompleteBlock:(void (^)(id data, NSError *error))completeBlock{
13+
AddMDCommentViewController *vc = [AddMDCommentViewController new];
14+
vc.relatedObj = relatedObj;
15+
vc.commentToObj = commentToObj;
16+
vc.completeBlock = completeBlock;
17+
return vc;
18+
}
1219

1320
@end

Coding_iOS/Controllers/MRPRCommitsViewController.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
//
88

99
#import "BaseViewController.h"
10+
#import "MRPR.h"
11+
#import "Commit.h"
1012

1113
@interface MRPRCommitsViewController : BaseViewController
14+
@property (strong, nonatomic) MRPR *curMRPR;
1215

1316
@end

Coding_iOS/Controllers/MRPRDetailViewController.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
//
88

99
#import "BaseViewController.h"
10+
#import "MRPRBaseInfo.h"
1011

1112
@interface MRPRDetailViewController : BaseViewController
12-
13+
@property (strong, nonatomic) MRPR *curMRPR;
1314
@end

Coding_iOS/Controllers/MRPRDetailViewController.m

Lines changed: 251 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,259 @@
66
// Copyright (c) 2015年 Coding. All rights reserved.
77
//
88

9+
#define kMRPRDetailViewController_BottomViewHeight 49.0
10+
911
#import "MRPRDetailViewController.h"
12+
#import "Coding_NetAPIManager.h"
13+
#import "ODRefreshControl.h"
14+
15+
#import "MRPRTopCell.h"
16+
#import "MRPRDetailCell.h"
17+
#import "MRPRDisclosureCell.h"
18+
#import "MRPRCommentCell.h"
19+
#import "AddCommentCell.h"
20+
21+
#import "WebViewController.h"
22+
#import "MJPhotoBrowser.h"
23+
24+
#import "MRPRCommitsViewController.h"
25+
#import "MRPRFilesViewController.h"
26+
#import "AddMDCommentViewController.h"
27+
28+
@interface MRPRDetailViewController ()<UITableViewDataSource, UITableViewDelegate, TTTAttributedLabelDelegate>
29+
@property (strong, nonatomic) MRPRBaseInfo *curMRPRInfo;
30+
@property (strong, nonatomic) UITableView *myTableView;
31+
@property (nonatomic, strong) ODRefreshControl *myRefreshControl;
32+
@property (strong, nonatomic) UIView *bottomView;
33+
@end
1034

1135
@implementation MRPRDetailViewController
36+
- (void)viewDidLoad{
37+
[super viewDidLoad];
38+
self.title = [NSString stringWithFormat:@"#%@", _curMRPR.iid.stringValue];
39+
40+
_myTableView = ({
41+
UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
42+
tableView.backgroundColor = kColorTableSectionBg;
43+
tableView.dataSource = self;
44+
tableView.delegate = self;
45+
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
46+
47+
[tableView registerClass:[MRPRTopCell class] forCellReuseIdentifier:kCellIdentifier_MRPRTopCell];
48+
[tableView registerClass:[MRPRDetailCell class] forCellReuseIdentifier:kCellIdentifier_MRPRDetailCell];
49+
[tableView registerClass:[MRPRDisclosureCell class] forCellReuseIdentifier:kCellIdentifier_MRPRDisclosureCell];
50+
[tableView registerClass:[MRPRCommentCell class] forCellReuseIdentifier:kCellIdentifier_MRPRCommentCell];
51+
[tableView registerClass:[MRPRCommentCell class] forCellReuseIdentifier:kCellIdentifier_MRPRCommentCell_Media];
52+
[tableView registerClass:[AddCommentCell class] forCellReuseIdentifier:kCellIdentifier_AddCommentCell];
53+
54+
[self.view addSubview:tableView];
55+
[tableView mas_makeConstraints:^(MASConstraintMaker *make) {
56+
make.edges.equalTo(self.view);
57+
}];
58+
tableView;
59+
});
60+
_myRefreshControl = [[ODRefreshControl alloc] initInScrollView:self.myTableView];
61+
[_myRefreshControl addTarget:self action:@selector(refresh) forControlEvents:UIControlEventValueChanged];
62+
[self refresh];
63+
}
64+
65+
- (void)configBottomView{
66+
if (_bottomView) {
67+
[_bottomView removeFromSuperview];
68+
}
69+
if (_curMRPR.status <= MRPRStatusCannotMerge) {
70+
_bottomView = [UIView new];
71+
_bottomView.backgroundColor = [UIColor redColor];
72+
[self.view addSubview:_bottomView];
73+
74+
75+
76+
77+
[_bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
78+
make.left.right.bottom.equalTo(self.view);
79+
make.height.mas_equalTo(kMRPRDetailViewController_BottomViewHeight);
80+
}];
81+
82+
}
83+
84+
85+
UIEdgeInsets insets = UIEdgeInsetsMake(0, 0,
86+
_curMRPR.status <= MRPRStatusCannotMerge? kMRPRDetailViewController_BottomViewHeight: 0,
87+
0);
88+
_myTableView.contentInset = insets;
89+
_myTableView.scrollIndicatorInsets = insets;
90+
91+
}
92+
- (void)refresh{
93+
if (_curMRPR.isLoading) {
94+
return;
95+
}
96+
if (!_curMRPRInfo) {
97+
[self.view beginLoading];
98+
}
99+
__weak typeof(self) weakSelf = self;
100+
[[Coding_NetAPIManager sharedManager] request_MRPRBaseInfo_WithObj:_curMRPR andBlock:^(MRPRBaseInfo *data, NSError *error) {
101+
[weakSelf.view endLoading];
102+
[weakSelf.myRefreshControl endRefreshing];
103+
if (data) {
104+
weakSelf.curMRPRInfo = data;
105+
[weakSelf.myTableView reloadData];
106+
}
107+
[weakSelf.view configBlankPage:EaseBlankPageTypeView hasData:(_curMRPRInfo != nil) hasError:(error != nil) reloadButtonBlock:^(id sender) {
108+
[weakSelf refresh];
109+
}];
110+
}];
111+
}
112+
113+
#pragma mark TableM Footer Header
114+
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
115+
return 20.0;
116+
}
117+
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
118+
return 0.5;
119+
}
120+
121+
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
122+
UIView *view = [UIView new];
123+
view.backgroundColor = [UIColor colorWithHexString:@"0xe5e5e5"];
124+
return view;
125+
}
126+
127+
#pragma mark TableM
128+
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
129+
return _curMRPRInfo == nil? 0: _curMRPRInfo.discussions.count <= 0? 3: 4;
130+
}
131+
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
132+
NSInteger row = 0;
133+
if (section == 0 || section == 1) {
134+
row = 2;
135+
}else if (_curMRPRInfo.discussions.count > 0 && section == 2){
136+
row = _curMRPRInfo.discussions.count;
137+
}else{
138+
row = 1;
139+
}
140+
return row;
141+
}
142+
143+
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
144+
__weak typeof(self) weakSelf = self;
145+
if (indexPath.section == 0) {//Content
146+
if (indexPath.row == 0) {
147+
MRPRTopCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_MRPRTopCell forIndexPath:indexPath];
148+
cell.curMRPRInfo = _curMRPRInfo;
149+
return cell;
150+
}else{
151+
MRPRDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_MRPRDetailCell forIndexPath:indexPath];
152+
cell.curMRPRInfo = _curMRPRInfo;
153+
cell.cellHeightChangedBlock = ^(){
154+
[weakSelf.myTableView reloadData];
155+
};
156+
cell.loadRequestBlock = ^(NSURLRequest *curRequest){
157+
[weakSelf loadRequest:curRequest];
158+
};
159+
return cell;
160+
}
161+
}else if (indexPath.section == 1){//Disclosure
162+
MRPRDisclosureCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_MRPRDisclosureCell forIndexPath:indexPath];
163+
if (indexPath.row == 0) {
164+
[cell setImageStr:@"mrpr_icon_commit" andTitle:@"提交记录"];
165+
}else{
166+
[cell setImageStr:@"mrpr_icon_fileChange" andTitle:@"文件改动"];
167+
}
168+
[tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:50];
169+
return cell;
170+
}else if (_curMRPRInfo.discussions.count > 0 && indexPath.section == 2){//Comment
171+
MRPRCommentItem *curCommentItem = [[_curMRPRInfo.discussions objectAtIndex:indexPath.row] firstObject];
172+
MRPRCommentCell *cell = [tableView dequeueReusableCellWithIdentifier:curCommentItem.htmlMedia.imageItems.count> 0? kCellIdentifier_MRPRCommentCell_Media: kCellIdentifier_MRPRCommentCell forIndexPath:indexPath];
173+
cell.curItem = curCommentItem;
174+
cell.contentLabel.delegate = self;
175+
[tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:50];
176+
return cell;
177+
}else{//Add Comment
178+
AddCommentCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_AddCommentCell forIndexPath:indexPath];
179+
[tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:50];
180+
return cell;
181+
}
182+
}
183+
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
184+
CGFloat cellHeight = 0;
185+
if (indexPath.section == 0) {//Content
186+
if (indexPath.row == 0) {
187+
return [MRPRTopCell cellHeightWithObj:_curMRPRInfo];
188+
}else{
189+
return [MRPRDetailCell cellHeightWithObj:_curMRPRInfo];
190+
}
191+
}else if (indexPath.section == 1){//Disclosure
192+
return [MRPRDisclosureCell cellHeight];
193+
}else if (_curMRPRInfo.discussions.count > 0 && indexPath.section == 2){//Comment
194+
MRPRCommentItem *curCommentItem = [[_curMRPRInfo.discussions objectAtIndex:indexPath.row] firstObject];
195+
return [MRPRCommentCell cellHeightWithObj:curCommentItem];
196+
}else{//Add Comment
197+
return [AddCommentCell cellHeight];
198+
}
199+
return cellHeight;
200+
}
201+
202+
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
203+
[tableView deselectRowAtIndexPath:indexPath animated:YES];
204+
if (indexPath.section == 0) {//Content
205+
}else if (indexPath.section == 1){//Disclosure
206+
if (indexPath.row == 0) {
207+
MRPRCommitsViewController *vc = [MRPRCommitsViewController new];
208+
vc.curMRPR = _curMRPR;
209+
[self.navigationController pushViewController:vc animated:YES];
210+
}else{
211+
MRPRFilesViewController *vc = [MRPRFilesViewController new];
212+
vc.curMRPR = _curMRPR;
213+
[self.navigationController pushViewController:vc animated:YES];
214+
}
215+
}else if (_curMRPRInfo.discussions.count > 0 && indexPath.section == 2){//Comment
216+
MRPRCommentItem *curCommentItem = [[_curMRPRInfo.discussions objectAtIndex:indexPath.row] firstObject];
217+
DebugLog(@"%@", curCommentItem.content);
218+
}else{//Add Comment
219+
AddMDCommentViewController *vc = [AddMDCommentViewController new];
220+
[self.navigationController pushViewController:vc animated:YES];
221+
}
222+
}
223+
224+
#pragma mark loadCellRequest
225+
- (void)loadRequest:(NSURLRequest *)curRequest
226+
{
227+
NSString *linkStr = curRequest.URL.absoluteString;
228+
[self analyseLinkStr:linkStr];
229+
}
230+
231+
- (void)analyseLinkStr:(NSString *)linkStr
232+
{
233+
if (linkStr.length <= 0) {
234+
return;
235+
}
236+
UIViewController *vc = [BaseViewController analyseVCFromLinkStr:linkStr];
237+
if (vc) {
238+
[self.navigationController pushViewController:vc animated:YES];
239+
}else{
240+
// 可能是图片链接
241+
HtmlMedia *htmlMedia = self.curMRPRInfo.htmlMedia;
242+
if (htmlMedia.imageItems.count > 0) {
243+
for (HtmlMediaItem *item in htmlMedia.imageItems) {
244+
if ((item.src.length > 0 && [item.src isEqualToString:linkStr])
245+
|| (item.href.length > 0 && [item.href isEqualToString:linkStr])) {
246+
[MJPhotoBrowser showHtmlMediaItems:htmlMedia.imageItems originalItem:item];
247+
return;
248+
}
249+
}
250+
}
251+
// 跳转去网页
252+
WebViewController *webVc = [WebViewController webVCWithUrlStr:linkStr];
253+
[self.navigationController pushViewController:webVc animated:YES];
254+
}
255+
}
256+
257+
#pragma mark TTTAttributedLabelDelegate
258+
- (void)attributedLabel:(TTTAttributedLabel *)label didSelectLinkWithTransitInformation:(NSDictionary *)components{
259+
HtmlMediaItem *clickedItem = [components objectForKey:@"value"];
260+
[self analyseLinkStr:clickedItem.href];
261+
}
262+
12263

13264
@end

Coding_iOS/Controllers/MRPRFilesViewController.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
//
88

99
#import "BaseViewController.h"
10+
#import "MRPR.h"
11+
#import "FileChanges.h"
1012

1113
@interface MRPRFilesViewController : BaseViewController
14+
@property (strong, nonatomic) MRPR *curMRPR;
1215

1316
@end

Coding_iOS/Controllers/MRPRListViewController.m

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
// Copyright (c) 2015年 Coding. All rights reserved.
77
//
88

9-
#define MRPRListViewController_BottomViewHeight 49.0
9+
#define kMRPRListViewController_BottomViewHeight 49.0
1010

1111
#import "MRPRListViewController.h"
1212
#import "ODRefreshControl.h"
1313
#import "SVPullToRefresh.h"
1414
#import "MRPRS.h"
1515
#import "Coding_NetAPIManager.h"
1616
#import "MRPRListCell.h"
17+
#import "MRPRDetailViewController.h"
1718

1819
@interface MRPRListViewController ()<UITableViewDataSource, UITableViewDelegate>
1920
@property (strong, nonatomic) NSMutableDictionary *dataDict;
@@ -41,7 +42,7 @@ - (void)viewDidLoad{
4142
[tableView mas_makeConstraints:^(MASConstraintMaker *make) {
4243
make.edges.equalTo(self.view);
4344
}];
44-
UIEdgeInsets insets = UIEdgeInsetsMake(0, 0, MRPRListViewController_BottomViewHeight, 0);
45+
UIEdgeInsets insets = UIEdgeInsetsMake(0, 0, kMRPRListViewController_BottomViewHeight, 0);
4546
tableView.contentInset = insets;
4647
tableView.scrollIndicatorInsets = insets;
4748
tableView;
@@ -133,7 +134,7 @@ - (void)configBottomView{
133134
[self.view addSubview:_bottomView];
134135
[_bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
135136
make.left.right.bottom.equalTo(self.view);
136-
make.height.mas_equalTo(MRPRListViewController_BottomViewHeight);
137+
make.height.mas_equalTo(kMRPRListViewController_BottomViewHeight);
137138
}];
138139
}
139140
if (!_mySegmentedControl) {
@@ -152,7 +153,7 @@ - (void)configBottomView{
152153
[segmentedControl addTarget:self action:@selector(segmentedControlSelected:) forControlEvents:UIControlEventValueChanged];
153154
segmentedControl;
154155
});
155-
_mySegmentedControl.frame = CGRectMake(kPaddingLeftWidth, (MRPRListViewController_BottomViewHeight - 30)/2, kScreen_Width - 2*kPaddingLeftWidth, 30);
156+
_mySegmentedControl.frame = CGRectMake(kPaddingLeftWidth, (kMRPRListViewController_BottomViewHeight - 30)/2, kScreen_Width - 2*kPaddingLeftWidth, 30);
156157
[_bottomView addSubview:_mySegmentedControl];
157158
}
158159
}
@@ -166,6 +167,7 @@ - (void)segmentedControlSelected:(id)sender{
166167
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
167168
return [self curMRPRS].list.count;
168169
}
170+
169171
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
170172
MRPR *curMRPR = [[self curMRPRS].list objectAtIndex:indexPath.row];
171173
MRPRListCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_MRPRListCell forIndexPath:indexPath];
@@ -177,10 +179,13 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
177179
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
178180
return [MRPRListCell cellHeight];
179181
}
182+
180183
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
181184
[tableView deselectRowAtIndexPath:indexPath animated:YES];
182185
MRPR *curMRPR = [[self curMRPRS].list objectAtIndex:indexPath.row];
183-
NSLog(@"%@", curMRPR.title);
186+
MRPRDetailViewController *vc = [MRPRDetailViewController new];
187+
vc.curMRPR = curMRPR;
188+
[self.navigationController pushViewController:vc animated:YES];
184189
}
185190

186191

Coding_iOS/Controllers/TopicDetailViewController.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
303303
TopicCommentCell *cell = [tableView dequeueReusableCellWithIdentifier:toComment.htmlMedia.imageItems.count > 0? kCellIdentifier_TopicComment_Media: kCellIdentifier_TopicComment forIndexPath:indexPath];
304304
cell.toComment = toComment;
305305
cell.contentLabel.delegate = self;
306-
[tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:45];
306+
[tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:50];
307307
return cell;
308308
}
309309
}
@@ -402,7 +402,6 @@ - (void)sendCommentMessage:(id)obj
402402
- (void)loadRequest:(NSURLRequest *)curRequest
403403
{
404404
NSString *linkStr = curRequest.URL.absoluteString;
405-
DebugLog(@"\n linkStr : %@", linkStr);
406405
[self analyseLinkStr:linkStr];
407406
}
408407

0 commit comments

Comments
 (0)