previewAudioOrDocumentViewController.m 33 KB

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