uploadImageOrVideoViewController.m 28 KB

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