uploadImageOrVideoViewController.m 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841
  1. //
  2. // uploadImageOrVideoViewController.m
  3. // 隐私保护
  4. //
  5. // Created by xd h on 2023/11/9.
  6. //
  7. #import "uploadImageOrVideoViewController.h"
  8. #import <AssetsLibrary/AssetsLibrary.h>
  9. #import <AVFoundation/AVFoundation.h>
  10. #import "AJPhotoListView.h"
  11. #import "AJPhotoGroupView.h"
  12. #import "AJPhotoListCell.h"
  13. #import "uploadFileBottomView.h"
  14. #import "PhotoPreviewViewController.h"
  15. #import "TZAssetModel+imageData.h"
  16. #import "uploadFileRecordViewController.h"
  17. #import "couldPhoneBaseInfoModel.h"
  18. #import "fileTransferPathCheckViewController.h"
  19. #import "ComontAlretViewController.h"
  20. @interface uploadImageOrVideoViewController ()<AJPhotoGroupViewProtocol,UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout,DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>
  21. {
  22. couldPhoneBaseInfoModel *baseInfoModel;
  23. BOOL isNotPhotoPermission;//没有权限
  24. }
  25. @property (strong, nonatomic) AJPhotoGroupView *photoGroupView;
  26. @property (strong, nonatomic) UILabel *MytitleLabel;
  27. @property (strong, nonatomic) UIImageView *selectTip;
  28. @property (nonatomic,assign) BOOL isNotAllowed;
  29. @property (strong, nonatomic) UIView *bgMaskView;
  30. @property (strong, nonatomic) AJPhotoListView *photoListView;
  31. @property (strong, nonatomic) NSMutableArray *assets;
  32. @property (strong, nonatomic) NSIndexPath *lastAccessed;
  33. @property (strong, nonatomic) uploadFileBottomView *uploadFileBottomV;
  34. //最多选择项
  35. //@property (nonatomic, assign) NSInteger maximumNumberOfSelection;
  36. //最少选择项
  37. @property (nonatomic, assign) NSInteger minimumNumberOfSelection;
  38. //是否开启多选
  39. @property (nonatomic, assign) BOOL multipleSelection;
  40. @property (nonatomic,assign) BOOL isNotFirstType;
  41. @end
  42. @implementation uploadImageOrVideoViewController
  43. - (void)viewDidLoad {
  44. [super viewDidLoad];
  45. // Do any additional setup after loading the view.
  46. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getCouldPhoneBaseInfoFun:) name:getCouldPhoneBaseInfoNotification object:nil];
  47. [self.view setBackgroundColor:HWF5F7FAColor];
  48. [self.toolBar setHidden:YES];
  49. [self.navigationBar setHidden:YES];
  50. [self.navBarBGView setHidden:NO];
  51. [self initBaselUIFun];
  52. _isNotAllowed = YES;
  53. //_maximumNumberOfSelection = 3;
  54. _minimumNumberOfSelection = 0;
  55. _multipleSelection = YES;
  56. if(!_selectionFilter)
  57. {
  58. _selectionFilter = [NSPredicate predicateWithValue:YES];
  59. }
  60. [self checkVideoAccessFun];
  61. [[webRtcManager shareManager] getBaseInfoFun];
  62. }
  63. - (void)initBaselUIFun
  64. {
  65. [self initNavHeadUIFun];
  66. //列表view
  67. [self setupPhotoListView];
  68. [self setupUploadFileBottomView];
  69. //相册分组
  70. [self setupGroupView];
  71. }
  72. - (void)initNavHeadUIFun
  73. {
  74. //title
  75. UILabel *titleLabel = [[UILabel alloc] init];
  76. titleLabel.textAlignment = NSTextAlignmentCenter;
  77. titleLabel.font = [UIFont boldSystemFontOfSize:18.0];
  78. titleLabel.textColor = [UIColor blackColor];
  79. titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
  80. [self.navBarBGView addSubview:titleLabel];
  81. self.MytitleLabel = titleLabel;
  82. //selectTipImageView
  83. UIImageView *selectTip = [[UIImageView alloc] init];
  84. selectTip.image = [UIImage imageNamed:@"upload_image_arrow"];
  85. selectTip.translatesAutoresizingMaskIntoConstraints = NO;
  86. [self.navBarBGView addSubview:selectTip];
  87. self.selectTip = selectTip;
  88. UIButton *tapBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  89. tapBtn.backgroundColor = [UIColor clearColor];
  90. tapBtn.translatesAutoresizingMaskIntoConstraints = NO;
  91. [tapBtn addTarget:self action:@selector(selectGroupAction:) forControlEvents:UIControlEventTouchUpInside];
  92. [self.navBarBGView addSubview:tapBtn];
  93. [tapBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  94. make.centerX.mas_equalTo(self.navBarBGView.mas_centerX);
  95. make.centerY.mas_equalTo(self.backBtn.mas_centerY);
  96. make.width.mas_equalTo(100);
  97. make.height.mas_equalTo(30);
  98. }];
  99. [self setTitleLabelText:@""];
  100. UIButton *rightBut = [[UIButton alloc] init];
  101. [rightBut setTitle:NSLocalizedString(@"File_upload_Record_select_all",nil) forState:UIControlStateNormal];
  102. [rightBut setTitle:NSLocalizedString(@"File_upload_cancel_select_all",nil) forState:UIControlStateSelected];
  103. [rightBut setTitleColor:[UIColor hwColor:@"#01B7EA" alpha:1.0] forState:UIControlStateNormal];
  104. rightBut.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
  105. [rightBut addTarget:self action:@selector(didClickSelectAllButton:) forControlEvents:UIControlEventTouchUpInside];
  106. [self.navBarBGView addSubview:rightBut];
  107. //多国语言适配
  108. NSString *languageCode = [NSLocale preferredLanguages][0];
  109. if([languageCode rangeOfString:@"ja-"].location != NSNotFound)
  110. {
  111. rightBut.titleLabel.font = [UIFont systemFontOfSize:13.0];
  112. }
  113. [rightBut mas_makeConstraints:^(MASConstraintMaker *make) {
  114. make.right.mas_equalTo(-20);
  115. make.centerY.mas_equalTo(self.backBtn.mas_centerY);
  116. make.width.mas_equalTo(100);
  117. make.height.mas_equalTo(30);
  118. }];
  119. }
  120. #pragma mark 设置相册标题
  121. - (void)setTitleLabelText:(NSString*)title
  122. {
  123. self.MytitleLabel.text = title;
  124. CGFloat curWidth = [title boundingRectWithSize:CGSizeMake(SCREEN_W, 30) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:18.f]} context:nil].size.width;
  125. curWidth += 20;
  126. //HLog(@"title w:%f",curWidth);
  127. [self.MytitleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  128. make.centerX.mas_equalTo(self.navBarBGView.mas_centerX).offset(-10);
  129. make.centerY.mas_equalTo(self.backBtn.mas_centerY);
  130. make.width.mas_equalTo(curWidth);
  131. make.height.mas_equalTo(30);
  132. }];
  133. //self.MytitleLabel.backgroundColor = [UIColor greenColor];
  134. [self.selectTip mas_makeConstraints:^(MASConstraintMaker *make) {
  135. make.left.mas_equalTo(self.MytitleLabel.mas_right).offset(2);
  136. make.centerY.mas_equalTo(self.backBtn.mas_centerY);
  137. make.width.mas_equalTo(15);
  138. make.height.mas_equalTo(15);
  139. }];
  140. }
  141. #pragma mark 点击全选
  142. - (void)didClickSelectAllButton:(UIButton*)but
  143. {
  144. if(!self.assets ||self.assets.count == 0){
  145. return;
  146. }
  147. but.selected = !but.selected;
  148. if(but.selected){
  149. [self.indexPathsForSelectedItems removeAllObjects];
  150. [SVProgressHUD show];
  151. for (int i= 0; i<self.assets.count; i++) {
  152. TZAssetModel *model = self.assets[i];
  153. if(i == self.assets.count -1){
  154. [self didSelectModel:model isLastModel:YES];
  155. }
  156. else{
  157. [self didSelectModel:model isLastModel:NO];
  158. }
  159. }
  160. // for (TZAssetModel *model in self.assets) {
  161. // [self didSelectModel:model isLastModel:NO];
  162. // }
  163. }
  164. else{
  165. for (TZAssetModel *model in self.assets) {
  166. model.isSelected = NO;
  167. }
  168. [self.indexPathsForSelectedItems removeAllObjects];
  169. }
  170. [self refreshAllDataFun];
  171. }
  172. #pragma mark 判断手机相册权限
  173. - (void)checkVideoAccessFun
  174. {
  175. AVAuthorizationStatus authStatus =[AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
  176. //判断摄像头状态是否可用
  177. if(authStatus==AVAuthorizationStatusAuthorized){
  178. _isNotAllowed = NO;
  179. }else{
  180. NSLog(@"未开启相机权限,请前往设置中开启");
  181. [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
  182. if (granted){
  183. self->_isNotAllowed = NO;
  184. // mainBlock(^{
  185. //
  186. // });
  187. }
  188. }];
  189. }
  190. //相册权限
  191. if (![[TZImageManager manager] authorizationStatusAuthorized]){
  192. KWeakSelf
  193. [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
  194. if(status == PHAuthorizationStatusAuthorized){
  195. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  196. [weakSelf.photoGroupView setupGroup];
  197. [weakSelf delayedSetPhotoGroupViewFrameFun];
  198. });
  199. }
  200. else if (status == PHAuthorizationStatusDenied || status == PHAuthorizationStatusRestricted) {
  201. mainBlock(^{
  202. // 用户拒绝授权或设备受限,提示用户去系统设置中开启权限
  203. [weakSelf requestPhotoLibraryAccessWithAlert];
  204. });
  205. }
  206. }];
  207. }
  208. }
  209. /**
  210. * 照片列表
  211. */
  212. - (void)setupPhotoListView {
  213. AJPhotoListView *collectionView = [[AJPhotoListView alloc] init];
  214. collectionView.dataSource = self;
  215. collectionView.delegate = self;
  216. collectionView.translatesAutoresizingMaskIntoConstraints = NO;
  217. [self.view insertSubview:collectionView atIndex:0];
  218. self.photoListView = collectionView;
  219. //空数据引入第三方开源处理
  220. collectionView.emptyDataSetSource = self;
  221. collectionView.emptyDataSetDelegate = self;
  222. [collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  223. make.left.mas_equalTo(0);
  224. make.right.mas_equalTo(0);
  225. make.bottom.mas_equalTo(-(60 + safeArea));
  226. make.top.equalTo(self.navBarBGView.mas_bottom).offset(0.f);
  227. }];
  228. }
  229. /**
  230. * 照片列表
  231. */
  232. - (void)setupUploadFileBottomView
  233. {
  234. uploadFileBottomView *bottomView = [[uploadFileBottomView alloc] init];
  235. [self.view insertSubview:bottomView atIndex:0];
  236. self.uploadFileBottomV = bottomView;
  237. [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
  238. make.left.mas_equalTo(0);
  239. make.right.mas_equalTo(0);
  240. make.bottom.mas_equalTo(0);
  241. make.height.mas_equalTo(60 + safeArea);
  242. }];
  243. KWeakSelf
  244. bottomView.didClickUploadFile = ^{
  245. [weakSelf gotoUploadFileRecordFun];
  246. };
  247. bottomView.didClickbottomFun = ^{
  248. [weakSelf gotofileTransferPathCheckVCFun];
  249. };
  250. }
  251. /**
  252. * 相册
  253. */
  254. - (void)setupGroupView {
  255. AJPhotoGroupView *photoGroupView = [[AJPhotoGroupView alloc] init];
  256. photoGroupView.my_delegate = self;
  257. photoGroupView.isPhotoType = _isPhotoType;
  258. [self.view insertSubview:photoGroupView belowSubview:self.navBarBGView];
  259. self.photoGroupView = photoGroupView;
  260. photoGroupView.hidden = YES;
  261. photoGroupView.translatesAutoresizingMaskIntoConstraints = NO;
  262. [self.photoGroupView setupGroup];
  263. [self delayedSetPhotoGroupViewFrameFun];
  264. }
  265. #pragma mark 延时设置photoGroupView frame
  266. - (void)delayedSetPhotoGroupViewFrameFun
  267. {
  268. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  269. NSInteger maxCount = 6;
  270. if(self.photoGroupView.albumGroups.count < maxCount){
  271. maxCount = self.photoGroupView.albumGroups.count;
  272. }
  273. [self.photoGroupView mas_remakeConstraints:^(MASConstraintMaker *make) {
  274. make.left.mas_equalTo(0);
  275. make.right.mas_equalTo(0);
  276. make.height.mas_equalTo(60.0 * maxCount);
  277. make.top.equalTo(self.navBarBGView.mas_bottom).offset(0.f);
  278. }];
  279. });
  280. }
  281. #pragma mark - 相册切换
  282. - (void)selectGroupAction:(UIButton *)sender {
  283. //无权限
  284. if (self.isNotAllowed) {
  285. return;
  286. }
  287. if (self.photoGroupView.hidden) {
  288. [self bgMaskView];
  289. self.bgMaskView.hidden = NO;
  290. self.photoGroupView.hidden = NO;
  291. [UIView animateWithDuration:0.3 animations:^{
  292. CGRect rect = self.photoGroupView.frame;
  293. rect.origin.y = CGRectGetMaxY(self.navBarBGView.frame);
  294. self.photoGroupView.frame = rect;
  295. self.selectTip.transform = CGAffineTransformMakeRotation(M_PI);
  296. }];
  297. } else {
  298. [self hidenGroupView];
  299. }
  300. }
  301. - (void)hidenGroupView {
  302. //[self.bgMaskView removeFromSuperview];
  303. self.bgMaskView.hidden = YES;
  304. [UIView animateWithDuration:0.3 animations:^{
  305. CGRect rect = self.photoGroupView.frame;
  306. rect.origin.y = -SCREEN_H;
  307. self.photoGroupView.frame = rect;
  308. self.selectTip.transform = CGAffineTransformIdentity;
  309. }completion:^(BOOL finished) {
  310. self.photoGroupView.hidden = YES;
  311. }];
  312. }
  313. #pragma mark - 遮罩背景
  314. - (UIView *)bgMaskView {
  315. if (_bgMaskView == nil) {
  316. UIView *bgMaskView = [[UIView alloc] init];
  317. bgMaskView.alpha = 0.5;
  318. bgMaskView.translatesAutoresizingMaskIntoConstraints = NO;
  319. bgMaskView.backgroundColor = [UIColor blackColor];
  320. //[self.view insertSubview:bgMaskView aboveSubview:self.photoListView];
  321. [self.view insertSubview:bgMaskView belowSubview:self.photoGroupView];
  322. bgMaskView.userInteractionEnabled = YES;
  323. [bgMaskView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapBgMaskView:)]];
  324. _bgMaskView = bgMaskView;
  325. [bgMaskView mas_makeConstraints:^(MASConstraintMaker *make) {
  326. make.left.mas_equalTo(0);
  327. make.right.mas_equalTo(0);
  328. make.bottom.mas_equalTo(0);
  329. make.top.equalTo(self.navBarBGView.mas_bottom).offset(0.f);
  330. }];
  331. }
  332. return _bgMaskView;
  333. }
  334. - (void)tapBgMaskView:(UITapGestureRecognizer *)sender {
  335. if (!self.photoGroupView.hidden) {
  336. [self hidenGroupView];
  337. }
  338. }
  339. #pragma mark - BoPhotoGroupViewProtocol
  340. - (void)didSelectGroup:(TZAlbumModel *)model {
  341. [self loadAssets:model];
  342. [self setTitleLabelText:model.name];
  343. [self hidenGroupView];
  344. }
  345. //加载图片
  346. - (void)loadAssets:(TZAlbumModel *)model {
  347. [self.indexPathsForSelectedItems removeAllObjects];
  348. [self.assets removeAllObjects];
  349. [[TZImageManager manager] getAssetsFromFetchResult:model.result completion:^(NSArray<TZAssetModel *> *models) {
  350. self->_assets = [NSMutableArray arrayWithArray:models];
  351. [self.photoListView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:YES];
  352. [self.photoListView reloadData];
  353. }];
  354. }
  355. #pragma mark - uicollectionDelegate
  356. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  357. return self.assets.count;
  358. }
  359. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  360. static NSString *cellIdentifer = @"cell";
  361. AJPhotoListCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifer forIndexPath:indexPath];
  362. BOOL isSelected = [self.indexPathsForSelectedItems containsObject:self.assets[indexPath.row]];
  363. [cell bind:self.assets[indexPath.row] selectionFilter:self.selectionFilter isSelected:isSelected];
  364. KWeakSelf
  365. cell.didClckSelectBut = ^(BOOL isSelect) {
  366. [weakSelf handlCellSelectFunBy:indexPath];
  367. };
  368. return cell;
  369. }
  370. - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
  371. return UIEdgeInsetsMake(5, 5, 5, 5);
  372. }
  373. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  374. CGFloat wh = (collectionView.bounds.size.width - 20)/3.0;
  375. return CGSizeMake(wh, wh);
  376. }
  377. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
  378. return 5.0;
  379. }
  380. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
  381. return 5.0;
  382. }
  383. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  384. NSInteger curRow = indexPath.row;
  385. PhotoPreviewViewController *vc =[PhotoPreviewViewController new];
  386. vc.assets = _assets;
  387. vc.currentIndex = curRow;
  388. vc.indexPathsForSelectedItems = _indexPathsForSelectedItems;
  389. //vc.maximumNumberOfSelection = _maximumNumberOfSelection;
  390. vc.minimumNumberOfSelection = _minimumNumberOfSelection;
  391. vc.availableStorage = self.uploadFileBottomV.availableStorage;
  392. vc.isPhotoType = _isPhotoType;
  393. [self.navigationController pushViewController:vc animated:YES];
  394. KWeakSelf
  395. vc.changeSelectIndex = ^(NSMutableArray * _Nonnull indexPathsForSelectedItems) {
  396. [weakSelf refreshDataAndUIFunWith:indexPathsForSelectedItems];
  397. };
  398. }
  399. #pragma mark 空数据
  400. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
  401. NSString *imageName = @"common_no_data_pic";
  402. return [UIImage imageNamed:imageName];
  403. }
  404. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {
  405. NSString *text = NSLocalizedString(@"common_no_data_tip",nil);
  406. if(isNotPhotoPermission){
  407. text = NSLocalizedString(@"enable_photo_permission_noData_tip",nil);
  408. }
  409. NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:16.0f],
  410. NSForegroundColorAttributeName: HW999999Color};
  411. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  412. }
  413. //调整图片位置
  414. - (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView {
  415. return -50;
  416. }
  417. #pragma mark 从详情页回来 刷新数据和UI
  418. - (void)refreshDataAndUIFunWith:(NSMutableArray *)indexPathsForSelectedItems
  419. {
  420. self.indexPathsForSelectedItems = indexPathsForSelectedItems;
  421. [self refreshAllDataFun];
  422. }
  423. #pragma mark 刷新所有数据
  424. - (void)refreshAllDataFun
  425. {
  426. [self setDataToBottomViewFun];
  427. [self.photoListView reloadData];
  428. }
  429. #pragma mark 处理点击选中相关
  430. - (void)handlCellSelectFunBy:(NSIndexPath *)indexPath
  431. {
  432. AJPhotoListCell *cell = (AJPhotoListCell *)[self.photoListView cellForItemAtIndexPath:indexPath];
  433. TZAssetModel *model = self.assets[indexPath.row];
  434. //超出最大限制
  435. // if (self.indexPathsForSelectedItems.count >= self.maximumNumberOfSelection ) {
  436. // return;
  437. // }
  438. //取消选中
  439. if ([self.indexPathsForSelectedItems containsObject:model]) {
  440. [self.indexPathsForSelectedItems removeObject:model];
  441. model.isSelected = NO;
  442. [cell isSelected:NO];
  443. [self setDataToBottomViewFun];
  444. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  445. [self.uploadFileBottomV setUploadButtonCanClickFunBy:YES];
  446. });
  447. }
  448. else
  449. {//选中
  450. [self didSelectModel:model isLastModel:YES];
  451. [cell isSelected:YES];
  452. }
  453. }
  454. #pragma mark 选中某个cell
  455. - (void)didSelectModel:(TZAssetModel *)model isLastModel:(BOOL)isLast
  456. {//选中
  457. [self.indexPathsForSelectedItems addObject:model];
  458. model.isSelected = YES;
  459. if(!model.totalBytes)
  460. {
  461. [[PHImageManager defaultManager] requestImageDataForAsset:model.asset options:nil resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
  462. // 直接得到最终的 NSData 数据
  463. if (imageData) {
  464. //model.imageData = imageData;
  465. model.totalBytes = [imageData length];
  466. }
  467. if(model.type != TZAssetModelMediaTypeVideo){
  468. [self setDataToBottomViewFun];
  469. }
  470. if(isLast){
  471. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  472. [SVProgressHUD dismiss];
  473. [self.uploadFileBottomV setUploadButtonCanClickFunBy:YES];
  474. });
  475. }
  476. }];
  477. if(model.type == TZAssetModelMediaTypeVideo){
  478. PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
  479. options.version = PHVideoRequestOptionsVersionOriginal;
  480. [[PHImageManager defaultManager] requestAVAssetForVideo:model.asset options:options resultHandler:^(AVAsset *asset, AVAudioMix *audioMix, NSDictionary *info) {
  481. if ([asset isKindOfClass:[AVURLAsset class]]) {
  482. AVURLAsset* urlAsset = (AVURLAsset*)asset;
  483. //NSData *videoData = [NSData dataWithContentsOfURL:urlAsset.URL];
  484. NSNumber *size;
  485. [urlAsset.URL getResourceValue:&size forKey:NSURLFileSizeKey error:nil];
  486. //NSLog(@"size is %f",[size floatValue]/(1024.0*1024.0));
  487. //model.videoData = videoData;
  488. //model.totalBytes = [videoData length];
  489. model.totalBytes = size.longLongValue;
  490. [self setDataToBottomViewFun];
  491. }
  492. if(isLast){
  493. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  494. [SVProgressHUD dismiss];
  495. [self.uploadFileBottomV setUploadButtonCanClickFunBy:YES];
  496. });
  497. }
  498. }];
  499. }
  500. }
  501. else{
  502. [self setDataToBottomViewFun];
  503. if(isLast){
  504. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  505. [SVProgressHUD dismiss];
  506. [self.uploadFileBottomV setUploadButtonCanClickFunBy:YES];
  507. });
  508. }
  509. }
  510. }
  511. #pragma mark 同步数据到底部
  512. - (void)setDataToBottomViewFun
  513. {
  514. mainBlock(^{
  515. self.uploadFileBottomV.indexPathsForSelectedItems = self.indexPathsForSelectedItems;
  516. });
  517. }
  518. #pragma mark - getter/setter
  519. - (NSMutableArray *)assets {
  520. if (!_assets) {
  521. _assets = [[NSMutableArray alloc] init];
  522. }
  523. return _assets;
  524. }
  525. - (NSMutableArray *)indexPathsForSelectedItems {
  526. if (!_indexPathsForSelectedItems) {
  527. _indexPathsForSelectedItems = [[NSMutableArray alloc] init];
  528. }
  529. return _indexPathsForSelectedItems;
  530. }
  531. #pragma mark 跳转上传记录
  532. - (void)gotoUploadFileRecordFun
  533. {
  534. uploadFileRecordViewController *vc = [uploadFileRecordViewController new];
  535. [self.navigationController pushViewController:vc animated:YES];
  536. vc.isUploadingType = YES;
  537. [vc gotoUploadFile:_indexPathsForSelectedItems];
  538. if(_isPhotoType){
  539. //数据埋点
  540. [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"Image_upload"];
  541. }
  542. else{
  543. //数据埋点
  544. [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"Video_upload"];
  545. }
  546. }
  547. - (void)getCouldPhoneBaseInfoFun:(NSNotification*)not
  548. {
  549. baseInfoModel = [not object];
  550. //HLog(@"%@",baseInfoModel);
  551. [self handelAfterGetBaseInfoModelData];
  552. }
  553. - (void)handelAfterGetBaseInfoModelData
  554. {
  555. // if(!baseInfoModel || ![baseInfoModel isKindOfClass:[couldPhoneBaseInfoModel class]]){
  556. // return;
  557. // }
  558. NSString * uploadDefaultPath = [HWDataManager getStringWithKey:stringKeyAddSn(Const_photo_upload_default_path)];
  559. if(!uploadDefaultPath || uploadDefaultPath.length == 0){
  560. [HWDataManager setStringWithKey:stringKeyAddSn(Const_photo_upload_default_path) value:Const_default_upload_path];
  561. uploadDefaultPath = Const_default_upload_path;
  562. }
  563. BOOL isExtraFileType = NO;
  564. BOOL isExtraPathFind = NO;
  565. if(uploadDefaultPath){
  566. if(![uploadDefaultPath containsString:@"sdcard/"]){
  567. isExtraFileType = YES;
  568. }
  569. }
  570. if(uploadDefaultPath && ksharedAppDelegate.cloudPhoneExtraFileListMod){
  571. NSArray*arr = ksharedAppDelegate.cloudPhoneExtraFileListMod.data;
  572. for (cloudPhoneExtraFileModel*model in arr) {
  573. if([uploadDefaultPath containsString:model.extraPath]){
  574. NSString * availableStorage = @"";
  575. NSInteger totalSize_k = model.extraAvableSize / 1024;
  576. if(totalSize_k < 1024){
  577. availableStorage = [[NSString alloc] initWithFormat:@"%ldKB",totalSize_k];
  578. }
  579. else if( totalSize_k >= 1024 && totalSize_k < 1024*1024){
  580. availableStorage = [[NSString alloc] initWithFormat:@"%.2fMB",totalSize_k/1024.0];
  581. }
  582. else{
  583. availableStorage = [[NSString alloc] initWithFormat:@"%.2fG",totalSize_k/1024.0/1024.0];
  584. }
  585. self.uploadFileBottomV.availableStorage = availableStorage;
  586. self.uploadFileBottomV.available = model.extraAvableSize;
  587. isExtraPathFind = YES;
  588. break;
  589. }
  590. }
  591. }
  592. if(!isExtraPathFind){
  593. // self.uploadFileBottomV.availableStorage = baseInfoModel.data.availableStorage;
  594. // self.uploadFileBottomV.available = baseInfoModel.data.available;
  595. }
  596. if(isExtraFileType && !isExtraPathFind){
  597. self.uploadFileBottomV.isExtraFileAndNotFindPathType = YES;
  598. }
  599. else{
  600. self.uploadFileBottomV.isExtraFileAndNotFindPathType = NO;
  601. }
  602. [self setDataToBottomViewFun];
  603. }
  604. - (void)gotofileTransferPathCheckVCFun
  605. {
  606. fileTransferPathCheckViewController *vc = [fileTransferPathCheckViewController new];
  607. vc.curType = 1;
  608. [self.navigationController pushViewController:vc animated:YES];
  609. KWeakSelf
  610. vc.didChangeSavePathFun = ^{
  611. [weakSelf.uploadFileBottomV setSavePathDataFun];
  612. [weakSelf handelAfterGetBaseInfoModelData];
  613. };
  614. }
  615. - (void)viewDidAppear:(BOOL)animated{
  616. [super viewDidAppear:animated];
  617. if(!_isNotFirstType){
  618. [self showUploadTipFun];
  619. //权限访问时 重新拿数据 验证iOS 15.0有效 17.5.1无效 (viewDidAppear 和applicationDidBecomeActive 均不走)
  620. [self.photoGroupView setupGroup];
  621. [self delayedSetPhotoGroupViewFrameFun];
  622. _isNotFirstType = YES;
  623. }
  624. }
  625. - (void)viewWillDisappear:(BOOL)animated
  626. {
  627. [super viewWillDisappear:animated];
  628. [SVProgressHUD dismiss];
  629. }
  630. - (void)showUploadTipFun
  631. {
  632. BOOL didReadUploadTipType = [HWDataManager getBoolWithKey:Const_file_upLoad_need_read];
  633. if(didReadUploadTipType){
  634. return;
  635. }
  636. //KWeakSelf
  637. /*弹窗提示恢复出厂*/
  638. ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:nil
  639. msg:NSLocalizedString(@"upload_download_need_read_msg",nil)
  640. imageStr:nil
  641. cancelTitle:NSLocalizedString(@"guide_set_pwd_guide_know",nil)
  642. okTitle:nil
  643. isOkBtnHighlight:NO
  644. didClickOk:^{
  645. } didClickCancel:^{
  646. [HWDataManager setBoolWithKey:Const_file_upLoad_need_read value:YES];
  647. }];
  648. nextVC.modalPresentationStyle = UIModalPresentationCustom;
  649. [self presentViewController:nextVC animated:YES completion:^{
  650. nextVC.view.superview.backgroundColor = [UIColor clearColor];
  651. }];
  652. }
  653. #pragma mark 用户拒接授权相册
  654. - (void)requestPhotoLibraryAccessWithAlert {
  655. isNotPhotoPermission = YES;
  656. [self.photoListView reloadData];
  657. //KWeakSelf
  658. /*弹窗提示重启*/
  659. ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"enable_photo_permission",nil)
  660. msg:NSLocalizedString(@"enable_photo_permission_tip",nil)
  661. imageStr:@""
  662. cancelTitle:NSLocalizedString(@"other_cancel",nil)
  663. okTitle:NSLocalizedString(@"more_set",nil) isOkBtnHighlight:YES
  664. didClickOk:^{
  665. // 打开应用的设置页面
  666. NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
  667. if ([[UIApplication sharedApplication] canOpenURL:url]) {
  668. [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
  669. }
  670. } didClickCancel:^{
  671. }];
  672. nextVC.modalPresentationStyle = UIModalPresentationCustom;
  673. [self presentViewController:nextVC animated:YES completion:^{
  674. nextVC.view.superview.backgroundColor = [UIColor clearColor];
  675. }];
  676. }
  677. @end