previewImageOrVideoViewController.m 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135
  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 "downloadThumbnailManager.h"
  10. #import "downloadManager.h"
  11. #import "uploadFileRecordViewController.h"
  12. #import "UIScrollView+EmptyDataSet.h"
  13. #import "diskListBgView.h"
  14. #import "diskListTableView.h"
  15. #import "imageCollectionViewCell.h"
  16. #import "titleLabelReusableView.h"
  17. #import "editTypeHeadView.h"
  18. #import "editTypeBottomView.h"
  19. #import "editShareView.h"
  20. #import "previewToUploadFileView.h"
  21. #import "NASFilePicModel.h"
  22. #import "imageDetailsScrollViewController.h"
  23. #import "queryShareModel.h"
  24. #import "videoPlayViewController.h"
  25. #import "videoPlayByAVPlayerViewController.h"
  26. @interface previewImageOrVideoViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>
  27. {
  28. UIButton *tapBtn;
  29. UIButton* rightTransferListButton;//传输列表
  30. UIView* rightRedView;
  31. BOOL hadUploadTaskType;
  32. BOOL hadDownloadTaskType;
  33. BOOL canShareType;
  34. }
  35. @property (nonatomic, strong) UICollectionView *dataCollectionView;
  36. @property (strong, nonatomic) UILabel *MytitleLabel;
  37. @property (strong, nonatomic) UIImageView *selectTip;
  38. @property (nonatomic, strong) diskListBgView *diskListBgV;
  39. @property (nonatomic, strong) diskListTableView *diskListTableV;
  40. @property (nonatomic, strong) NSMutableArray*diskListArr;
  41. @property (nonatomic, copy) NSString *defaultDiskPath;
  42. @property(nonatomic,assign) BOOL isEditType;
  43. @property(nonatomic,strong) editTypeHeadView*curEditTypeHeadView;
  44. @property(nonatomic,strong) editTypeBottomView*curEditTypeBottomView;
  45. @property(nonatomic,strong) UIButton*uploadFileButton;
  46. //@property(nonatomic,strong) couldPhoneFileListModel *curCouldPhoneFileListMod;
  47. @property(nonatomic,strong) NASFilePicModel *curNASFilePicModel;
  48. @property (nonatomic, strong) NSMutableArray*didSelectListArr;//选中的数据
  49. @end
  50. @implementation previewImageOrVideoViewController
  51. - (void)viewDidLoad {
  52. [super viewDidLoad];
  53. // Do any additional setup after loading the view.
  54. [self.toolBar setHidden:YES];
  55. [self.navigationBar setHidden:YES];
  56. [self.navBarBGView setHidden:NO];
  57. self.navBarBGView.backgroundColor = [UIColor whiteColor];
  58. [self.view setBackgroundColor:[UIColor whiteColor]];
  59. [self drawAnyView];
  60. _didSelectListArr = [NSMutableArray new];
  61. }
  62. - (void)drawAnyView{
  63. [self initNavHeadUIFun];
  64. _curEditTypeHeadView = [[editTypeHeadView alloc] init];
  65. _curEditTypeHeadView.hidden = YES;
  66. [self.navBarBGView addSubview:_curEditTypeHeadView];
  67. [_curEditTypeHeadView mas_makeConstraints:^(MASConstraintMaker *make) {
  68. make.left.mas_equalTo(0);
  69. make.right.mas_equalTo(0);
  70. make.bottom.mas_equalTo(0);
  71. make.height.mas_equalTo(NAVIHEIGHT - AdaptNaviHeight);
  72. }];
  73. #pragma mark 编辑状态的 取消 和全选按钮 响应事件
  74. KWeakSelf
  75. _curEditTypeHeadView.didClickButtonFun = ^(NSInteger tag) {
  76. if(tag==1){
  77. [weakSelf userCancelEditTypeFun];
  78. }
  79. };
  80. _curEditTypeHeadView.didClickSelectAllFun = ^(UIButton * _Nonnull but) {
  81. [weakSelf didClickSelectAllButton:but];
  82. };
  83. _curEditTypeBottomView = [[editTypeBottomView alloc] init];
  84. _curEditTypeBottomView.hidden = YES;
  85. [self.view addSubview:_curEditTypeBottomView];
  86. [_curEditTypeBottomView mas_makeConstraints:^(MASConstraintMaker *make) {
  87. make.left.mas_equalTo(0);
  88. make.right.mas_equalTo(0);
  89. make.bottom.mas_equalTo(0);
  90. make.height.mas_equalTo(60 + AdaptTabHeight);
  91. }];
  92. #pragma mark 编辑状态的 下载 分享 删除 响应事件
  93. _curEditTypeBottomView.didClickButtonFun = ^(NSInteger tag) {
  94. if(tag==1){
  95. [weakSelf gotoDownLoadFileFun];
  96. }
  97. else if(tag==2){
  98. [weakSelf gotoShareViewFun];
  99. }
  100. else if(tag==3){
  101. [weakSelf showDeleteAlearViewFun];
  102. }
  103. };
  104. [self.view addSubview:self.dataCollectionView];
  105. [self.dataCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  106. make.left.mas_equalTo(0);
  107. make.right.mas_equalTo(0);
  108. //make.bottom.mas_equalTo(-(safeArea));
  109. make.bottom.mas_equalTo(0);
  110. make.top.equalTo(self.navBarBGView.mas_bottom).offset(10.f);
  111. }];
  112. //大+号
  113. _uploadFileButton = [[UIButton alloc] init];
  114. [_uploadFileButton setBackgroundImage:[UIImage imageNamed:@"add_file_icon"] forState:UIControlStateNormal];
  115. [_uploadFileButton addTarget:self action:@selector(userDidClickUploadViewFun) forControlEvents:UIControlEventTouchUpInside];
  116. [self.view addSubview:_uploadFileButton];
  117. [_uploadFileButton mas_makeConstraints:^(MASConstraintMaker *make) {
  118. make.right.mas_equalTo(-15);
  119. make.width.mas_equalTo(52);
  120. make.height.mas_equalTo(52);
  121. make.bottom.mas_equalTo(-30 - AdaptTabHeight);
  122. }];
  123. NSMutableArray *arr = [NSMutableArray new];
  124. NSArray *diskList = ksharedAppDelegate.cloudPhoneExtraFileListMod.data;
  125. if(diskList && [diskList isKindOfClass:[NSArray class]]){
  126. for (cloudPhoneExtraFileModel *model in diskList) {
  127. model.isCheckType = NO;
  128. [arr addObject:model];
  129. }
  130. }
  131. if(arr.count >0){
  132. cloudPhoneExtraFileModel *model = arr.firstObject;
  133. model.isCheckType = YES;
  134. _defaultDiskPath = model.extraPath;
  135. }
  136. _diskListArr = arr;
  137. [self setTitleAfterGetdiskFun];
  138. }
  139. - (void)initNavHeadUIFun
  140. {
  141. //title
  142. UILabel *titleLabel = [[UILabel alloc] init];
  143. titleLabel.textAlignment = NSTextAlignmentCenter;
  144. titleLabel.font = [UIFont boldSystemFontOfSize:16.0];
  145. titleLabel.textColor = [UIColor blackColor];
  146. titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
  147. [self.navBarBGView addSubview:titleLabel];
  148. self.MytitleLabel = titleLabel;
  149. //selectTipImageView
  150. UIImageView *selectTip = [[UIImageView alloc] init];
  151. selectTip.image = [UIImage imageNamed:@"upload_image_arrow"];
  152. selectTip.translatesAutoresizingMaskIntoConstraints = NO;
  153. [self.navBarBGView addSubview:selectTip];
  154. self.selectTip = selectTip;
  155. tapBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  156. tapBtn.backgroundColor = [UIColor clearColor];
  157. tapBtn.translatesAutoresizingMaskIntoConstraints = NO;
  158. [tapBtn addTarget:self action:@selector(selectDiskAction:) forControlEvents:UIControlEventTouchUpInside];
  159. [self.navBarBGView addSubview:tapBtn];
  160. [tapBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  161. make.centerX.mas_equalTo(self.navBarBGView.mas_centerX);
  162. make.centerY.mas_equalTo(self.backBtn.mas_centerY);
  163. make.width.mas_equalTo(100);
  164. make.height.mas_equalTo(30);
  165. }];
  166. [self setTitleLabelText:@""];
  167. rightTransferListButton = [[UIButton alloc] init];
  168. [rightTransferListButton setImage:[UIImage imageNamed:@"icon_file_transfer"] forState:UIControlStateNormal];
  169. [rightTransferListButton addTarget:self action:@selector(didiClikRightButGotoTransferListFun:) forControlEvents:UIControlEventTouchUpInside];
  170. [self.navBarBGView addSubview:rightTransferListButton];
  171. [rightTransferListButton mas_makeConstraints:^(MASConstraintMaker *make) {
  172. make.width.mas_equalTo(40);
  173. make.height.mas_equalTo(40);
  174. make.right.mas_equalTo(-15);
  175. make.centerY.mas_equalTo(self.titleLabel.mas_centerY);
  176. }];
  177. rightRedView = [[UIView alloc] init];
  178. rightRedView.backgroundColor = [UIColor hwColor:@"#DD4E4E" alpha:1.0];
  179. [rightTransferListButton addSubview:rightRedView];
  180. rightRedView.layer.cornerRadius = 7;
  181. rightRedView.hidden = YES;
  182. [rightRedView mas_makeConstraints:^(MASConstraintMaker *make) {
  183. make.width.mas_equalTo(14);
  184. make.height.mas_equalTo(14);
  185. make.right.mas_equalTo(0);
  186. make.top.mas_equalTo(6);
  187. }];
  188. }
  189. #pragma mark - 懒加载
  190. - (UICollectionView *)dataCollectionView{
  191. if (!_dataCollectionView) {
  192. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  193. // 设置item的行间距和列间距
  194. layout.minimumInteritemSpacing = 1;
  195. layout.minimumLineSpacing = 1;
  196. // 设置item的大小
  197. CGFloat itemW = ([UIScreen mainScreen].bounds.size.width - 10) /4 ;
  198. layout.itemSize = CGSizeMake(itemW, itemW);
  199. layout.headerReferenceSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, 40);
  200. //layout.footerReferenceSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, 40);
  201. // 设置每个分区的 上左下右 的内边距
  202. layout.sectionInset = UIEdgeInsetsMake(1, 1 ,1, 1);
  203. // 设置区头和区尾的大小
  204. layout.headerReferenceSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, 10);
  205. //layout.footerReferenceSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, 10);
  206. // 设置分区的头视图和尾视图 是否始终固定在屏幕上边和下边
  207. layout.sectionFootersPinToVisibleBounds = YES;
  208. //设置滚动条方向
  209. layout.scrollDirection = UICollectionViewScrollDirectionVertical;
  210. _dataCollectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:layout];
  211. _dataCollectionView.backgroundColor = [UIColor whiteColor];
  212. _dataCollectionView.scrollEnabled = YES;
  213. //注册cell
  214. [_dataCollectionView registerClass:[imageCollectionViewCell class] forCellWithReuseIdentifier:@"imageCollectionViewCell"];
  215. [_dataCollectionView registerClass:[titleLabelReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"titleLabelReusableView"];
  216. _dataCollectionView.delegate = self;
  217. _dataCollectionView.dataSource = self;
  218. //空数据引入第三方开源处理
  219. _dataCollectionView.emptyDataSetSource = self;
  220. _dataCollectionView.emptyDataSetDelegate = self;
  221. }
  222. return _dataCollectionView;
  223. }
  224. - (diskListBgView*)diskListBgV
  225. {
  226. if(!_diskListBgV){
  227. _diskListBgV = [[diskListBgView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
  228. _diskListBgV.hidden = YES;
  229. [self.view addSubview:_diskListBgV];
  230. KWeakSelf
  231. _diskListBgV.didTapWhitePlace = ^{
  232. [weakSelf hideDiskListVieFun];
  233. };
  234. [_diskListBgV mas_makeConstraints:^(MASConstraintMaker *make) {
  235. make.left.mas_equalTo(0);
  236. make.bottom.mas_equalTo(0);
  237. make.right.mas_equalTo(0);
  238. make.top.mas_equalTo(self.navBarBGView.mas_bottom);
  239. }];
  240. [self.view addSubview:self.diskListTableV];
  241. self.diskListTableV.hidden = YES;
  242. [self.diskListTableV mas_makeConstraints:^(MASConstraintMaker *make) {
  243. make.left.mas_equalTo(0);
  244. make.height.mas_equalTo(3*70);
  245. make.right.mas_equalTo(0);
  246. make.top.mas_equalTo(self.navBarBGView.mas_bottom);
  247. }];
  248. self.diskListTableV.diskListArr = _diskListArr;
  249. self.diskListTableV.didClickDiskModel = ^(NSString * _Nonnull checkPath) {
  250. [weakSelf didCheckDiskFunByPath:checkPath];
  251. };
  252. }
  253. return _diskListBgV;
  254. }
  255. - (UITableView *)diskListTableV{
  256. if (!_diskListTableV) {
  257. _diskListTableV = [[diskListTableView alloc] init];
  258. //
  259. }
  260. return _diskListTableV;
  261. }
  262. #pragma mark 选中磁盘
  263. - (void)didCheckDiskFunByPath:(NSString*)pathStr
  264. {
  265. if(self.defaultDiskPath
  266. && self.defaultDiskPath.length>0
  267. && ![self.defaultDiskPath isEqualToString:pathStr]){
  268. //切换硬盘了 取消全选
  269. [_didSelectListArr removeAllObjects];
  270. }
  271. self.defaultDiskPath = pathStr;
  272. [self getFileListFun];
  273. [self setTitleAfterGetdiskFun];
  274. [self hideDiskListVieFun];
  275. }
  276. #pragma mark - 瀑布流委托
  277. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  278. if(_curNASFilePicModel){
  279. return _curNASFilePicModel.data.fileList.count;
  280. }
  281. return 1;
  282. }
  283. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  284. if(_curNASFilePicModel && _curNASFilePicModel.data.fileList.count >section){
  285. NASFilePicTimeArrModel *timeArrModel = _curNASFilePicModel.data.fileList[section];
  286. return timeArrModel.list.count;
  287. }
  288. return 0;
  289. }
  290. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  291. {
  292. __block NSInteger row = indexPath.row;
  293. __block NSInteger section = indexPath.section;
  294. //创建item 从缓存池中拿 Item
  295. imageCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"imageCollectionViewCell" forIndexPath:indexPath];
  296. if(!cell){
  297. cell = [[imageCollectionViewCell alloc] init];
  298. }
  299. if(_curNASFilePicModel && _curNASFilePicModel.data.fileList.count > section){
  300. NASFilePicTimeArrModel *timeArrModel = _curNASFilePicModel.data.fileList[section];
  301. if (timeArrModel.list.count > row) {
  302. NASFilePicDataArrModel * dataModel = timeArrModel.list[row];
  303. cell.isEditType = _isEditType;
  304. if(_isPhotoType){
  305. cell.fileType = @"pic";
  306. }
  307. else{
  308. cell.fileType = @"video";
  309. }
  310. cell.curFileModel = dataModel;
  311. KWeakSelf
  312. cell.didClckSelectBut = ^(BOOL selectType){
  313. if([weakSelf userCheckFileModel:dataModel withShowTip:YES]){
  314. [weakSelf userCheckFilePreviewByRow:row withSection:section];
  315. }
  316. };
  317. cell.didClickEditType = ^(BOOL editType) {
  318. [weakSelf setViewEditTypeFun];
  319. };
  320. }
  321. }
  322. return cell;
  323. }
  324. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
  325. if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
  326. NSInteger section = indexPath.section;
  327. titleLabelReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"titleLabelReusableView" forIndexPath:indexPath];
  328. if(_curNASFilePicModel && _curNASFilePicModel.data.fileList.count > section){
  329. NASFilePicTimeArrModel *timeArrModel = _curNASFilePicModel.data.fileList[section];
  330. headerView.titlelabel.text = timeArrModel.time;
  331. }
  332. return headerView;
  333. }
  334. return nil;
  335. }
  336. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
  337. return CGSizeMake([UIScreen mainScreen].bounds.size.width, 40);
  338. }
  339. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  340. {
  341. NSInteger row = indexPath.row;
  342. NSInteger section = indexPath.section;
  343. if(_curNASFilePicModel && _curNASFilePicModel.data.fileList.count > section){
  344. NASFilePicTimeArrModel *timeArrModel = _curNASFilePicModel.data.fileList[section];
  345. if (timeArrModel.list.count > row) {
  346. //NASFilePicDataArrModel * dataModel = timeArrModel.list[row];
  347. if(_isPhotoType){
  348. [self didClickPicDetailsWithSection:section withRow:row];
  349. }
  350. else{
  351. [self didClickVideoWithSection:section withRow:row];
  352. }
  353. }
  354. }
  355. }
  356. #pragma mark 空数据
  357. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
  358. NSString *imageName = @"common_no_data_pic";
  359. return [UIImage imageNamed:imageName];
  360. }
  361. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {
  362. NSString *text = NSLocalizedString(@"common_no_data_tip",nil);
  363. NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:16.0f],
  364. NSForegroundColorAttributeName: HW999999Color};
  365. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  366. }
  367. //调整图片位置
  368. - (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView {
  369. return -150;
  370. }
  371. //ios端:
  372. //1、需求说明:解决除MP4 MOV 3GP M4V 总计4种格式外,其他格式下载失败的问题;
  373. //2、交互说明:下载列表勾选文件中含有其他格式,toast提示“IOS系统仅支持MP4、MOV、3GP、M4V 的视频格式,其他格式无法下载”。点击下载按钮,过滤其他格式文件,仅下载MP4、MOV、3GP、M4V 的视频格式文件;
  374. //ios支持图片格式: (SVG 不支持)
  375. //需求说明:解决除JPG PNG GIF TIFF BMP总计5种格式外,其他格式下载失败的问题
  376. //视觉交互:选择文件中含有其他格式,toast提示“IOS系统仅支持JPG 、PNG、GIF、TIFF、BMP的图片格式,其他格式无法下载”。点击下载按钮,过滤其他格式文件,仅下载JPG 、PNG、GIF、TIFF、BMP的图片格式文件;
  377. - (BOOL)userCheckFileModel:(NASFilePicDataArrModel*)fileModel withShowTip:(BOOL)canShow{
  378. // NSString*name = [fileModel.name lowercaseString];
  379. // NSArray *nameArr = [name componentsSeparatedByString:@"."];
  380. // if(nameArr.count >0 && !_isPhotoType){
  381. // BOOL canDownLoadType = NO;
  382. //
  383. // NSString *lastName = nameArr.lastObject;
  384. // if([lastName isEqualToString:@"mp4"]
  385. // ||[lastName isEqualToString:@"mov"]
  386. // ||[lastName isEqualToString:@"3gp"]
  387. // ||[lastName isEqualToString:@"m4v"]){
  388. // canDownLoadType = YES;
  389. // }
  390. //
  391. // if(!canDownLoadType){
  392. // if(canShow){
  393. // [[iToast makeText:NSLocalizedString(@"download_video_disable_state",nil)] show];
  394. // }
  395. //
  396. // return NO;
  397. // }
  398. // }
  399. //
  400. // if(nameArr.count >0 && _isPhotoType){
  401. // BOOL canDownLoadType = NO;
  402. // //JPG 、PNG、GIF、TIFF、BMP
  403. // NSString *lastName = nameArr.lastObject;
  404. // if([lastName isEqualToString:@"jpg"]
  405. // ||[lastName isEqualToString:@"png"]
  406. // ||[lastName isEqualToString:@"gif"]
  407. // ||[lastName isEqualToString:@"tiff"]
  408. // ||[lastName isEqualToString:@"bmp"]
  409. // ||[lastName isEqualToString:@"heic"]
  410. // ||[lastName isEqualToString:@"jpeg"]
  411. // ||[lastName isEqualToString:@"heif"]){
  412. // canDownLoadType = YES;
  413. // }
  414. //
  415. // if(!canDownLoadType){
  416. // if(canShow){
  417. // [[iToast makeText:NSLocalizedString(@"download_image_disable_state",nil)] show];
  418. // }
  419. // return NO;
  420. // }
  421. // }
  422. return YES;
  423. }
  424. #pragma mark 用户长按图片进入编辑
  425. - (void)setViewEditTypeFun
  426. {
  427. _isEditType = YES;
  428. [_dataCollectionView reloadData];
  429. _curEditTypeHeadView.hidden = NO;
  430. _curEditTypeBottomView.hidden = NO;
  431. _uploadFileButton.hidden = YES;
  432. [self setEditTypeTitleFun];
  433. [self.dataCollectionView mas_remakeConstraints:^(MASConstraintMaker *make) {
  434. make.left.mas_equalTo(0);
  435. make.right.mas_equalTo(0);
  436. make.bottom.mas_equalTo(_curEditTypeBottomView.mas_top);
  437. make.top.equalTo(self.navBarBGView.mas_bottom).offset(10.f);
  438. }];
  439. }
  440. #pragma mark 用户取消编辑编辑
  441. - (void)userCancelEditTypeFun
  442. {
  443. //数据还原
  444. for (NASFilePicDataArrModel*model in _didSelectListArr) {
  445. model.isSelectType = NO;
  446. }
  447. _isEditType = NO;
  448. [_didSelectListArr removeAllObjects];
  449. [_dataCollectionView reloadData];
  450. _curEditTypeHeadView.hidden = YES;
  451. _curEditTypeBottomView.hidden = YES;
  452. _uploadFileButton.hidden = NO;
  453. [self.dataCollectionView mas_remakeConstraints:^(MASConstraintMaker *make) {
  454. make.left.mas_equalTo(0);
  455. make.right.mas_equalTo(0);
  456. make.bottom.mas_equalTo(0);
  457. make.top.equalTo(self.navBarBGView.mas_bottom).offset(10.f);
  458. }];
  459. }
  460. - (void)userCheckFilePreviewByRow:(NSInteger)row withSection:(NSInteger)section
  461. {
  462. if(_curNASFilePicModel && _curNASFilePicModel.data.fileList.count > section){
  463. NASFilePicTimeArrModel *timeArrModel = _curNASFilePicModel.data.fileList[section];
  464. if (timeArrModel.list.count > row) {
  465. NASFilePicDataArrModel * dataModel = timeArrModel.list[row];
  466. if(dataModel.isSelectType)
  467. {
  468. [_didSelectListArr removeObject:dataModel];
  469. }
  470. else{
  471. [_didSelectListArr addObject:dataModel];
  472. }
  473. dataModel.isSelectType = !dataModel.isSelectType;
  474. [self setEditTypeTitleFun];
  475. }
  476. }
  477. }
  478. - (void)didClickSelectAllButton:(UIButton*)button
  479. {
  480. //button.selected = !button.selected;
  481. BOOL isNeedShowTip = NO;
  482. [_didSelectListArr removeAllObjects];
  483. for (NASFilePicTimeArrModel* fileModel in _curNASFilePicModel.data.fileList) {
  484. for (NASFilePicDataArrModel*dataModel in fileModel.list) {
  485. if(!button.selected){
  486. dataModel.isSelectType = button.selected;
  487. }
  488. else{
  489. [_didSelectListArr addObject:dataModel];
  490. if([self userCheckFileModel:dataModel withShowTip:NO]){
  491. dataModel.isSelectType = button.selected;
  492. }
  493. else{
  494. isNeedShowTip = YES;
  495. }
  496. }
  497. }
  498. }
  499. // if(isNeedShowTip){
  500. // if(_isPhotoType){
  501. // [[iToast makeText:NSLocalizedString(@"download_image_disable_state",nil)] show];
  502. // }
  503. // else{
  504. // [[iToast makeText:NSLocalizedString(@"download_video_disable_state",nil)] show];
  505. // }
  506. // }
  507. //[self.tableView reloadData];
  508. [self.dataCollectionView reloadData];
  509. [self setEditTypeTitleFun];
  510. }
  511. #pragma mark 设置选中标题
  512. - (void)setEditTypeTitleFun
  513. {
  514. [_curEditTypeHeadView setTitleLabetextByNumbers:_didSelectListArr.count];
  515. BOOL canClick = _didSelectListArr.count >0 ? YES : NO;
  516. [_curEditTypeBottomView setButtonStateFunBy:canClick];
  517. }
  518. #pragma mark 用户点击分享
  519. - (void)gotoShareViewFun
  520. {
  521. if(_isPhotoType){
  522. if (_didSelectListArr.count > 20) {
  523. [[iToast makeText:NSLocalizedString(@"share_max_count_tip1",nil)] show];
  524. return;
  525. }
  526. }
  527. else{
  528. if (_didSelectListArr.count > 5) {
  529. [[iToast makeText:NSLocalizedString(@"share_max_count_tip2",nil)] show];
  530. return;
  531. }
  532. }
  533. editShareView *editShareV = [[editShareView alloc] init];
  534. editShareV.didSelectListArr = _didSelectListArr;
  535. if(_isPhotoType){
  536. editShareV.shareFileType = @"2";
  537. }
  538. else{
  539. editShareV.shareFileType = @"3";
  540. }
  541. [self.view addSubview:editShareV];
  542. [editShareV mas_makeConstraints:^(MASConstraintMaker *make) {
  543. make.left.mas_equalTo(0);
  544. make.right.mas_equalTo(0);
  545. make.bottom.mas_equalTo(0);
  546. make.top.mas_equalTo(0);
  547. }];
  548. }
  549. #pragma mark 用户点击上传文件
  550. - (void)userDidClickUploadViewFun
  551. {
  552. previewToUploadFileView *previewToUploadFileV = [[previewToUploadFileView alloc] init];
  553. [self.view addSubview:previewToUploadFileV];
  554. [previewToUploadFileV mas_makeConstraints:^(MASConstraintMaker *make) {
  555. make.left.mas_equalTo(0);
  556. make.right.mas_equalTo(0);
  557. make.bottom.mas_equalTo(0);
  558. make.top.mas_equalTo(0);
  559. }];
  560. KWeakSelf
  561. previewToUploadFileV.didClickButtonFun = ^(NSInteger tag) {
  562. [weakSelf gotoUploadFileFunWith:tag];
  563. };
  564. }
  565. #pragma mark 设置标题
  566. - (void)setTitleLabelText:(NSString*)title
  567. {
  568. NSArray *diskNameArr = [_defaultDiskPath componentsSeparatedByString:@"/"];
  569. if(diskNameArr && diskNameArr.count >= 2){
  570. NSString *name = diskNameArr.lastObject;
  571. if(name.length == 0)
  572. {
  573. name = diskNameArr[diskNameArr.count -2];
  574. }
  575. title = [[NSString alloc] initWithFormat:@"[%@]%@",name,title];
  576. }
  577. self.MytitleLabel.text = title;
  578. CGFloat curWidth = [title boundingRectWithSize:CGSizeMake(SCREEN_W, 30) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:16.f]} context:nil].size.width;
  579. curWidth += 20;
  580. //HLog(@"title w:%f",curWidth);
  581. [self.MytitleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  582. make.centerX.mas_equalTo(self.navBarBGView.mas_centerX).offset(-10);
  583. make.centerY.mas_equalTo(self.backBtn.mas_centerY);
  584. make.width.mas_equalTo(curWidth);
  585. make.height.mas_equalTo(30);
  586. }];
  587. //self.MytitleLabel.backgroundColor = [UIColor greenColor];
  588. [self.selectTip mas_makeConstraints:^(MASConstraintMaker *make) {
  589. make.left.mas_equalTo(self.MytitleLabel.mas_right).offset(0);
  590. make.centerY.mas_equalTo(self.backBtn.mas_centerY);
  591. make.width.mas_equalTo(15);
  592. make.height.mas_equalTo(15);
  593. }];
  594. [tapBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
  595. make.centerX.mas_equalTo(self.navBarBGView.mas_centerX);
  596. make.centerY.mas_equalTo(self.backBtn.mas_centerY);
  597. make.width.mas_equalTo(curWidth+15);
  598. make.height.mas_equalTo(30);
  599. }];
  600. }
  601. #pragma mark 选择硬盘
  602. - (void)selectDiskAction:(UIButton*)but
  603. {
  604. if(self.diskListBgV.hidden){
  605. [self showDiskListVieFun];
  606. }
  607. else{
  608. [self hideDiskListVieFun];
  609. }
  610. }
  611. - (void)showDiskListVieFun
  612. {
  613. self.diskListBgV.hidden = NO;
  614. self.diskListTableV.hidden = NO;
  615. [UIView animateWithDuration:0.3 animations:^{
  616. CGRect rect = self.diskListTableV.frame;
  617. rect.origin.y = CGRectGetMaxY(self.navBarBGView.frame);
  618. self.diskListTableV.frame = rect;
  619. self.selectTip.transform = CGAffineTransformMakeRotation(M_PI);
  620. }];
  621. }
  622. - (void)hideDiskListVieFun
  623. {
  624. self.diskListBgV.hidden = YES;
  625. [UIView animateWithDuration:0.3 animations:^{
  626. self.diskListTableV.hidden = YES;
  627. self.selectTip.transform = CGAffineTransformIdentity;
  628. }completion:^(BOOL finished) {
  629. CGRect rect = self.diskListTableV.frame;
  630. rect.origin.y = 0;
  631. self.diskListTableV.frame = rect;
  632. }];
  633. }
  634. #pragma mark 设置标题
  635. - (void)setTitleAfterGetdiskFun
  636. {
  637. if(_isPhotoType){
  638. //self.titleLabel.text = NSLocalizedString(@"my_set_no_image_upload",nil) ;
  639. [self setTitleLabelText:NSLocalizedString(@"my_set_no_image_upload",nil)];
  640. }
  641. else{
  642. //self.titleLabel.text = NSLocalizedString(@"my_set_no_video_upload",nil) ;
  643. [self setTitleLabelText:NSLocalizedString(@"my_set_no_video_upload",nil)];
  644. }
  645. }
  646. - (void)viewWillAppear:(BOOL)animated
  647. {
  648. [super viewWillAppear:animated];
  649. }
  650. - (void)viewDidAppear:(BOOL)animated{
  651. [super viewDidAppear:animated];
  652. [self showDownloadTipFun];
  653. [self checkFileTransferTask];
  654. if(!_curNASFilePicModel){
  655. [self getFileListFun];
  656. }
  657. }
  658. - (void)viewWillDisappear:(BOOL)animated{
  659. [super viewWillDisappear:animated];
  660. //[self removeNewIndicator];
  661. [self removeNewIndicatorHaveStr];
  662. }
  663. - (void)gotoDownloadloadFileRecordFun
  664. {
  665. uploadFileRecordViewController *vc = [uploadFileRecordViewController new];
  666. [self.navigationController pushViewController:vc animated:YES];
  667. vc.isDownloadingType = YES;
  668. //[vc gotoDownloadFile:_downloadFileBottomV.indexPathsForSelectedItems];
  669. }
  670. - (void)showDownloadTipFun
  671. {
  672. BOOL didReadUploadTipType = [HWDataManager getBoolWithKey:Const_file_downLoad_need_read];
  673. if(didReadUploadTipType){
  674. return;
  675. }
  676. //KWeakSelf
  677. /*弹窗提示恢复出厂*/
  678. ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:nil
  679. msg:NSLocalizedString(@"upload_download_need_read_msg",nil)
  680. imageStr:nil
  681. cancelTitle:NSLocalizedString(@"guide_set_pwd_guide_know",nil)
  682. okTitle:nil
  683. isOkBtnHighlight:NO
  684. didClickOk:^{
  685. } didClickCancel:^{
  686. [HWDataManager setBoolWithKey:Const_file_downLoad_need_read value:YES];
  687. }];
  688. nextVC.modalPresentationStyle = UIModalPresentationCustom;
  689. [self presentViewController:nextVC animated:YES completion:^{
  690. nextVC.view.superview.backgroundColor = [UIColor clearColor];
  691. }];
  692. }
  693. - (void)checkFileTransferTask
  694. {//有个偶现的闪退在BGFMDB
  695. [[uploadFileManager shareInstance] checkHadUploadTaskWithComplete:^(BOOL isSuccess) {
  696. self->hadUploadTaskType = isSuccess;
  697. [self setRightButtonRedTypeFun];
  698. }];
  699. KWeakSelf
  700. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  701. [[downloadManager shareInstance] checkHadDownloadTaskWithComplete:^(BOOL isSuccess) {
  702. self->hadDownloadTaskType = isSuccess;
  703. [weakSelf setRightButtonRedTypeFun];
  704. }];
  705. });
  706. }
  707. - (void)setRightButtonRedTypeFun
  708. {
  709. mainBlock(^{
  710. if(self->hadUploadTaskType || self->hadDownloadTaskType){
  711. self->rightRedView.hidden = NO;
  712. }
  713. else{
  714. self->rightRedView.hidden = YES;
  715. }
  716. });
  717. }
  718. - (void)didiClikRightButGotoTransferListFun:(UIButton*)but
  719. {
  720. uploadFileRecordViewController *vc = [uploadFileRecordViewController new];
  721. [self.navigationController pushViewController:vc animated:YES];
  722. }
  723. #pragma mark 获取文件数据
  724. - (void)getFileListFun
  725. {
  726. NSMutableDictionary*paraDict = [NSMutableDictionary new];
  727. if(_isPhotoType){
  728. [paraDict setValue:@"pic" forKey:@"type"];
  729. }
  730. else{
  731. [paraDict setValue:@"video" forKey:@"type"];
  732. }
  733. NSArray *diskNameArr = [_defaultDiskPath componentsSeparatedByString:@"/"];
  734. if(diskNameArr && diskNameArr.count >= 2){
  735. NSString *name = diskNameArr.lastObject;
  736. if(name.length == 0)
  737. {
  738. name = diskNameArr[diskNameArr.count -2];
  739. }
  740. [paraDict setValue:name forKey:@"path"];
  741. }
  742. [self showNewIndicatorHaveStrWithCanBack:YES canTouch:NO showText:NSLocalizedString(@"common_loading_tip",nil)];
  743. KWeakSelf
  744. [[netWorkManager shareInstance] cloudPhoneGETCallBackCode:@"getFileListByDay" Parameters:paraDict success:^(id _Nonnull responseObject) {
  745. [weakSelf removeNewIndicatorHaveStr];
  746. weakSelf.curNASFilePicModel = [[NASFilePicModel alloc] initWithDictionary:responseObject error:nil];
  747. [weakSelf.dataCollectionView reloadData];
  748. } failure:^(NSError * _Nonnull error) {
  749. [weakSelf removeNewIndicatorHaveStr];
  750. }];
  751. }
  752. #pragma mark 点击图片详情
  753. - (void)didClickPicDetailsWithSection:(NSInteger)section withRow:(NSInteger)row{
  754. if(_curNASFilePicModel){
  755. NSMutableArray *totalArr = [NSMutableArray new];
  756. NSInteger index = 0;
  757. for (int i=0; i<_curNASFilePicModel.data.fileList.count; i++) {
  758. NASFilePicTimeArrModel *timeModel = _curNASFilePicModel.data.fileList[i];
  759. if(i == section){
  760. index = totalArr.count + row;
  761. }
  762. [totalArr addObjectsFromArray:timeModel.list];
  763. }
  764. imageDetailsScrollViewController *vc = [imageDetailsScrollViewController new];
  765. vc.index = index;
  766. vc.totalDataArr = totalArr;
  767. [self.navigationController pushViewController:vc animated:YES];
  768. vc.canShareType = canShareType;
  769. KWeakSelf
  770. vc.didNeedToRegetDataFun = ^{
  771. [weakSelf delayedGetFileListFun];
  772. };
  773. }
  774. }
  775. #pragma mark 点击视频详情
  776. - (void)didClickVideoWithSection:(NSInteger)section withRow:(NSInteger)row{
  777. if(_curNASFilePicModel){
  778. if(section < _curNASFilePicModel.data.fileList.count){
  779. NASFilePicTimeArrModel *timeModel = _curNASFilePicModel.data.fileList[section];
  780. if(row < timeModel.list.count){
  781. NASFilePicDataArrModel *dataModel = timeModel.list[row];
  782. //videoPlayViewController *vc = [videoPlayViewController new];
  783. videoPlayByAVPlayerViewController *vc = [videoPlayByAVPlayerViewController new];
  784. vc.VideoDataMode = dataModel;
  785. [self.navigationController pushViewController:vc animated:YES];
  786. }
  787. }
  788. // imageDetailsScrollViewController *vc = [imageDetailsScrollViewController new];
  789. // vc.index = index;
  790. // vc.totalDataArr = totalArr;
  791. // [self.navigationController pushViewController:vc animated:YES];
  792. // vc.canShareType = canShareType;
  793. //
  794. // KWeakSelf
  795. // vc.didNeedToRegetDataFun = ^{
  796. // [weakSelf getFileListFun];
  797. // };
  798. }
  799. }
  800. - (void)gotoDownLoadFileFun
  801. {
  802. if(_didSelectListArr.count == 0){
  803. [[iToast makeText:@""] show];
  804. return;
  805. }
  806. NSMutableArray *arr = [NSMutableArray new];
  807. for (NASFilePicDataArrModel *dataModel in _didSelectListArr) {
  808. couldPhoneFileModel* fileModel = [couldPhoneFileModel new];
  809. if(_isPhotoType){
  810. fileModel.fileType = @".jpg";
  811. }
  812. else{
  813. fileModel.fileType = @"video";
  814. }
  815. fileModel.path = dataModel.path;
  816. fileModel.name = dataModel.name;
  817. fileModel.length = dataModel.size;
  818. fileModel.time = dataModel.duration;
  819. [arr addObject:fileModel];
  820. }
  821. uploadFileRecordViewController *vc = [uploadFileRecordViewController new];
  822. [self.navigationController pushViewController:vc animated:YES];
  823. vc.isDownloadingType = YES;
  824. [vc gotoDownloadFile:arr];
  825. }
  826. - (void)setIsPhotoType:(BOOL)isPhotoType
  827. {
  828. _isPhotoType = isPhotoType;
  829. [self queryShareSwitchFunFun];
  830. }
  831. #pragma mark 获取分享开关
  832. -(void)queryShareSwitchFunFun
  833. {
  834. NSMutableDictionary *paraDict = [NSMutableDictionary new];
  835. if(_isPhotoType){
  836. [paraDict setValue:@2 forKey:@"type"];
  837. }
  838. else{
  839. [paraDict setValue:@3 forKey:@"type"];
  840. }
  841. KWeakSelf
  842. [[netWorkManager shareInstance] CommonGetWithCallBackCode:queryShareSwitchFun Parameters:paraDict success:^(id _Nonnull responseObject){
  843. queryShareModel *queryShareMod = [[queryShareModel alloc] initWithDictionary:responseObject error:nil];
  844. if(queryShareMod){
  845. self->canShareType = queryShareMod.data.configValue;
  846. [weakSelf.curEditTypeBottomView setCanShaewFunBy:queryShareMod.data.configValue];
  847. }
  848. } failure:^(NSError * _Nonnull error) {
  849. }];
  850. }
  851. #pragma mark 调整文件上传
  852. - (void)gotoUploadFileFunWith:(NSInteger)tag
  853. {
  854. uploadImageOrVideoViewController *vc = [uploadImageOrVideoViewController new];
  855. if(tag ==10){
  856. vc.isPhotoType = YES;
  857. }
  858. else{
  859. vc.isPhotoType = NO;
  860. }
  861. [self.navigationController pushViewController:vc animated:YES];
  862. }
  863. #pragma mark 删除图片
  864. - (void)showDeleteAlearViewFun
  865. {
  866. NSString *titleStr = NSLocalizedString(@"delete_file_title_msg",nil);
  867. NSString *tipStr = NSLocalizedString(@"delete_file_tip_msg",nil);
  868. KWeakSelf
  869. ComontAlretViewController *curAlretVC= [[ComontAlretViewController alloc] initWithTiTle:titleStr
  870. msg:tipStr
  871. imageStr:nil
  872. cancelTitle:NSLocalizedString(@"other_cancel",nil)
  873. okTitle:NSLocalizedString(@"other_confirm",nil) isOkBtnHighlight:YES
  874. didClickOk:^{
  875. [weakSelf delFileListFun];
  876. } didClickCancel:^{
  877. }];
  878. curAlretVC.modalPresentationStyle = UIModalPresentationCustom;
  879. [self presentViewController:curAlretVC animated:YES completion:^{
  880. curAlretVC.view.superview.backgroundColor = [UIColor clearColor];
  881. }];
  882. }
  883. #pragma mark 删除文件数据
  884. - (void)delFileListFun
  885. {
  886. NSMutableDictionary*paraDict = [NSMutableDictionary new];
  887. NSMutableArray *pathArr = [NSMutableArray new];
  888. for (NASFilePicDataArrModel *dataModel in _didSelectListArr) {
  889. [pathArr addObject:dataModel.path];
  890. }
  891. [paraDict setValue:pathArr forKey:@"path"];
  892. [self showNewIndicatorWithCanBack:YES canTouch:NO];
  893. //NSString*code = [[NSString alloc] initWithFormat:@"delFile?path=%@",paraDict[@"path"]]; //delFile?path=[/storage/emulated/0/Download/IMG_6464.HEIC]
  894. KWeakSelf //@"delFile"
  895. [[netWorkManager shareInstance] cloudPhonePostCallBackCode:@"delFile" Parameters:paraDict success:^(id _Nonnull responseObject) {
  896. [weakSelf removeNewIndicator];
  897. SuperModel *model = [[SuperModel alloc] initWithDictionary:responseObject error:nil];
  898. if(model && model.status == 0){
  899. [[iToast makeText:NSLocalizedString(@"delete_file_suc_msg",nil)] show];
  900. [weakSelf didDeleteSucFun];
  901. }
  902. else{
  903. }
  904. } failure:^(NSError * _Nonnull error) {
  905. [weakSelf removeNewIndicator];
  906. }];
  907. }
  908. #pragma mark 删除成功
  909. - (void)didDeleteSucFun
  910. {
  911. [_didSelectListArr removeAllObjects];
  912. [self setEditTypeTitleFun];
  913. [self delayedGetFileListFun];
  914. }
  915. - (void)delayedGetFileListFun{
  916. KWeakSelf
  917. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  918. [self getFileListFun];
  919. });
  920. }
  921. @end