uploadImageOrVideoViewController.m 26 KB

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