previewImageOrVideoViewController.m 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975
  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. [[iToast makeText:@"点击删除"] show];
  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(@"File_download_file_no_data",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. }
  540. #pragma mark 设置标题
  541. - (void)setTitleLabelText:(NSString*)title
  542. {
  543. NSArray *diskNameArr = [_defaultDiskPath componentsSeparatedByString:@"/"];
  544. if(diskNameArr && diskNameArr.count >= 2){
  545. NSString *name = diskNameArr.lastObject;
  546. if(name.length == 0)
  547. {
  548. name = diskNameArr[diskNameArr.count -2];
  549. }
  550. title = [[NSString alloc] initWithFormat:@"[%@]%@",name,title];
  551. }
  552. self.MytitleLabel.text = title;
  553. CGFloat curWidth = [title boundingRectWithSize:CGSizeMake(SCREEN_W, 30) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:16.f]} context:nil].size.width;
  554. curWidth += 20;
  555. //HLog(@"title w:%f",curWidth);
  556. [self.MytitleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  557. make.centerX.mas_equalTo(self.navBarBGView.mas_centerX).offset(-10);
  558. make.centerY.mas_equalTo(self.backBtn.mas_centerY);
  559. make.width.mas_equalTo(curWidth);
  560. make.height.mas_equalTo(30);
  561. }];
  562. //self.MytitleLabel.backgroundColor = [UIColor greenColor];
  563. [self.selectTip mas_makeConstraints:^(MASConstraintMaker *make) {
  564. make.left.mas_equalTo(self.MytitleLabel.mas_right).offset(0);
  565. make.centerY.mas_equalTo(self.backBtn.mas_centerY);
  566. make.width.mas_equalTo(15);
  567. make.height.mas_equalTo(15);
  568. }];
  569. [tapBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
  570. make.centerX.mas_equalTo(self.navBarBGView.mas_centerX);
  571. make.centerY.mas_equalTo(self.backBtn.mas_centerY);
  572. make.width.mas_equalTo(curWidth+15);
  573. make.height.mas_equalTo(30);
  574. }];
  575. }
  576. #pragma mark 选择硬盘
  577. - (void)selectDiskAction:(UIButton*)but
  578. {
  579. if(self.diskListBgV.hidden){
  580. [self showDiskListVieFun];
  581. }
  582. else{
  583. [self hideDiskListVieFun];
  584. }
  585. }
  586. - (void)showDiskListVieFun
  587. {
  588. self.diskListBgV.hidden = NO;
  589. self.diskListTableV.hidden = NO;
  590. [UIView animateWithDuration:0.3 animations:^{
  591. CGRect rect = self.diskListTableV.frame;
  592. rect.origin.y = CGRectGetMaxY(self.navBarBGView.frame);
  593. self.diskListTableV.frame = rect;
  594. self.selectTip.transform = CGAffineTransformMakeRotation(M_PI);
  595. }];
  596. }
  597. - (void)hideDiskListVieFun
  598. {
  599. self.diskListBgV.hidden = YES;
  600. [UIView animateWithDuration:0.3 animations:^{
  601. self.diskListTableV.hidden = YES;
  602. self.selectTip.transform = CGAffineTransformIdentity;
  603. }completion:^(BOOL finished) {
  604. CGRect rect = self.diskListTableV.frame;
  605. rect.origin.y = 0;
  606. self.diskListTableV.frame = rect;
  607. }];
  608. }
  609. #pragma mark 设置标题
  610. - (void)setTitleAfterGetdiskFun
  611. {
  612. if(_isPhotoType){
  613. //self.titleLabel.text = NSLocalizedString(@"my_set_no_image_upload",nil) ;
  614. [self setTitleLabelText:NSLocalizedString(@"my_set_no_image_upload",nil)];
  615. }
  616. else{
  617. //self.titleLabel.text = NSLocalizedString(@"my_set_no_video_upload",nil) ;
  618. [self setTitleLabelText:NSLocalizedString(@"my_set_no_video_upload",nil)];
  619. }
  620. }
  621. - (void)viewWillAppear:(BOOL)animated
  622. {
  623. [super viewWillAppear:animated];
  624. }
  625. - (void)viewDidAppear:(BOOL)animated{
  626. [super viewDidAppear:animated];
  627. [self showDownloadTipFun];
  628. [self checkFileTransferTask];
  629. if(!_curNASFilePicModel){
  630. [self getFileListFun];
  631. }
  632. }
  633. - (void)viewWillDisappear:(BOOL)animated{
  634. [super viewWillDisappear:animated];
  635. //[self removeNewIndicator];
  636. [self removeNewIndicatorHaveStr];
  637. }
  638. - (void)gotoDownloadloadFileRecordFun
  639. {
  640. uploadFileRecordViewController *vc = [uploadFileRecordViewController new];
  641. [self.navigationController pushViewController:vc animated:YES];
  642. vc.isDownloadingType = YES;
  643. //[vc gotoDownloadFile:_downloadFileBottomV.indexPathsForSelectedItems];
  644. }
  645. - (void)showDownloadTipFun
  646. {
  647. BOOL didReadUploadTipType = [HWDataManager getBoolWithKey:Const_file_downLoad_need_read];
  648. if(didReadUploadTipType){
  649. return;
  650. }
  651. //KWeakSelf
  652. /*弹窗提示恢复出厂*/
  653. ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:nil
  654. msg:NSLocalizedString(@"upload_download_need_read_msg",nil)
  655. imageStr:nil
  656. cancelTitle:NSLocalizedString(@"guide_set_pwd_guide_know",nil)
  657. okTitle:nil
  658. isOkBtnHighlight:NO
  659. didClickOk:^{
  660. } didClickCancel:^{
  661. [HWDataManager setBoolWithKey:Const_file_downLoad_need_read value:YES];
  662. }];
  663. nextVC.modalPresentationStyle = UIModalPresentationCustom;
  664. [self presentViewController:nextVC animated:YES completion:^{
  665. nextVC.view.superview.backgroundColor = [UIColor clearColor];
  666. }];
  667. }
  668. - (void)checkFileTransferTask
  669. {//有个偶现的闪退在BGFMDB
  670. [[uploadFileManager shareInstance] checkHadUploadTaskWithComplete:^(BOOL isSuccess) {
  671. self->hadUploadTaskType = isSuccess;
  672. [self setRightButtonRedTypeFun];
  673. }];
  674. KWeakSelf
  675. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  676. [[downloadManager shareInstance] checkHadDownloadTaskWithComplete:^(BOOL isSuccess) {
  677. self->hadDownloadTaskType = isSuccess;
  678. [weakSelf setRightButtonRedTypeFun];
  679. }];
  680. });
  681. }
  682. - (void)setRightButtonRedTypeFun
  683. {
  684. mainBlock(^{
  685. if(self->hadUploadTaskType || self->hadDownloadTaskType){
  686. self->rightRedView.hidden = NO;
  687. }
  688. else{
  689. self->rightRedView.hidden = YES;
  690. }
  691. });
  692. }
  693. - (void)didiClikRightButGotoTransferListFun:(UIButton*)but
  694. {
  695. uploadFileRecordViewController *vc = [uploadFileRecordViewController new];
  696. [self.navigationController pushViewController:vc animated:YES];
  697. }
  698. #pragma mark 获取文件数据
  699. - (void)getFileListFun
  700. {
  701. NSMutableDictionary*paraDict = [NSMutableDictionary new];
  702. if(_isPhotoType){
  703. [paraDict setValue:@"pic" forKey:@"type"];
  704. }
  705. else{
  706. [paraDict setValue:@"video" forKey:@"type"];
  707. }
  708. NSArray *diskNameArr = [_defaultDiskPath componentsSeparatedByString:@"/"];
  709. if(diskNameArr && diskNameArr.count >= 2){
  710. NSString *name = diskNameArr.lastObject;
  711. if(name.length == 0)
  712. {
  713. name = diskNameArr[diskNameArr.count -2];
  714. }
  715. [paraDict setValue:name forKey:@"path"];
  716. }
  717. [self showNewIndicatorHaveStrWithCanBack:YES canTouch:NO showText:NSLocalizedString(@"common_loading_tip",nil)];
  718. KWeakSelf
  719. [[netWorkManager shareInstance] cloudPhoneGETCallBackCode:@"getFileListByDay" Parameters:paraDict success:^(id _Nonnull responseObject) {
  720. [weakSelf removeNewIndicatorHaveStr];
  721. weakSelf.curNASFilePicModel = [[NASFilePicModel alloc] initWithDictionary:responseObject error:nil];
  722. [weakSelf.dataCollectionView reloadData];
  723. } failure:^(NSError * _Nonnull error) {
  724. [weakSelf removeNewIndicatorHaveStr];
  725. }];
  726. }
  727. #pragma mark 点击图片详情
  728. - (void)didClickPicDetailsWithSection:(NSInteger)section withRow:(NSInteger)row{
  729. if(_curNASFilePicModel){
  730. NSMutableArray *totalArr = [NSMutableArray new];
  731. NSInteger index = 0;
  732. for (int i=0; i<_curNASFilePicModel.data.fileList.count; i++) {
  733. NASFilePicTimeArrModel *timeModel = _curNASFilePicModel.data.fileList[i];
  734. if(i == section){
  735. index = totalArr.count + row;
  736. }
  737. [totalArr addObjectsFromArray:timeModel.list];
  738. }
  739. imageDetailsScrollViewController *vc = [imageDetailsScrollViewController new];
  740. vc.index = index;
  741. vc.totalDataArr = totalArr;
  742. [self.navigationController pushViewController:vc animated:YES];
  743. vc.canShareType = canShareType;
  744. }
  745. }
  746. - (void)gotoDownLoadFileFun
  747. {
  748. if(_didSelectListArr.count == 0){
  749. [[iToast makeText:@""] show];
  750. return;
  751. }
  752. NSMutableArray *arr = [NSMutableArray new];
  753. for (NASFilePicDataArrModel *dataModel in _didSelectListArr) {
  754. couldPhoneFileModel* fileModel = [couldPhoneFileModel new];
  755. fileModel.fileType = @".jpg";
  756. fileModel.path = dataModel.path;
  757. fileModel.name = dataModel.name;
  758. fileModel.length = dataModel.size;
  759. [arr addObject:fileModel];
  760. }
  761. uploadFileRecordViewController *vc = [uploadFileRecordViewController new];
  762. [self.navigationController pushViewController:vc animated:YES];
  763. vc.isDownloadingType = YES;
  764. [vc gotoDownloadFile:arr];
  765. }
  766. - (void)setIsPhotoType:(BOOL)isPhotoType
  767. {
  768. _isPhotoType = isPhotoType;
  769. [self queryShareSwitchFunFun];
  770. }
  771. #pragma mark 获取分享开关
  772. -(void)queryShareSwitchFunFun
  773. {
  774. NSMutableDictionary *paraDict = [NSMutableDictionary new];
  775. if(_isPhotoType){
  776. [paraDict setValue:@2 forKey:@"type"];
  777. }
  778. else{
  779. [paraDict setValue:@3 forKey:@"type"];
  780. }
  781. KWeakSelf
  782. [[netWorkManager shareInstance] CommonGetWithCallBackCode:queryShareSwitchFun Parameters:paraDict success:^(id _Nonnull responseObject){
  783. queryShareModel *queryShareMod = [[queryShareModel alloc] initWithDictionary:responseObject error:nil];
  784. if(queryShareMod){
  785. self->canShareType = queryShareMod.data.configValue;
  786. [weakSelf.curEditTypeBottomView setCanShaewFunBy:queryShareMod.data.configValue];
  787. }
  788. } failure:^(NSError * _Nonnull error) {
  789. }];
  790. }
  791. @end