previewImageOrVideoViewController.m 36 KB

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