forked from coding/Coding-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectCommitsViewController.m
More file actions
149 lines (121 loc) · 5.16 KB
/
ProjectCommitsViewController.m
File metadata and controls
149 lines (121 loc) · 5.16 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
//
// ProjectCommitsViewController.m
// Coding_iOS
//
// Created by Ease on 15/6/1.
// Copyright (c) 2015年 Coding. All rights reserved.
//
#import "ProjectCommitsViewController.h"
#import "CommitListCell.h"
#import "ODRefreshControl.h"
#import "SVPullToRefresh.h"
#import "Coding_NetAPIManager.h"
#import "CommitFilesViewController.h"
@interface ProjectCommitsViewController ()
<UITableViewDataSource, UITableViewDelegate>
@property (strong, nonatomic) UITableView *myTableView;
@property (nonatomic, strong) ODRefreshControl *myRefreshControl;
@end
@implementation ProjectCommitsViewController
- (void)viewDidLoad{
[super viewDidLoad];
if (_curCommits.path.length > 0) {
self.title = [NSString stringWithFormat:@"%@ : /%@", _curCommits.ref, _curCommits.path];
}else{
self.title = _curCommits.ref;
}
_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];
__weak typeof(self) weakSelf = self;
[_myTableView addInfiniteScrollingWithActionHandler:^{
[weakSelf refreshMore:YES];
}];
[self refresh];
}
- (void)refresh{
[self refreshMore:NO];
}
- (void)refreshMore:(BOOL)willLoadMore{
if (_curCommits.isLoading) {
return;
}
if (willLoadMore && !_curCommits.canLoadMore) {
[_myTableView.infiniteScrollingView stopAnimating];
return;
}
_curCommits.willLoadMore = willLoadMore;
if (_curCommits.list.count <= 0) {
[self.view beginLoading];
}
__weak typeof(self) weakSelf = self;
[[Coding_NetAPIManager sharedManager] request_Commits:_curCommits withPro:_curProject andBlock:^(id data, NSError *error) {
[weakSelf.view endLoading];
[weakSelf.myRefreshControl endRefreshing];
[weakSelf.myTableView.infiniteScrollingView stopAnimating];
if (data) {
[weakSelf.curCommits configWithCommits:data];
[weakSelf.myTableView reloadData];
weakSelf.myTableView.showsInfiniteScrolling = [weakSelf curCommits].canLoadMore;
}
[weakSelf.view configBlankPage:EaseBlankPageTypeView hasData:(weakSelf.curCommits.list > 0) hasError:(error != nil) reloadButtonBlock:^(id sender) {
[weakSelf refresh];
}];
}];
}
#pragma mark TableViewHeader
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return kScaleFrom_iPhone5_Desgin(24);
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
ListGroupItem *item = [_curCommits.listGroups objectAtIndex:section];
return [tableView getHeaderViewWithStr:[item.date string_yyyy_MM_dd_EEE] andBlock:^(id obj) {
DebugLog(@"\nitem.date.description :%@", item.date.description);
}];
}
#pragma mark Table
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return _curCommits.listGroups.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
ListGroupItem *item = [_curCommits.listGroups objectAtIndex:section];
return item.length;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
ListGroupItem *item = [_curCommits.listGroups objectAtIndex:indexPath.section];
NSInteger row = indexPath.row + item.location;
Commit *curCommit = [_curCommits.list objectAtIndex: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];
ListGroupItem *item = [_curCommits.listGroups objectAtIndex:indexPath.section];
NSInteger row = indexPath.row + item.location;
Commit *curCommit = [_curCommits.list objectAtIndex:row];
DebugLog(@"%@", curCommit.fullMessage);
CommitFilesViewController *vc = [CommitFilesViewController new];
vc.curProject = _curProject;
vc.ownerGK = _curProject.owner_user_name;
vc.projectName = _curProject.name;
vc.commitId = curCommit.commitId;
[self.navigationController pushViewController:vc animated:YES];
}
@end