uploadImageOrVideoViewController.m 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  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. }];
  198. }
  199. }
  200. /**
  201. * 照片列表
  202. */
  203. - (void)setupPhotoListView {
  204. AJPhotoListView *collectionView = [[AJPhotoListView alloc] init];
  205. collectionView.dataSource = self;
  206. collectionView.delegate = self;
  207. collectionView.translatesAutoresizingMaskIntoConstraints = NO;
  208. [self.view insertSubview:collectionView atIndex:0];
  209. self.photoListView = collectionView;
  210. [collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  211. make.left.mas_equalTo(0);
  212. make.right.mas_equalTo(0);
  213. make.bottom.mas_equalTo(-(60 + safeArea));
  214. make.top.equalTo(self.navBarBGView.mas_bottom).offset(0.f);
  215. }];
  216. }
  217. /**
  218. * 照片列表
  219. */
  220. - (void)setupUploadFileBottomView
  221. {
  222. uploadFileBottomView *bottomView = [[uploadFileBottomView alloc] init];
  223. [self.view insertSubview:bottomView atIndex:0];
  224. self.uploadFileBottomV = bottomView;
  225. [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
  226. make.left.mas_equalTo(0);
  227. make.right.mas_equalTo(0);
  228. make.bottom.mas_equalTo(0);
  229. make.height.mas_equalTo(60 + safeArea);
  230. }];
  231. KWeakSelf
  232. bottomView.didClickUploadFile = ^{
  233. [weakSelf gotoUploadFileRecordFun];
  234. };
  235. bottomView.didClickbottomFun = ^{
  236. [weakSelf gotofileTransferPathCheckVCFun];
  237. };
  238. }
  239. /**
  240. * 相册
  241. */
  242. - (void)setupGroupView {
  243. AJPhotoGroupView *photoGroupView = [[AJPhotoGroupView alloc] init];
  244. photoGroupView.my_delegate = self;
  245. photoGroupView.isPhotoType = _isPhotoType;
  246. [self.view insertSubview:photoGroupView belowSubview:self.navBarBGView];
  247. self.photoGroupView = photoGroupView;
  248. photoGroupView.hidden = YES;
  249. photoGroupView.translatesAutoresizingMaskIntoConstraints = NO;
  250. [self.photoGroupView setupGroup];
  251. [self delayedSetPhotoGroupViewFrameFun];
  252. }
  253. #pragma mark 延时设置photoGroupView frame
  254. - (void)delayedSetPhotoGroupViewFrameFun
  255. {
  256. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  257. NSInteger maxCount = 6;
  258. if(self.photoGroupView.albumGroups.count < maxCount){
  259. maxCount = self.photoGroupView.albumGroups.count;
  260. }
  261. [self.photoGroupView mas_remakeConstraints:^(MASConstraintMaker *make) {
  262. make.left.mas_equalTo(0);
  263. make.right.mas_equalTo(0);
  264. make.height.mas_equalTo(60.0 * maxCount);
  265. make.top.equalTo(self.navBarBGView.mas_bottom).offset(0.f);
  266. }];
  267. });
  268. }
  269. #pragma mark - 相册切换
  270. - (void)selectGroupAction:(UIButton *)sender {
  271. //无权限
  272. if (self.isNotAllowed) {
  273. return;
  274. }
  275. if (self.photoGroupView.hidden) {
  276. [self bgMaskView];
  277. self.bgMaskView.hidden = NO;
  278. self.photoGroupView.hidden = NO;
  279. [UIView animateWithDuration:0.3 animations:^{
  280. CGRect rect = self.photoGroupView.frame;
  281. rect.origin.y = CGRectGetMaxY(self.navBarBGView.frame);
  282. self.photoGroupView.frame = rect;
  283. self.selectTip.transform = CGAffineTransformMakeRotation(M_PI);
  284. }];
  285. } else {
  286. [self hidenGroupView];
  287. }
  288. }
  289. - (void)hidenGroupView {
  290. //[self.bgMaskView removeFromSuperview];
  291. self.bgMaskView.hidden = YES;
  292. [UIView animateWithDuration:0.3 animations:^{
  293. CGRect rect = self.photoGroupView.frame;
  294. rect.origin.y = -SCREEN_H;
  295. self.photoGroupView.frame = rect;
  296. self.selectTip.transform = CGAffineTransformIdentity;
  297. }completion:^(BOOL finished) {
  298. self.photoGroupView.hidden = YES;
  299. }];
  300. }
  301. #pragma mark - 遮罩背景
  302. - (UIView *)bgMaskView {
  303. if (_bgMaskView == nil) {
  304. UIView *bgMaskView = [[UIView alloc] init];
  305. bgMaskView.alpha = 0.5;
  306. bgMaskView.translatesAutoresizingMaskIntoConstraints = NO;
  307. bgMaskView.backgroundColor = [UIColor blackColor];
  308. //[self.view insertSubview:bgMaskView aboveSubview:self.photoListView];
  309. [self.view insertSubview:bgMaskView belowSubview:self.photoGroupView];
  310. bgMaskView.userInteractionEnabled = YES;
  311. [bgMaskView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapBgMaskView:)]];
  312. _bgMaskView = bgMaskView;
  313. [bgMaskView mas_makeConstraints:^(MASConstraintMaker *make) {
  314. make.left.mas_equalTo(0);
  315. make.right.mas_equalTo(0);
  316. make.bottom.mas_equalTo(0);
  317. make.top.equalTo(self.navBarBGView.mas_bottom).offset(0.f);
  318. }];
  319. }
  320. return _bgMaskView;
  321. }
  322. - (void)tapBgMaskView:(UITapGestureRecognizer *)sender {
  323. if (!self.photoGroupView.hidden) {
  324. [self hidenGroupView];
  325. }
  326. }
  327. #pragma mark - BoPhotoGroupViewProtocol
  328. - (void)didSelectGroup:(TZAlbumModel *)model {
  329. [self loadAssets:model];
  330. [self setTitleLabelText:model.name];
  331. [self hidenGroupView];
  332. }
  333. //加载图片
  334. - (void)loadAssets:(TZAlbumModel *)model {
  335. [self.indexPathsForSelectedItems removeAllObjects];
  336. [self.assets removeAllObjects];
  337. [[TZImageManager manager] getAssetsFromFetchResult:model.result completion:^(NSArray<TZAssetModel *> *models) {
  338. self->_assets = [NSMutableArray arrayWithArray:models];
  339. [self.photoListView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:YES];
  340. [self.photoListView reloadData];
  341. }];
  342. }
  343. #pragma mark - uicollectionDelegate
  344. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  345. return self.assets.count;
  346. }
  347. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  348. static NSString *cellIdentifer = @"cell";
  349. AJPhotoListCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifer forIndexPath:indexPath];
  350. BOOL isSelected = [self.indexPathsForSelectedItems containsObject:self.assets[indexPath.row]];
  351. [cell bind:self.assets[indexPath.row] selectionFilter:self.selectionFilter isSelected:isSelected];
  352. KWeakSelf
  353. cell.didClckSelectBut = ^(BOOL isSelect) {
  354. [weakSelf handlCellSelectFunBy:indexPath];
  355. };
  356. return cell;
  357. }
  358. - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
  359. return UIEdgeInsetsMake(5, 5, 5, 5);
  360. }
  361. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  362. CGFloat wh = (collectionView.bounds.size.width - 20)/3.0;
  363. return CGSizeMake(wh, wh);
  364. }
  365. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
  366. return 5.0;
  367. }
  368. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
  369. return 5.0;
  370. }
  371. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  372. NSInteger curRow = indexPath.row;
  373. PhotoPreviewViewController *vc =[PhotoPreviewViewController new];
  374. vc.assets = _assets;
  375. vc.currentIndex = curRow;
  376. vc.indexPathsForSelectedItems = _indexPathsForSelectedItems;
  377. //vc.maximumNumberOfSelection = _maximumNumberOfSelection;
  378. vc.minimumNumberOfSelection = _minimumNumberOfSelection;
  379. vc.availableStorage = self.uploadFileBottomV.availableStorage;
  380. vc.isPhotoType = _isPhotoType;
  381. [self.navigationController pushViewController:vc animated:YES];
  382. KWeakSelf
  383. vc.changeSelectIndex = ^(NSMutableArray * _Nonnull indexPathsForSelectedItems) {
  384. [weakSelf refreshDataAndUIFunWith:indexPathsForSelectedItems];
  385. };
  386. }
  387. #pragma mark 从详情页回来 刷新数据和UI
  388. - (void)refreshDataAndUIFunWith:(NSMutableArray *)indexPathsForSelectedItems
  389. {
  390. self.indexPathsForSelectedItems = indexPathsForSelectedItems;
  391. [self refreshAllDataFun];
  392. }
  393. #pragma mark 刷新所有数据
  394. - (void)refreshAllDataFun
  395. {
  396. [self setDataToBottomViewFun];
  397. [self.photoListView reloadData];
  398. }
  399. #pragma mark 处理点击选中相关
  400. - (void)handlCellSelectFunBy:(NSIndexPath *)indexPath
  401. {
  402. AJPhotoListCell *cell = (AJPhotoListCell *)[self.photoListView cellForItemAtIndexPath:indexPath];
  403. TZAssetModel *model = self.assets[indexPath.row];
  404. //超出最大限制
  405. // if (self.indexPathsForSelectedItems.count >= self.maximumNumberOfSelection ) {
  406. // return;
  407. // }
  408. //取消选中
  409. if ([self.indexPathsForSelectedItems containsObject:model]) {
  410. [self.indexPathsForSelectedItems removeObject:model];
  411. model.isSelected = NO;
  412. [cell isSelected:NO];
  413. [self setDataToBottomViewFun];
  414. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  415. [self.uploadFileBottomV setUploadButtonCanClickFunBy:YES];
  416. });
  417. }
  418. else
  419. {//选中
  420. [self didSelectModel:model isLastModel:YES];
  421. [cell isSelected:YES];
  422. }
  423. }
  424. #pragma mark 选中某个cell
  425. - (void)didSelectModel:(TZAssetModel *)model isLastModel:(BOOL)isLast
  426. {//选中
  427. [self.indexPathsForSelectedItems addObject:model];
  428. model.isSelected = YES;
  429. if(!model.totalBytes)
  430. {
  431. [[PHImageManager defaultManager] requestImageDataForAsset:model.asset options:nil resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
  432. // 直接得到最终的 NSData 数据
  433. if (imageData) {
  434. //model.imageData = imageData;
  435. model.totalBytes = [imageData length];
  436. }
  437. if(model.type != TZAssetModelMediaTypeVideo){
  438. [self setDataToBottomViewFun];
  439. }
  440. if(isLast){
  441. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  442. [SVProgressHUD dismiss];
  443. [self.uploadFileBottomV setUploadButtonCanClickFunBy:YES];
  444. });
  445. }
  446. }];
  447. if(model.type == TZAssetModelMediaTypeVideo){
  448. PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
  449. options.version = PHVideoRequestOptionsVersionOriginal;
  450. [[PHImageManager defaultManager] requestAVAssetForVideo:model.asset options:options resultHandler:^(AVAsset *asset, AVAudioMix *audioMix, NSDictionary *info) {
  451. if ([asset isKindOfClass:[AVURLAsset class]]) {
  452. AVURLAsset* urlAsset = (AVURLAsset*)asset;
  453. //NSData *videoData = [NSData dataWithContentsOfURL:urlAsset.URL];
  454. NSNumber *size;
  455. [urlAsset.URL getResourceValue:&size forKey:NSURLFileSizeKey error:nil];
  456. //NSLog(@"size is %f",[size floatValue]/(1024.0*1024.0));
  457. //model.videoData = videoData;
  458. //model.totalBytes = [videoData length];
  459. model.totalBytes = size.longLongValue;
  460. [self setDataToBottomViewFun];
  461. }
  462. if(isLast){
  463. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  464. [SVProgressHUD dismiss];
  465. [self.uploadFileBottomV setUploadButtonCanClickFunBy:YES];
  466. });
  467. }
  468. }];
  469. }
  470. }
  471. else{
  472. [self setDataToBottomViewFun];
  473. if(isLast){
  474. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  475. [SVProgressHUD dismiss];
  476. [self.uploadFileBottomV setUploadButtonCanClickFunBy:YES];
  477. });
  478. }
  479. }
  480. }
  481. #pragma mark 同步数据到底部
  482. - (void)setDataToBottomViewFun
  483. {
  484. mainBlock(^{
  485. self.uploadFileBottomV.indexPathsForSelectedItems = self.indexPathsForSelectedItems;
  486. });
  487. }
  488. #pragma mark - getter/setter
  489. - (NSMutableArray *)assets {
  490. if (!_assets) {
  491. _assets = [[NSMutableArray alloc] init];
  492. }
  493. return _assets;
  494. }
  495. - (NSMutableArray *)indexPathsForSelectedItems {
  496. if (!_indexPathsForSelectedItems) {
  497. _indexPathsForSelectedItems = [[NSMutableArray alloc] init];
  498. }
  499. return _indexPathsForSelectedItems;
  500. }
  501. #pragma mark 跳转上传记录
  502. - (void)gotoUploadFileRecordFun
  503. {
  504. uploadFileRecordViewController *vc = [uploadFileRecordViewController new];
  505. [self.navigationController pushViewController:vc animated:YES];
  506. vc.isUploadingType = YES;
  507. [vc gotoUploadFile:_indexPathsForSelectedItems];
  508. if(_isPhotoType){
  509. //数据埋点
  510. [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"Image_upload"];
  511. }
  512. else{
  513. //数据埋点
  514. [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"Video_upload"];
  515. }
  516. }
  517. - (void)getCouldPhoneBaseInfoFun:(NSNotification*)not
  518. {
  519. baseInfoModel = [not object];
  520. //HLog(@"%@",baseInfoModel);
  521. [self handelAfterGetBaseInfoModelData];
  522. }
  523. - (void)handelAfterGetBaseInfoModelData
  524. {
  525. // if(!baseInfoModel || ![baseInfoModel isKindOfClass:[couldPhoneBaseInfoModel class]]){
  526. // return;
  527. // }
  528. NSString * uploadDefaultPath = [HWDataManager getStringWithKey:stringKeyAddSn(Const_photo_upload_default_path)];
  529. if(!uploadDefaultPath || uploadDefaultPath.length == 0){
  530. [HWDataManager setStringWithKey:stringKeyAddSn(Const_photo_upload_default_path) value:Const_default_upload_path];
  531. uploadDefaultPath = Const_default_upload_path;
  532. }
  533. BOOL isExtraFileType = NO;
  534. BOOL isExtraPathFind = NO;
  535. if(uploadDefaultPath){
  536. if(![uploadDefaultPath containsString:@"sdcard/"]){
  537. isExtraFileType = YES;
  538. }
  539. }
  540. if(uploadDefaultPath && ksharedAppDelegate.cloudPhoneExtraFileListMod){
  541. NSArray*arr = ksharedAppDelegate.cloudPhoneExtraFileListMod.data;
  542. for (cloudPhoneExtraFileModel*model in arr) {
  543. if([uploadDefaultPath containsString:model.extraPath]){
  544. NSString * availableStorage = @"";
  545. NSInteger totalSize_k = model.extraAvableSize / 1024;
  546. if(totalSize_k < 1024){
  547. availableStorage = [[NSString alloc] initWithFormat:@"%ldKB",totalSize_k];
  548. }
  549. else if( totalSize_k >= 1024 && totalSize_k < 1024*1024){
  550. availableStorage = [[NSString alloc] initWithFormat:@"%.2fMB",totalSize_k/1024.0];
  551. }
  552. else{
  553. availableStorage = [[NSString alloc] initWithFormat:@"%.2fG",totalSize_k/1024.0/1024.0];
  554. }
  555. self.uploadFileBottomV.availableStorage = availableStorage;
  556. self.uploadFileBottomV.available = model.extraAvableSize;
  557. isExtraPathFind = YES;
  558. break;
  559. }
  560. }
  561. }
  562. if(!isExtraPathFind){
  563. // self.uploadFileBottomV.availableStorage = baseInfoModel.data.availableStorage;
  564. // self.uploadFileBottomV.available = baseInfoModel.data.available;
  565. }
  566. if(isExtraFileType && !isExtraPathFind){
  567. self.uploadFileBottomV.isExtraFileAndNotFindPathType = YES;
  568. }
  569. else{
  570. self.uploadFileBottomV.isExtraFileAndNotFindPathType = NO;
  571. }
  572. [self setDataToBottomViewFun];
  573. }
  574. - (void)gotofileTransferPathCheckVCFun
  575. {
  576. fileTransferPathCheckViewController *vc = [fileTransferPathCheckViewController new];
  577. vc.curType = 1;
  578. [self.navigationController pushViewController:vc animated:YES];
  579. KWeakSelf
  580. vc.didChangeSavePathFun = ^{
  581. [weakSelf.uploadFileBottomV setSavePathDataFun];
  582. [weakSelf handelAfterGetBaseInfoModelData];
  583. };
  584. }
  585. - (void)viewDidAppear:(BOOL)animated{
  586. [super viewDidAppear:animated];
  587. if(!_isNotFirstType){
  588. [self showUploadTipFun];
  589. //权限访问时 重新拿数据 验证iOS 15.0有效 17.5.1无效 (viewDidAppear 和applicationDidBecomeActive 均不走)
  590. [self.photoGroupView setupGroup];
  591. [self delayedSetPhotoGroupViewFrameFun];
  592. _isNotFirstType = YES;
  593. }
  594. }
  595. - (void)viewWillDisappear:(BOOL)animated
  596. {
  597. [super viewWillDisappear:animated];
  598. [SVProgressHUD dismiss];
  599. }
  600. - (void)showUploadTipFun
  601. {
  602. BOOL didReadUploadTipType = [HWDataManager getBoolWithKey:Const_file_upLoad_need_read];
  603. if(didReadUploadTipType){
  604. return;
  605. }
  606. //KWeakSelf
  607. /*弹窗提示恢复出厂*/
  608. ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:nil
  609. msg:NSLocalizedString(@"upload_download_need_read_msg",nil)
  610. imageStr:nil
  611. cancelTitle:NSLocalizedString(@"guide_set_pwd_guide_know",nil)
  612. okTitle:nil
  613. isOkBtnHighlight:NO
  614. didClickOk:^{
  615. } didClickCancel:^{
  616. [HWDataManager setBoolWithKey:Const_file_upLoad_need_read value:YES];
  617. }];
  618. nextVC.modalPresentationStyle = UIModalPresentationCustom;
  619. [self presentViewController:nextVC animated:YES completion:^{
  620. nextVC.view.superview.backgroundColor = [UIColor clearColor];
  621. }];
  622. }
  623. @end