Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
executable file
·
177 lines (158 loc) · 6.62 KB

File metadata and controls

executable file
·
177 lines (158 loc) · 6.62 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
//
// CodeViewController.m
// Coding_iOS
//
// Created by 王 原闯 on 14/10/30.
// Copyright (c) 2014年 Coding. All rights reserved.
//
#import "CodeViewController.h"
#import "Coding_NetAPIManager.h"
#import "WebContentManager.h"
#import "ProjectCommitsViewController.h"
#import "ProjectViewController.h"
@interface CodeViewController ()
@property (strong, nonatomic) UIWebView *webContentView;
@property (strong, nonatomic) UIActivityIndicatorView *activityIndicator;
@end
@implementation CodeViewController
+ (CodeViewController *)codeVCWithProject:(Project *)project andCodeFile:(CodeFile *)codeFile{
CodeViewController *vc = [[CodeViewController alloc] init];
vc.myProject = project;
vc.myCodeFile = codeFile;
return vc;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.title = [[_myCodeFile.path componentsSeparatedByString:@"/"] lastObject];
{
//用webView显示内容
_webContentView = [[UIWebView alloc] initWithFrame:self.view.bounds];
_webContentView.delegate = self;
_webContentView.backgroundColor = [UIColor clearColor];
_webContentView.opaque = NO;
_webContentView.scalesPageToFit = YES;
[self.view addSubview:_webContentView];
//webview加载指示
_activityIndicator = [[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:
UIActivityIndicatorViewStyleGray];
_activityIndicator.hidesWhenStopped = YES;
[_activityIndicator setCenter:CGPointMake(CGRectGetWidth(_webContentView.frame)/2, CGRectGetHeight(_webContentView.frame)/2)];
[_webContentView addSubview:_activityIndicator];
[_webContentView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view);
}];
}
[self sendRequest];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Orientations
- (BOOL)shouldAutorotate {
return YES;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
#pragma mark Request
- (void)sendRequest{
[self.view beginLoading];
__weak typeof(self) weakSelf = self;
if (_myCodeFile.ref.length <= 0 && [_myCodeFile.path isEqualToString:@"README"]) {
[[Coding_NetAPIManager sharedManager] request_ReadMeOFProject:_myProject andBlock:^(id data, NSError *error) {
[weakSelf doSomethingWithResponse:data andError:error];
}];
}else{
[[Coding_NetAPIManager sharedManager] request_CodeFile:_myCodeFile withPro:_myProject andBlock:^(id data, NSError *error) {
[weakSelf doSomethingWithResponse:data andError:error];
[weakSelf configRightNavBtn];
}];
}
}
- (void)doSomethingWithResponse:(id)data andError:(NSError *)error{
[self.view endLoading];
if ([data isKindOfClass:[CodeFile class]]) {
self.myCodeFile = data;
[self refreshCodeViewData];
}else{
self.myCodeFile = [CodeFile codeFileWithMDStr:data];
[self refreshCodeViewData];
}
[self.view configBlankPage:EaseBlankPageTypeView hasData:(data != nil) hasError:(error != nil) reloadButtonBlock:^(id sender) {
[self sendRequest];
}];
}
- (void)refreshCodeViewData{
if ([_myCodeFile.file.mode isEqualToString:@"image"]) {
NSURL *imageUrl = [NSURL URLWithString:[NSString stringWithFormat:@"%@u/%@/p/%@/git/raw/%@", [NSObject baseURLStr], _myProject.owner_user_name, _myProject.name, [NSString handelRef:_myCodeFile.ref path:_myCodeFile.file.path]]];
DebugLog(@"imageUrl: %@", imageUrl);
[self.webContentView loadRequest:[NSURLRequest requestWithURL:imageUrl]];
}else if ([_myCodeFile.file.mode isEqualToString:@"file"] ||
[_myCodeFile.file.mode isEqualToString:@"sym_link"]){
NSString *contentStr = [WebContentManager codePatternedWithContent:_myCodeFile];
[self.webContentView loadHTMLString:contentStr baseURL:nil];
}
}
#pragma mark UIWebViewDelegate
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
DebugLog(@"strLink=[%@]",request.URL.absoluteString);
return YES;
}
- (void)webViewDidStartLoad:(UIWebView *)webView{
[_activityIndicator startAnimating];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView{
[_activityIndicator stopAnimating];
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
if([error code] == NSURLErrorCancelled)
return;
else
DebugLog(@"%@", error.description);
}
#pragma mark Nav
- (void)configRightNavBtn{
if (!self.navigationItem.rightBarButtonItem) {
[self.navigationItem setRightBarButtonItem:[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"moreBtn_Nav"] style:UIBarButtonItemStylePlain target:self action:@selector(rightNavBtnClicked)] animated:NO];
}
}
- (void)rightNavBtnClicked{
__weak typeof(self) weakSelf = self;
[[UIActionSheet bk_actionSheetCustomWithTitle:nil buttonTitles:@[@"查看提交记录", @"退出代码查看"] destructiveTitle:nil cancelTitle:@"取消" andDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) {
switch (index) {
case 0:{
[weakSelf goToCommitsVC];
}
break;
case 1:{
[weakSelf.navigationController.viewControllers enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(UIViewController *obj, NSUInteger idx, BOOL *stop) {
if (![obj isKindOfClass:[weakSelf class]]) {
if ([obj isKindOfClass:[ProjectViewController class]]) {
if ([(ProjectViewController *)obj curType] != ProjectViewTypeCodes) {
*stop = YES;
}
}else{
*stop = YES;
}
}
if (*stop) {
[weakSelf.navigationController popToViewController:obj animated:YES];
}
}];
}
break;
default:
break;
}
}] showInView:self.view];
}
- (void)goToCommitsVC{
ProjectCommitsViewController *vc = [ProjectCommitsViewController new];
vc.curProject = self.myProject;
vc.curCommits = [Commits commitsWithRef:self.myCodeFile.ref Path:self.myCodeFile.path];
[self.navigationController pushViewController:vc animated:YES];
}
@end
Morty Proxy This is a proxified and sanitized view of the page, visit original site.