|
| 1 | +// |
| 2 | +// EACodeBranchListViewController.m |
| 3 | +// Coding_iOS |
| 4 | +// |
| 5 | +// Created by Easeeeeeeeee on 2018/3/22. |
| 6 | +// Copyright © 2018年 Coding. All rights reserved. |
| 7 | +// |
| 8 | + |
| 9 | +#import "EACodeBranchListViewController.h" |
| 10 | +#import "EACodeBranches.h" |
| 11 | +#import "ODRefreshControl.h" |
| 12 | +#import "SVPullToRefresh.h" |
| 13 | +#import "Coding_NetAPIManager.h" |
| 14 | +#import "EACodeBranchListCell.h" |
| 15 | +#import "ProjectViewController.h" |
| 16 | + |
| 17 | +@interface EACodeBranchListViewController ()<UITableViewDataSource, UITableViewDelegate, SWTableViewCellDelegate> |
| 18 | +@property (strong, nonatomic) UITableView *myTableView; |
| 19 | +@property (nonatomic, strong) ODRefreshControl *myRefreshControl; |
| 20 | + |
| 21 | +@property (strong, nonatomic) EACodeBranches *myCodeBranches; |
| 22 | + |
| 23 | +@end |
| 24 | + |
| 25 | +@implementation EACodeBranchListViewController |
| 26 | + |
| 27 | +- (void)viewDidLoad { |
| 28 | + [super viewDidLoad]; |
| 29 | + // Do any additional setup after loading the view. |
| 30 | + self.title = @"分支管理"; |
| 31 | + self.view.backgroundColor = kColorTableSectionBg; |
| 32 | + _myTableView = ({ |
| 33 | + UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain]; |
| 34 | + tableView.backgroundColor = [UIColor clearColor]; |
| 35 | + tableView.dataSource = self; |
| 36 | + tableView.delegate = self; |
| 37 | + tableView.separatorStyle = UITableViewCellSeparatorStyleNone; |
| 38 | +// [tableView registerClass:[EACodeBranchListCell class] forCellReuseIdentifier:[EACodeBranchListCell nameOfClass]]; |
| 39 | + [tableView registerNib:[UINib nibWithNibName:[EACodeBranchListCell nameOfClass] bundle:nil] forCellReuseIdentifier:[EACodeBranchListCell nameOfClass]]; |
| 40 | + [self.view addSubview:tableView]; |
| 41 | + [tableView mas_makeConstraints:^(MASConstraintMaker *make) { |
| 42 | + make.edges.equalTo(self.view); |
| 43 | + }]; |
| 44 | + UIEdgeInsets insets = UIEdgeInsetsMake(0, 0, 0, 0); |
| 45 | + tableView.contentInset = insets; |
| 46 | + tableView.scrollIndicatorInsets = insets; |
| 47 | + tableView.estimatedRowHeight = 0; |
| 48 | + tableView.estimatedSectionHeaderHeight = 0; |
| 49 | + tableView.estimatedSectionFooterHeight = 0; |
| 50 | + tableView; |
| 51 | + }); |
| 52 | + _myRefreshControl = [[ODRefreshControl alloc] initInScrollView:self.myTableView]; |
| 53 | + [_myRefreshControl addTarget:self action:@selector(refresh) forControlEvents:UIControlEventValueChanged]; |
| 54 | + |
| 55 | + __weak typeof(self) weakSelf = self; |
| 56 | + [_myTableView addInfiniteScrollingWithActionHandler:^{ |
| 57 | + [weakSelf refreshMore:YES]; |
| 58 | + }]; |
| 59 | + [self refresh]; |
| 60 | +} |
| 61 | + |
| 62 | +- (void)setMyProject:(Project *)myProject{ |
| 63 | + _myProject = myProject; |
| 64 | + _myCodeBranches = [EACodeBranches new]; |
| 65 | + _myCodeBranches.curPro = _myProject; |
| 66 | +} |
| 67 | + |
| 68 | +#pragma Data |
| 69 | +- (void)refresh{ |
| 70 | + [self refreshMore:NO]; |
| 71 | +} |
| 72 | +- (void)refreshMore:(BOOL)willLoadMore{ |
| 73 | + if (_myCodeBranches.isLoading) { |
| 74 | + return; |
| 75 | + } |
| 76 | + if (willLoadMore && !_myCodeBranches.canLoadMore) { |
| 77 | + [_myTableView.infiniteScrollingView stopAnimating]; |
| 78 | + return; |
| 79 | + } |
| 80 | + _myCodeBranches.willLoadMore = willLoadMore; |
| 81 | + [self sendRequest]; |
| 82 | +} |
| 83 | + |
| 84 | +- (void)sendRequest{ |
| 85 | + if (_myCodeBranches.list.count <= 0) { |
| 86 | + [self.view beginLoading]; |
| 87 | + } |
| 88 | + __weak typeof(self) weakSelf = self; |
| 89 | + [[Coding_NetAPIManager sharedManager] request_CodeBranches_WithObj:_myCodeBranches andBlock:^(EACodeBranches *data, NSError *error) { |
| 90 | + [weakSelf.view endLoading]; |
| 91 | + [weakSelf.myRefreshControl endRefreshing]; |
| 92 | + [weakSelf.myTableView.infiniteScrollingView stopAnimating]; |
| 93 | + if (data) { |
| 94 | + [weakSelf.myCodeBranches configWithObj:data]; |
| 95 | + [weakSelf.myTableView reloadData]; |
| 96 | + weakSelf.myTableView.showsInfiniteScrolling = weakSelf.myCodeBranches.canLoadMore; |
| 97 | + } |
| 98 | + [weakSelf.view configBlankPage:EaseBlankPageTypeView hasData:(weakSelf.myCodeBranches.list.count > 0) hasError:(error != nil) reloadButtonBlock:^(id sender) { |
| 99 | + [weakSelf refreshMore:NO]; |
| 100 | + }]; |
| 101 | + }]; |
| 102 | +} |
| 103 | + |
| 104 | +#pragma mark TableM |
| 105 | +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ |
| 106 | + return _myCodeBranches.list.count; |
| 107 | +} |
| 108 | + |
| 109 | +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ |
| 110 | + EACodeBranchListCell *cell = [tableView dequeueReusableCellWithIdentifier:[EACodeBranchListCell nameOfClass] forIndexPath:indexPath]; |
| 111 | + cell.curBranch = self.myCodeBranches.list[indexPath.row]; |
| 112 | + cell.delegate = self; |
| 113 | + [tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:kPaddingLeftWidth]; |
| 114 | + return cell; |
| 115 | +} |
| 116 | + |
| 117 | +- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ |
| 118 | + return 80; |
| 119 | +} |
| 120 | + |
| 121 | +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ |
| 122 | + [tableView deselectRowAtIndexPath:indexPath animated:YES]; |
| 123 | + CodeBranchOrTag *curB = self.myCodeBranches.list[indexPath.row]; |
| 124 | + ProjectViewController *vc = [ProjectViewController codeVCWithCodeRef:curB.name andProject:self.myProject]; |
| 125 | + vc.hideBranchTagButton = YES; |
| 126 | + [self.navigationController pushViewController:vc animated:YES]; |
| 127 | +} |
| 128 | + |
| 129 | +#pragma mark SWTableViewCellDelegate |
| 130 | +- (void)swipeableTableViewCell:(SWTableViewCell *)cell didTriggerRightUtilityButtonWithIndex:(NSInteger)index{ |
| 131 | + NSIndexPath *indexPath = [self.myTableView indexPathForCell:cell]; |
| 132 | + CodeBranchOrTag *curB = self.myCodeBranches.list[indexPath.row]; |
| 133 | + __weak typeof(self) weakSelf = self; |
| 134 | + [[UIActionSheet bk_actionSheetCustomWithTitle:[NSString stringWithFormat:@"请确认是否要删除分支 %@ ?", curB.name] buttonTitles:nil destructiveTitle:@"确认删除" cancelTitle:@"取消" andDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) { |
| 135 | + if (index == 0) { |
| 136 | + [weakSelf deleteBranch:curB]; |
| 137 | + } |
| 138 | + }] showInView:self.view]; |
| 139 | +} |
| 140 | +- (BOOL)swipeableTableViewCellShouldHideUtilityButtonsOnSwipe:(SWTableViewCell *)cell{ |
| 141 | + return YES; |
| 142 | +} |
| 143 | +- (BOOL)swipeableTableViewCell:(SWTableViewCell *)cell canSwipeToState:(SWCellState)state{ |
| 144 | + NSIndexPath *indexPath = [self.myTableView indexPathForCell:cell]; |
| 145 | + return (indexPath.row != 0); |
| 146 | +} |
| 147 | + |
| 148 | +- (void)deleteBranch:(CodeBranchOrTag *)curB{ |
| 149 | + __weak typeof(self) weakSelf = self; |
| 150 | + [NSObject showHUDQueryStr:@"请稍等..."]; |
| 151 | + [[Coding_NetAPIManager sharedManager] request_DeleteCodeBranch:curB inProject:_myProject andBlock:^(id data, NSError *error) { |
| 152 | + [NSObject hideHUDQuery]; |
| 153 | + if (data) { |
| 154 | + [NSObject showHudTipStr:@"删除成功"]; |
| 155 | +// [weakSelf.myCodeBranches.list removeObject:curB]; |
| 156 | +// [weakSelf.myTableView reloadData]; |
| 157 | + [weakSelf refresh]; |
| 158 | + } |
| 159 | + }]; |
| 160 | +} |
| 161 | + |
| 162 | +@end |
0 commit comments