GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Coding-iOS/Coding_iOS/Controllers/FileListViewController.m at master · kimoms/Coding-iOS Expand file tree/ Copy pathFileListViewController.mMore file actions executable file ·834 lines (767 loc) · 35.6 KB / Copy pathFileListViewController.mFile metadata and controlsexecutable file ·834 lines (767 loc) · 35.6 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 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 // // FileListViewController.m // Coding_iOS // // Created by Ease on 14/11/14. // Copyright (c) 2014年 Coding. All rights reserved. // #import "FileListViewController.h" #import "ODRefreshControl.h" #import "Coding_NetAPIManager.h" #import "FileListFolderCell.h" #import "FileListFileCell.h" #import "ProjectFiles.h" #import "BasicPreviewItem.h" #import "SettingTextViewController.h" #import "FolderToMoveViewController.h" #import "FileViewController.h" #import "EaseToolBar.h" #import "QBImagePickerController.h" #import "Helper.h" #import "FileListUploadCell.h" #import "Coding_FileManager.h" @interface FileListViewController () <SWTableViewCellDelegate, EaseToolBarDelegate, QBImagePickerControllerDelegate> @property (nonatomic, strong) UITableView *myTableView; @property (nonatomic, strong) ODRefreshControl *refreshControl; @property (strong, nonatomic) ProjectFiles *myFiles; @property (nonatomic, strong) EaseToolBar *myToolBar, *myEditToolBar; @property (strong, nonatomic) NSArray *uploadFiles; @end @implementation FileListViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.title = self.curFolder.name; _myFiles = [[ProjectFiles alloc] init]; // 添加myTableView _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 registerClass:[FileListFolderCell class] forCellReuseIdentifier:kCellIdentifier_FileListFolder]; [tableView registerClass:[FileListFileCell class] forCellReuseIdentifier:kCellIdentifier_FileListFile]; [tableView registerClass:[FileListUploadCell class] forCellReuseIdentifier:kCellIdentifier_FileListUpload]; [self.view addSubview:tableView]; [tableView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.view); }]; tableView.allowsMultipleSelectionDuringEditing = YES; tableView; }); _refreshControl = [[ODRefreshControl alloc] initInScrollView:self.myTableView]; [_refreshControl addTarget:self action:@selector(refreshRootFolders) forControlEvents:UIControlEventValueChanged]; if (!self.rootFolders) { self.rootFolders = [ProjectFolders emptyFolders]; } [self refresh]; __weak typeof(self) weakSelf = self; [[[[NSNotificationCenter defaultCenter] rac_addObserverForName:kNotificationUploadCompled object:nil] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSNotification *aNotification) { //{NSURLResponse: response, NSError: error, ProjectFile: data} NSDictionary* userInfo = [aNotification userInfo]; [weakSelf completionUploadWithResult:[userInfo objectForKey:@"data"] error:[userInfo objectForKey:@"error"]]; }]; } - (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; if (!_myTableView.isEditing) { [_myTableView reloadData]; } } - (void)changeEditState{ [self changeEditStateToEditing:!_myTableView.isEditing]; } - (void)changeEditStateToEditing:(BOOL)isEditing{ [_myTableView setEditing:isEditing animated:YES]; NSArray *rightBarButtonItems; if (isEditing) { UIBarButtonItem *item1 = [UIBarButtonItem itemWithBtnTitle:@"完成" target:self action:@selector(changeEditState)]; UIBarButtonItem *spaceItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]; spaceItem.width = 20; UIBarButtonItem *item2 = [UIBarButtonItem itemWithBtnTitle:@"反选" target:self action:@selector(reverseSelect)]; rightBarButtonItems = @[item1, spaceItem, item2]; }else{ UIBarButtonItem *item1 = [UIBarButtonItem itemWithBtnTitle:@"编辑" target:self action:@selector(changeEditState)]; rightBarButtonItems = @[item1]; } [self.navigationItem setRightBarButtonItems:rightBarButtonItems animated:YES]; [self configToolBar]; [self.myTableView performSelector:@selector(reloadData) withObject:nil afterDelay:0.3]; } - (void)reverseSelect{ if (_myTableView.isEditing) { NSArray *selectedIndexList = [_myTableView indexPathsForSelectedRows]; NSInteger startIndex = _curFolder.sub_folders.count + _uploadFiles.count; NSInteger endIndex = [self totalDataRow]; NSMutableArray *reverseIndexList = [[NSMutableArray alloc] init]; for (NSInteger index = startIndex; index < endIndex; index++) { NSIndexPath *curIndex = [NSIndexPath indexPathForRow:index inSection:0]; if (![selectedIndexList containsObject:curIndex]) { [reverseIndexList addObject:curIndex]; } } for (NSIndexPath *indexPath in selectedIndexList) { [_myTableView deselectRowAtIndexPath:indexPath animated:YES]; } for (NSIndexPath *indexPath in reverseIndexList) { [_myTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone]; } } } - (void)configuploadFiles{ self.uploadFiles = [Coding_FileManager uploadFilesInProject:self.curProject.id.stringValue andFolder:self.curFolder.file_id.stringValue]; if (!self.uploadFiles) { self.uploadFiles = [NSArray array]; } [self.myTableView reloadData]; } - (void)configToolBar{ //添加底部ToolBar if (!_myToolBar) { EaseToolBarItem *item1 = [EaseToolBarItem easeToolBarItemWithTitle:@" 新建文件夹" image:@"button_file_createFolder_enable" disableImage:@"button_file_createFolder_unable"]; EaseToolBarItem *item2 = [EaseToolBarItem easeToolBarItemWithTitle:@" 上传文件" image:@"button_file_upload_enable" disableImage:nil]; _myToolBar = [EaseToolBar easeToolBarWithItems:@[item1, item2]]; _myToolBar.delegate = self; [self.view addSubview:_myToolBar]; [_myToolBar mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.equalTo(self.view.mas_bottom); make.size.mas_equalTo(_myToolBar.frame.size); }]; } if (!_myEditToolBar) { EaseToolBarItem *item1 = [EaseToolBarItem easeToolBarItemWithTitle:@" 下载" image:@"button_file_download_enable" disableImage:@"button_file_createFolder_unable"]; EaseToolBarItem *item2 = [EaseToolBarItem easeToolBarItemWithTitle:@" 移动" image:@"button_file_move_enable" disableImage:nil]; EaseToolBarItem *item3 = [EaseToolBarItem easeToolBarItemWithTitle:@" 删除" image:@"button_file_denete_enable" disableImage:nil]; _myEditToolBar = [EaseToolBar easeToolBarWithItems:@[item1, item2, item3]]; _myEditToolBar.delegate = self; [self.view addSubview:_myEditToolBar]; [_myEditToolBar mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.equalTo(self.view.mas_bottom); make.size.mas_equalTo(_myToolBar.frame.size); }]; } if (_myTableView.isEditing) { _myToolBar.hidden = YES; _myEditToolBar.hidden = NO; }else{ _myToolBar.hidden = NO; _myEditToolBar.hidden = YES; EaseToolBarItem *item1 = [_myToolBar itemOfIndex:0]; item1.enabled = [self canCreatNewFolder]; EaseToolBarItem *item2 = [_myToolBar itemOfIndex:1]; item2.enabled = [self canUploadNewFile]; } UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0,CGRectGetHeight(_myToolBar.frame), 0.0); self.myTableView.contentInset = contentInsets; self.myTableView.scrollIndicatorInsets = contentInsets; } - (BOOL)canCreatNewFolder{ return (self.curFolder == nil || (self.curFolder.parent_id.intValue == 0 && ![_curFolder isDefaultFolder] && ![_curFolder isShareFolder])); } - (BOOL)canUploadNewFile{ return ![self.curFolder isShareFolder]; } - (void)refresh{ [self configuploadFiles]; if (![self.rootFolders isEmpty]) { [self configToolBar]; [self refreshFileList]; }else{ [self refreshRootFolders]; } } - (void)refreshRootFolders{ if (_rootFolders.isLoading) { return; } [self sendRequestRootFolders]; } - (void)sendRequestRootFolders{ if ([self totalDataRow] <= 0) { [self.view beginLoading]; } __weak typeof(self) weakSelf = self; [[Coding_NetAPIManager sharedManager] request_Folders:_rootFolders inProject:_curProject andBlock:^(id data, NSError *error) { if (data) { ProjectFolders *preRootFolders = weakSelf.rootFolders; weakSelf.rootFolders = data; ProjectFolder *curFolder = [weakSelf.rootFolders hasFolderWithId:weakSelf.curFolder.file_id]; if (curFolder) { weakSelf.curFolder = curFolder; weakSelf.title = curFolder.name; [weakSelf configuploadFiles]; [weakSelf configToolBar]; [weakSelf refreshFileList]; }else{ [weakSelf.refreshControl endRefreshing]; [weakSelf.view endLoading]; weakSelf.rootFolders = preRootFolders; [NSObject showHudTipStr:@"文件夹不存在"]; weakSelf.navigationItem.rightBarButtonItem = nil; [weakSelf.view configBlankPage:EaseBlankPageTypeFolderDleted hasData:([weakSelf totalDataRow] > 0) hasError:NO reloadButtonBlock:nil]; } }else{ [weakSelf.refreshControl endRefreshing]; [weakSelf.view endLoading]; [weakSelf.view configBlankPage:EaseBlankPageTypeFile hasData:([weakSelf totalDataRow] > 0) hasError:YES reloadButtonBlock:^(id sender) { [weakSelf refreshRootFolders]; }]; } }]; } - (void)refreshFileList{ if (_myFiles.isLoading) { return; } [self sendRequestFileList]; } - (void)sendRequestFileList{ if ([self totalDataRow] <= 0) { [self.view beginLoading]; } __weak typeof(self) weakSelf = self; weakSelf.myFiles.isLoading = YES; [[Coding_NetAPIManager sharedManager] request_FilesInFolder:_curFolder andBlock:^(id data, NSError *error) { weakSelf.myFiles.isLoading = NO; [weakSelf.refreshControl endRefreshing]; [weakSelf.view endLoading]; if (data) { weakSelf.myFiles = data; self.navigationItem.rightBarButtonItem = weakSelf.myFiles.list.count > 0? [UIBarButtonItem itemWithBtnTitle:@"编辑" target:self action:@selector(changeEditState)]: nil; [weakSelf.myTableView reloadData]; } [weakSelf.view configBlankPage:EaseBlankPageTypeFile hasData:([weakSelf totalDataRow] > 0) hasError:(error != nil) reloadButtonBlock:^(id sender) { [weakSelf refreshRootFolders]; }]; }]; } #pragma mark EaseToolBarDelegate - (void)easeToolBar:(EaseToolBar *)toolBar didClickedIndex:(NSInteger)index{ if (toolBar == _myToolBar) { switch (index) { case 0: [self creatFolderBtnClicked]; break; case 1: [self uploadFileBtnClicked]; break; default: break; } }else if (toolBar == _myEditToolBar){ switch (index) { case 0: [self downloadFilesBtnClicked]; break; case 1: [self moveFilesBtnClicked]; break; case 2: [self deleteFilesBtnClicked]; break; default: break; } } } - (void)creatFolderBtnClicked{ DebugLog(@"新建文件夹"); __weak typeof(self) weakSelf = self; [SettingTextViewController showSettingFolderNameVCFromVC:self withTitle:@"新建文件夹" textValue:nil type:SettingTypeNewFolderName doneBlock:^(NSString *textValue) { DebugLog(@"%@", textValue); [[Coding_NetAPIManager sharedManager] request_CreatFolder:textValue inFolder:weakSelf.curFolder inProject:weakSelf.curProject andBlock:^(id data, NSError *error) { if (data) { if (weakSelf.curFolder) { [weakSelf.curFolder.sub_folders insertObject:data atIndex:0]; }else{ [weakSelf.rootFolders.list insertObject:data atIndex:1]; } [weakSelf.myTableView reloadData]; [weakSelf.view configBlankPage:EaseBlankPageTypeFile hasData:([weakSelf totalDataRow] > 0) hasError:(error != nil) reloadButtonBlock:^(id sender) { [weakSelf refreshRootFolders]; }]; [NSObject showHudTipStr:@"创建文件夹成功"]; } }]; }]; } - (void)uploadFileBtnClicked{ DebugLog(@"上传文件"); // 相册 if (![Helper checkPhotoLibraryAuthorizationStatus]) { return; } QBImagePickerController *imagePickerController = [[QBImagePickerController alloc] init]; imagePickerController.filterType = QBImagePickerControllerFilterTypePhotos; imagePickerController.delegate = self; imagePickerController.allowsMultipleSelection = YES; imagePickerController.maximumNumberOfSelection = 6; UINavigationController *navigationController = [[BaseNavigationController alloc] initWithRootViewController:imagePickerController]; [self presentViewController:navigationController animated:YES completion:NULL]; } - (NSArray *)selectedFiles{ NSArray *selectedIndexPath = [_myTableView indexPathsForSelectedRows]; NSMutableArray *selectedFiles = [[NSMutableArray alloc] initWithCapacity:selectedIndexPath.count]; for (NSIndexPath *indexPath in selectedIndexPath) { if (indexPath.row >= _curFolder.sub_folders.count + _uploadFiles.count) { ProjectFile *file = [_myFiles.list objectAtIndex:(indexPath.row - _curFolder.sub_folders.count - _uploadFiles.count)]; [selectedFiles addObject:file]; } } return selectedFiles; } - (void)downloadFilesBtnClicked{ NSArray *selectedFiles = [self selectedFiles]; if (selectedFiles.count > 0) { NSInteger downloadedCount = 0, downloadingCount = 0, addDownloadCount = 0; Coding_FileManager *manager = [Coding_FileManager sharedManager]; for (ProjectFile *file in selectedFiles) { if ([file hasBeenDownload]) {//已下载 downloadedCount++; DebugLog(@"%@: 已在队列", file.name); }else if ([file cDownloadTask]) {//正在下载 downloadingCount++; DebugLog(@"%@: 已在队列", file.name); }else{ addDownloadCount++; [manager addDownloadTaskForObj:file completionHandler:nil]; } } if (addDownloadCount == 0) { NSString *tipStr = downloadingCount == 0? @"所选的文件都已经下载到本地了" : @"所选的文件都已经在下载队列中了"; [NSObject showHudTipStr:tipStr]; } [self changeEditStateToEditing:NO]; } } - (void)moveFilesBtnClicked{ NSArray *selectedFiles = [self selectedFiles]; if (selectedFiles.count > 0) { [self moveFiles:selectedFiles fromFolder:self.curFolder]; } } - (void)deleteFilesBtnClicked{ __weak typeof(self) weakSelf = self; NSArray *selectedFiles = [self selectedFiles]; if (selectedFiles.count > 0) { [[UIActionSheet bk_actionSheetCustomWithTitle:[NSString stringWithFormat:@"确认删除选定的 %lu 个文件?\n删除后将无法恢复!", (unsigned long)selectedFiles.count] buttonTitles:nil destructiveTitle:@"确认删除" cancelTitle:@"取消" andDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) { if (index == 0) { [weakSelf deleteFiles:selectedFiles]; [weakSelf changeEditStateToEditing:NO]; } }] showInView:self.view]; } } - (void)deleteFiles:(NSArray *)selectedFiles{ NSMutableArray *fileIdList = [[NSMutableArray alloc] initWithCapacity:selectedFiles.count]; for (ProjectFile *file in selectedFiles) { [fileIdList addObject:file.file_id]; [self deleteFile:file fromDisk:YES];//先要处理正在下载的和已下载的文件 } __weak typeof(self) weakSelf = self; [[Coding_NetAPIManager sharedManager] request_DeleteFiles:fileIdList inProject:self.curProject.id andBlock:^(id data, NSError *error) { if (data) { [weakSelf refreshRootFolders]; } }]; } #pragma mark QBImagePickerControllerDelegate - (void)qb_imagePickerController:(QBImagePickerController *)imagePickerController didSelectAssets:(NSArray *)assets{ NSMutableArray *needToUploads = [NSMutableArray arrayWithCapacity:assets.count]; for (ALAsset *assetItem in assets) { //保存到app内 NSString* originalFileName = [[assetItem defaultRepresentation] filename]; NSString *fileName = [NSString stringWithFormat:@"%@|||%@|||%@", self.curProject.id.stringValue, self.curFolder.file_id.stringValue, originalFileName]; if ([Coding_FileManager writeUploadDataWithName:fileName andAsset:assetItem]) { [needToUploads addObject:fileName]; }else{ [NSObject showHudTipStr:[NSString stringWithFormat:@"%@ 文件处理失败", originalFileName]]; } } for (NSString *fileName in needToUploads) { [self uploadFileWithFileName:fileName]; } [self.view configBlankPage:EaseBlankPageTypeFile hasData:([self totalDataRow] > 0) hasError:NO reloadButtonBlock:^(id sender) { [self refreshRootFolders]; }]; [self dismissViewControllerAnimated:YES completion:nil]; } - (void)qb_imagePickerControllerDidCancel:(QBImagePickerController *)imagePickerController{ [self dismissViewControllerAnimated:YES completion:nil]; } #pragma mark uploadTask - (void)uploadFileWithFileName:(NSString *)fileName{ Coding_FileManager *manager = [Coding_FileManager sharedManager]; [manager addUploadTaskWithFileName:fileName projectIsPublic:_curProject.is_public.boolValue]; [self configuploadFiles]; } - (void)removeUploadTaskWithFileName:(NSString *)fileName{ [Coding_FileManager cancelCUploadTaskForFile:fileName hasError:NO]; [self configuploadFiles]; } - (void)completionUploadWithResult:(id)responseObject error:(NSError *)error{ if (!responseObject || ![responseObject isKindOfClass:[ProjectFile class]]) { return; } ProjectFile *curFile = responseObject; if (curFile.parent_id.integerValue != self.curFolder.file_id.integerValue) { return; } NSRange range = [curFile.owner_preview rangeOfString:@"project/"]; if (curFile.owner_preview && range.location != NSNotFound) { NSString *project_id = [[[curFile.owner_preview substringFromIndex:(range.location+range.length)] componentsSeparatedByString:@"/"] firstObject]; if (project_id && project_id.integerValue != self.curProject.id.integerValue) { return; } } curFile.project_id = self.curProject.id; [self.myFiles.list insertObject:curFile atIndex:0]; self.curFolder.count = @(self.curFolder.count.integerValue +1); [self configuploadFiles]; [self.view configBlankPage:EaseBlankPageTypeFile hasData:([self totalDataRow] > 0) hasError:(error != nil) reloadButtonBlock:^(id sender) { [self refreshRootFolders]; }]; if (self.navigationItem.rightBarButtonItem == nil) { self.navigationItem.rightBarButtonItem = self.myFiles.list.count > 0? [UIBarButtonItem itemWithBtnTitle:@"编辑" target:self action:@selector(changeEditState)]: nil; } } #pragma mark Table M - (NSInteger)totalDataRow{ return (_uploadFiles.count + _curFolder.sub_folders.count + _myFiles.list.count); } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return [self totalDataRow]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ __weak typeof(self) weakSelf = self; if (indexPath.row < _uploadFiles.count) { FileListUploadCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_FileListUpload forIndexPath:indexPath]; cell.fileName = [self.uploadFiles objectAtIndex:indexPath.row]; cell.reUploadBlock = ^(NSString *fileName){ [weakSelf uploadFileWithFileName:fileName]; }; cell.cancelUploadBlock = ^(NSString *fileName){ [weakSelf removeUploadTaskWithFileName:fileName]; }; return cell; }else if (indexPath.row < _curFolder.sub_folders.count + _uploadFiles.count) { FileListFolderCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_FileListFolder forIndexPath:indexPath]; ProjectFolder *folder = [_curFolder.sub_folders objectAtIndex:indexPath.row - _uploadFiles.count]; cell.folder = folder; [cell setRightUtilityButtons:[self rightButtonsWithObj:folder] WithButtonWidth:[FileListFolderCell cellHeight]]; cell.delegate = self; [tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:kPaddingLeftWidth]; return cell; }else{ FileListFileCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_FileListFile forIndexPath:indexPath]; ProjectFile *file = [_myFiles.list objectAtIndex:(indexPath.row - _curFolder.sub_folders.count - _uploadFiles.count)]; cell.file = file; cell.showDiskFileBlock = ^(NSURL *fileUrl, ProjectFile *file){ [weakSelf goToFileVC:file]; }; [cell setRightUtilityButtons:[self rightButtonsWithObj:file] WithButtonWidth:[FileListFileCell cellHeight]]; cell.delegate = self; [tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:kPaddingLeftWidth]; return cell; } } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ CGFloat cellHeight = 0; if (indexPath.row < _uploadFiles.count) { cellHeight = [FileListUploadCell cellHeight]; }else if (indexPath.row < _curFolder.sub_folders.count + _uploadFiles.count) { cellHeight = [FileListFolderCell cellHeight]; }else{ cellHeight = [FileListFileCell cellHeight]; } return cellHeight; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ if (tableView.isEditing) { if (indexPath.row < _curFolder.sub_folders.count + _uploadFiles.count) { if (indexPath.row < _uploadFiles.count) { [NSObject showHudTipStr:@"正在上传的不能批处理"]; }else{ [NSObject showHudTipStr:@"文件夹不能批处理"]; } [tableView deselectRowAtIndexPath:indexPath animated:YES]; } }else{ [tableView deselectRowAtIndexPath:indexPath animated:YES]; if (indexPath.row < _uploadFiles.count) { }else if (indexPath.row < _curFolder.sub_folders.count) { ProjectFolder *clickedFolder = [_curFolder.sub_folders objectAtIndex:indexPath.row - _uploadFiles.count];; [self goToVCWithFolder:clickedFolder inProject:self.curProject]; }else{ ProjectFile *file = [_myFiles.list objectAtIndex:(indexPath.row - _curFolder.sub_folders.count - _uploadFiles.count)]; [self goToFileVC:file]; } } } #pragma mark Edit Table - (NSArray *)rightButtonsWithObj:(id)obj{ NSMutableArray *rightUtilityButtons = [NSMutableArray new]; if ([obj isKindOfClass:[ProjectFolder class]]) { ProjectFolder *folder = (ProjectFolder *)obj; if (![folder isDefaultFolder] && ![folder isShareFolder]) { if (folder.sub_folders.count <= 0) { [rightUtilityButtons sw_addUtilityButtonWithColor:kColorDDD icon:[UIImage imageNamed:@"icon_file_cell_move"]]; } [rightUtilityButtons sw_addUtilityButtonWithColor:[UIColor colorWithHexString:@"0xe6e6e6"] icon:[UIImage imageNamed:@"icon_file_cell_rename"]]; [rightUtilityButtons sw_addUtilityButtonWithColor:kColorBrandRed icon:[UIImage imageNamed:@"icon_file_cell_delete"]]; } }else{ [rightUtilityButtons sw_addUtilityButtonWithColor:kColorDDD icon:[UIImage imageNamed:@"icon_file_cell_move"]]; [rightUtilityButtons sw_addUtilityButtonWithColor:[UIColor colorWithHexString:@"0xe6e6e6"] icon:[UIImage imageNamed:@"icon_file_cell_rename"]]; [rightUtilityButtons sw_addUtilityButtonWithColor:kColorBrandRed icon:[UIImage imageNamed:@"icon_file_cell_delete"]]; } return rightUtilityButtons; } - (BOOL)swipeableTableViewCellShouldHideUtilityButtonsOnSwipe:(SWTableViewCell *)cell{ return YES; } - (BOOL)swipeableTableViewCell:(SWTableViewCell *)cell canSwipeToState:(SWCellState)state{ if (state == kCellStateRight) { NSIndexPath *indexPath = [self.myTableView indexPathForCell:cell]; if (indexPath.row < _uploadFiles.count) { return NO; }else if (indexPath.row >= _curFolder.sub_folders.count + _uploadFiles.count) { ProjectFile *file = [_myFiles.list objectAtIndex:(indexPath.row - _curFolder.sub_folders.count - _uploadFiles.count)]; Coding_DownloadTask *cDownloadTask = file.cDownloadTask; if (cDownloadTask && cDownloadTask.task && cDownloadTask.task.state == NSURLSessionTaskStateRunning) { return NO; } } } return YES; } - (void)swipeableTableViewCell:(SWTableViewCell *)cell didTriggerRightUtilityButtonWithIndex:(NSInteger)index { [cell hideUtilityButtonsAnimated:YES]; NSIndexPath *indexPath = [self.myTableView indexPathForCell:cell]; if (indexPath.row < _curFolder.sub_folders.count && indexPath.row >= _uploadFiles.count) { ProjectFolder *folder = [_curFolder.sub_folders objectAtIndex:indexPath.row - _uploadFiles.count]; NSInteger buttonCount = cell.rightUtilityButtons.count; if (index == buttonCount - 3) {//移动 [self moveFolder:folder fromFolder:self.curFolder]; }else if (index == buttonCount - 2) {//重命名 [self renameFolder:folder]; }else{//删除 __weak typeof(self) weakSelf = self; UIActionSheet *actionSheet = [UIActionSheet bk_actionSheetCustomWithTitle:[NSString stringWithFormat:@"确定要删除文件夹:%@?",folder.name] buttonTitles:nil destructiveTitle:@"确认删除" cancelTitle:@"取消" andDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) { if (index == 0) { [weakSelf deleteFolder:folder]; } }]; [actionSheet showInView:self.view]; } }else{ ProjectFile *file = [_myFiles.list objectAtIndex:(indexPath.row - _curFolder.sub_folders.count - _uploadFiles.count)]; if (index == 0) { [self moveFiles:@[file] fromFolder:self.curFolder]; }else if (index == 1){ [self renameFile:file]; }else{ [self deleteFile:file]; } } } - (void)deleteFolder:(ProjectFolder *)folder{ __weak typeof(self) weakSelf = self; [[Coding_NetAPIManager sharedManager] request_DeleteFolder:folder andBlock:^(id data, NSError *error) { if (data) { ProjectFolder *originalFolder = (ProjectFolder *)data; DebugLog(@"删除文件夹成功:%@", originalFolder.name); [weakSelf.curFolder.sub_folders removeObject:originalFolder]; weakSelf.curFolder.count = [NSNumber numberWithInt:weakSelf.curFolder.count.intValue-1]; [weakSelf.myTableView reloadData]; [weakSelf.view configBlankPage:EaseBlankPageTypeFile hasData:([weakSelf totalDataRow] > 0) hasError:(error != nil) reloadButtonBlock:^(id sender) { [weakSelf refreshRootFolders]; }]; } }]; } - (void)renameFolder:(ProjectFolder *)folder{ __weak typeof(self) weakSelf = self; @weakify(folder); [SettingTextViewController showSettingFolderNameVCFromVC:nil withTitle:@"重命名文件夹" textValue:folder.name type:SettingTypeFolderName doneBlock:^(NSString *textValue) { @strongify(folder); folder.next_name = textValue; [[Coding_NetAPIManager sharedManager] request_RenameFolder:folder andBlock:^(id data, NSError *error) { if (data) { ProjectFolder *originalFolder = (ProjectFolder *)data; originalFolder.name = originalFolder.next_name; [NSObject showHudTipStr:[NSString stringWithFormat:@"成功重命名为:%@", originalFolder.name]]; [weakSelf.myTableView reloadData]; } }]; }]; } - (void)renameFile:(ProjectFile *)file{ __weak typeof(self) weakSelf = self; @weakify(file); NSString *nameValue = file.name; NSRange rangeOfType = [nameValue rangeOfString:[NSString stringWithFormat:@".%@", file.fileType] options:NSBackwardsSearch]; if (rangeOfType.location != NSNotFound) { nameValue = [nameValue stringByReplacingCharactersInRange:rangeOfType withString:@""]; } [SettingTextViewController showSettingFolderNameVCFromVC:nil withTitle:@"重命名文件" textValue:nameValue type:SettingTypeFolderName doneBlock:^(NSString *textValue) { textValue = [NSString stringWithFormat:@"%@.%@", textValue, file.fileType]; @strongify(file); [[Coding_NetAPIManager sharedManager] request_RenameFile:file withName:textValue andBlock:^(id data, NSError *error) { if (data) { file.name = textValue; [NSObject showHudTipStr:[NSString stringWithFormat:@"成功重命名为:%@", file.name]]; [weakSelf.myTableView reloadData]; } }]; }]; } - (void)deleteFile:(ProjectFile *)file{ __weak typeof(self) weakSelf = self; __weak typeof(file) weakFile = file; NSURL *fileUrl = [file hasBeenDownload]; Coding_DownloadTask *cDownloadTask = [file cDownloadTask]; UIActionSheet *actionSheet; if (fileUrl) { actionSheet = [UIActionSheet bk_actionSheetCustomWithTitle:@"只是删除本地文件还是连同服务器文件一起删除?" buttonTitles:@[@"仅删除本地文件"] destructiveTitle:@"一起删除" cancelTitle:@"取消" andDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) { switch (index) { case 0: [weakSelf deleteFile:weakFile fromDisk:YES]; break; case 1: [weakSelf deleteFile:weakFile fromDisk:NO]; break; default: break; } }]; }else if (cDownloadTask){ actionSheet = [UIActionSheet bk_actionSheetCustomWithTitle:@"确定将服务器上的该文件删除?" buttonTitles:@[@"只是取消下载"] destructiveTitle:@"确认删除" cancelTitle:@"取消" andDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) { switch (index) { case 0: [weakSelf deleteFile:weakFile fromDisk:YES]; break; case 1: [weakSelf deleteFile:weakFile fromDisk:NO]; break; default: break; } }]; }else{ actionSheet = [UIActionSheet bk_actionSheetCustomWithTitle:@"确定将服务器上的该文件删除?" buttonTitles:nil destructiveTitle:@"确认删除" cancelTitle:@"取消" andDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) { if (index == 0) { [weakSelf deleteFile:weakFile fromDisk:NO]; } }]; } [actionSheet showInView:self.view]; } - (void)deleteFile:(ProjectFile *)file fromDisk:(BOOL)fromDisk{ // 取消当前的下载任务 Coding_DownloadTask *cDownloadTask = [file cDownloadTask]; if (cDownloadTask) { [Coding_FileManager cancelCDownloadTaskForKey:file.storage_key]; } // 删除本地文件 NSURL *fileUrl = [file hasBeenDownload]; NSString *filePath = fileUrl.path; NSFileManager *fm = [NSFileManager defaultManager]; if ([fm fileExistsAtPath:filePath]) { NSError *fileError; [fm removeItemAtPath:filePath error:&fileError]; if (fileError) { [NSObject showError:fileError]; } } [self.myTableView performSelector:@selector(reloadData) withObject:nil afterDelay:0.1]; // 删除服务器文件 if (!fromDisk) { __weak typeof(self) weakSelf = self; [[Coding_NetAPIManager sharedManager] request_DeleteFiles:@[file.file_id] inProject:self.curProject.id andBlock:^(id data, NSError *error) { if (data) { [weakSelf refreshRootFolders]; } }]; } } - (void)moveFiles:(NSArray *)files fromFolder:(ProjectFolder *)folder{ NSMutableArray *fileIdList = [[NSMutableArray alloc] initWithCapacity:files.count]; for (ProjectFile *file in files) { [fileIdList addObject:file.file_id]; } __weak typeof(self) weakSelf = self; FolderToMoveViewController *vc = [[FolderToMoveViewController alloc] init]; vc.fromFolder = folder; vc.toMovedIdList = fileIdList; vc.curProject = self.curProject; vc.rootFolders = self.rootFolders; vc.curFolder = nil; vc.moveToFolderBlock = ^(ProjectFolder *curFolder, NSArray *toMovedIdList){ [weakSelf changeEditStateToEditing:NO]; [[Coding_NetAPIManager sharedManager] request_MoveFiles:toMovedIdList toFolder:curFolder andBlock:^(id data, NSError *error) { if (data) { [weakSelf refreshRootFolders]; } }]; }; UINavigationController *nav = [[BaseNavigationController alloc] initWithRootViewController:vc]; [self presentViewController:nav animated:YES completion:nil]; } - (void)moveFolder:(ProjectFolder *)movedFolder fromFolder:(ProjectFolder *)folder{ __weak typeof(self) weakSelf = self; FolderToMoveViewController *vc = [[FolderToMoveViewController alloc] init]; vc.isMoveFolder = YES; vc.fromFolder = folder; vc.toMovedIdList = @[movedFolder.file_id]; vc.curProject = self.curProject; vc.rootFolders = self.rootFolders; vc.curFolder = nil; vc.moveToFolderBlock = ^(ProjectFolder *curFolder, NSArray *toMovedIdList){ [weakSelf changeEditStateToEditing:NO]; [[Coding_NetAPIManager sharedManager] request_MoveFolder:toMovedIdList.firstObject toFolder:curFolder inProject:weakSelf.curProject andBlock:^(id data, NSError *error) { if (data) { [weakSelf refreshRootFolders]; } }]; }; UINavigationController *nav = [[BaseNavigationController alloc] initWithRootViewController:vc]; [self presentViewController:nav animated:YES completion:nil]; } #pragma mark toVC - (void)goToVCWithFolder:(ProjectFolder *)folder inProject:(Project *)project{ FileListViewController *vc = [[FileListViewController alloc] init]; vc.curFolder = folder; vc.curProject = project; vc.rootFolders = self.rootFolders; [self.navigationController pushViewController:vc animated:YES]; } - (void)goToFileVC:(ProjectFile *)file{ FileViewController *vc = [FileViewController vcWithFile:file andVersion:nil]; @weakify(self); vc.fileHasBeenDeletedBlock = ^(){ @strongify(self); [self refreshFileList]; }; vc.fileHasChangedBlock = ^(){ @strongify(self); [self refreshFileList]; }; [self.navigationController pushViewController:vc animated:YES]; } - (void)dealloc { _myTableView.delegate = nil; _myTableView.dataSource = nil; } @end |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |