forked from coding/Coding-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMRPRCommitsViewController.m
More file actions
140 lines (118 loc) · 5.01 KB
/
MRPRCommitsViewController.m
File metadata and controls
140 lines (118 loc) · 5.01 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
//
// MRPRCommitsViewController.m
// Coding_iOS
//
// Created by Ease on 15/6/1.
// Copyright (c) 2015年 Coding. All rights reserved.
//
#import "MRPRCommitsViewController.h"
#import "CommitListCell.h"
#import "ODRefreshControl.h"
#import "Coding_NetAPIManager.h"
#import "CommitFilesViewController.h"
@interface MRPRCommitsViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (strong, nonatomic) NSMutableArray *listGroups;
@property (strong, nonatomic) UITableView *myTableView;
@property (nonatomic, strong) ODRefreshControl *myRefreshControl;
@end
@implementation MRPRCommitsViewController
- (void)viewDidLoad{
[super viewDidLoad];
self.title = [NSString stringWithFormat:@"#%@", _curMRPR.iid.stringValue];
_myTableView = ({
UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
tableView.backgroundColor = kColorTableBG;
tableView.dataSource = self;
tableView.delegate = self;
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[tableView registerClass:[CommitListCell class] forCellReuseIdentifier:kCellIdentifier_CommitListCell];
[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 (_curMRPR.isLoading) {
return;
}
if (_listGroups.count <= 0) {
[self.view beginLoading];
}
__weak typeof(self) weakSelf = self;
[[Coding_NetAPIManager sharedManager] request_MRPRCommits_WithObj:_curMRPR andBlock:^(NSArray *data, NSError *error) {
[weakSelf.view endLoading];
[weakSelf.myRefreshControl endRefreshing];
if (data) {
[weakSelf configListGroupsWithCommitList:data];
[weakSelf.myTableView reloadData];
}
[weakSelf.view configBlankPage:EaseBlankPageTypeView hasData:(_listGroups.count > 0) hasError:(error != nil) reloadButtonBlock:^(id sender) {
[weakSelf refresh];
}];
}];
}
- (void)configListGroupsWithCommitList:(NSArray *)commitList{
if (!_listGroups) {
_listGroups = [NSMutableArray new];
}
[_listGroups removeAllObjects];
NSMutableArray *valueList = nil;
for (int i = 0; i < commitList.count; i++) {
Commit *preCommit = [valueList lastObject];
Commit *curCommit = commitList[i];
if (preCommit && [curCommit.commitTime isSameDay:preCommit.commitTime]) {
[valueList addObject:curCommit];
}else{
valueList = [NSMutableArray new];
[_listGroups addObject:valueList];
[valueList addObject:curCommit];
}
}
}
#pragma mark TableViewHeader
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return kScaleFrom_iPhone5_Desgin(24);
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
Commit *curCommit = [[_listGroups objectAtIndex:section] firstObject];
return [tableView getHeaderViewWithStr:[curCommit.commitTime string_yyyy_MM_dd_EEE] andBlock:^(id obj) {
DebugLog(@"\nitem.date.description :%@", curCommit.commitTime.description);
}];
}
#pragma mark Table
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return _listGroups.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
NSArray *curList = [_listGroups objectAtIndex:section];
return curList.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
NSArray *curList = [_listGroups objectAtIndex:indexPath.section];
Commit *curCommit = [curList objectAtIndex:indexPath.row];
CommitListCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_CommitListCell forIndexPath:indexPath];
cell.curCommit = curCommit;
[tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:60];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return [CommitListCell cellHeight];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
NSArray *curList = [_listGroups objectAtIndex:indexPath.section];
Commit *curCommit = [curList objectAtIndex:indexPath.row];
DebugLog(@"%@", curCommit.fullMessage);
CommitFilesViewController *vc = [CommitFilesViewController new];
vc.curProject = _curProject;
vc.ownerGK = _curMRPR.des_owner_name;
vc.projectName = _curMRPR.des_project_name;
vc.commitId = curCommit.commitId;
[self.navigationController pushViewController:vc animated:YES];
}
@end