| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,6 +9,8 @@ | |||
| 9 | 9 | /* Begin PBXBuildFile section */ | |
| 10 | 10 | 4E15C7D01A26D2F000FB8DAD /* FolderToMoveViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E15C7CF1A26D2F000FB8DAD /* FolderToMoveViewController.m */; }; | |
| 11 | 11 | 4E15C7D61A271A6300FB8DAD /* EaseToolBar.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E15C7D51A271A6300FB8DAD /* EaseToolBar.m */; }; | |
| 12 | + 4E2906A21A403B7D008A5B97 /* FileDownloadView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E2906A11A403B7D008A5B97 /* FileDownloadView.m */; }; | ||
| 13 | + 4E35A99F1A3EC47E00CE35F1 /* FileViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E35A99E1A3EC47E00CE35F1 /* FileViewController.m */; }; | ||
| 12 | 14 | 4E3AD3CF1A273A4A005C749B /* FAImageView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E3AD3C11A273A4A005C749B /* FAImageView.m */; }; | |
| 13 | 15 | 4E3AD3D01A273A4A005C749B /* NSString+FontAwesome.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E3AD3C31A273A4A005C749B /* NSString+FontAwesome.m */; }; | |
| 14 | 16 | 4E3AD3D11A273A4A005C749B /* FontAwesome.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 4E3AD3C51A273A4A005C749B /* FontAwesome.ttf */; }; | |
@@ -483,6 +485,10 @@ | |||
| 483 | 485 | 4E15C7CF1A26D2F000FB8DAD /* FolderToMoveViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FolderToMoveViewController.m; sourceTree = "<group>"; }; | |
| 484 | 486 | 4E15C7D41A271A6300FB8DAD /* EaseToolBar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EaseToolBar.h; sourceTree = "<group>"; }; | |
| 485 | 487 | 4E15C7D51A271A6300FB8DAD /* EaseToolBar.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EaseToolBar.m; sourceTree = "<group>"; }; | |
| 488 | + 4E2906A01A403B7D008A5B97 /* FileDownloadView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FileDownloadView.h; sourceTree = "<group>"; }; | ||
| 489 | + 4E2906A11A403B7D008A5B97 /* FileDownloadView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FileDownloadView.m; sourceTree = "<group>"; }; | ||
| 490 | + 4E35A99D1A3EC47E00CE35F1 /* FileViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FileViewController.h; sourceTree = "<group>"; }; | ||
| 491 | + 4E35A99E1A3EC47E00CE35F1 /* FileViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FileViewController.m; sourceTree = "<group>"; }; | ||
| 486 | 492 | 4E3AD3C01A273A4A005C749B /* FAImageView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FAImageView.h; sourceTree = "<group>"; }; | |
| 487 | 493 | 4E3AD3C11A273A4A005C749B /* FAImageView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FAImageView.m; sourceTree = "<group>"; }; | |
| 488 | 494 | 4E3AD3C21A273A4A005C749B /* NSString+FontAwesome.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+FontAwesome.h"; sourceTree = "<group>"; }; | |
@@ -1891,6 +1897,8 @@ | |||
| 1891 | 1897 | 4EA6791F1A15AB9F001A0324 /* FileListViewController.m */, | |
| 1892 | 1898 | 4E15C7CE1A26D2F000FB8DAD /* FolderToMoveViewController.h */, | |
| 1893 | 1899 | 4E15C7CF1A26D2F000FB8DAD /* FolderToMoveViewController.m */, | |
| 1900 | + 4E35A99D1A3EC47E00CE35F1 /* FileViewController.h */, | ||
| 1901 | + 4E35A99E1A3EC47E00CE35F1 /* FileViewController.m */, | ||
| 1894 | 1902 | ); | |
| 1895 | 1903 | path = Controllers; | |
| 1896 | 1904 | sourceTree = "<group>"; | |
@@ -2329,6 +2337,8 @@ | |||
| 2329 | 2337 | 8E59F0F01A00F38A009A905F /* ProjectFolderListView.m */, | |
| 2330 | 2338 | 8EA6D12319E240C40076D59C /* UIMessageInputView.h */, | |
| 2331 | 2339 | 8EA6D12419E240C40076D59C /* UIMessageInputView.m */, | |
| 2340 | + 4E2906A01A403B7D008A5B97 /* FileDownloadView.h */, | ||
| 2341 | + 4E2906A11A403B7D008A5B97 /* FileDownloadView.m */, | ||
| 2332 | 2342 | ); | |
| 2333 | 2343 | path = Views; | |
| 2334 | 2344 | sourceTree = "<group>"; | |
@@ -2871,6 +2881,7 @@ | |||
| 2871 | 2881 | 8EA6D13819E240C40076D59C /* Message_RootViewController.m in Sources */, | |
| 2872 | 2882 | 8EF643B219FF7E2900F7EEB0 /* Input_GlobalKey_Cell.m in Sources */, | |
| 2873 | 2883 | 8EA6D1BD19E240C40076D59C /* QcTask.m in Sources */, | |
| 2884 | + 4E35A99F1A3EC47E00CE35F1 /* FileViewController.m in Sources */, | ||
| 2874 | 2885 | 4ECE8B001A3946C10021E29C /* CodingNetAPIClient.m in Sources */, | |
| 2875 | 2886 | 8EF643B119FF7E2900F7EEB0 /* ConversationCell.m in Sources */, | |
| 2876 | 2887 | 8EF643D019FF7E2900F7EEB0 /* TweetSendImagesCell.m in Sources */, | |
@@ -2914,6 +2925,7 @@ | |||
| 2914 | 2925 | 4E6BA2E11A1EE6AF005FD721 /* AFNetworkActivityIndicatorManager.m in Sources */, | |
| 2915 | 2926 | 8EA6D1B619E240C40076D59C /* Login.m in Sources */, | |
| 2916 | 2927 | 8EF643C419FF7E2900F7EEB0 /* TitleDisclosureCell.m in Sources */, | |
| 2928 | + 4E2906A21A403B7D008A5B97 /* FileDownloadView.m in Sources */, | ||
| 2917 | 2929 | 4E6BA2DC1A1EE6AF005FD721 /* AFNetworkReachabilityManager.m in Sources */, | |
| 2918 | 2930 | 8E59F0E31A0098BA009A905F /* UIScrollView+SVPullToRefresh.m in Sources */, | |
| 2919 | 2931 | 8EA6D13419E240C40076D59C /* ProjectMemberListViewController.m in Sources */, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -90,14 +90,8 @@ - (void)refreshCodeViewData{ | |||
| 90 | 90 | ||
| 91 | 91 | #pragma mark UIWebViewDelegate | |
| 92 | 92 | - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{ | |
| 93 | - NSString *strLink = request.URL.absoluteString; | ||
| 94 | - NSLog(@"strLink=[%@]",strLink); | ||
| 95 | - if ([strLink rangeOfString:@"about:blank"].location != NSNotFound) { | ||
| 96 | - return YES; | ||
| 97 | - }else{ | ||
| 98 | - return YES; | ||
| 99 | - // return NO; | ||
| 100 | - } | ||
| 93 | + NSLog(@"strLink=[%@]",request.URL.absoluteString); | ||
| 94 | + return YES; | ||
| 101 | 95 | } | |
| 102 | 96 | - (void)webViewDidStartLoad:(UIWebView *)webView{ | |
| 103 | 97 | [_activityIndicator startAnimating]; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,8 +18,9 @@ | |||
| 18 | 18 | #import "BasicPreviewItem.h" | |
| 19 | 19 | #import "SettingTextViewController.h" | |
| 20 | 20 | #import "FolderToMoveViewController.h" | |
| 21 | + #import "FileViewController.h" | ||
| 21 | 22 | ||
| 22 | - @interface FileListViewController () <QLPreviewControllerDataSource, QLPreviewControllerDelegate,SWTableViewCellDelegate> | ||
| 23 | + @interface FileListViewController () <QLPreviewControllerDataSource, QLPreviewControllerDelegate, SWTableViewCellDelegate> | ||
| 23 | 24 | @property (nonatomic, strong) UITableView *myTableView; | |
| 24 | 25 | @property (nonatomic, strong) ODRefreshControl *refreshControl; | |
| 25 | 26 | @property (strong, nonatomic) ProjectFiles *myFiles; | |
@@ -48,6 +49,13 @@ - (void)didReceiveMemoryWarning | |||
| 48 | 49 | // Dispose of any resources that can be recreated. | |
| 49 | 50 | } | |
| 50 | 51 | ||
| 52 | + - (void)viewWillAppear:(BOOL)animated{ | ||
| 53 | + [super viewWillAppear:animated]; | ||
| 54 | + if (self.myTableView) { | ||
| 55 | + [self.myTableView reloadData]; | ||
| 56 | + } | ||
| 57 | + } | ||
| 58 | + | ||
| 51 | 59 | - (void)loadView{ | |
| 52 | 60 | [super loadView]; | |
| 53 | 61 | self.title = self.curFolder.name; | |
@@ -198,8 +206,11 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath | |||
| 198 | 206 | ProjectFolder *clickedFolder = [_curFolder.sub_folders objectAtIndex:indexPath.row];; | |
| 199 | 207 | [self goToVCWithFolder:clickedFolder inProject:self.curProject]; | |
| 200 | 208 | }else{ | |
| 201 | - FileListFileCell *cell = (FileListFileCell *)[tableView cellForRowAtIndexPath:indexPath]; | ||
| 202 | - [cell clickedByUser]; | ||
| 209 | + // FileListFileCell *cell = (FileListFileCell *)[tableView cellForRowAtIndexPath:indexPath]; | ||
| 210 | + // [cell clickedByUser]; | ||
| 211 | + | ||
| 212 | + ProjectFile *file = [_myFiles.list objectAtIndex:(indexPath.row - _curFolder.sub_folders.count)]; | ||
| 213 | + [self goToFileVC:file]; | ||
| 203 | 214 | } | |
| 204 | 215 | } | |
| 205 | 216 | ||
@@ -434,6 +445,12 @@ - (void)goToVCWithFolder:(ProjectFolder *)folder inProject:(Project *)project{ | |||
| 434 | 445 | [self.navigationController pushViewController:vc animated:YES]; | |
| 435 | 446 | } | |
| 436 | 447 | ||
| 448 | + - (void)goToFileVC:(ProjectFile *)file{ | ||
| 449 | + FileViewController *vc = [[FileViewController alloc] init]; | ||
| 450 | + vc.curFile = file; | ||
| 451 | + [self.navigationController pushViewController:vc animated:YES]; | ||
| 452 | + } | ||
| 453 | + | ||
| 437 | 454 | - (void)showDiskFile:(NSURL *)fileUrl{ | |
| 438 | 455 | QLPreviewController *previewController = [[QLPreviewController alloc] init]; | |
| 439 | 456 | previewController.dataSource = self; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,16 @@ | |||
| 1 | + // | ||
| 2 | + // FileViewController.h | ||
| 3 | + // Coding_iOS | ||
| 4 | + // | ||
| 5 | + // Created by Ease on 14/12/15. | ||
| 6 | + // Copyright (c) 2014年 Coding. All rights reserved. | ||
| 7 | + // | ||
| 8 | + #import <QuickLook/QuickLook.h> | ||
| 9 | + #import "BaseViewController.h" | ||
| 10 | + #import "ProjectFolder.h" | ||
| 11 | + #import "ProjectFolders.h" | ||
| 12 | + #import "ProjectFile.h" | ||
| 13 | + | ||
| 14 | + @interface FileViewController : BaseViewController | ||
| 15 | + @property (strong, nonatomic) ProjectFile *curFile; | ||
| 16 | + @end | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,251 @@ | |||
| 1 | + // | ||
| 2 | + // FileViewController.m | ||
| 3 | + // Coding_iOS | ||
| 4 | + // | ||
| 5 | + // Created by Ease on 14/12/15. | ||
| 6 | + // Copyright (c) 2014年 Coding. All rights reserved. | ||
| 7 | + // | ||
| 8 | + | ||
| 9 | + #import "FileViewController.h" | ||
| 10 | + #import "BasicPreviewItem.h" | ||
| 11 | + #import "FileDownloadView.h" | ||
| 12 | + #import "Coding_NetAPIManager.h" | ||
| 13 | + #import "WebContentManager.h" | ||
| 14 | + #import <MMMarkdown/MMMarkdown.h> | ||
| 15 | + | ||
| 16 | + @interface FileViewController () <QLPreviewControllerDataSource, QLPreviewControllerDelegate, UIDocumentInteractionControllerDelegate, UIWebViewDelegate> | ||
| 17 | + @property (strong, nonatomic) NSURL *fileUrl; | ||
| 18 | + @property (strong, nonatomic) QLPreviewController *previewController; | ||
| 19 | + @property (strong, nonatomic) FileDownloadView *downloadView; | ||
| 20 | + @property (nonatomic, strong) UIDocumentInteractionController *docInteractionController; | ||
| 21 | + | ||
| 22 | + @property (strong, nonatomic) UIWebView *contentWebView; | ||
| 23 | + @property (strong, nonatomic) UIActivityIndicatorView *activityIndicator; | ||
| 24 | + | ||
| 25 | + @end | ||
| 26 | + | ||
| 27 | + @implementation FileViewController | ||
| 28 | + | ||
| 29 | + - (void)viewDidLoad { | ||
| 30 | + [super viewDidLoad]; | ||
| 31 | + // Do any additional setup after loading the view. | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + - (void)didReceiveMemoryWarning { | ||
| 35 | + [super didReceiveMemoryWarning]; | ||
| 36 | + // Dispose of any resources that can be recreated. | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + - (void)loadView{ | ||
| 40 | + [super loadView]; | ||
| 41 | + self.title = self.curFile.name; | ||
| 42 | + self.view = [[UIView alloc] initWithFrame:[UIView frameWithOutNav]]; | ||
| 43 | + self.view.backgroundColor = [UIColor whiteColor]; | ||
| 44 | + | ||
| 45 | + if ([self.curFile isEmpty]) { | ||
| 46 | + [self requestFileData]; | ||
| 47 | + }else{ | ||
| 48 | + [self configContent]; | ||
| 49 | + } | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + - (void)viewWillDisappear:(BOOL)animated{ | ||
| 53 | + [super viewDidDisappear:animated]; | ||
| 54 | + | ||
| 55 | + [self.navigationController setNavigationBarHidden:NO]; | ||
| 56 | + [UIApplication sharedApplication].statusBarHidden = NO; | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + - (void)requestFileData{ | ||
| 60 | + [self.view beginLoading]; | ||
| 61 | + __weak typeof(self) weakSelf = self; | ||
| 62 | + [[Coding_NetAPIManager sharedManager] request_FileDetail:self.curFile andBlock:^(id data, NSError *error) { | ||
| 63 | + [weakSelf.view endLoading]; | ||
| 64 | + | ||
| 65 | + if (data) { | ||
| 66 | + weakSelf.curFile = data; | ||
| 67 | + [weakSelf configContent]; | ||
| 68 | + }else{ | ||
| 69 | + [weakSelf.view configBlankPage:EaseBlankPageTypeView hasData:NO hasError:(error != nil) reloadButtonBlock:^(id sender) { | ||
| 70 | + [weakSelf requestFileData]; | ||
| 71 | + }]; | ||
| 72 | + } | ||
| 73 | + }]; | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + - (void)configContent{ | ||
| 77 | + self.title = self.curFile.name; | ||
| 78 | + NSURL *fileUrl = [self.curFile hasBeenDownload]; | ||
| 79 | + | ||
| 80 | + if (!fileUrl ) { | ||
| 81 | + [self showDownloadView]; | ||
| 82 | + return; | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + self.fileUrl = fileUrl; | ||
| 86 | + [self setupDocumentControllerWithURL:fileUrl]; | ||
| 87 | + | ||
| 88 | + if ([self.curFile.fileType isEqualToString:@"md"] | ||
| 89 | + || [self.curFile.fileType isEqualToString:@"html"] | ||
| 90 | + || [self.curFile.fileType isEqualToString:@"txt"] | ||
| 91 | + || [self.curFile.fileType isEqualToString:@"plist"]){ | ||
| 92 | + [self loadWebView:fileUrl]; | ||
| 93 | + }else if ([QLPreviewController canPreviewItem:fileUrl]) { | ||
| 94 | + [self showDiskFile:fileUrl]; | ||
| 95 | + }else { | ||
| 96 | + [self showDownloadView]; | ||
| 97 | + } | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + | ||
| 101 | + - (void)showDiskFile:(NSURL *)fileUrl{ | ||
| 102 | + if (self.downloadView) { | ||
| 103 | + self.downloadView.hidden = YES; | ||
| 104 | + } | ||
| 105 | + | ||
| 106 | + CGRect frame = self.view.bounds; | ||
| 107 | + QLPreviewController* preview = [[QLPreviewController alloc] init]; | ||
| 108 | + preview.dataSource = self; | ||
| 109 | + preview.delegate = self; | ||
| 110 | + preview.view.frame = frame; | ||
| 111 | + | ||
| 112 | + [self.view addSubview:preview.view]; | ||
| 113 | + self.previewController = preview; | ||
| 114 | + } | ||
| 115 | + | ||
| 116 | + - (void)loadWebView:(NSURL *)fileUrl{ | ||
| 117 | + if (self.downloadView) { | ||
| 118 | + self.downloadView.hidden = YES; | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + if (!_contentWebView) { | ||
| 122 | + //用webView显示内容 | ||
| 123 | + _contentWebView = [[UIWebView alloc] initWithFrame:self.view.bounds]; | ||
| 124 | + _contentWebView.delegate = self; | ||
| 125 | + _contentWebView.backgroundColor = [UIColor clearColor]; | ||
| 126 | + _contentWebView.opaque = NO; | ||
| 127 | + _contentWebView.scalesPageToFit = YES; | ||
| 128 | + //webview加载指示 | ||
| 129 | + _activityIndicator = [[UIActivityIndicatorView alloc] | ||
| 130 | + initWithActivityIndicatorStyle: | ||
| 131 | + UIActivityIndicatorViewStyleGray]; | ||
| 132 | + _activityIndicator.hidesWhenStopped = YES; | ||
| 133 | + [_activityIndicator setCenter:CGPointMake(CGRectGetWidth(_contentWebView.frame)/2, CGRectGetHeight(_contentWebView.frame)/2)]; | ||
| 134 | + [_contentWebView addSubview:_activityIndicator]; | ||
| 135 | + [self.view addSubview:_contentWebView]; | ||
| 136 | + } | ||
| 137 | + if ([self.curFile.fileType isEqualToString:@"md"]){ | ||
| 138 | + // NSData *mdData = [NSData dataWithContentsOfURL:fileUrl]; | ||
| 139 | + // NSString *mdStr = [[NSString alloc] initWithData:mdData encoding:NSUTF8StringEncoding]; | ||
| 140 | + NSError *error = nil; | ||
| 141 | + NSString *htmlStr; | ||
| 142 | + @try { | ||
| 143 | + NSString *mdStr = [NSString stringWithContentsOfURL:fileUrl encoding:NSUTF8StringEncoding error:&error]; | ||
| 144 | + htmlStr = [MMMarkdown HTMLStringWithMarkdown:mdStr error:&error]; | ||
| 145 | + } | ||
| 146 | + @catch (NSException *exception) { | ||
| 147 | + htmlStr = @"加载失败!"; | ||
| 148 | + } | ||
| 149 | + | ||
| 150 | + if (error) { | ||
| 151 | + htmlStr = @"加载失败!"; | ||
| 152 | + } | ||
| 153 | + NSString *contentStr = [WebContentManager markdownPatternedWithContent:htmlStr]; | ||
| 154 | + [self.contentWebView loadHTMLString:contentStr baseURL:nil]; | ||
| 155 | + }else if ([self.curFile.fileType isEqualToString:@"html"]){ | ||
| 156 | + NSString* htmlString = [NSString stringWithContentsOfURL:fileUrl encoding:NSUTF8StringEncoding error:nil]; | ||
| 157 | + [self.contentWebView loadHTMLString:htmlString baseURL:nil]; | ||
| 158 | + }else if ([self.curFile.fileType isEqualToString:@"plist"] | ||
| 159 | + || [self.curFile.fileType isEqualToString:@"txt"]){ | ||
| 160 | + NSData *fileData = [NSData dataWithContentsOfURL:fileUrl]; | ||
| 161 | + [self.contentWebView loadData:fileData MIMEType:@"text/text" textEncodingName:@"UTF-8" baseURL:nil]; | ||
| 162 | + }else{ | ||
| 163 | + [self.contentWebView loadRequest:[NSURLRequest requestWithURL:fileUrl]]; | ||
| 164 | + } | ||
| 165 | + } | ||
| 166 | + | ||
| 167 | + - (void)showDownloadView{ | ||
| 168 | + if (!self.downloadView) { | ||
| 169 | + self.downloadView = [[FileDownloadView alloc] initWithFrame:self.view.bounds]; | ||
| 170 | + self.downloadView.file = self.curFile; | ||
| 171 | + [self.view addSubview:self.downloadView]; | ||
| 172 | + } | ||
| 173 | + __weak typeof(self) weakSelf = self; | ||
| 174 | + self.downloadView.hidden = NO; | ||
| 175 | + self.downloadView.completionBlock = ^(){ | ||
| 176 | + [weakSelf configContent]; | ||
| 177 | + }; | ||
| 178 | + self.downloadView.goToFileBlock = ^(ProjectFile *file){ | ||
| 179 | + [weakSelf.docInteractionController presentOpenInMenuFromBarButtonItem:weakSelf.navigationItem.rightBarButtonItem animated:YES]; | ||
| 180 | + }; | ||
| 181 | + } | ||
| 182 | + | ||
| 183 | + - (void)setupDocumentControllerWithURL:(NSURL *)url{ | ||
| 184 | + if (self.docInteractionController == nil){ | ||
| 185 | + self.docInteractionController = [UIDocumentInteractionController interactionControllerWithURL:url]; | ||
| 186 | + }else{ | ||
| 187 | + self.docInteractionController.URL = url; | ||
| 188 | + } | ||
| 189 | + [self setupNavigationItem]; | ||
| 190 | + } | ||
| 191 | + | ||
| 192 | + - (void)setupNavigationItem{ | ||
| 193 | + UIButton *itemButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 19, 19)]; | ||
| 194 | + [itemButton setImage:[UIImage imageNamed:@"addBtn_Nav"] forState:UIControlStateNormal]; | ||
| 195 | + @weakify(self); | ||
| 196 | + [[itemButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) { | ||
| 197 | + @strongify(self); | ||
| 198 | + [self.docInteractionController presentOpenInMenuFromBarButtonItem:self.navigationItem.rightBarButtonItem animated:YES]; | ||
| 199 | + }]; | ||
| 200 | + | ||
| 201 | + if (self.fileUrl) { | ||
| 202 | + self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:itemButton]; | ||
| 203 | + }else{ | ||
| 204 | + self.navigationItem.rightBarButtonItem = nil; | ||
| 205 | + } | ||
| 206 | + } | ||
| 207 | + | ||
| 208 | + #pragma mark - QLPreviewControllerDataSource | ||
| 209 | + - (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller{ | ||
| 210 | + NSInteger num = 0; | ||
| 211 | + if (self.fileUrl) { | ||
| 212 | + num = 1; | ||
| 213 | + } | ||
| 214 | + return num; | ||
| 215 | + } | ||
| 216 | + | ||
| 217 | + - (id <QLPreviewItem>)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index{ | ||
| 218 | + return [BasicPreviewItem itemWithUrl:self.fileUrl]; | ||
| 219 | + } | ||
| 220 | + | ||
| 221 | + #pragma mark UIWebViewDelegate | ||
| 222 | + - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{ | ||
| 223 | + NSLog(@"strLink=[%@]",request.URL.absoluteString); | ||
| 224 | + return YES; | ||
| 225 | + } | ||
| 226 | + - (void)webViewDidStartLoad:(UIWebView *)webView{ | ||
| 227 | + [_activityIndicator startAnimating]; | ||
| 228 | + } | ||
| 229 | + - (void)webViewDidFinishLoad:(UIWebView *)webView{ | ||
| 230 | + [_activityIndicator stopAnimating]; | ||
| 231 | + if ([self.curFile.fileType isEqualToString:@"plist"] | ||
| 232 | + || [self.curFile.fileType isEqualToString:@"txt"]){ | ||
| 233 | + [webView stringByEvaluatingJavaScriptFromString:@"document.body.style.zoom = 3.0;"]; | ||
| 234 | + }else if ([self.curFile.fileType isEqualToString:@"html"]){ | ||
| 235 | + [webView stringByEvaluatingJavaScriptFromString:@"document.body.style.zoom = 2.0;"]; | ||
| 236 | + } | ||
| 237 | + } | ||
| 238 | + | ||
| 239 | + - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{ | ||
| 240 | + if([error code] == NSURLErrorCancelled) | ||
| 241 | + return; | ||
| 242 | + else{ | ||
| 243 | + DebugLog(@"%@", error.description); | ||
| 244 | + [self showError:error]; | ||
| 245 | + } | ||
| 246 | + } | ||
| 247 | + @end | ||
| 248 | + | ||
| 249 | + | ||
| 250 | + | ||
| 251 | + | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments