forked from coding/Coding-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectCodeListView.m
More file actions
executable file
·142 lines (129 loc) · 5.16 KB
/
ProjectCodeListView.m
File metadata and controls
executable file
·142 lines (129 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
//
// ProjectCodeListView.m
// Coding_iOS
//
// Created by 王 原闯 on 14/10/29.
// Copyright (c) 2014年 Coding. All rights reserved.
//
#import "ProjectCodeListView.h"
#import "ODRefreshControl.h"
#import "Coding_NetAPIManager.h"
#import "ProjectCodeListCell.h"
#import "CodeBranchTagButton.h"
@interface ProjectCodeListView ()
@property (nonatomic, strong) Project *curProject;
@property (nonatomic , strong) CodeTree *myCodeTree;
@property (nonatomic, strong) UITableView *myTableView;
@property (nonatomic, strong) ODRefreshControl *myRefreshControl;
@property (strong, nonatomic) CodeBranchTagButton *branchTagButton;
@end
@implementation ProjectCodeListView
- (id)initWithFrame:(CGRect)frame project:(Project *)project andCodeTree:(CodeTree *)codeTree{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
_curProject = project;
if (codeTree) {
_myCodeTree = codeTree;
}else{
_myCodeTree = [CodeTree codeTreeMaster];
}
_myTableView = ({
UITableView *tableView = [[UITableView alloc] initWithFrame:self.bounds style:UITableViewStylePlain];
tableView.backgroundColor = [UIColor clearColor];
tableView.delegate = self;
tableView.dataSource = self;
[tableView registerClass:[ProjectCodeListCell class] forCellReuseIdentifier:kCellIdentifier_ProjectCodeList];
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[self addSubview:tableView];
[tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self);
}];
tableView;
});
_myRefreshControl = [[ODRefreshControl alloc] initInScrollView:self.myTableView];
[_myRefreshControl addTarget:self action:@selector(refresh) forControlEvents:UIControlEventValueChanged];
[self sendRequest];
}
return self;
}
- (void)addBranchTagButton{
CGFloat bottonToolBarHeight = 49.0;
if (!_branchTagButton) {
_branchTagButton = ({
CodeBranchTagButton *button = [CodeBranchTagButton buttonWithProject:_curProject andTitleStr:_myCodeTree.ref];
[self addSubview:button];
[button mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.bottom.equalTo(self);
make.height.mas_equalTo(bottonToolBarHeight);
}];
button;
});
}
__weak typeof(self) weakSelf = self;
_branchTagButton.selectedBranchTagBlock = ^(NSString *branchTag){
if ([weakSelf.myCodeTree.ref isEqualToString:branchTag]) {
return ;
}else if (weakSelf.refChangedBlock){
weakSelf.refChangedBlock(branchTag);
}
weakSelf.myCodeTree = [CodeTree codeTreeWithRef:branchTag andPath:weakSelf.myCodeTree.path];
[weakSelf.myTableView reloadData];
[weakSelf sendRequest];
};
[self.myTableView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self).insets(UIEdgeInsetsMake(0, 0, bottonToolBarHeight, 0));
}];
}
- (void)refresh{
if (_myCodeTree.isLoading) {
return;
}
[self sendRequest];
}
- (void)sendRequest{
if (_myCodeTree.files.count <= 0) {
[self beginLoading];
}
__weak typeof(self) weakSelf = self;
[[Coding_NetAPIManager sharedManager] request_CodeTree:_myCodeTree withPro:_curProject codeTreeBlock:^(id codeTreeData, NSError *codeTreeError) {
[weakSelf.myRefreshControl endRefreshing];
[weakSelf endLoading];
if (codeTreeData) {
weakSelf.myCodeTree = codeTreeData;
[weakSelf.myTableView reloadData];
}
BOOL hasError = NO;
if (codeTreeError != nil && codeTreeError.code == 1024) {
hasError = YES;
}
[weakSelf configBlankPage:EaseBlankPageTypeView hasData:(weakSelf.myCodeTree.files.count > 0) hasError:hasError reloadButtonBlock:^(id sender) {
[weakSelf refresh];
}];
}];
}
#pragma mark Table
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
NSInteger row = 0;
if (_myCodeTree && _myCodeTree.files) {
row = _myCodeTree.files.count;
}
return row;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
ProjectCodeListCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_ProjectCodeList forIndexPath:indexPath];
cell.file = [self.myCodeTree.files objectAtIndex:indexPath.row];
[tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:kPaddingLeftWidth];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return [ProjectCodeListCell cellHeight];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if (_codeTreeFileOfRefBlock) {
CodeTree_File *file = [self.myCodeTree.files objectAtIndex:indexPath.row];
_codeTreeFileOfRefBlock(file, _myCodeTree.ref);
}
}
@end