previewAudioOrDocumentViewController.m 33 KB

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