previewAudioOrDocumentViewController.m 34 KB

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