forked from coding/Coding-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEACodeReleaseViewController.m
More file actions
185 lines (167 loc) · 7.49 KB
/
EACodeReleaseViewController.m
File metadata and controls
185 lines (167 loc) · 7.49 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
//
// EACodeReleaseViewController.m
// Coding_iOS
//
// Created by Easeeeeeeeee on 2018/3/23.
// Copyright © 2018年 Coding. All rights reserved.
//
#import "EACodeReleaseViewController.h"
#import "ODRefreshControl.h"
#import "Coding_NetAPIManager.h"
#import "EACodeReleaseTopCell.h"
#import "EACodeReleaseBodyCell.h"
#import "EACodeReleaseAttachmentsOrReferencesCell.h"
#import "ProjectViewController.h"
#import "WebViewController.h"
#import "EAEditCodeReleaseViewController.h"
@interface EACodeReleaseViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (strong, nonatomic) UITableView *myTableView;
@property (nonatomic, strong) ODRefreshControl *myRefreshControl;
@end
@implementation EACodeReleaseViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.title = _curRelease.tag_name;
self.view.backgroundColor = kColorTableBG;
_myTableView = ({
UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
tableView.backgroundColor = [UIColor clearColor];
tableView.dataSource = self;
tableView.delegate = self;
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[tableView registerNib:[UINib nibWithNibName:[EACodeReleaseTopCell nameOfClass] bundle:nil] forCellReuseIdentifier:[EACodeReleaseTopCell nameOfClass]];
[tableView registerClass:[EACodeReleaseBodyCell class] forCellReuseIdentifier:[EACodeReleaseBodyCell nameOfClass]];
[tableView registerClass:[EACodeReleaseAttachmentsOrReferencesCell class] forCellReuseIdentifier:[EACodeReleaseAttachmentsOrReferencesCell nameOfClass]];
[self.view addSubview:tableView];
[tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view);
}];
UIEdgeInsets insets = UIEdgeInsetsMake(0, 0, 0, 0);
tableView.contentInset = insets;
tableView.scrollIndicatorInsets = insets;
tableView.estimatedRowHeight = 0;
tableView.estimatedSectionHeaderHeight = 0;
tableView.estimatedSectionFooterHeight = 0;
tableView;
});
_myRefreshControl = [[ODRefreshControl alloc] initInScrollView:self.myTableView];
[_myRefreshControl addTarget:self action:@selector(refresh) forControlEvents:UIControlEventValueChanged];
[self.navigationItem setRightBarButtonItem:[UIBarButtonItem itemWithBtnTitle:@"编辑" target:self action:@selector(editBtnClicked)] animated:YES];
}
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self refresh];
}
#pragma Data
- (void)refresh{
if (!_curRelease.author) {
[self.view beginLoading];
}
__weak typeof(self) weakSelf = self;
[[Coding_NetAPIManager sharedManager] request_CodeRelease_WithObj:_curRelease andBlock:^(EACodeRelease *data, NSError *error) {
[weakSelf.view endLoading];
[weakSelf.myRefreshControl endRefreshing];
if (data) {
if (weakSelf.curRelease.contentHeight > 1) {
[(EACodeRelease *)data setContentHeight:weakSelf.curRelease.contentHeight];
}
weakSelf.curRelease = data;
[weakSelf.myTableView reloadData];
}
[weakSelf.view configBlankPage:EaseBlankPageTypeView hasData:(weakSelf.curRelease.author != nil) hasError:(error != nil) reloadButtonBlock:^(id sender) {
[weakSelf refresh];
}];
}];
}
#pragma mark TableM
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return _curRelease.author != nil? 4: 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row == 0) {
EACodeReleaseTopCell *cell = [tableView dequeueReusableCellWithIdentifier:[EACodeReleaseTopCell nameOfClass] forIndexPath:indexPath];
cell.curR = self.curRelease;
__weak typeof(self) weakSelf = self;
cell.tagClickedBlock = ^(EACodeRelease *curR) {
ProjectViewController *vc = [ProjectViewController codeVCWithCodeRef:curR.tag_name andProject:curR.project];
vc.hideBranchTagButton = YES;
[weakSelf.navigationController pushViewController:vc animated:YES];
};
return cell;
}else if (indexPath.row == 1){
EACodeReleaseBodyCell *cell = [tableView dequeueReusableCellWithIdentifier:[EACodeReleaseBodyCell nameOfClass] forIndexPath:indexPath];
cell.curR = self.curRelease;
__weak typeof(self) weakSelf = self;
cell.cellHeightChangedBlock = ^{
[weakSelf.myTableView reloadData];
};
cell.loadRequestBlock = ^(NSURLRequest *curRequest) {
[weakSelf loadRequest:curRequest];
};
return cell;
}else{
EACodeReleaseAttachmentsOrReferencesCell *cell = [tableView dequeueReusableCellWithIdentifier:[EACodeReleaseAttachmentsOrReferencesCell nameOfClass] forIndexPath:indexPath];
[cell setupCodeRelease:_curRelease type:(indexPath.row - 2)];
__weak typeof(self) weakSelf = self;
cell.itemClickedBlock = ^(id item) {
[weakSelf handleItem:item];
};
return cell;
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
CGFloat cellHeight = 0;
if (indexPath.row == 0) {
cellHeight = [EACodeReleaseTopCell cellHeightWithObj:_curRelease];
}else if (indexPath.row == 1){
cellHeight = [EACodeReleaseBodyCell cellHeightWithObj:_curRelease];
}else{
cellHeight = [EACodeReleaseAttachmentsOrReferencesCell cellHeightWithObj:_curRelease type:(indexPath.row - 2)];
}
return cellHeight;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
#pragma mark loadCellRequest
- (void)loadRequest:(NSURLRequest *)curRequest
{
NSString *linkStr = curRequest.URL.absoluteString;
[self analyseLinkStr:linkStr];
}
- (void)analyseLinkStr:(NSString *)linkStr
{
if (linkStr.length <= 0) {
return;
}
UIViewController *vc = [BaseViewController analyseVCFromLinkStr:linkStr];
if (vc) {
[self.navigationController pushViewController:vc animated:YES];
}else{
// 跳转去网页
WebViewController *webVc = [WebViewController webVCWithUrlStr:linkStr];
[self.navigationController pushViewController:webVc animated:YES];
}
}
#pragma mark goTo
- (void)handleItem:(id)item{
if ([item isKindOfClass:[EACodeReleaseAttachment class]]) {
NSString *linkStr = [NSString stringWithFormat:@"/api/user/%@/project/%@/git/releases/attachments/download/%@", _curRelease.project.owner_user_name, _curRelease.project.name, ((EACodeReleaseAttachment *)item).id];
WebViewController *webVc = [WebViewController webVCWithUrlStr:linkStr];
[self.navigationController pushViewController:webVc animated:YES];
}else if ([item isKindOfClass:[ResourceReferenceItem class]]){
UIViewController *vc = [BaseViewController analyseVCFromLinkStr:((ResourceReferenceItem *)item).link];
if (vc) {
[self.navigationController pushViewController:vc animated:YES];
}else{
[NSObject showHudTipStr:@"暂时不支持查看该资源"];
}
}
}
- (void)editBtnClicked{
EAEditCodeReleaseViewController *vc = [EAEditCodeReleaseViewController new];
vc.curR = _curRelease;
[self.navigationController pushViewController:vc animated:YES];
}
@end