previewImageOrVideoViewController.m 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934
  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. [_didSelectListArr removeAllObjects];
  266. }
  267. self.defaultDiskPath = pathStr;
  268. [self getFileListFun];
  269. [self setTitleAfterGetdiskFun];
  270. [self hideDiskListVieFun];
  271. }
  272. #pragma mark - 瀑布流委托
  273. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  274. if(_curNASFilePicModel){
  275. return _curNASFilePicModel.data.fileList.count;
  276. }
  277. return 1;
  278. }
  279. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  280. if(_curNASFilePicModel && _curNASFilePicModel.data.fileList.count >section){
  281. NASFilePicTimeArrModel *timeArrModel = _curNASFilePicModel.data.fileList[section];
  282. return timeArrModel.list.count;
  283. }
  284. return 0;
  285. }
  286. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  287. {
  288. __block NSInteger row = indexPath.row;
  289. __block NSInteger section = indexPath.section;
  290. //创建item 从缓存池中拿 Item
  291. imageCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"imageCollectionViewCell" forIndexPath:indexPath];
  292. if(!cell){
  293. cell = [[imageCollectionViewCell alloc] init];
  294. }
  295. if(_curNASFilePicModel && _curNASFilePicModel.data.fileList.count > section){
  296. NASFilePicTimeArrModel *timeArrModel = _curNASFilePicModel.data.fileList[section];
  297. if (timeArrModel.list.count > row) {
  298. NASFilePicDataArrModel * dataModel = timeArrModel.list[row];
  299. cell.isEditType = _isEditType;
  300. if(_isPhotoType){
  301. cell.fileType = @"pic";
  302. }
  303. else{
  304. cell.fileType = @"video";
  305. }
  306. cell.curFileModel = dataModel;
  307. KWeakSelf
  308. cell.didClckSelectBut = ^(BOOL selectType){
  309. if([weakSelf userCheckFileModel:dataModel withShowTip:YES]){
  310. [weakSelf userCheckFilePreviewByRow:row withSection:section];
  311. }
  312. };
  313. cell.didClickEditType = ^(BOOL editType) {
  314. [weakSelf setViewEditTypeFun];
  315. };
  316. }
  317. }
  318. return cell;
  319. }
  320. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
  321. if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
  322. NSInteger section = indexPath.section;
  323. titleLabelReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"titleLabelReusableView" forIndexPath:indexPath];
  324. if(_curNASFilePicModel && _curNASFilePicModel.data.fileList.count > section){
  325. NASFilePicTimeArrModel *timeArrModel = _curNASFilePicModel.data.fileList[section];
  326. headerView.titlelabel.text = timeArrModel.time;
  327. }
  328. return headerView;
  329. }
  330. return nil;
  331. }
  332. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
  333. return CGSizeMake([UIScreen mainScreen].bounds.size.width, 40);
  334. }
  335. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  336. {
  337. NSInteger row = indexPath.row;
  338. NSInteger section = indexPath.section;
  339. if(_curNASFilePicModel && _curNASFilePicModel.data.fileList.count > section){
  340. NASFilePicTimeArrModel *timeArrModel = _curNASFilePicModel.data.fileList[section];
  341. if (timeArrModel.list.count > row) {
  342. //NASFilePicDataArrModel * dataModel = timeArrModel.list[row];
  343. if(_isPhotoType){
  344. [self didClickPicDetailsWithSection:section withRow:row];
  345. }
  346. }
  347. }
  348. }
  349. #pragma mark 空数据
  350. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
  351. NSString *imageName = @"common_no_data_pic";
  352. return [UIImage imageNamed:imageName];
  353. }
  354. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {
  355. NSString *text = NSLocalizedString(@"File_download_file_no_data",nil);
  356. NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:16.0f],
  357. NSForegroundColorAttributeName: HW999999Color};
  358. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  359. }
  360. //调整图片位置
  361. - (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView {
  362. return -150;
  363. }
  364. //ios端:
  365. //1、需求说明:解决除MP4 MOV 3GP M4V 总计4种格式外,其他格式下载失败的问题;
  366. //2、交互说明:下载列表勾选文件中含有其他格式,toast提示“IOS系统仅支持MP4、MOV、3GP、M4V 的视频格式,其他格式无法下载”。点击下载按钮,过滤其他格式文件,仅下载MP4、MOV、3GP、M4V 的视频格式文件;
  367. //ios支持图片格式: (SVG 不支持)
  368. //需求说明:解决除JPG PNG GIF TIFF BMP总计5种格式外,其他格式下载失败的问题
  369. //视觉交互:选择文件中含有其他格式,toast提示“IOS系统仅支持JPG 、PNG、GIF、TIFF、BMP的图片格式,其他格式无法下载”。点击下载按钮,过滤其他格式文件,仅下载JPG 、PNG、GIF、TIFF、BMP的图片格式文件;
  370. - (BOOL)userCheckFileModel:(NASFilePicDataArrModel*)fileModel withShowTip:(BOOL)canShow{
  371. // NSString*name = [fileModel.name lowercaseString];
  372. // NSArray *nameArr = [name componentsSeparatedByString:@"."];
  373. // if(nameArr.count >0 && !_isPhotoType){
  374. // BOOL canDownLoadType = NO;
  375. //
  376. // NSString *lastName = nameArr.lastObject;
  377. // if([lastName isEqualToString:@"mp4"]
  378. // ||[lastName isEqualToString:@"mov"]
  379. // ||[lastName isEqualToString:@"3gp"]
  380. // ||[lastName isEqualToString:@"m4v"]){
  381. // canDownLoadType = YES;
  382. // }
  383. //
  384. // if(!canDownLoadType){
  385. // if(canShow){
  386. // [[iToast makeText:NSLocalizedString(@"download_video_disable_state",nil)] show];
  387. // }
  388. //
  389. // return NO;
  390. // }
  391. // }
  392. //
  393. // if(nameArr.count >0 && _isPhotoType){
  394. // BOOL canDownLoadType = NO;
  395. // //JPG 、PNG、GIF、TIFF、BMP
  396. // NSString *lastName = nameArr.lastObject;
  397. // if([lastName isEqualToString:@"jpg"]
  398. // ||[lastName isEqualToString:@"png"]
  399. // ||[lastName isEqualToString:@"gif"]
  400. // ||[lastName isEqualToString:@"tiff"]
  401. // ||[lastName isEqualToString:@"bmp"]
  402. // ||[lastName isEqualToString:@"heic"]
  403. // ||[lastName isEqualToString:@"jpeg"]
  404. // ||[lastName isEqualToString:@"heif"]){
  405. // canDownLoadType = YES;
  406. // }
  407. //
  408. // if(!canDownLoadType){
  409. // if(canShow){
  410. // [[iToast makeText:NSLocalizedString(@"download_image_disable_state",nil)] show];
  411. // }
  412. // return NO;
  413. // }
  414. // }
  415. return YES;
  416. }
  417. #pragma mark 用户长按图片进入编辑
  418. - (void)setViewEditTypeFun
  419. {
  420. _isEditType = YES;
  421. [_dataCollectionView reloadData];
  422. _curEditTypeHeadView.hidden = NO;
  423. _curEditTypeBottomView.hidden = NO;
  424. _uploadFileButton.hidden = YES;
  425. [self setEditTypeTitleFun];
  426. [self.dataCollectionView mas_remakeConstraints:^(MASConstraintMaker *make) {
  427. make.left.mas_equalTo(0);
  428. make.right.mas_equalTo(0);
  429. make.bottom.mas_equalTo(_curEditTypeBottomView.mas_top);
  430. make.top.equalTo(self.navBarBGView.mas_bottom).offset(10.f);
  431. }];
  432. }
  433. #pragma mark 用户取消编辑编辑
  434. - (void)userCancelEditTypeFun
  435. {
  436. _isEditType = NO;
  437. [_didSelectListArr removeAllObjects];
  438. [_dataCollectionView reloadData];
  439. _curEditTypeHeadView.hidden = YES;
  440. _curEditTypeBottomView.hidden = YES;
  441. _uploadFileButton.hidden = NO;
  442. [self.dataCollectionView mas_remakeConstraints:^(MASConstraintMaker *make) {
  443. make.left.mas_equalTo(0);
  444. make.right.mas_equalTo(0);
  445. make.bottom.mas_equalTo(0);
  446. make.top.equalTo(self.navBarBGView.mas_bottom).offset(10.f);
  447. }];
  448. }
  449. - (void)userCheckFilePreviewByRow:(NSInteger)row withSection:(NSInteger)section
  450. {
  451. if(_curNASFilePicModel && _curNASFilePicModel.data.fileList.count > section){
  452. NASFilePicTimeArrModel *timeArrModel = _curNASFilePicModel.data.fileList[section];
  453. if (timeArrModel.list.count > row) {
  454. NASFilePicDataArrModel * dataModel = timeArrModel.list[row];
  455. if(dataModel.isSelectType)
  456. {
  457. [_didSelectListArr removeObject:dataModel];
  458. }
  459. else{
  460. [_didSelectListArr addObject:dataModel];
  461. }
  462. dataModel.isSelectType = !dataModel.isSelectType;
  463. [self setEditTypeTitleFun];
  464. }
  465. }
  466. }
  467. - (void)didClickSelectAllButton:(UIButton*)button
  468. {
  469. //button.selected = !button.selected;
  470. BOOL isNeedShowTip = NO;
  471. [_didSelectListArr removeAllObjects];
  472. for (NASFilePicTimeArrModel* fileModel in _curNASFilePicModel.data.fileList) {
  473. for (NASFilePicDataArrModel*dataModel in fileModel.list) {
  474. if(!button.selected){
  475. dataModel.isSelectType = button.selected;
  476. }
  477. else{
  478. [_didSelectListArr addObject:dataModel];
  479. if([self userCheckFileModel:dataModel withShowTip:NO]){
  480. dataModel.isSelectType = button.selected;
  481. }
  482. else{
  483. isNeedShowTip = YES;
  484. }
  485. }
  486. }
  487. }
  488. // if(isNeedShowTip){
  489. // if(_isPhotoType){
  490. // [[iToast makeText:NSLocalizedString(@"download_image_disable_state",nil)] show];
  491. // }
  492. // else{
  493. // [[iToast makeText:NSLocalizedString(@"download_video_disable_state",nil)] show];
  494. // }
  495. // }
  496. //[self.tableView reloadData];
  497. [self.dataCollectionView reloadData];
  498. [self setEditTypeTitleFun];
  499. }
  500. #pragma mark 设置选中标题
  501. - (void)setEditTypeTitleFun
  502. {
  503. [_curEditTypeHeadView setTitleLabetextByNumbers:_didSelectListArr.count];
  504. BOOL canClick = _didSelectListArr.count >0 ? YES : NO;
  505. [_curEditTypeBottomView setButtonStateFunBy:canClick];
  506. }
  507. #pragma mark 用户点击分享
  508. - (void)gotoShareViewFun
  509. {
  510. editShareView *editShareV = [[editShareView alloc] init];
  511. [self.view addSubview:editShareV];
  512. [editShareV mas_makeConstraints:^(MASConstraintMaker *make) {
  513. make.left.mas_equalTo(0);
  514. make.right.mas_equalTo(0);
  515. make.bottom.mas_equalTo(0);
  516. make.top.mas_equalTo(0);
  517. }];
  518. }
  519. #pragma mark 用户点击上传文件
  520. - (void)userDidClickUploadViewFun
  521. {
  522. previewToUploadFileView *previewToUploadFileV = [[previewToUploadFileView alloc] init];
  523. [self.view addSubview:previewToUploadFileV];
  524. [previewToUploadFileV mas_makeConstraints:^(MASConstraintMaker *make) {
  525. make.left.mas_equalTo(0);
  526. make.right.mas_equalTo(0);
  527. make.bottom.mas_equalTo(0);
  528. make.top.mas_equalTo(0);
  529. }];
  530. }
  531. #pragma mark 设置标题
  532. - (void)setTitleLabelText:(NSString*)title
  533. {
  534. NSArray *diskNameArr = [_defaultDiskPath componentsSeparatedByString:@"/"];
  535. if(diskNameArr && diskNameArr.count >= 2){
  536. NSString *name = diskNameArr.lastObject;
  537. if(name.length == 0)
  538. {
  539. name = diskNameArr[diskNameArr.count -2];
  540. }
  541. title = [[NSString alloc] initWithFormat:@"[%@]%@",name,title];
  542. }
  543. self.MytitleLabel.text = title;
  544. CGFloat curWidth = [title boundingRectWithSize:CGSizeMake(SCREEN_W, 30) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:16.f]} context:nil].size.width;
  545. curWidth += 20;
  546. //HLog(@"title w:%f",curWidth);
  547. [self.MytitleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  548. make.centerX.mas_equalTo(self.navBarBGView.mas_centerX).offset(-10);
  549. make.centerY.mas_equalTo(self.backBtn.mas_centerY);
  550. make.width.mas_equalTo(curWidth);
  551. make.height.mas_equalTo(30);
  552. }];
  553. //self.MytitleLabel.backgroundColor = [UIColor greenColor];
  554. [self.selectTip mas_makeConstraints:^(MASConstraintMaker *make) {
  555. make.left.mas_equalTo(self.MytitleLabel.mas_right).offset(0);
  556. make.centerY.mas_equalTo(self.backBtn.mas_centerY);
  557. make.width.mas_equalTo(15);
  558. make.height.mas_equalTo(15);
  559. }];
  560. [tapBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
  561. make.centerX.mas_equalTo(self.navBarBGView.mas_centerX);
  562. make.centerY.mas_equalTo(self.backBtn.mas_centerY);
  563. make.width.mas_equalTo(curWidth+15);
  564. make.height.mas_equalTo(30);
  565. }];
  566. }
  567. #pragma mark 选择硬盘
  568. - (void)selectDiskAction:(UIButton*)but
  569. {
  570. if(self.diskListBgV.hidden){
  571. [self showDiskListVieFun];
  572. }
  573. else{
  574. [self hideDiskListVieFun];
  575. }
  576. }
  577. - (void)showDiskListVieFun
  578. {
  579. self.diskListBgV.hidden = NO;
  580. self.diskListTableV.hidden = NO;
  581. [UIView animateWithDuration:0.3 animations:^{
  582. CGRect rect = self.diskListTableV.frame;
  583. rect.origin.y = CGRectGetMaxY(self.navBarBGView.frame);
  584. self.diskListTableV.frame = rect;
  585. self.selectTip.transform = CGAffineTransformMakeRotation(M_PI);
  586. }];
  587. }
  588. - (void)hideDiskListVieFun
  589. {
  590. self.diskListBgV.hidden = YES;
  591. [UIView animateWithDuration:0.3 animations:^{
  592. self.diskListTableV.hidden = YES;
  593. self.selectTip.transform = CGAffineTransformIdentity;
  594. }completion:^(BOOL finished) {
  595. CGRect rect = self.diskListTableV.frame;
  596. rect.origin.y = 0;
  597. self.diskListTableV.frame = rect;
  598. }];
  599. }
  600. #pragma mark 设置标题
  601. - (void)setTitleAfterGetdiskFun
  602. {
  603. if(_isPhotoType){
  604. //self.titleLabel.text = NSLocalizedString(@"my_set_no_image_upload",nil) ;
  605. [self setTitleLabelText:NSLocalizedString(@"my_set_no_image_upload",nil)];
  606. }
  607. else{
  608. //self.titleLabel.text = NSLocalizedString(@"my_set_no_video_upload",nil) ;
  609. [self setTitleLabelText:NSLocalizedString(@"my_set_no_video_upload",nil)];
  610. }
  611. }
  612. - (void)viewWillAppear:(BOOL)animated
  613. {
  614. [super viewWillAppear:animated];
  615. }
  616. - (void)viewDidAppear:(BOOL)animated{
  617. [super viewDidAppear:animated];
  618. [self showDownloadTipFun];
  619. [self checkFileTransferTask];
  620. if(!_curNASFilePicModel){
  621. [self getFileListFun];
  622. }
  623. }
  624. - (void)viewWillDisappear:(BOOL)animated{
  625. [super viewWillDisappear:animated];
  626. //[self removeNewIndicator];
  627. [self removeNewIndicatorHaveStr];
  628. }
  629. - (void)gotoDownloadloadFileRecordFun
  630. {
  631. uploadFileRecordViewController *vc = [uploadFileRecordViewController new];
  632. [self.navigationController pushViewController:vc animated:YES];
  633. vc.isDownloadingType = YES;
  634. //[vc gotoDownloadFile:_downloadFileBottomV.indexPathsForSelectedItems];
  635. }
  636. - (void)showDownloadTipFun
  637. {
  638. BOOL didReadUploadTipType = [HWDataManager getBoolWithKey:Const_file_downLoad_need_read];
  639. if(didReadUploadTipType){
  640. return;
  641. }
  642. //KWeakSelf
  643. /*弹窗提示恢复出厂*/
  644. ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:nil
  645. msg:NSLocalizedString(@"upload_download_need_read_msg",nil)
  646. imageStr:nil
  647. cancelTitle:NSLocalizedString(@"guide_set_pwd_guide_know",nil)
  648. okTitle:nil
  649. isOkBtnHighlight:NO
  650. didClickOk:^{
  651. } didClickCancel:^{
  652. [HWDataManager setBoolWithKey:Const_file_downLoad_need_read value:YES];
  653. }];
  654. nextVC.modalPresentationStyle = UIModalPresentationCustom;
  655. [self presentViewController:nextVC animated:YES completion:^{
  656. nextVC.view.superview.backgroundColor = [UIColor clearColor];
  657. }];
  658. }
  659. - (void)checkFileTransferTask
  660. {//有个偶现的闪退在BGFMDB
  661. [[uploadFileManager shareInstance] checkHadUploadTaskWithComplete:^(BOOL isSuccess) {
  662. self->hadUploadTaskType = isSuccess;
  663. [self setRightButtonRedTypeFun];
  664. }];
  665. KWeakSelf
  666. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  667. [[downloadManager shareInstance] checkHadDownloadTaskWithComplete:^(BOOL isSuccess) {
  668. self->hadDownloadTaskType = isSuccess;
  669. [weakSelf setRightButtonRedTypeFun];
  670. }];
  671. });
  672. }
  673. - (void)setRightButtonRedTypeFun
  674. {
  675. mainBlock(^{
  676. if(self->hadUploadTaskType || self->hadDownloadTaskType){
  677. self->rightRedView.hidden = NO;
  678. }
  679. else{
  680. self->rightRedView.hidden = YES;
  681. }
  682. });
  683. }
  684. - (void)didiClikRightButGotoTransferListFun:(UIButton*)but
  685. {
  686. uploadFileRecordViewController *vc = [uploadFileRecordViewController new];
  687. [self.navigationController pushViewController:vc animated:YES];
  688. }
  689. #pragma mark 获取文件数据
  690. - (void)getFileListFun
  691. {
  692. NSMutableDictionary*paraDict = [NSMutableDictionary new];
  693. if(_isPhotoType){
  694. [paraDict setValue:@"pic" forKey:@"type"];
  695. }
  696. else{
  697. [paraDict setValue:@"video" forKey:@"type"];
  698. }
  699. NSArray *diskNameArr = [_defaultDiskPath componentsSeparatedByString:@"/"];
  700. if(diskNameArr && diskNameArr.count >= 2){
  701. NSString *name = diskNameArr.lastObject;
  702. if(name.length == 0)
  703. {
  704. name = diskNameArr[diskNameArr.count -2];
  705. }
  706. [paraDict setValue:name forKey:@"path"];
  707. }
  708. [self showNewIndicatorHaveStrWithCanBack:YES canTouch:NO showText:NSLocalizedString(@"common_loading_tip",nil)];
  709. KWeakSelf
  710. [[netWorkManager shareInstance] cloudPhoneGETCallBackCode:@"getFileListByDay" Parameters:paraDict success:^(id _Nonnull responseObject) {
  711. [weakSelf removeNewIndicatorHaveStr];
  712. weakSelf.curNASFilePicModel = [[NASFilePicModel alloc] initWithDictionary:responseObject error:nil];
  713. [weakSelf.dataCollectionView reloadData];
  714. } failure:^(NSError * _Nonnull error) {
  715. [weakSelf removeNewIndicatorHaveStr];
  716. }];
  717. }
  718. #pragma mark 点击图片详情
  719. - (void)didClickPicDetailsWithSection:(NSInteger)section withRow:(NSInteger)row{
  720. if(_curNASFilePicModel){
  721. NSMutableArray *totalArr = [NSMutableArray new];
  722. NSInteger index = 0;
  723. for (int i=0; i<_curNASFilePicModel.data.fileList.count; i++) {
  724. NASFilePicTimeArrModel *timeModel = _curNASFilePicModel.data.fileList[i];
  725. if(i == section){
  726. index = totalArr.count + row;
  727. }
  728. [totalArr addObjectsFromArray:timeModel.list];
  729. }
  730. imageDetailsScrollViewController *vc = [imageDetailsScrollViewController new];
  731. vc.index = index;
  732. vc.totalDataArr = totalArr;
  733. [self.navigationController pushViewController:vc animated:YES];
  734. }
  735. }
  736. - (void)gotoDownLoadFileFun
  737. {
  738. if(_didSelectListArr.count == 0){
  739. [[iToast makeText:@""] show];
  740. return;
  741. }
  742. NSMutableArray *arr = [NSMutableArray new];
  743. for (NASFilePicDataArrModel *dataModel in _didSelectListArr) {
  744. couldPhoneFileModel* fileModel = [couldPhoneFileModel new];
  745. fileModel.fileType = @".jpg";
  746. fileModel.path = dataModel.path;
  747. fileModel.name = dataModel.name;
  748. fileModel.length = dataModel.size;
  749. [arr addObject:fileModel];
  750. }
  751. uploadFileRecordViewController *vc = [uploadFileRecordViewController new];
  752. [self.navigationController pushViewController:vc animated:YES];
  753. vc.isDownloadingType = YES;
  754. [vc gotoDownloadFile:arr];
  755. }
  756. @end