uploadImageOrVideoViewController.m 24 KB

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