|
7 | 7 | // |
8 | 8 |
|
9 | 9 | #import "ProjectCommitsViewController.h" |
| 10 | +#import "CommitListCell.h" |
| 11 | + |
| 12 | +#import "ODRefreshControl.h" |
| 13 | +#import "SVPullToRefresh.h" |
| 14 | + |
| 15 | +#import "Coding_NetAPIManager.h" |
| 16 | + |
| 17 | +#import "CommitFilesViewController.h" |
| 18 | + |
| 19 | +@interface ProjectCommitsViewController () |
| 20 | +<UITableViewDataSource, UITableViewDelegate> |
| 21 | +@property (strong, nonatomic) UITableView *myTableView; |
| 22 | +@property (nonatomic, strong) ODRefreshControl *myRefreshControl; |
| 23 | + |
| 24 | +@end |
10 | 25 |
|
11 | 26 | @implementation ProjectCommitsViewController |
| 27 | +- (void)viewDidLoad{ |
| 28 | + [super viewDidLoad]; |
| 29 | + |
| 30 | + self.title = [NSString stringWithFormat:@"%@:%@", _curCommits.ref, _curCommits.path]; |
| 31 | + |
| 32 | + _myTableView = ({ |
| 33 | + UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain]; |
| 34 | + tableView.dataSource = self; |
| 35 | + tableView.delegate = self; |
| 36 | + tableView.separatorStyle = UITableViewCellSeparatorStyleNone; |
| 37 | + [tableView registerClass:[CommitListCell class] forCellReuseIdentifier:kCellIdentifier_CommitListCell]; |
| 38 | + [self.view addSubview:tableView]; |
| 39 | + [tableView mas_makeConstraints:^(MASConstraintMaker *make) { |
| 40 | + make.edges.equalTo(self.view); |
| 41 | + }]; |
| 42 | + tableView; |
| 43 | + }); |
| 44 | + _myRefreshControl = [[ODRefreshControl alloc] initInScrollView:self.myTableView]; |
| 45 | + [_myRefreshControl addTarget:self action:@selector(refresh) forControlEvents:UIControlEventValueChanged]; |
| 46 | + |
| 47 | + __weak typeof(self) weakSelf = self; |
| 48 | + [_myTableView addInfiniteScrollingWithActionHandler:^{ |
| 49 | + [weakSelf refreshMore:YES]; |
| 50 | + }]; |
| 51 | + |
| 52 | + [self refresh]; |
| 53 | +} |
| 54 | + |
| 55 | +- (void)refresh{ |
| 56 | + [self refreshMore:NO]; |
| 57 | +} |
| 58 | + |
| 59 | +- (void)refreshMore:(BOOL)willLoadMore{ |
| 60 | + if (_curCommits.isLoading) { |
| 61 | + return; |
| 62 | + } |
| 63 | + |
| 64 | + if (willLoadMore && !_curCommits.canLoadMore) { |
| 65 | + [_myTableView.infiniteScrollingView stopAnimating]; |
| 66 | + return; |
| 67 | + } |
| 68 | + |
| 69 | + _curCommits.willLoadMore = willLoadMore; |
| 70 | + if (_curCommits.list.count <= 0) { |
| 71 | + [self.view beginLoading]; |
| 72 | + } |
| 73 | + __weak typeof(self) weakSelf = self; |
| 74 | + |
| 75 | + [[Coding_NetAPIManager sharedManager] request_Commits:_curCommits withPro:_curProject andBlock:^(id data, NSError *error) { |
| 76 | + [weakSelf.view endLoading]; |
| 77 | + [weakSelf.myRefreshControl endRefreshing]; |
| 78 | + if (data) { |
| 79 | + [weakSelf.curCommits configWithCommits:data]; |
| 80 | + [weakSelf.myTableView reloadData]; |
| 81 | + } |
| 82 | + [weakSelf.view configBlankPage:EaseBlankPageTypeView hasData:(weakSelf.curCommits.list > 0) hasError:(error != nil) reloadButtonBlock:^(id sender) { |
| 83 | + [weakSelf refresh]; |
| 84 | + }]; |
| 85 | + }]; |
| 86 | +} |
| 87 | + |
| 88 | +#pragma mark TableViewHeader |
| 89 | +- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ |
| 90 | + return kScaleFrom_iPhone5_Desgin(24); |
| 91 | +} |
| 92 | + |
| 93 | +- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ |
| 94 | + ListGroupItem *item = [_curCommits.listGroups objectAtIndex:section]; |
| 95 | + return [tableView getHeaderViewWithStr:[item.date string_yyyy_MM_dd_EEE] andBlock:^(id obj) { |
| 96 | + DebugLog(@"\nitem.date.description :%@", item.date.description); |
| 97 | + }]; |
| 98 | +} |
| 99 | + |
| 100 | +#pragma mark Table |
| 101 | + |
| 102 | +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ |
| 103 | + return _curCommits.listGroups.count; |
| 104 | +} |
| 105 | + |
| 106 | +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ |
| 107 | + ListGroupItem *item = [_curCommits.listGroups objectAtIndex:section]; |
| 108 | + return item.length; |
| 109 | +} |
| 110 | + |
| 111 | +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ |
| 112 | + ListGroupItem *item = [_curCommits.listGroups objectAtIndex:indexPath.section]; |
| 113 | + NSInteger row = indexPath.row + item.location; |
| 114 | + Commit *curCommit = [_curCommits.list objectAtIndex:row]; |
| 115 | + CommitListCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_CommitListCell forIndexPath:indexPath]; |
| 116 | + cell.curCommit = curCommit; |
| 117 | + [tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:60]; |
| 118 | + return cell; |
| 119 | +} |
| 120 | + |
| 121 | +- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ |
| 122 | + return [CommitListCell cellHeight]; |
| 123 | +} |
| 124 | + |
| 125 | +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ |
| 126 | + [tableView deselectRowAtIndexPath:indexPath animated:YES]; |
| 127 | + |
| 128 | + ListGroupItem *item = [_curCommits.listGroups objectAtIndex:indexPath.section]; |
| 129 | + NSInteger row = indexPath.row + item.location; |
| 130 | + Commit *curCommit = [_curCommits.list objectAtIndex:row]; |
| 131 | + |
| 132 | + DebugLog(@"%@", curCommit.fullMessage); |
| 133 | + |
| 134 | + CommitFilesViewController *vc = [CommitFilesViewController new]; |
| 135 | + vc.curProject = _curProject; |
| 136 | + vc.ownerGK = _curProject.owner_user_name; |
| 137 | + vc.projectName = _curProject.name; |
| 138 | + vc.commitId = curCommit.commitId; |
| 139 | + [self.navigationController pushViewController:vc animated:YES]; |
| 140 | +} |
| 141 | + |
12 | 142 |
|
13 | 143 | @end |
0 commit comments