CSFirstPageController.m 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141
  1. //
  2. // CSFirstPageController.m
  3. // zhuxun
  4. //
  5. // Created by winsoft on 17/6/15.
  6. //
  7. //
  8. #import <Bugly/Bugly.h>
  9. #import "CSAlertView.h"
  10. #import "CSFirstPageController.h"
  11. //#import "NewMessageTransController.h"
  12. #import "IWNavigationController.h"
  13. #import "CSTabBarController.h"
  14. #import "CSRouterSelectController.h"
  15. #import "HttpRequest.h"
  16. #import <MJExtension/MJExtension.h>
  17. #import "UIBarButtonItem+Addition.h"
  18. #import "UIActionSheet+Blocks.h"
  19. #import "UIAlertView+Blocks.h"
  20. #import "CloudStorageDownloadCenter.h"
  21. #import "CSFileCell.h"
  22. #import "CSFileExtensionViewForCell.h"
  23. #import "CloudStorageBar.h"
  24. #import "CloudStorageTableView.h"
  25. #import "CSFileTypeClassView.h"
  26. #import "CSFileFrameModel.h"
  27. #import "CloudStorageDB.h"
  28. #define TabBarHeight ((self.hidesBottomBarWhenPushed == 0) ? (self.tabBarController.tabBar.frame.size.height) : 0)
  29. //剥离ui/控制器可以复用.
  30. @interface CSFirstPageController ()<UITableViewDelegate, UITableViewDataSource, CSSearchBarDelegate>
  31. /**
  32. * 来源,可提供的网盘文件操作不同
  33. */
  34. @property (nonatomic , assign) CSFileSourceType csFileSourceType;
  35. @property (nonatomic , copy) NSString *pid;
  36. @property (nonatomic , copy) NSString *shareID;
  37. #warning 2017-07-17
  38. @property (nonatomic , weak) CloudStorageTableView *mainTableView;
  39. @property (nonatomic , weak) CSFileExtensionViewForCell *csFilesExensionView;
  40. @property (nonatomic , weak) CSFileTypeClassView *csFileTypeClassView;
  41. /**
  42. * 根据是否searchmodel 选择normal还是search array
  43. */
  44. @property (nonatomic , strong) NSMutableArray *fileModelArray;
  45. @property (nonatomic , strong) NSMutableArray *normalFilesArray;
  46. @property (nonatomic , strong) NSMutableArray *searchResultArray;
  47. @property (nonatomic , assign) BOOL searchModel;
  48. /**
  49. * 多选操作.
  50. */
  51. @property (nonatomic , strong) NSMutableArray *muilterOpFilesArray;
  52. @property (nonatomic , strong) CSFileModel *father_csFileModel;
  53. @end
  54. @implementation CSFirstPageController
  55. - (NSMutableArray *)fileModelArray
  56. {
  57. if (self.searchModel) {
  58. return self.searchResultArray;
  59. }else return self.normalFilesArray;
  60. }
  61. - (NSMutableArray *)normalFilesArray
  62. {
  63. if (!_normalFilesArray) {
  64. _normalFilesArray = [NSMutableArray array];
  65. }
  66. return _normalFilesArray;
  67. }
  68. - (NSMutableArray *)searchResultArray
  69. {
  70. if (!_searchResultArray) {
  71. _searchResultArray = [NSMutableArray array];
  72. }
  73. return _searchResultArray;
  74. }
  75. - (NSMutableArray *)muilterOpFilesArray
  76. {
  77. if (!_muilterOpFilesArray) {
  78. _muilterOpFilesArray = [NSMutableArray array];
  79. }
  80. return _muilterOpFilesArray;
  81. }
  82. //首次启动使用.
  83. + (CSFirstPageController *)csFirstPageControllerWithCSFileSourceType:(CSFileSourceType)csFileSourceType pid:(NSString *)pid shareId:(NSString *)shareId
  84. {
  85. CSFirstPageController *csFirstPageController = [[CSFirstPageController alloc]initCSFirstPageControllerWithCSFileSourceType:csFileSourceType pid:pid shareId:shareId];
  86. return csFirstPageController;
  87. }
  88. - (instancetype)initCSFirstPageControllerWithCSFileSourceType:(CSFileSourceType)csFileSourceType pid:(NSString *)pid shareId:(NSString *)shareId
  89. {
  90. if (self = [super init]) {
  91. self.csFileSourceType = csFileSourceType;
  92. _pid = pid;
  93. _shareID = shareId;
  94. if (csFileSourceType == CSFileSourceTypeSelf) {
  95. self.title = @"我的网盘";
  96. }else self.title = @"分享";
  97. self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(outCloudStorage) icon:@"returnBackArrow" highlightedIcon:nil title:nil iconSize:CGSizeMake(20, 20) fontSize:14 titleColor:[UIColor whiteColor]];
  98. }
  99. return self;
  100. }
  101. - (void)viewWillAppear:(BOOL)animated
  102. {
  103. [super viewWillAppear:animated];
  104. if (self.searchModel) {
  105. CGPoint point = CGPointMake(0, STATUSBAR_HEIGHT);
  106. // self.tabBarController.tabBar.isHidden
  107. __block CGRect adjusetedFrame = CGRectMake(point.x, point.y, SCREEN_WIDTH, SCREEN_HEIGHT - NavBarHeight + STATUSBAR_HEIGHT - TabBarHeight);
  108. [self.navigationController setNavigationBarHidden:YES animated:YES];
  109. [[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
  110. self.mainTableView.frame = adjusetedFrame;
  111. }else{
  112. __block CGRect origionFrame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - STATUSBAR_HEIGHT - NavBarHeight - TabBarHeight);
  113. [self.navigationController setNavigationBarHidden:NO animated:YES];
  114. self.mainTableView.frame = origionFrame;
  115. }
  116. }
  117. - (void)viewDidLoad {
  118. [super viewDidLoad];
  119. if([self respondsToSelector:@selector(setEdgesForExtendedLayout:)])
  120. {
  121. self.edgesForExtendedLayout = UIRectEdgeNone;
  122. }
  123. UIBarButtonItem *muiltSelectItem = [UIBarButtonItem itemWithTarget:self action:@selector(moreOperate) icon:@"navbar_muiltSel" highlightedIcon:nil title:nil iconSize:CGSizeMake(20, 20) fontSize:14 titleColor:[UIColor whiteColor]];
  124. UIBarButtonItem *fileClassItem = [UIBarButtonItem itemWithTarget:self action:@selector(classFile) icon:nil highlightedIcon:nil title:@"分类" iconSize:CGSizeZero fontSize:14 titleColor:[UIColor whiteColor]];
  125. if ([self.pid isEqualToString:@"0"] && self.csFileSourceType == CSFileSourceTypeSelf) {
  126. //self.navigationItem.rightBarButtonItems = @[muiltSelectItem, fileClassItem];
  127. self.navigationItem.leftBarButtonItem = fileClassItem;
  128. self.navigationItem.rightBarButtonItem = muiltSelectItem;
  129. }else self.navigationItem.rightBarButtonItems = @[muiltSelectItem];
  130. [self initSubViews];
  131. if (self.pid) {
  132. [self getTopFilesLists];
  133. }
  134. if (self.shareID) {
  135. [self getAllShareFiles];
  136. }
  137. }
  138. - (void)outCloudStorage
  139. {
  140. if (self.tabBarController) {
  141. [self.tabBarController dismissViewControllerAnimated:YES completion:nil];
  142. }else [self.navigationController dismissViewControllerAnimated:YES completion:nil];
  143. }
  144. - (void)moreOperate
  145. {
  146. if (self.csFileTypeClassView) {
  147. [self.csFileTypeClassView removeFromSuperview];
  148. self.csFileTypeClassView = nil;
  149. }
  150. self.mainTableView.allowsMultipleSelection = !self.mainTableView.allowsMultipleSelection;
  151. //置空.
  152. for (CSFileFrameModel *fileFrameModel in self.fileModelArray) {
  153. fileFrameModel.isFileExtensionOP = NO;
  154. fileFrameModel.isSelected = NO;
  155. }
  156. [self.muilterOpFilesArray removeAllObjects];
  157. [self.mainTableView reloadData];
  158. __weak typeof(self)weakSelf = self;
  159. __weak typeof(self.mainTableView)weakTableView = self.mainTableView;
  160. __weak typeof(self.view)weakView = self.view;
  161. if (self.mainTableView.allowsMultipleSelection) {
  162. CSFileExtensionViewForCell *extensionView = nil;
  163. if (self.csFileSourceType == CSFileSourceTypeSelf) {
  164. extensionView = [[CSFileExtensionViewForCell alloc]initWithItmes:@[@{@"icon":@"file_down_narmal",@"title":@"下载",@"opType":@(ExtensionOPDownLoad)},@{@"icon":@"file_share_normal",@"title":@"分享",@"opType":@(ExtensionOPShare)},@{@"icon":@"file_delete_normal",@"title":@"删除",@"opType":@(ExtensionOPDelete)},@{@"icon":@"file_move_normal",@"title":@"迁移",@"opType":@(ExtensionOPEdit)}]];
  165. }else{
  166. extensionView = [[CSFileExtensionViewForCell alloc]initWithItmes:@[@{@"icon":@"file_down_narmal",@"title":@"下载",@"opType":@(ExtensionOPDownLoad)}]];
  167. }
  168. extensionView.extensionOpBlock = ^(ExtensionOP extensionOP, CSFileFrameModel *csFileFrameModel){
  169. switch (extensionOP) {
  170. case ExtensionOPDelete:
  171. [weakSelf fileDeletesWithFileFrameModels:weakSelf.muilterOpFilesArray];
  172. break;
  173. case ExtensionOPEdit:
  174. //yidong 文件夹;
  175. [weakSelf moveCSFilesWithFileModels:weakSelf.muilterOpFilesArray];
  176. break;
  177. case ExtensionOPShare:
  178. //分享 文件夹;
  179. [weakSelf shareFilesToUserOrGroups:weakSelf.muilterOpFilesArray];
  180. break;
  181. case ExtensionOPDownLoad:
  182. //2017-07-17 待对多文件夹选择进行合并请求
  183. [weakSelf downloadFileWithFileModels:weakSelf.muilterOpFilesArray];
  184. [Utils showSuccess:@"已加入下载队列" toView:weakView finish:nil];
  185. break;
  186. default:
  187. break;
  188. }
  189. };
  190. extensionView.disable = YES;
  191. extensionView.frame = CGRectMake(0, self.view.frame.size.height - FileExtensionViewH, SCREEN_WIDTH, FileExtensionViewH);
  192. [self.view addSubview:extensionView];
  193. self.csFilesExensionView = extensionView;
  194. }else{
  195. [self.csFilesExensionView removeFromSuperview];
  196. self.csFilesExensionView = nil;
  197. }
  198. //调整tableview.frame
  199. self.mainTableView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - NavBarHeight - STATUSBAR_HEIGHT -(self.hidesBottomBarWhenPushed?0:self.tabBarController.tabBar.frame.size.height) -(self.csFilesExensionView?self.csFilesExensionView.frame.size.height:0));
  200. }
  201. - (void)classFile
  202. {
  203. __weak typeof(self)weakself = self;
  204. if (!self.csFileTypeClassView) {
  205. CSFileTypeClassView *csFileTypeClassView = [[CSFileTypeClassView alloc]init];
  206. csFileTypeClassView.utilityOperateBlock = ^(CSFileType csFileType){
  207. [weakself classFileWithFileType:csFileType];
  208. //hidden
  209. [weakself classFile];
  210. };
  211. [self.view addSubview:csFileTypeClassView];
  212. [UIView transitionWithView:csFileTypeClassView
  213. duration:1
  214. options:UIViewAnimationOptionShowHideTransitionViews //any animation
  215. animations:^ { }
  216. completion:nil];
  217. [self.view addSubview:csFileTypeClassView];
  218. // [self.view addSubview:csFileTypeClassView];
  219. csFileTypeClassView.frame = CGRectMake(0, 0, self.view.frame.size.width, CSFileTypeClassViewH);
  220. self.csFileTypeClassView = csFileTypeClassView;
  221. }else{
  222. [self.csFileTypeClassView removeFromSuperview];
  223. self.csFileTypeClassView = nil;
  224. }
  225. }
  226. - (void)initSubViews
  227. {
  228. CloudStorageTableView *mainTableView = [[CloudStorageTableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - NavBarHeight - STATUSBAR_HEIGHT - TabBarHeight) style:UITableViewStylePlain] ;
  229. mainTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  230. mainTableView.delegate = self;
  231. mainTableView.dataSource = self;
  232. mainTableView.tableFooterView = [[UIView alloc]init];
  233. mainTableView.tableFooterView.backgroundColor = [UIColor clearColor];
  234. [self.view addSubview:mainTableView];
  235. self.mainTableView = mainTableView;
  236. if (self.csFileSourceType == CSFileSourceTypeSelf) {
  237. __weak typeof(self)weakSelf = self;
  238. CloudStorageBar *cloudStorageBar = [CloudStorageBar new];
  239. cloudStorageBar.delegate = self;
  240. cloudStorageBar.barSortBlock = ^(SortType sortType){
  241. [weakSelf sortFilesWithSortType:sortType];
  242. };
  243. cloudStorageBar.barNewFolderBlock = ^(){
  244. [weakSelf createNewFileFolder];
  245. };
  246. cloudStorageBar.frame = CGRectMake(0, 0, self.view.frame.size.width, CloudStorageBarHeight);
  247. mainTableView.tableHeaderView = cloudStorageBar;
  248. __weak typeof(cloudStorageBar)weakCSBar = cloudStorageBar;
  249. mainTableView.gestureResponseBlock = ^(){
  250. //退出搜索
  251. [weakCSBar giveUpSearch];
  252. //退出筛选
  253. if (weakSelf.csFileTypeClassView) {
  254. [weakSelf classFile];
  255. }
  256. };
  257. }
  258. }
  259. #pragma mark --
  260. #pragma mark -- tableViewDatasource
  261. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  262. {
  263. return 1;
  264. }
  265. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  266. {
  267. return self.fileModelArray.count;
  268. }
  269. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  270. {
  271. CSFileCell *csFileCell = nil;
  272. if (self.csFileSourceType == CSFileSourceTypeSelf) {
  273. csFileCell = [CSFileCell fileCellWithTableView:tableView indexPath:indexPath identifier:CSFileCellIdentifier opItems:@[@{@"icon":@"file_down_narmal",@"title":@"下载",@"opType":@(ExtensionOPDownLoad)},@{@"icon":@"file_share_normal",@"title":@"分享",@"opType":@(ExtensionOPShare)},@{@"icon":@"file_delete_normal",@"title":@"删除",@"opType":@(ExtensionOPDelete)},@{@"icon":@"file_down_rename_normal",@"title":@"重命名",@"opType":@(ExtensionOPEdit)}]];
  274. }else
  275. {
  276. csFileCell = [CSFileCell fileCellWithTableView:tableView indexPath:indexPath identifier:CSFileCellIdentifier opItems:@[@{@"icon":@"file_down_narmal",@"title":@"下载",@"opType":@(ExtensionOPDownLoad)}]];
  277. }
  278. csFileCell.allowsMultipleSelection = tableView.allowsMultipleSelection;
  279. csFileCell.csFileFrameModel = self.fileModelArray[indexPath.row];
  280. csFileCell.indexPath = indexPath;
  281. __weak typeof(self.mainTableView)weakTableView = self.mainTableView;
  282. __weak typeof(self.view)weakView = self.view;
  283. __weak typeof(self)weakself = self;
  284. csFileCell.extensionSwitchBlock = ^(CSFileFrameModel *csFileFrameModel){
  285. NSInteger index = [weakself.fileModelArray indexOfObject:csFileFrameModel];
  286. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:index inSection:0];
  287. csFileFrameModel.isFileExtensionOP = !csFileFrameModel.isFileExtensionOP;
  288. [weakTableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
  289. [weakTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionNone animated:YES];
  290. };
  291. csFileCell.extensionOpBlock = ^(ExtensionOP extensionOP, CSFileFrameModel *csFileFrameModel){
  292. switch (extensionOP) {
  293. case ExtensionOPDelete:
  294. [weakself fileDeletesWithFileFrameModels:@[csFileFrameModel]];
  295. break;
  296. case ExtensionOPEdit:
  297. [weakself renameFilesWithFileFrameModel:csFileFrameModel indexPath:indexPath];
  298. break;
  299. case ExtensionOPShare:
  300. //yidong 文件夹;
  301. [weakself shareFilesToUserOrGroups:@[csFileFrameModel]];
  302. break;
  303. case ExtensionOPDownLoad:
  304. //download 文件;
  305. [weakself downloadFileWithFileModels:@[csFileFrameModel]];
  306. [Utils showSuccess:@"已加入下载队列" toView:weakView finish:nil];
  307. break;
  308. default:
  309. break;
  310. }
  311. };
  312. return csFileCell;
  313. }
  314. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  315. {
  316. CSFileFrameModel *csFileFrameModel = self.fileModelArray[indexPath.row];
  317. return csFileFrameModel.cellHeight;
  318. }
  319. #pragma mark --
  320. #pragma mark -- tableViewDelegate
  321. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  322. {
  323. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  324. CSFileFrameModel *csFileFrameModel = self.fileModelArray[indexPath.row];
  325. if (tableView.allowsMultipleSelection) {
  326. csFileFrameModel.isSelected = !csFileFrameModel.isSelected;
  327. if (csFileFrameModel.isSelected) {
  328. [self.muilterOpFilesArray addObject:csFileFrameModel];
  329. }else [self.muilterOpFilesArray removeObject:csFileFrameModel];
  330. if (self.muilterOpFilesArray.count) {
  331. self.csFilesExensionView.disable = NO;
  332. }else self.csFilesExensionView.disable = YES;
  333. [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
  334. }else{
  335. //
  336. CSFileModel *csFileModel = csFileFrameModel.fileModel;
  337. if (csFileModel.isdir) {
  338. //文件夹
  339. CSFirstPageController *csPage = [CSFirstPageController new];
  340. csPage.title = csFileModel.name;
  341. csPage.pid = csFileModel.sid;
  342. csPage.csFileSourceType = self.csFileSourceType;
  343. csPage.father_csFileModel = csFileModel;
  344. // __block CGRect origionFrame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - STATUSBAR_HEIGHT - NavBarHeight);
  345. //
  346. // [self.navigationController setNavigationBarHidden:NO animated:NO];
  347. //
  348. // self.mainTableView.frame = origionFrame;
  349. [self.navigationController pushViewController:csPage animated:YES];
  350. }
  351. }
  352. }
  353. #pragma mark --
  354. #pragma mark -- CSBarDelegate
  355. - (void)searchBarStartSearch:(UISearchBar *)searchBar withSearchContent:(NSString *)searchContent
  356. {
  357. [self searchFilesWithContent:searchContent];
  358. }
  359. - (void)searchBarPrepareToSearch
  360. {
  361. self.searchModel = YES;
  362. [self.mainTableView reloadData];
  363. CGPoint point = CGPointMake(0, STATUSBAR_HEIGHT);
  364. __block CGRect adjusetedFrame = CGRectMake(point.x, point.y, SCREEN_WIDTH, SCREEN_HEIGHT - NavBarHeight - TabBarHeight + STATUSBAR_HEIGHT);
  365. [self.navigationController setNavigationBarHidden:YES animated:YES];
  366. [[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
  367. self.mainTableView.frame = adjusetedFrame;
  368. }
  369. - (void)searchBarCancerSearch
  370. {
  371. self.searchModel = NO;
  372. [self.mainTableView reloadData];
  373. __block CGRect origionFrame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - STATUSBAR_HEIGHT - NavBarHeight - TabBarHeight);
  374. [self.navigationController setNavigationBarHidden:NO animated:YES];
  375. self.mainTableView.frame = origionFrame;
  376. }
  377. #pragma mark --
  378. #pragma mark -- fileOp汇总
  379. - (void)fileDeletesWithFileFrameModels:(NSArray *)fileFrameModels
  380. {
  381. NSMutableArray *fileIds = [NSMutableArray array];
  382. NSMutableArray *indexArray = [NSMutableArray array];
  383. for (CSFileFrameModel *csFileFrameModel in fileFrameModels) {
  384. [fileIds addObject:csFileFrameModel.fileModel.sid];
  385. NSInteger index = [self.fileModelArray indexOfObject:csFileFrameModel];
  386. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:index inSection:0];
  387. [indexArray addObject:indexPath];
  388. }
  389. UIActionSheet *sheet = [UIActionSheet actionSheetWithTitle:@"请选择删除方式" cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@[@"彻底删除",@"移到垃圾桶"] completionBlock:^(UIActionSheet *actionSheet, NSInteger selectedButtonIndex) {
  390. [Utils showWaitingToView:self.mainTableView];
  391. __weak typeof(self.mainTableView)weakTableView = self.mainTableView;
  392. __weak typeof(self.csFilesExensionView)weakExtensionView = self.csFilesExensionView;
  393. __weak typeof(self)weakself = self;
  394. [[HttpRequest sharedManager]cloudStorageFileDeleteWithItemIDs:fileIds deleteLevel:selectedButtonIndex complete:^(BOOL success, id data, NSError *error) {
  395. [Utils HiddenWaitingToView:weakTableView];
  396. if (success && data) {
  397. [Utils showSuccess:@"删除成功" toView:weakTableView finish:nil];
  398. [weakself.fileModelArray removeObjectsInArray:fileFrameModels];//删除数据源 内对于的对象
  399. [weakTableView deleteRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationBottom];
  400. weakExtensionView.disable = YES;
  401. //[weakTableView beginUpdates];
  402. }else{
  403. [Utils showError:@"删除失败" ToView:weakTableView];
  404. }
  405. }];
  406. } cancelBlock:^{
  407. }];
  408. [sheet showInView:self.mainTableView];
  409. }
  410. - (void)getTopFilesLists
  411. {
  412. [self getFileListWithPid:self.pid searchKey:nil classExt:nil];
  413. }
  414. - (void)getAllShareFiles
  415. {
  416. __weak typeof(self)weakself = self;
  417. __weak typeof(self.mainTableView)weakTableView = self.mainTableView;
  418. [[HttpRequest sharedManager]cloudStorageGetShareFiles:self.shareID complete:^(BOOL success, id data, NSError *error) {
  419. if (success && data) {
  420. NSArray *fileDataModel = [CSFileModel mj_objectArrayWithKeyValuesArray:data[@"data"]];
  421. for (CSFileModel *fileModel in fileDataModel) {
  422. if (fileModel.isdir) {
  423. fileModel.serverFullPath = self.father_csFileModel?[NSString stringWithFormat:@"%@%@/",self.father_csFileModel.serverFullPath,fileModel.name]:[NSString stringWithFormat:@"%@/",fileModel.name];
  424. }else fileModel.serverFullPath = self.father_csFileModel?[NSString stringWithFormat:@"%@%@",self.father_csFileModel.serverFullPath,fileModel.name]:[NSString stringWithFormat:@"%@",fileModel.name];;
  425. //不存储.
  426. // [CloudStorageDB addcsFiletoDB:fileModel];
  427. CSFileFrameModel *csFileFrameModel = [[CSFileFrameModel alloc]initWithFileModel:fileModel];
  428. [weakself.fileModelArray addObject:csFileFrameModel];
  429. }
  430. [weakTableView reloadData];
  431. }
  432. }];
  433. }
  434. - (void)renameFilesWithFileFrameModel:(CSFileFrameModel *)fileFrameModel indexPath:(NSIndexPath *)indexPath
  435. {
  436. __weak typeof(self)weakSelf = self;
  437. __weak typeof(self.mainTableView)weakTableView = self.mainTableView;
  438. UIAlertViewStyle type = UIAlertViewStylePlainTextInput;
  439. //new name
  440. [UIAlertView showAlertViewWithType:type Title:@"重命名" message:nil cancelButtonTitle:@"取消" otherButtonTitles:@[@"确定"] onDismiss:^(int buttonIndex, UIAlertView *alertView) {
  441. UITextField *applyTextField = [alertView textFieldAtIndex:0];
  442. if (!applyTextField.text) {
  443. [Utils showError:@"请输入新命名" ToView:weakTableView];
  444. return ;
  445. }
  446. [Utils showWaitingToView:weakTableView];
  447. [[HttpRequest sharedManager]cloudStorageFileReNameWithNewName:applyTextField.text fileID:fileFrameModel.fileModel.sid complete:^(BOOL success, id data, NSError *error) {
  448. [Utils HiddenWaitingToView:weakTableView];
  449. if (success && data) {
  450. [Utils showSuccess:@"重命名成功" toView:weakTableView finish:nil];
  451. //reload.
  452. //重新计算尺寸.
  453. CSFileFrameModel *newfileFrameModel = weakSelf.fileModelArray[indexPath.row];
  454. newfileFrameModel.fileModel.name = applyTextField.text;
  455. [newfileFrameModel renameItemWithNewFileModel:newfileFrameModel.fileModel];
  456. if (indexPath) {
  457. [weakTableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
  458. }
  459. }else{
  460. [Utils showError:@"重命名失败" ToView:weakTableView];
  461. }
  462. }];
  463. } onCancel:^(UIAlertView *alertView) {
  464. }];
  465. }
  466. - (void)createNewFileFolder{
  467. CSAlertView * alertview = [[CSAlertView alloc]initWithTitle:@"新建文件夹" message:@"" inputMode:YES sureBtn:@"创建" cancleBtn:@"取消"];
  468. __weak typeof(self)weakSelf = self;
  469. __weak typeof(alertview)weakalertview = alertview;
  470. __weak typeof(self.mainTableView)weakTableView = self.mainTableView;
  471. [alertview showXBAlertView];
  472. alertview.alertresult = ^(NSString *folderName){
  473. [[HttpRequest sharedManager]cloudStorageCreateNewFileFolderWithFolderName:folderName pid:weakSelf.pid delflag:@"0" complete:^(BOOL success, id data, NSError *error) {
  474. if (success && data) {
  475. [weakalertview stopActityAndRemoveAlertView];
  476. [Utils showSuccess:@"文件夹创建成功" toView:weakTableView finish:nil];
  477. //reload.
  478. CSFileModel *csfileModel = [CSFileModel mj_objectWithKeyValues:data[@"data"]];
  479. csfileModel.serverFullPath = self.father_csFileModel?[NSString stringWithFormat:@"%@%@/",self.father_csFileModel.serverFullPath,csfileModel.name]:[NSString stringWithFormat:@"%@/",csfileModel.name];
  480. [kCloudStorageDB addcsFiletoDB:csfileModel];
  481. CSFileFrameModel *csframeModel = [[CSFileFrameModel alloc]initWithFileModel:csfileModel];
  482. [weakSelf.fileModelArray addObject:csframeModel];
  483. [weakTableView reloadData];
  484. // [weakTableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:[weakTableView numberOfRowsInSection:0] - 1 inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
  485. //
  486. [weakTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:weakSelf.fileModelArray.count - 1 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:YES];
  487. }else{
  488. [weakalertview showErrorMsg:@"文件夹创建失败"];
  489. NSError *createFolderError = [NSError errorWithDomain:@"com.wswinsoft.zhuxun" code:40002 userInfo:@{@"error":error,@"APIDescription":@"cloudStorageCreateNewFileFolderWithFolderName",@"param":[NSString stringWithFormat:@"foldername:%@ pid:%@",folderName,weakSelf.pid],@"systemerrorinfo":error.userInfo}];
  490. [Bugly reportError:createFolderError];
  491. }
  492. //[weakalertview stopActity];
  493. }];
  494. };
  495. // CustomAlertView *alertView =
  496. // alertVc.messageColor = [UIColor redColor];
  497. // [alertVc alertViewControllerWithMessage:@"测试而已" andBlock:^{
  498. // NSLog(@"test");
  499. // }];
  500. // [self.navigationController presentViewController:alertVc animated:NO completion:nil];
  501. //presentModalViewController:alertVc animated:YES];
  502. /*UIAlertViewStyle type = UIAlertViewStylePlainTextInput;
  503. __weak typeof(self)weakSelf = self;
  504. __weak typeof(self.mainTableView)weakTableView = self.mainTableView;
  505. //待使用新的createNEWFOLDERVIEW
  506. [UIAlertView showAlertViewWithType:type Title:@"新建文件夹" message:nil cancelButtonTitle:@"取消" otherButtonTitles:@[@"确定"] onDismiss:^(int buttonIndex, UIAlertView *alertView) {
  507. UITextField *applyTextField = [alertView textFieldAtIndex:0];
  508. if (!applyTextField.text.length) {
  509. [Utils showError:@"请输入文件夹名称" ToView:weakTableView];
  510. return ;
  511. }
  512. [Utils showWaitingToView:weakTableView];
  513. #warning 2016-06-20 貌似有连续请求的问题..
  514. [[HttpRequest sharedManager]cloudStorageCreateNewFileFolderWithFolderName:applyTextField.text pid:weakSelf.pid delflag:@"0" complete:^(BOOL success, id data, NSError *error) {
  515. [Utils HiddenWaitingToView:weakTableView];
  516. if (success && data) {
  517. //
  518. [Utils showSuccess:@"文件夹创建成功" toView:weakTableView finish:nil];
  519. //reload.
  520. CSFileModel *csfileModel = [CSFileModel mj_objectWithKeyValues:data[@"data"]];
  521. csfileModel.serverFullPath = self.father_csFileModel?[NSString stringWithFormat:@"%@%@/",self.father_csFileModel.serverFullPath,csfileModel.name]:[NSString stringWithFormat:@"%@/",csfileModel.name];
  522. [CloudStorageDB addcsFiletoDB:csfileModel];
  523. CSFileFrameModel *csframeModel = [[CSFileFrameModel alloc]initWithFileModel:csfileModel];
  524. [weakSelf.fileModelArray addObject:csframeModel];
  525. [weakTableView reloadData];
  526. // [weakTableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:[weakTableView numberOfRowsInSection:0] - 1 inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
  527. //
  528. [weakTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:weakSelf.fileModelArray.count - 1 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:YES];
  529. }else{
  530. [Utils showError:@"文件夹创建失败" ToView:weakTableView];
  531. }
  532. }];
  533. } onCancel:^(UIAlertView *alertView) {
  534. }];
  535. */}
  536. - (void)sortFilesWithSortType:(SortType)sortType
  537. {
  538. NSComparator cmptr = nil;
  539. //本地排序
  540. if (sortType == SortTypeFileName) {
  541. cmptr = ^(CSFileFrameModel *frameModelA, CSFileFrameModel *frameModelB){
  542. if (frameModelA.fileModel.name > frameModelB.fileModel.name) {
  543. return (NSComparisonResult)NSOrderedDescending;
  544. }
  545. if (frameModelA.fileModel.name < frameModelB.fileModel.name) {
  546. return (NSComparisonResult)NSOrderedAscending;
  547. }
  548. return (NSComparisonResult)NSOrderedSame;
  549. };
  550. }else if(sortType == SortTypeFileTime){
  551. cmptr = ^(CSFileFrameModel *frameModelA, CSFileFrameModel *frameModelB){
  552. if (frameModelA.fileModel.server_ctime > frameModelB.fileModel.server_ctime) {
  553. return (NSComparisonResult)NSOrderedDescending;
  554. }
  555. if (frameModelA.fileModel.server_ctime < frameModelB.fileModel.server_ctime) {
  556. return (NSComparisonResult)NSOrderedAscending;
  557. }
  558. return (NSComparisonResult)NSOrderedSame;
  559. };
  560. }
  561. NSArray *newSortArray = [self.fileModelArray sortedArrayUsingComparator:cmptr];
  562. [self.fileModelArray removeAllObjects];
  563. [self.fileModelArray addObjectsFromArray:newSortArray];
  564. [self.mainTableView reloadData];
  565. }
  566. //丢给filetype choose.
  567. - (void)classFileWithFileType:(CSFileType)fileType
  568. {
  569. if (!self.searchModel) {
  570. //全目录分类,quanbu 时是否不动..
  571. NSString *classExtNumStr = nil;
  572. if (fileType != CSFileTypeAll) {
  573. classExtNumStr = [NSString stringWithFormat:@"%d",fileType];
  574. }
  575. [self getFileListWithPid:nil searchKey:nil classExt:classExtNumStr];
  576. }else{
  577. //本地搜索结果分类
  578. }
  579. }
  580. - (void)searchFilesWithContent:(NSString *)content
  581. {
  582. self.searchModel = YES;
  583. [self getFileListWithPid:nil searchKey:content classExt:nil];
  584. }
  585. - (void)shareFilesToUserOrGroups:(NSArray *)fileModels
  586. {
  587. #warning 2016-06-20待新增云盘文件消息体.,转发中心待调整.
  588. // //取出fileModels(FrameModels)中的entity
  589. // NSMutableArray *tmparr = [NSMutableArray array];
  590. // [fileModels enumerateObjectsUsingBlock:^(CSFileFrameModel *obj, NSUInteger idx, BOOL * _Nonnull stop) {
  591. // [tmparr addObject:obj.fileModel];
  592. // }];
  593. // NewMessageTransController *tanrsController = [NewMessageTransController new];
  594. // tanrsController.csfilesArray = tmparr;
  595. // tanrsController.isDisableMulitselect = YES;
  596. // IWNavigationController *navCor = [[IWNavigationController alloc]initWithRootViewController:tanrsController];
  597. //
  598. // [self.navigationController presentViewController:navCor animated:YES completion:nil];
  599. }
  600. - (void)moveCSFilesWithFileModels:(NSArray *)csfileModels
  601. {
  602. NSMutableArray *csFileIDsArray = [NSMutableArray array];
  603. for (CSFileFrameModel *csfileFrameModel in csfileModels) {
  604. [csFileIDsArray addObject:csfileFrameModel.fileModel.sid];
  605. }
  606. CSRouterSelectController *csRouterSelectController = [CSRouterSelectController new];
  607. IWNavigationController *navCloud = [[IWNavigationController alloc]initWithRootViewController:csRouterSelectController];
  608. __weak typeof(self.view)weakView = self.view;
  609. #pragma mark -- 2017-07-26 01文件迁移 serverFullPath未处理 --sql
  610. navCloud.cloudControlerBlock = ^(NSString *pid, NSString *serverFullPath){
  611. [[HttpRequest sharedManager]cloudStorageMoveFilesToOtherPid:pid needMoveFiles:csFileIDsArray complete:^(BOOL success, id data, NSError *error) {
  612. #warning 2017-07-26 02 文件迁移完成后控制器刷新 未实现
  613. //update new files.
  614. //[[CloudStorageDB shareInstance]addcsFilestoDB:csFileIDsArray];
  615. if (!error&&success) {
  616. [kCloudStorageDB updateCSFilestoDB:csFileIDsArray targetid:pid];
  617. [Utils showSuccess:@"移动成功" toView:weakView finish:nil];
  618. }
  619. else{
  620. [Utils showSuccess:@"移动失败" toView:weakView finish:nil];
  621. }
  622. }];
  623. };
  624. [self.navigationController presentViewController:navCloud animated:YES completion:nil];
  625. }
  626. - (void)downloadFileWithFileModels:(NSArray *)csfileModels
  627. {
  628. //获取最外层文件夹.
  629. //再创建数据库模型,不用考虑重复,uuid相同无法添加
  630. //全部丢给tarncenter,相同的uuid会自动过滤.
  631. //最后.通知tarns.(如果是文件,带上subfiles.)
  632. //先获取所有文件.0
  633. NSMutableArray *tempSidsArrray = [NSMutableArray array];
  634. //need downfiles0
  635. NSMutableArray *totalNeedDownloadFileArray = [NSMutableArray array];
  636. //trans show 0
  637. NSMutableArray *totalPidZeroDownloadFilesArray = [NSMutableArray array];//缺少返回allsubfiles.
  638. //save db for all files.csdownfile *
  639. NSMutableArray *totalDBSaveDownloadFilesArray = [NSMutableArray array];
  640. for (CSFileFrameModel *csFileFrameModel in csfileModels) {
  641. if (csFileFrameModel.fileModel.isdir) {
  642. [tempSidsArrray addObject:csFileFrameModel.fileModel.sid];
  643. }
  644. //创建downupmodel
  645. csFileFrameModel.fileModel.pid = @"0";
  646. CSFileDownUpModel *newCSFileDownUpModel = [CSFileDownUpModel csfileDownupModelWithfileModel:csFileFrameModel.fileModel downUpType:DownUpModelDown downUpStatus:DownUpStatusWait fileSource:FileSourceCSCloud fileType:FileTypeOther localRootPath:csFileFrameModel.fileModel.name file_category:csFileFrameModel.fileModel.path.pathComponents.count downUpTimeStamp:[NSDate date] downUpUUID:nil downUpSize:0];
  647. [totalPidZeroDownloadFilesArray addObject:newCSFileDownUpModel];//need show to transcontroller - done
  648. [totalDBSaveDownloadFilesArray addObject:newCSFileDownUpModel]; //need save file/filefolder model
  649. if (!newCSFileDownUpModel.isdir) {
  650. [totalNeedDownloadFileArray addObject:newCSFileDownUpModel];//need download file
  651. }
  652. }
  653. [self getAllFileFoldersFilesWithPidsArray:tempSidsArrray resultBlock:^(NSArray *fileModels) {
  654. for (CSFileModel *fileModel in fileModels) {
  655. //创建downupmodel
  656. CSFileDownUpModel *newCSFileDownUpModel = [CSFileDownUpModel csfileDownupModelWithfileModel:fileModel downUpType:DownUpModelDown downUpStatus:DownUpStatusWait fileSource:FileSourceCSCloud fileType:FileTypeOther localRootPath:fileModel.name file_category:fileModel.path.pathComponents.count downUpTimeStamp:[NSDate date] downUpUUID:nil downUpSize:0];
  657. [totalDBSaveDownloadFilesArray addObject:newCSFileDownUpModel];
  658. if (!fileModel.isdir) {
  659. [totalNeedDownloadFileArray addObject:newCSFileDownUpModel];
  660. }
  661. }
  662. NSMutableArray *tempUUIDsArray = [NSMutableArray array];
  663. for (CSFileDownUpModel *csFileDownUpModel in totalDBSaveDownloadFilesArray) {
  664. [tempUUIDsArray addObject:[NSString stringWithFormat:@"'%@'",csFileDownUpModel.downUpUUID]];
  665. }
  666. //过滤数据库中成功的文件.
  667. if (tempUUIDsArray.count) {
  668. [kCloudStorageDB getCSDownUpFilesWithUUIDs:tempUUIDsArray downUpModel:DownUpModelDown resultBlock:^(NSArray *dbCSFileModels) {
  669. //过滤掉成功的.
  670. NSArray *successFiles = [dbCSFileModels filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"downUpStatus = %d",DownUpStatusSuccess]];
  671. NSMutableArray *tempSuccessFilesSortArray = [NSMutableArray array];
  672. for (CSFileDownUpModel *sortFileDownUpModel in totalDBSaveDownloadFilesArray) {
  673. //if total的在返回的成功列表内能找到,则移除
  674. if ([successFiles filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"downUpUUID = %@",sortFileDownUpModel.downUpUUID]].count) {
  675. [tempSuccessFilesSortArray addObject:sortFileDownUpModel];
  676. }
  677. }
  678. [totalNeedDownloadFileArray removeObjectsInArray:tempSuccessFilesSortArray];
  679. if (totalNeedDownloadFileArray.count) {
  680. [kCloudStorageDB addCSDownUpFilesToDB:totalDBSaveDownloadFilesArray downUpModel:DownUpModelDown];
  681. CSTabBarController *iwNav = (CSTabBarController *)self.tabBarController;
  682. if (iwNav.cloudControlerFileDownloadBlock) {
  683. iwNav.cloudControlerFileDownloadBlock(totalPidZeroDownloadFilesArray);
  684. }
  685. //downUpFiles
  686. //待过滤successfiles
  687. [[CloudStorageDownloadCenter sharedInstance]addOneDownloadWithFileDownUpModels:totalNeedDownloadFileArray];
  688. }
  689. }];
  690. }
  691. }];
  692. }
  693. - (void)getAllFileFoldersFilesWithPidsArray:(NSArray *)pidsArray resultBlock:(void(^)(NSArray *fileModels))resultBlock
  694. {
  695. if (pidsArray) {
  696. [[HttpRequest sharedManager]cloudStorageGetAllChildsWithPids:pidsArray complete:^(BOOL success, id data, NSError *error) {
  697. if (data && success) {
  698. NSArray *fileModels = [CSFileModel mj_objectArrayWithKeyValuesArray:data[@"data"]];
  699. resultBlock(fileModels);
  700. //resultBlock();
  701. }else resultBlock(nil);
  702. }];
  703. }else resultBlock(nil);
  704. }
  705. - (void)getFileListWithPid:(NSString *)pid searchKey:(NSString *)key classExt:(NSString *)ext
  706. {
  707. [self.fileModelArray removeAllObjects];
  708. __weak typeof(self)weakSelf = self;
  709. __weak typeof(self.mainTableView)weakTableView = self.mainTableView;
  710. __weak typeof(self.view)weakView = self.view;
  711. [Utils showWaitingToView:self.view];
  712. [[HttpRequest sharedManager]cloudStorageGetFilesWithPid:pid searchKey:key ext:ext complete:^(BOOL success, id data, NSError *error) {
  713. if (success && data) {
  714. NSArray *fileDataModel = [CSFileModel mj_objectArrayWithKeyValuesArray:data[@"data"]];
  715. for (CSFileModel *fileModel in fileDataModel) {
  716. if (fileModel.isdir) {
  717. fileModel.serverFullPath = self.father_csFileModel?[NSString stringWithFormat:@"%@%@/",self.father_csFileModel.serverFullPath,fileModel.name]:[NSString stringWithFormat:@"%@/",fileModel.name];
  718. }else fileModel.serverFullPath = self.father_csFileModel?[NSString stringWithFormat:@"%@%@",self.father_csFileModel.serverFullPath,fileModel.name]:[NSString stringWithFormat:@"%@",fileModel.name];;
  719. CSFileFrameModel *csFileFrameModel = [[CSFileFrameModel alloc]initWithFileModel:fileModel];
  720. [weakSelf.fileModelArray addObject:csFileFrameModel];
  721. }
  722. [Utils HiddenWaitingToView:weakView];
  723. [weakTableView reloadData];
  724. if (weakSelf.csFileSourceType == CSFileSourceTypeSelf) {
  725. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  726. [kCloudStorageDB addcsFilestoDB:fileDataModel];
  727. });
  728. }
  729. }else{
  730. [Utils HiddenWaitingToView:weakView];
  731. [kCloudStorageDB getAllCloudFilesWithPid:pid resultBlock:^(NSArray *result) {
  732. for (CSFileModel *fileModel in result) {
  733. CSFileFrameModel *csFileFrameModel = [[CSFileFrameModel alloc]initWithFileModel:fileModel];
  734. [weakSelf.fileModelArray addObject:csFileFrameModel];
  735. }
  736. [weakTableView reloadData];
  737. }];
  738. }
  739. }];
  740. }
  741. - (void)dealloc
  742. {
  743. NSLog(@"firstpage delloc");
  744. }
  745. @end