previewImageOrVideoViewController.m 32 KB

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