previewImageOrVideoViewController.m 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432
  1. //
  2. // previewImageOrVideoViewController.m
  3. // 双子星云手机
  4. //
  5. // Created by xd h on 2024/5/13.
  6. //
  7. #import "previewImageOrVideoViewController.h"
  8. #import "couldPhoneFileListModel.h"
  9. #import "downloadManager.h"
  10. #import "uploadFileRecordViewController.h"
  11. #import "UIScrollView+EmptyDataSet.h"
  12. #import "diskListBgView.h"
  13. #import "diskListTableView.h"
  14. #import "imageCollectionViewCell.h"
  15. #import "titleLabelReusableView.h"
  16. #import "editTypeHeadView.h"
  17. #import "editTypeBottomView.h"
  18. #import "editShareView.h"
  19. #import "previewToUploadFileView.h"
  20. #import "NASFilePicModel.h"
  21. #import "imageDetailsScrollViewController.h"
  22. #import "queryShareModel.h"
  23. #import "videoPlayViewController.h"
  24. #import "videoPlayByAVPlayerViewController.h"
  25. #import "MJRefresh.h"
  26. #import "searchBarThridTypeView.h"
  27. #import "NasSearchViewController.h"
  28. #import "DocumentPickerManager.h"
  29. @interface previewImageOrVideoViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>
  30. {
  31. UIButton *tapBtn;
  32. UIButton* rightTransferListButton;//传输列表
  33. UIView* rightRedView;
  34. BOOL hadUploadTaskType;
  35. BOOL hadDownloadTaskType;
  36. BOOL canShareType;
  37. }
  38. @property (nonatomic, strong) UICollectionView *dataCollectionView;
  39. @property (strong, nonatomic) UILabel *MytitleLabel;
  40. @property (strong, nonatomic) UIImageView *selectTip;
  41. @property (nonatomic, strong) diskListBgView *diskListBgV;
  42. @property (nonatomic, strong) diskListTableView *diskListTableV;
  43. @property (nonatomic, strong) NSMutableArray*diskListArr;
  44. @property (nonatomic, copy) NSString *defaultDiskPath;
  45. @property(nonatomic,assign) BOOL isEditType;
  46. @property(nonatomic,strong) editTypeHeadView*curEditTypeHeadView;
  47. @property(nonatomic,strong) editTypeBottomView*curEditTypeBottomView;
  48. @property(nonatomic,strong) searchBarThridTypeView* searchBarThridTypeV;//
  49. @property(nonatomic,strong) UIButton*uploadFileButton;
  50. //@property(nonatomic,strong) couldPhoneFileListModel *curCouldPhoneFileListMod;
  51. @property(nonatomic,strong) NASFilePicModel *curNASFilePicModel;
  52. @property (nonatomic, strong) NSMutableArray*didSelectListArr;//选中的数据
  53. @end
  54. @implementation previewImageOrVideoViewController
  55. - (void)viewDidLoad {
  56. [super viewDidLoad];
  57. // Do any additional setup after loading the view.
  58. [self.toolBar setHidden:YES];
  59. [self.navigationBar setHidden:YES];
  60. [self.navBarBGView setHidden:NO];
  61. self.navBarBGView.backgroundColor = [UIColor whiteColor];
  62. [self.view setBackgroundColor:[UIColor whiteColor]];
  63. [self drawAnyView];
  64. _didSelectListArr = [NSMutableArray new];
  65. //数据埋点
  66. [[netWorkManager shareInstance] DataEmbeddingPointBy:2 withEventValue:@"Image"];
  67. }
  68. - (void)drawAnyView{
  69. [self initNavHeadUIFun];
  70. _curEditTypeHeadView = [[editTypeHeadView alloc] init];
  71. _curEditTypeHeadView.hidden = YES;
  72. [self.navBarBGView addSubview:_curEditTypeHeadView];
  73. [_curEditTypeHeadView mas_makeConstraints:^(MASConstraintMaker *make) {
  74. make.left.mas_equalTo(0);
  75. make.right.mas_equalTo(0);
  76. make.bottom.mas_equalTo(0);
  77. make.height.mas_equalTo(NAVIHEIGHT - AdaptNaviHeight);
  78. }];
  79. #pragma mark 编辑状态的 取消 和全选按钮 响应事件
  80. KWeakSelf
  81. _curEditTypeHeadView.didClickButtonFun = ^(NSInteger tag) {
  82. if(tag==1){
  83. [weakSelf userCancelEditTypeFun];
  84. }
  85. };
  86. _curEditTypeHeadView.didClickSelectAllFun = ^(UIButton * _Nonnull but) {
  87. [weakSelf didClickSelectAllButton:but];
  88. };
  89. _curEditTypeBottomView = [[editTypeBottomView alloc] init];
  90. _curEditTypeBottomView.hidden = YES;
  91. [self.view addSubview:_curEditTypeBottomView];
  92. [_curEditTypeBottomView mas_makeConstraints:^(MASConstraintMaker *make) {
  93. make.left.mas_equalTo(0);
  94. make.right.mas_equalTo(0);
  95. make.bottom.mas_equalTo(0);
  96. make.height.mas_equalTo(60 + AdaptTabHeight);
  97. }];
  98. #pragma mark 编辑状态的 下载 分享 删除 响应事件
  99. _curEditTypeBottomView.didClickButtonFun = ^(NSInteger tag) {
  100. if(tag==1){
  101. [weakSelf gotoDownLoadFileFun];
  102. }
  103. else if(tag==2){
  104. [weakSelf gotoShareViewFun];
  105. }
  106. else if(tag==3){
  107. [weakSelf showDeleteAlearViewFun];
  108. }
  109. };
  110. _searchBarThridTypeV = [[searchBarThridTypeView alloc] init];
  111. [self.view addSubview:_searchBarThridTypeV];
  112. [_searchBarThridTypeV mas_makeConstraints:^(MASConstraintMaker *make) {
  113. make.top.equalTo(self.navBarBGView.mas_bottom).offset(10.f);
  114. make.height.mas_equalTo(32.0);
  115. make.left.mas_equalTo(20.0);
  116. //make.right.mas_equalTo(-48.0);
  117. make.right.mas_equalTo(-20.0);
  118. }];
  119. #pragma mark 点击搜索
  120. _searchBarThridTypeV.didClickBgFun = ^{
  121. [weakSelf gotoSearchVCFun];
  122. };
  123. [self.view addSubview:self.dataCollectionView];
  124. [self.dataCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  125. make.left.mas_equalTo(0);
  126. make.right.mas_equalTo(0);
  127. //make.bottom.mas_equalTo(-(safeArea));
  128. make.bottom.mas_equalTo(0);
  129. //make.top.equalTo(self.navBarBGView.mas_bottom).offset(10.f);
  130. make.top.equalTo(self.searchBarThridTypeV.mas_bottom).offset(10.f);
  131. }];
  132. //大+号
  133. _uploadFileButton = [[UIButton alloc] init];
  134. [_uploadFileButton setBackgroundImage:[UIImage imageNamed:@"add_file_icon"] forState:UIControlStateNormal];
  135. [_uploadFileButton addTarget:self action:@selector(userDidClickUploadViewFun) forControlEvents:UIControlEventTouchUpInside];
  136. [self.view addSubview:_uploadFileButton];
  137. [_uploadFileButton mas_makeConstraints:^(MASConstraintMaker *make) {
  138. make.right.mas_equalTo(-15);
  139. make.width.mas_equalTo(52);
  140. make.height.mas_equalTo(52);
  141. make.bottom.mas_equalTo(-30 - AdaptTabHeight);
  142. }];
  143. // 添加拖拽手势
  144. UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
  145. [_uploadFileButton addGestureRecognizer:panGesture];
  146. NSMutableArray *arr = [NSMutableArray new];
  147. NSArray *diskList = ksharedAppDelegate.cloudPhoneExtraFileListMod.data;
  148. if(diskList && [diskList isKindOfClass:[NSArray class]]){
  149. for (cloudPhoneExtraFileModel *model in diskList) {
  150. model.isCheckType = NO;
  151. [arr addObject:model];
  152. }
  153. }
  154. if(arr.count >0){
  155. //上一次选中的磁盘
  156. NSString*preChekDiskStr = [HWDataManager getStringWithKey:Const_image_pre_disk_check];
  157. //1.没有选择过 默认选择第一次(云机)
  158. if(!preChekDiskStr || preChekDiskStr.length == 0){
  159. cloudPhoneExtraFileModel *model = arr.firstObject;
  160. model.isCheckType = YES;
  161. _defaultDiskPath = model.extraPath;
  162. }
  163. else{//2.选择过 查询磁盘是否还存在
  164. BOOL didCheckDisk = NO;
  165. for (cloudPhoneExtraFileModel *model in arr) {
  166. HLog(@"磁盘路径比较 pre:%@---%@",preChekDiskStr,model.extraPath)
  167. if([model.extraPath isEqualToString:preChekDiskStr]){
  168. model.isCheckType = YES;
  169. _defaultDiskPath = model.extraPath;
  170. didCheckDisk = YES;
  171. break;
  172. }
  173. }
  174. //3.选择过 查询磁盘不存在
  175. if(!didCheckDisk){
  176. cloudPhoneExtraFileModel *model = arr.firstObject;
  177. model.isCheckType = YES;
  178. _defaultDiskPath = model.extraPath;
  179. }
  180. }
  181. }
  182. _diskListArr = arr;
  183. [self setTitleAfterGetdiskFun];
  184. //数据缓存
  185. // NSString *key = stringKeyAddSn(@"getFileListByDay");
  186. // NSDictionary * responseObject = [HWDataManager getObjectWithKey:key];
  187. // if(responseObject){
  188. // NASFilePicModel*NASFilePicMod = [[NASFilePicModel alloc] initWithDictionary:responseObject error:nil];
  189. // [self filterDataFun:NASFilePicMod];
  190. // [self.dataCollectionView reloadData];
  191. // }
  192. }
  193. - (void)initNavHeadUIFun
  194. {
  195. //title
  196. UILabel *titleLabel = [[UILabel alloc] init];
  197. titleLabel.textAlignment = NSTextAlignmentCenter;
  198. titleLabel.font = [UIFont boldSystemFontOfSize:16.0];
  199. titleLabel.textColor = [UIColor blackColor];
  200. titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
  201. [self.navBarBGView addSubview:titleLabel];
  202. self.MytitleLabel = titleLabel;
  203. //selectTipImageView
  204. UIImageView *selectTip = [[UIImageView alloc] init];
  205. selectTip.image = [UIImage imageNamed:@"upload_image_arrow"];
  206. selectTip.translatesAutoresizingMaskIntoConstraints = NO;
  207. [self.navBarBGView addSubview:selectTip];
  208. self.selectTip = selectTip;
  209. tapBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  210. tapBtn.backgroundColor = [UIColor clearColor];
  211. tapBtn.translatesAutoresizingMaskIntoConstraints = NO;
  212. [tapBtn addTarget:self action:@selector(selectDiskAction:) forControlEvents:UIControlEventTouchUpInside];
  213. [self.navBarBGView addSubview:tapBtn];
  214. [tapBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  215. make.centerX.mas_equalTo(self.navBarBGView.mas_centerX);
  216. make.centerY.mas_equalTo(self.backBtn.mas_centerY);
  217. make.width.mas_equalTo(100);
  218. make.height.mas_equalTo(30);
  219. }];
  220. [self setTitleLabelText:@""];
  221. rightTransferListButton = [[UIButton alloc] init];
  222. [rightTransferListButton setImage:[UIImage imageNamed:@"icon_file_transfer"] forState:UIControlStateNormal];
  223. [rightTransferListButton addTarget:self action:@selector(didiClikRightButGotoTransferListFun:) forControlEvents:UIControlEventTouchUpInside];
  224. [self.navBarBGView addSubview:rightTransferListButton];
  225. [rightTransferListButton mas_makeConstraints:^(MASConstraintMaker *make) {
  226. make.width.mas_equalTo(40);
  227. make.height.mas_equalTo(40);
  228. make.right.mas_equalTo(-15);
  229. make.centerY.mas_equalTo(self.titleLabel.mas_centerY);
  230. }];
  231. rightRedView = [[UIView alloc] init];
  232. rightRedView.backgroundColor = [UIColor hwColor:@"#DD4E4E" alpha:1.0];
  233. [rightTransferListButton addSubview:rightRedView];
  234. rightRedView.layer.cornerRadius = 7;
  235. rightRedView.hidden = YES;
  236. [rightRedView mas_makeConstraints:^(MASConstraintMaker *make) {
  237. make.width.mas_equalTo(14);
  238. make.height.mas_equalTo(14);
  239. make.right.mas_equalTo(0);
  240. make.top.mas_equalTo(6);
  241. }];
  242. }
  243. #pragma mark 处理拖拽手势
  244. - (void)handlePan:(UIPanGestureRecognizer *)gesture {
  245. if (gesture.state == UIGestureRecognizerStateChanged) {
  246. // 获取手指拖拽的偏移量
  247. CGPoint translation = [gesture translationInView:self.view];
  248. // 更新视图位置
  249. CGPoint newCenter = CGPointMake(
  250. _uploadFileButton.center.x + translation.x,
  251. _uploadFileButton.center.y + translation.y
  252. );
  253. _uploadFileButton.center = newCenter;
  254. // 重置偏移量,避免累加
  255. [gesture setTranslation:CGPointZero inView:self.view];
  256. }
  257. }
  258. #pragma mark - 懒加载
  259. - (UICollectionView *)dataCollectionView{
  260. if (!_dataCollectionView) {
  261. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  262. // 设置item的行间距和列间距
  263. layout.minimumInteritemSpacing = 1;
  264. layout.minimumLineSpacing = 1;
  265. // 设置item的大小
  266. CGFloat itemW = ([UIScreen mainScreen].bounds.size.width - 10) /4 ;
  267. layout.itemSize = CGSizeMake(itemW, itemW);
  268. layout.headerReferenceSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, 40);
  269. //layout.footerReferenceSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, 40);
  270. // 设置每个分区的 上左下右 的内边距
  271. layout.sectionInset = UIEdgeInsetsMake(1, 1 ,1, 1);
  272. // 设置区头和区尾的大小
  273. layout.headerReferenceSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, 10);
  274. //layout.footerReferenceSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, 10);
  275. // 设置分区的头视图和尾视图 是否始终固定在屏幕上边和下边
  276. layout.sectionFootersPinToVisibleBounds = YES;
  277. //设置滚动条方向
  278. layout.scrollDirection = UICollectionViewScrollDirectionVertical;
  279. _dataCollectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:layout];
  280. _dataCollectionView.backgroundColor = [UIColor whiteColor];
  281. _dataCollectionView.scrollEnabled = YES;
  282. //注册cell
  283. [_dataCollectionView registerClass:[imageCollectionViewCell class] forCellWithReuseIdentifier:@"imageCollectionViewCell"];
  284. [_dataCollectionView registerClass:[titleLabelReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"titleLabelReusableView"];
  285. _dataCollectionView.delegate = self;
  286. _dataCollectionView.dataSource = self;
  287. //空数据引入第三方开源处理
  288. _dataCollectionView.emptyDataSetSource = self;
  289. _dataCollectionView.emptyDataSetDelegate = self;
  290. // 下拉追加
  291. // MJRefreshAutoNormalFooter *footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  292. // [self getMoreNetWorkData];
  293. // }];
  294. //
  295. // NSString *text = NSLocalizedString(@"NAS_bottom_tip",nil);
  296. // [footer setTitle:text forState:MJRefreshStateNoMoreData];
  297. // _dataCollectionView.mj_footer = footer;
  298. }
  299. return _dataCollectionView;
  300. }
  301. - (diskListBgView*)diskListBgV
  302. {
  303. if(!_diskListBgV){
  304. _diskListBgV = [[diskListBgView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
  305. _diskListBgV.hidden = YES;
  306. [self.view addSubview:_diskListBgV];
  307. KWeakSelf
  308. _diskListBgV.didTapWhitePlace = ^{
  309. [weakSelf hideDiskListVieFun];
  310. };
  311. [_diskListBgV mas_makeConstraints:^(MASConstraintMaker *make) {
  312. make.left.mas_equalTo(0);
  313. make.bottom.mas_equalTo(0);
  314. make.right.mas_equalTo(0);
  315. make.top.mas_equalTo(self.navBarBGView.mas_bottom);
  316. }];
  317. [self.view addSubview:self.diskListTableV];
  318. self.diskListTableV.hidden = YES;
  319. [self.diskListTableV mas_makeConstraints:^(MASConstraintMaker *make) {
  320. make.left.mas_equalTo(0);
  321. make.height.mas_equalTo(3*70);
  322. make.right.mas_equalTo(0);
  323. make.top.mas_equalTo(self.navBarBGView.mas_bottom);
  324. }];
  325. self.diskListTableV.diskListArr = _diskListArr;
  326. self.diskListTableV.didClickDiskModel = ^(NSString * _Nonnull checkPath) {
  327. [weakSelf didCheckDiskFunByPath:checkPath];
  328. };
  329. }
  330. return _diskListBgV;
  331. }
  332. - (UITableView *)diskListTableV{
  333. if (!_diskListTableV) {
  334. _diskListTableV = [[diskListTableView alloc] init];
  335. //
  336. }
  337. return _diskListTableV;
  338. }
  339. #pragma mark 选中磁盘
  340. - (void)didCheckDiskFunByPath:(NSString*)pathStr
  341. {
  342. if(self.defaultDiskPath
  343. && self.defaultDiskPath.length>0
  344. && ![self.defaultDiskPath isEqualToString:pathStr]){
  345. //切换硬盘了 取消全选
  346. [_didSelectListArr removeAllObjects];
  347. }
  348. //保存选中的磁盘
  349. if(pathStr){
  350. [HWDataManager setStringWithKey:Const_image_pre_disk_check value:pathStr];
  351. }
  352. self.defaultDiskPath = pathStr;
  353. _curNASFilePicModel = nil;
  354. [self getFileListFun:NO];
  355. [self setTitleAfterGetdiskFun];
  356. [self hideDiskListVieFun];
  357. }
  358. #pragma mark - 瀑布流委托
  359. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  360. if(_curNASFilePicModel){
  361. return _curNASFilePicModel.data.fileList.count;
  362. }
  363. return 1;
  364. }
  365. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  366. if(_curNASFilePicModel && _curNASFilePicModel.data.fileList.count >section){
  367. NASFilePicTimeArrModel *timeArrModel = _curNASFilePicModel.data.fileList[section];
  368. return timeArrModel.list.count;
  369. }
  370. return 0;
  371. }
  372. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  373. {
  374. __block NSInteger row = indexPath.row;
  375. __block NSInteger section = indexPath.section;
  376. //创建item 从缓存池中拿 Item
  377. imageCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"imageCollectionViewCell" forIndexPath:indexPath];
  378. if(!cell){
  379. cell = [[imageCollectionViewCell alloc] init];
  380. }
  381. if(_curNASFilePicModel && _curNASFilePicModel.data.fileList.count > section){
  382. NASFilePicTimeArrModel *timeArrModel = _curNASFilePicModel.data.fileList[section];
  383. if (timeArrModel.list.count > row) {
  384. NASFilePicDataArrModel * dataModel = timeArrModel.list[row];
  385. cell.isEditType = _isEditType;
  386. if(_isPhotoType){
  387. cell.fileType = @"pic";
  388. }
  389. else{
  390. cell.fileType = @"video";
  391. }
  392. cell.curFileModel = dataModel;
  393. KWeakSelf
  394. cell.didClckSelectBut = ^(BOOL selectType){
  395. if([weakSelf userCheckFileModel:dataModel withShowTip:YES]){
  396. [weakSelf userCheckFilePreviewByRow:row withSection:section];
  397. }
  398. };
  399. cell.didClickEditType = ^(BOOL editType) {
  400. [weakSelf setViewEditTypeFun];
  401. };
  402. }
  403. }
  404. return cell;
  405. }
  406. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
  407. if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
  408. NSInteger section = indexPath.section;
  409. titleLabelReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"titleLabelReusableView" forIndexPath:indexPath];
  410. if(_curNASFilePicModel && _curNASFilePicModel.data.fileList.count > section){
  411. NASFilePicTimeArrModel *timeArrModel = _curNASFilePicModel.data.fileList[section];
  412. headerView.titlelabel.text = timeArrModel.time;
  413. }
  414. return headerView;
  415. }
  416. return nil;
  417. }
  418. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
  419. return CGSizeMake([UIScreen mainScreen].bounds.size.width, 40);
  420. }
  421. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  422. {
  423. NSInteger row = indexPath.row;
  424. NSInteger section = indexPath.section;
  425. if(_curNASFilePicModel && _curNASFilePicModel.data.fileList.count > section){
  426. NASFilePicTimeArrModel *timeArrModel = _curNASFilePicModel.data.fileList[section];
  427. if (timeArrModel.list.count > row) {
  428. //NASFilePicDataArrModel * dataModel = timeArrModel.list[row];
  429. [self didClickPicDetailsWithSection:section withRow:row];
  430. }
  431. }
  432. }
  433. #pragma mark 空数据
  434. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
  435. NSString *imageName = @"common_no_data_pic";
  436. return [UIImage imageNamed:imageName];
  437. }
  438. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {
  439. NSString *text = NSLocalizedString(@"common_no_data_tip",nil);
  440. NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:16.0f],
  441. NSForegroundColorAttributeName: HW999999Color};
  442. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  443. }
  444. //调整图片位置
  445. - (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView {
  446. return -150;
  447. }
  448. //ios端:
  449. //1、需求说明:解决除MP4 MOV 3GP M4V 总计4种格式外,其他格式下载失败的问题;
  450. //2、交互说明:下载列表勾选文件中含有其他格式,toast提示“IOS系统仅支持MP4、MOV、3GP、M4V 的视频格式,其他格式无法下载”。点击下载按钮,过滤其他格式文件,仅下载MP4、MOV、3GP、M4V 的视频格式文件;
  451. //ios支持图片格式: (SVG 不支持)
  452. //需求说明:解决除JPG PNG GIF TIFF BMP总计5种格式外,其他格式下载失败的问题
  453. //视觉交互:选择文件中含有其他格式,toast提示“IOS系统仅支持JPG 、PNG、GIF、TIFF、BMP的图片格式,其他格式无法下载”。点击下载按钮,过滤其他格式文件,仅下载JPG 、PNG、GIF、TIFF、BMP的图片格式文件;
  454. - (BOOL)userCheckFileModel:(NASFilePicDataArrModel*)fileModel withShowTip:(BOOL)canShow{
  455. // NSString*name = [fileModel.name lowercaseString];
  456. // NSArray *nameArr = [name componentsSeparatedByString:@"."];
  457. // if(nameArr.count >0 && !_isPhotoType){
  458. // BOOL canDownLoadType = NO;
  459. //
  460. // NSString *lastName = nameArr.lastObject;
  461. // if([lastName isEqualToString:@"mp4"]
  462. // ||[lastName isEqualToString:@"mov"]
  463. // ||[lastName isEqualToString:@"3gp"]
  464. // ||[lastName isEqualToString:@"m4v"]){
  465. // canDownLoadType = YES;
  466. // }
  467. //
  468. // if(!canDownLoadType){
  469. // if(canShow){
  470. // [[iToast makeText:NSLocalizedString(@"download_video_disable_state",nil)] show];
  471. // }
  472. //
  473. // return NO;
  474. // }
  475. // }
  476. //
  477. // if(nameArr.count >0 && _isPhotoType){
  478. // BOOL canDownLoadType = NO;
  479. // //JPG 、PNG、GIF、TIFF、BMP
  480. // NSString *lastName = nameArr.lastObject;
  481. // if([lastName isEqualToString:@"jpg"]
  482. // ||[lastName isEqualToString:@"png"]
  483. // ||[lastName isEqualToString:@"gif"]
  484. // ||[lastName isEqualToString:@"tiff"]
  485. // ||[lastName isEqualToString:@"bmp"]
  486. // ||[lastName isEqualToString:@"heic"]
  487. // ||[lastName isEqualToString:@"jpeg"]
  488. // ||[lastName isEqualToString:@"heif"]){
  489. // canDownLoadType = YES;
  490. // }
  491. //
  492. // if(!canDownLoadType){
  493. // if(canShow){
  494. // [[iToast makeText:NSLocalizedString(@"download_image_disable_state",nil)] show];
  495. // }
  496. // return NO;
  497. // }
  498. // }
  499. return YES;
  500. }
  501. #pragma mark 用户长按图片进入编辑
  502. - (void)setViewEditTypeFun
  503. {
  504. _isEditType = YES;
  505. //[_dataCollectionView reloadData];
  506. _curEditTypeHeadView.hidden = NO;
  507. _curEditTypeBottomView.hidden = NO;
  508. _uploadFileButton.hidden = YES;
  509. self.searchBarThridTypeV.hidden = YES;
  510. [self setEditTypeTitleFun];
  511. [self.dataCollectionView mas_remakeConstraints:^(MASConstraintMaker *make) {
  512. make.left.mas_equalTo(0);
  513. make.right.mas_equalTo(0);
  514. make.bottom.mas_equalTo(_curEditTypeBottomView.mas_top);
  515. make.top.equalTo(self.navBarBGView.mas_bottom).offset(10.f);
  516. }];
  517. }
  518. #pragma mark 用户取消编辑编辑
  519. - (void)userCancelEditTypeFun
  520. {
  521. //数据还原
  522. for (NASFilePicDataArrModel*model in _didSelectListArr) {
  523. model.isSelectType = NO;
  524. }
  525. // for (NASFilePicTimeArrModel *timeArrModel in _curNASFilePicModel.data.fileList) {
  526. // for (NASFilePicDataArrModel *model in timeArrModel.list) {
  527. // model.isSelectType = NO;
  528. // }
  529. // }
  530. _isEditType = NO;
  531. BOOL isNeedReload = NO;
  532. if(self->_didSelectListArr.count >0){
  533. isNeedReload = YES;
  534. }
  535. [_didSelectListArr removeAllObjects];
  536. if(isNeedReload){
  537. [_dataCollectionView reloadData];
  538. }
  539. _curEditTypeHeadView.hidden = YES;
  540. _curEditTypeBottomView.hidden = YES;
  541. _uploadFileButton.hidden = NO;
  542. self.searchBarThridTypeV.hidden = NO;
  543. [self.dataCollectionView mas_remakeConstraints:^(MASConstraintMaker *make) {
  544. make.left.mas_equalTo(0);
  545. make.right.mas_equalTo(0);
  546. make.bottom.mas_equalTo(0);
  547. //make.top.equalTo(self.navBarBGView.mas_bottom).offset(10.f);
  548. make.top.equalTo(self.searchBarThridTypeV.mas_bottom).offset(10.f);
  549. }];
  550. }
  551. - (void)userCheckFilePreviewByRow:(NSInteger)row withSection:(NSInteger)section
  552. {
  553. if(_curNASFilePicModel && _curNASFilePicModel.data.fileList.count > section){
  554. NASFilePicTimeArrModel *timeArrModel = _curNASFilePicModel.data.fileList[section];
  555. if (timeArrModel.list.count > row) {
  556. NASFilePicDataArrModel * dataModel = timeArrModel.list[row];
  557. dataModel.isSelectType = !dataModel.isSelectType;
  558. if(!dataModel.isSelectType)
  559. {
  560. [_didSelectListArr removeObject:dataModel];
  561. if(_didSelectListArr.count == 0){
  562. [self userCancelEditTypeFun];
  563. }
  564. }
  565. else{
  566. [_didSelectListArr addObject:dataModel];
  567. if(_didSelectListArr.count == 1){
  568. [self setViewEditTypeFun];
  569. }
  570. }
  571. [self setEditTypeTitleFun];
  572. }
  573. }
  574. }
  575. - (void)didClickSelectAllButton:(UIButton*)button
  576. {
  577. //button.selected = !button.selected;
  578. BOOL isNeedShowTip = NO;
  579. [_didSelectListArr removeAllObjects];
  580. for (NASFilePicTimeArrModel* fileModel in _curNASFilePicModel.data.fileList) {
  581. for (NASFilePicDataArrModel*dataModel in fileModel.list) {
  582. if(!button.selected){
  583. dataModel.isSelectType = button.selected;
  584. }
  585. else{
  586. [_didSelectListArr addObject:dataModel];
  587. if([self userCheckFileModel:dataModel withShowTip:NO]){
  588. dataModel.isSelectType = button.selected;
  589. }
  590. else{
  591. isNeedShowTip = YES;
  592. }
  593. }
  594. }
  595. }
  596. // if(isNeedShowTip){
  597. // if(_isPhotoType){
  598. // [[iToast makeText:NSLocalizedString(@"download_image_disable_state",nil)] show];
  599. // }
  600. // else{
  601. // [[iToast makeText:NSLocalizedString(@"download_video_disable_state",nil)] show];
  602. // }
  603. // }
  604. //[self.tableView reloadData];
  605. [self.dataCollectionView reloadData];
  606. [self setEditTypeTitleFun];
  607. }
  608. #pragma mark 设置选中标题
  609. - (void)setEditTypeTitleFun
  610. {
  611. [_curEditTypeHeadView setTitleLabetextByNumbers:_didSelectListArr.count];
  612. BOOL canClick = _didSelectListArr.count >0 ? YES : NO;
  613. [_curEditTypeBottomView setButtonStateFunBy:canClick];
  614. }
  615. #pragma mark 用户点击分享
  616. - (void)gotoShareViewFun
  617. {
  618. if (_didSelectListArr.count > 50) {
  619. [[iToast makeText:NSLocalizedString(@"share_max_count_tip1",nil)] show];
  620. return;
  621. }
  622. editShareView *editShareV = [[editShareView alloc] init];
  623. editShareV.didSelectListArr = _didSelectListArr;
  624. if(_isPhotoType){
  625. editShareV.shareFileType = @"2";
  626. }
  627. else{
  628. editShareV.shareFileType = @"3";
  629. }
  630. [self.view addSubview:editShareV];
  631. [editShareV mas_makeConstraints:^(MASConstraintMaker *make) {
  632. make.left.mas_equalTo(0);
  633. make.right.mas_equalTo(0);
  634. make.bottom.mas_equalTo(0);
  635. make.top.mas_equalTo(0);
  636. }];
  637. }
  638. #pragma mark 用户点击上传文件
  639. - (void)userDidClickUploadViewFun
  640. {
  641. previewToUploadFileView *previewToUploadFileV = [[previewToUploadFileView alloc] init];
  642. [self.view addSubview:previewToUploadFileV];
  643. [previewToUploadFileV mas_makeConstraints:^(MASConstraintMaker *make) {
  644. make.left.mas_equalTo(0);
  645. make.right.mas_equalTo(0);
  646. make.bottom.mas_equalTo(0);
  647. make.top.mas_equalTo(0);
  648. }];
  649. KWeakSelf
  650. previewToUploadFileV.didClickButtonFun = ^(NSInteger tag) {
  651. [weakSelf gotoUploadFileFunWith:tag];
  652. };
  653. }
  654. #pragma mark 设置标题
  655. - (void)setTitleLabelText:(NSString*)title
  656. {
  657. NSArray *diskNameArr = [_defaultDiskPath componentsSeparatedByString:@"/"];
  658. if(diskNameArr && diskNameArr.count >= 2){
  659. NSString *name = diskNameArr.lastObject;
  660. if(name.length == 0)
  661. {
  662. name = diskNameArr[diskNameArr.count -2];
  663. }
  664. //name = [name stringByReplacingOccurrencesOfString:@"sdcard" withString:NSLocalizedString(@"disk_phone_default_tip",nil)];
  665. name = [iTools changePathToShowPathBy:name];
  666. title = [[NSString alloc] initWithFormat:@"[%@]%@",name,title];
  667. }
  668. self.MytitleLabel.text = title;
  669. CGFloat curWidth = [title boundingRectWithSize:CGSizeMake(SCREEN_W, 30) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:16.f]} context:nil].size.width;
  670. curWidth += 20;
  671. //HLog(@"title w:%f",curWidth);
  672. [self.MytitleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  673. make.centerX.mas_equalTo(self.navBarBGView.mas_centerX).offset(-10);
  674. make.centerY.mas_equalTo(self.backBtn.mas_centerY);
  675. make.width.mas_equalTo(curWidth);
  676. make.height.mas_equalTo(30);
  677. }];
  678. //self.MytitleLabel.backgroundColor = [UIColor greenColor];
  679. [self.selectTip mas_makeConstraints:^(MASConstraintMaker *make) {
  680. make.left.mas_equalTo(self.MytitleLabel.mas_right).offset(0);
  681. make.centerY.mas_equalTo(self.backBtn.mas_centerY);
  682. make.width.mas_equalTo(15);
  683. make.height.mas_equalTo(15);
  684. }];
  685. [tapBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
  686. make.centerX.mas_equalTo(self.navBarBGView.mas_centerX);
  687. make.centerY.mas_equalTo(self.backBtn.mas_centerY);
  688. make.width.mas_equalTo(curWidth+15);
  689. make.height.mas_equalTo(30);
  690. }];
  691. }
  692. #pragma mark 选择硬盘
  693. - (void)selectDiskAction:(UIButton*)but
  694. {
  695. if(self.diskListBgV.hidden){
  696. [self showDiskListVieFun];
  697. }
  698. else{
  699. [self hideDiskListVieFun];
  700. }
  701. }
  702. - (void)showDiskListVieFun
  703. {
  704. self.diskListBgV.hidden = NO;
  705. self.diskListTableV.hidden = NO;
  706. [UIView animateWithDuration:0.3 animations:^{
  707. CGRect rect = self.diskListTableV.frame;
  708. rect.origin.y = CGRectGetMaxY(self.navBarBGView.frame);
  709. self.diskListTableV.frame = rect;
  710. self.selectTip.transform = CGAffineTransformMakeRotation(M_PI);
  711. }];
  712. }
  713. - (void)hideDiskListVieFun
  714. {
  715. self.diskListBgV.hidden = YES;
  716. [UIView animateWithDuration:0.3 animations:^{
  717. self.diskListTableV.hidden = YES;
  718. self.selectTip.transform = CGAffineTransformIdentity;
  719. }completion:^(BOOL finished) {
  720. CGRect rect = self.diskListTableV.frame;
  721. rect.origin.y = 0;
  722. self.diskListTableV.frame = rect;
  723. }];
  724. }
  725. #pragma mark 设置标题
  726. - (void)setTitleAfterGetdiskFun
  727. {
  728. if(_isPhotoType){
  729. //self.titleLabel.text = NSLocalizedString(@"my_set_no_image_upload",nil) ;
  730. [self setTitleLabelText:NSLocalizedString(@"my_set_no_image_upload",nil)];
  731. }
  732. else{
  733. //self.titleLabel.text = NSLocalizedString(@"my_set_no_video_upload",nil) ;
  734. [self setTitleLabelText:NSLocalizedString(@"my_set_no_video_upload",nil)];
  735. }
  736. }
  737. - (void)viewWillAppear:(BOOL)animated
  738. {
  739. [super viewWillAppear:animated];
  740. }
  741. - (void)viewDidAppear:(BOOL)animated{
  742. [super viewDidAppear:animated];
  743. [self showDownloadTipFun];
  744. [self checkFileTransferTask];
  745. if(!_curNASFilePicModel){
  746. [self getFileListFun:NO];
  747. }
  748. }
  749. - (void)viewWillDisappear:(BOOL)animated{
  750. [super viewWillDisappear:animated];
  751. //[self removeNewIndicator];
  752. [self removeNewIndicatorHaveStr];
  753. }
  754. - (void)gotoDownloadloadFileRecordFun
  755. {
  756. uploadFileRecordViewController *vc = [uploadFileRecordViewController new];
  757. [self.navigationController pushViewController:vc animated:YES];
  758. vc.isDownloadingType = YES;
  759. //[vc gotoDownloadFile:_downloadFileBottomV.indexPathsForSelectedItems];
  760. }
  761. - (void)showDownloadTipFun
  762. {
  763. BOOL didReadUploadTipType = [HWDataManager getBoolWithKey:Const_file_downLoad_need_read];
  764. if(didReadUploadTipType){
  765. return;
  766. }
  767. //KWeakSelf
  768. /*弹窗提示恢复出厂*/
  769. ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:nil
  770. msg:NSLocalizedString(@"upload_download_need_read_msg",nil)
  771. imageStr:nil
  772. cancelTitle:NSLocalizedString(@"guide_set_pwd_guide_know",nil)
  773. okTitle:nil
  774. isOkBtnHighlight:NO
  775. didClickOk:^{
  776. } didClickCancel:^{
  777. [HWDataManager setBoolWithKey:Const_file_downLoad_need_read value:YES];
  778. }];
  779. nextVC.modalPresentationStyle = UIModalPresentationCustom;
  780. [self presentViewController:nextVC animated:YES completion:^{
  781. nextVC.view.superview.backgroundColor = [UIColor clearColor];
  782. }];
  783. }
  784. - (void)checkFileTransferTask
  785. {//有个偶现的闪退在BGFMDB
  786. [[nasUploadFileManager shareInstance] checkHadUploadTaskWithComplete:^(BOOL isSuccess) {
  787. self->hadUploadTaskType = isSuccess;
  788. [self setRightButtonRedTypeFun];
  789. }];
  790. KWeakSelf
  791. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  792. [[nasDownloadFileManager shareInstance] checkHadDownloadTaskWithComplete:^(BOOL isSuccess) {
  793. self->hadDownloadTaskType = isSuccess;
  794. [weakSelf setRightButtonRedTypeFun];
  795. }];
  796. });
  797. }
  798. - (void)setRightButtonRedTypeFun
  799. {
  800. mainBlock(^{
  801. if(self->hadUploadTaskType || self->hadDownloadTaskType){
  802. self->rightRedView.hidden = NO;
  803. }
  804. else{
  805. self->rightRedView.hidden = YES;
  806. }
  807. });
  808. }
  809. - (void)didiClikRightButGotoTransferListFun:(UIButton*)but
  810. {
  811. uploadFileRecordViewController *vc = [uploadFileRecordViewController new];
  812. [self.navigationController pushViewController:vc animated:YES];
  813. }
  814. #pragma mark 获取文件数据
  815. - (void)getFileListFun:(BOOL)isMoreDataType
  816. {
  817. NSMutableDictionary*paraDict = [NSMutableDictionary new];
  818. if(_isPhotoType){
  819. [paraDict setValue:@"pic" forKey:@"type"];
  820. }
  821. else{
  822. [paraDict setValue:@"video" forKey:@"type"];
  823. }
  824. // if(!isMoreDataType){
  825. // self.pageIndex = 0;
  826. // }
  827. // else{
  828. // self.pageIndex ++;
  829. // }
  830. //
  831. // [paraDict setValue:[NSNumber numberWithInteger:self.pageIndex] forKey:@"index"];
  832. // [paraDict setValue:[NSNumber numberWithInteger:pageSizeNum] forKey:@"pageSize"];
  833. NSArray *diskNameArr = [_defaultDiskPath componentsSeparatedByString:@"/"];
  834. if(diskNameArr && diskNameArr.count >= 2){
  835. NSString *name = diskNameArr.lastObject;
  836. if(name.length == 0)
  837. {
  838. name = diskNameArr[diskNameArr.count -2];
  839. }
  840. [paraDict setValue:name forKey:@"path"];
  841. }
  842. [self showNewIndicatorHaveStrWithCanBack:YES canTouch:NO showText:NSLocalizedString(@"common_loading_tip",nil)];
  843. KWeakSelf
  844. [[netWorkManager shareInstance] cloudPhoneGETCallBackCode:@"getFileListByDay" Parameters:paraDict success:^(id _Nonnull responseObject) {
  845. //[weakSelf.dataCollectionView.mj_footer endRefreshing];
  846. [weakSelf removeNewIndicatorHaveStr];
  847. NASFilePicModel*NASFilePicMod = [[NASFilePicModel alloc] initWithDictionary:responseObject error:nil];
  848. //数据缓存
  849. if(NASFilePicMod && NASFilePicMod.status == 0){
  850. NSString *key = stringKeyAddSn(@"getFileListByDay");
  851. [HWDataManager setObjectWithKey:key value:responseObject];
  852. }
  853. // if(NASFilePicMod.data.fileList.count < pageSizeNum){
  854. // [weakSelf.dataCollectionView.mj_footer endRefreshingWithNoMoreData];
  855. // }
  856. [weakSelf filterDataFun:NASFilePicMod];
  857. [weakSelf.dataCollectionView reloadData];
  858. } failure:^(NSError * _Nonnull error) {
  859. [weakSelf removeNewIndicatorHaveStr];
  860. //[weakSelf.dataCollectionView.mj_footer endRefreshing];
  861. if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable)
  862. {
  863. [[iToast makeText:NSLocalizedString(@"phone_network_fail_Tips",nil)] show];
  864. }
  865. else{
  866. [[iToast makeText:NSLocalizedString(@"netWork_error_show_tip",nil)] show];
  867. }
  868. }];
  869. }
  870. #pragma mark 上拉或者点击更多数据
  871. - (void)getMoreNetWorkData
  872. {
  873. [self getFileListFun:YES];
  874. }
  875. #pragma mark 20230528需求:图片/视频模块,限制50KB以下文件展示;
  876. - (void)filterDataFun:(NASFilePicModel*)NASFilePicMod
  877. {
  878. if(!NASFilePicMod) return;
  879. for (NASFilePicTimeArrModel *timeArrModel in NASFilePicMod.data.fileList) {
  880. NSMutableArray *afterFilterArr = [NSMutableArray new];
  881. for (NASFilePicDataArrModel * dataModel in timeArrModel.list) {
  882. if (dataModel.size > 20*1024) {
  883. [afterFilterArr addObject:dataModel];
  884. }
  885. }
  886. timeArrModel.list = (NSArray<NASFilePicDataArrModel>*)afterFilterArr;
  887. }
  888. //2.检测是否有空数据组 有则去掉
  889. NSMutableArray *newFilterArr = [NSMutableArray new];
  890. for (NASFilePicTimeArrModel *timeArrModel in NASFilePicMod.data.fileList) {
  891. if(timeArrModel.list.count > 0){
  892. [newFilterArr addObject:timeArrModel];
  893. }
  894. }
  895. NASFilePicMod.data.fileList = (NSArray<NASFilePicTimeArrModel>*)newFilterArr;
  896. [self handelNetDataAfterFilterDataBy:NASFilePicMod];
  897. }
  898. #pragma mark 分页数据组装
  899. - (void)handelNetDataAfterFilterDataBy:(NASFilePicModel*)NASFilePicMod
  900. {
  901. NSMutableArray *handelDataArr = [NSMutableArray new];
  902. if(_curNASFilePicModel && _curNASFilePicModel.data && _curNASFilePicModel.data.fileList){
  903. [handelDataArr addObjectsFromArray:_curNASFilePicModel.data.fileList];
  904. }
  905. else{
  906. _curNASFilePicModel = [NASFilePicModel new];
  907. _curNASFilePicModel.data = [NASFilePicSecondModel new];
  908. }
  909. //数据处理
  910. for (NASFilePicTimeArrModel *timeArrModel in NASFilePicMod.data.fileList) {
  911. NSString *dataTimeStr = timeArrModel.time;
  912. if(timeArrModel.list > 0){//只处理有数据的 (数据可能被过滤掉)
  913. //全选的时候新加的也选上
  914. BOOL didAddTimeType = NO;//此日期是否存在在数据里面了
  915. for (NASFilePicTimeArrModel *preTimeArrModel in handelDataArr) {
  916. NSString *preDataTimeStr = preTimeArrModel.time;
  917. if([dataTimeStr isEqualToString:preDataTimeStr]){
  918. didAddTimeType = YES;
  919. NSMutableArray *afterHandelArr = [NSMutableArray new];
  920. //1.原来数据
  921. [afterHandelArr addObjectsFromArray:preTimeArrModel.list];
  922. //2.追加新的数据
  923. [afterHandelArr addObjectsFromArray:timeArrModel.list];
  924. preTimeArrModel.list = (NSArray<NASFilePicDataArrModel>*)afterHandelArr;
  925. break;
  926. }
  927. }
  928. //添加新日期数据
  929. if(!didAddTimeType){
  930. [handelDataArr addObject:timeArrModel];
  931. }
  932. }
  933. }
  934. _curNASFilePicModel.data.fileList = (NSArray<NASFilePicTimeArrModel> *)handelDataArr;
  935. // if(handelDataArr.count == 0 ){
  936. // _dataCollectionView.mj_footer.hidden = YES;
  937. // }
  938. // else{
  939. // _dataCollectionView.mj_footer.hidden = NO;
  940. // }
  941. }
  942. #pragma mark 点击图片详情
  943. - (void)didClickPicDetailsWithSection:(NSInteger)section withRow:(NSInteger)row{
  944. if(_curNASFilePicModel){
  945. NSMutableArray *totalArr = [NSMutableArray new];
  946. NSInteger index = 0;
  947. for (int i=0; i<_curNASFilePicModel.data.fileList.count; i++) {
  948. NASFilePicTimeArrModel *timeModel = _curNASFilePicModel.data.fileList[i];
  949. if(i == section){
  950. index = totalArr.count + row;
  951. }
  952. [totalArr addObjectsFromArray:timeModel.list];
  953. }
  954. imageDetailsScrollViewController *vc = [imageDetailsScrollViewController new];
  955. vc.index = index;
  956. vc.totalDataArr = totalArr;
  957. [self.navigationController pushViewController:vc animated:YES];
  958. vc.canShareType = canShareType;
  959. KWeakSelf
  960. vc.didNeedDeleteFile = ^(NSString * _Nonnull filePath) {
  961. [weakSelf deleteNetDataByFilePath:filePath];
  962. };
  963. }
  964. }
  965. - (void)gotoDownLoadFileFun
  966. {
  967. if(_didSelectListArr.count == 0){
  968. [[iToast makeText:@""] show];
  969. return;
  970. }
  971. NSMutableArray *arr = [NSMutableArray new];
  972. for (NASFilePicDataArrModel *dataModel in _didSelectListArr) {
  973. couldPhoneFileModel* fileModel = [couldPhoneFileModel new];
  974. // if(_isPhotoType){
  975. // fileModel.fileType = @".jpg";
  976. // }
  977. // else{
  978. // fileModel.fileType = @"video";
  979. // }
  980. fileModel.fileType = dataModel.type;
  981. fileModel.path = dataModel.path;
  982. fileModel.name = dataModel.name;
  983. fileModel.length = dataModel.size;
  984. fileModel.time = dataModel.duration;
  985. [arr addObject:fileModel];
  986. }
  987. uploadFileRecordViewController *vc = [uploadFileRecordViewController new];
  988. [self.navigationController pushViewController:vc animated:YES];
  989. vc.isDownloadingType = YES;
  990. [vc gotoDownloadFile:arr];
  991. }
  992. - (void)setIsPhotoType:(BOOL)isPhotoType
  993. {
  994. _isPhotoType = isPhotoType;
  995. [self queryShareSwitchFunFun];
  996. }
  997. #pragma mark 获取分享开关
  998. -(void)queryShareSwitchFunFun
  999. {
  1000. NSMutableDictionary *paraDict = [NSMutableDictionary new];
  1001. if(_isPhotoType){
  1002. [paraDict setValue:@2 forKey:@"type"];
  1003. }
  1004. else{
  1005. [paraDict setValue:@3 forKey:@"type"];
  1006. }
  1007. KWeakSelf
  1008. [[netWorkManager shareInstance] CommonGetWithCallBackCode:queryShareSwitchFun Parameters:paraDict success:^(id _Nonnull responseObject){
  1009. queryShareModel *queryShareMod = [[queryShareModel alloc] initWithDictionary:responseObject error:nil];
  1010. if(queryShareMod){
  1011. self->canShareType = queryShareMod.data.configValue;
  1012. [weakSelf.curEditTypeBottomView setCanShaewFunBy:queryShareMod.data.configValue];
  1013. }
  1014. } failure:^(NSError * _Nonnull error) {
  1015. }];
  1016. }
  1017. #pragma mark 调整文件上传
  1018. - (void)gotoUploadFileFunWith:(NSInteger)tag
  1019. {
  1020. if(tag == 10 || tag == 11){
  1021. uploadImageOrVideoViewController *vc = [uploadImageOrVideoViewController new];
  1022. if(tag ==10){
  1023. vc.isPhotoType = YES;
  1024. }
  1025. else{
  1026. vc.isPhotoType = NO;
  1027. }
  1028. [self.navigationController pushViewController:vc animated:YES];
  1029. }
  1030. else{
  1031. KWeakSelf
  1032. [[DocumentPickerManager shareManager] openDocumentPickerSuccess:^(NSArray * _Nonnull urls) {
  1033. [weakSelf gotoUploadFileRecordByFileAppWithUrls:urls];
  1034. }];
  1035. }
  1036. }
  1037. #pragma mark 删除图片
  1038. - (void)showDeleteAlearViewFun
  1039. {
  1040. NSString *titleStr = NSLocalizedString(@"delete_file_title_msg",nil);
  1041. NSString *tipStr = NSLocalizedString(@"delete_file_tip_msg",nil);
  1042. KWeakSelf
  1043. ComontAlretViewController *curAlretVC= [[ComontAlretViewController alloc] initWithTiTle:titleStr
  1044. msg:tipStr
  1045. imageStr:nil
  1046. cancelTitle:NSLocalizedString(@"other_cancel",nil)
  1047. okTitle:NSLocalizedString(@"other_confirm",nil) isOkBtnHighlight:YES
  1048. didClickOk:^{
  1049. [weakSelf delFileListFun];
  1050. } didClickCancel:^{
  1051. }];
  1052. curAlretVC.modalPresentationStyle = UIModalPresentationCustom;
  1053. [self presentViewController:curAlretVC animated:YES completion:^{
  1054. curAlretVC.view.superview.backgroundColor = [UIColor clearColor];
  1055. }];
  1056. }
  1057. #pragma mark 删除文件数据
  1058. - (void)delFileListFun
  1059. {
  1060. NSMutableDictionary*paraDict = [NSMutableDictionary new];
  1061. NSMutableArray *pathArr = [NSMutableArray new];
  1062. for (NASFilePicDataArrModel *dataModel in _didSelectListArr) {
  1063. [pathArr addObject:dataModel.path];
  1064. }
  1065. [paraDict setValue:pathArr forKey:@"path"];
  1066. [self showNewIndicatorWithCanBack:YES canTouch:NO];
  1067. //NSString*code = [[NSString alloc] initWithFormat:@"delFile?path=%@",paraDict[@"path"]]; //delFile?path=[/storage/emulated/0/Download/IMG_6464.HEIC]
  1068. KWeakSelf //@"delFile"
  1069. [[netWorkManager shareInstance] cloudPhonePostCallBackCode:@"delFile" Parameters:paraDict success:^(id _Nonnull responseObject) {
  1070. [weakSelf removeNewIndicator];
  1071. SuperModel *model = [[SuperModel alloc] initWithDictionary:responseObject error:nil];
  1072. if(model && model.status == 0){
  1073. [[iToast makeText:NSLocalizedString(@"delete_file_suc_msg",nil)] show];
  1074. [weakSelf didDeleteSucFun];
  1075. }
  1076. else{
  1077. }
  1078. } failure:^(NSError * _Nonnull error) {
  1079. [weakSelf removeNewIndicator];
  1080. }];
  1081. //数据埋点
  1082. [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"Image_delete"];
  1083. }
  1084. #pragma mark 删除成功
  1085. - (void)didDeleteSucFun
  1086. {
  1087. //1.删除最近文件
  1088. for (NASFilePicDataArrModel *dataModel in _didSelectListArr) {
  1089. [[lastFileManager shareManager] deleteFileInfoWithUrl:dataModel.path];
  1090. }
  1091. //2.删除已经获取到的网络数据
  1092. [self deleteNetDataByDeleteSucFun];
  1093. [_didSelectListArr removeAllObjects];
  1094. [self setEditTypeTitleFun];
  1095. }
  1096. #pragma mark 删除成功后 对应删除原来获取的网络数据
  1097. - (void)deleteNetDataByDeleteSucFun
  1098. {
  1099. //1.先删除数据
  1100. for (NASFilePicTimeArrModel *timeArrModel in _curNASFilePicModel.data.fileList) {
  1101. NSMutableArray *afterFilterArr = [NSMutableArray new];
  1102. for (NASFilePicDataArrModel * dataModel in timeArrModel.list) {
  1103. if (!dataModel.isSelectType) {
  1104. [afterFilterArr addObject:dataModel];
  1105. }
  1106. }
  1107. timeArrModel.list = (NSArray<NASFilePicDataArrModel>*)afterFilterArr;
  1108. }
  1109. //2.检测是否有空数据组 有则去掉
  1110. NSMutableArray *newFilterArr = [NSMutableArray new];
  1111. for (NASFilePicTimeArrModel *timeArrModel in _curNASFilePicModel.data.fileList) {
  1112. if(timeArrModel.list.count > 0){
  1113. [newFilterArr addObject:timeArrModel];
  1114. }
  1115. }
  1116. _curNASFilePicModel.data.fileList = (NSArray<NASFilePicTimeArrModel>*)newFilterArr;
  1117. [self.dataCollectionView reloadData];
  1118. }
  1119. #pragma mark 图片详情删除成功后 对应删除原来获取的网络数据
  1120. - (void)deleteNetDataByFilePath:(NSString*)filePath
  1121. {
  1122. if(!filePath || filePath.length == 0){
  1123. return;
  1124. }
  1125. //BOOL didFineFile = NO;
  1126. for (NASFilePicTimeArrModel *timeArrModel in _curNASFilePicModel.data.fileList) {
  1127. NSMutableArray *afterFilterArr = [NSMutableArray new];
  1128. for (NASFilePicDataArrModel * dataModel in timeArrModel.list) {
  1129. if(![dataModel.path isEqualToString:filePath]){
  1130. [afterFilterArr addObject:dataModel];
  1131. }
  1132. else{
  1133. // didFineFile = YES;
  1134. // break;
  1135. }
  1136. }
  1137. timeArrModel.list = (NSArray<NASFilePicDataArrModel>*)afterFilterArr;
  1138. // if(didFineFile){
  1139. // break;
  1140. // }
  1141. }
  1142. [self.dataCollectionView reloadData];
  1143. }
  1144. #pragma mark 点击了搜索
  1145. - (void)gotoSearchVCFun
  1146. {
  1147. NasSearchViewController *vc = [NasSearchViewController new];
  1148. vc.fileType = @"jpg";
  1149. [self.navigationController pushViewController:vc animated:YES];
  1150. }
  1151. #pragma mark 文件上传跳转上传记录
  1152. - (void)gotoUploadFileRecordByFileAppWithUrls:(NSArray*)urls
  1153. {
  1154. uploadFileRecordViewController *vc = [uploadFileRecordViewController new];
  1155. [self.navigationController pushViewController:vc animated:YES];
  1156. vc.isUploadingType = YES;
  1157. [vc gotoUploadFileByFileApp:urls];
  1158. }
  1159. @end