uploadImageOrVideoViewController.m 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  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 = 30;
  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. but.selected = !but.selected;
  141. if(but.selected){
  142. [self.indexPathsForSelectedItems removeAllObjects];
  143. [SVProgressHUD show];
  144. for (int i= 0; i<self.assets.count; i++) {
  145. TZAssetModel *model = self.assets[i];
  146. if(i == self.assets.count -1){
  147. [self didSelectModel:model isLastModel:YES];
  148. }
  149. else{
  150. [self didSelectModel:model isLastModel:NO];
  151. }
  152. }
  153. // for (TZAssetModel *model in self.assets) {
  154. // [self didSelectModel:model isLastModel:NO];
  155. // }
  156. }
  157. else{
  158. for (TZAssetModel *model in self.assets) {
  159. model.isSelected = NO;
  160. }
  161. [self.indexPathsForSelectedItems removeAllObjects];
  162. }
  163. [self refreshAllDataFun];
  164. }
  165. #pragma mark 判断手机相册权限
  166. - (void)checkVideoAccessFun
  167. {
  168. AVAuthorizationStatus authStatus =[AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
  169. //判断摄像头状态是否可用
  170. if(authStatus==AVAuthorizationStatusAuthorized){
  171. _isNotAllowed = NO;
  172. }else{
  173. NSLog(@"未开启相机权限,请前往设置中开启");
  174. [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
  175. if (granted){
  176. self->_isNotAllowed = NO;
  177. // mainBlock(^{
  178. //
  179. // });
  180. }
  181. }];
  182. }
  183. //相册权限
  184. if (![[TZImageManager manager] authorizationStatusAuthorized]){
  185. [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
  186. if(status == PHAuthorizationStatusAuthorized){
  187. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  188. [self.photoGroupView setupGroup];
  189. [self delayedSetPhotoGroupViewFrameFun];
  190. });
  191. }
  192. }];
  193. }
  194. }
  195. /**
  196. * 照片列表
  197. */
  198. - (void)setupPhotoListView {
  199. AJPhotoListView *collectionView = [[AJPhotoListView alloc] init];
  200. collectionView.dataSource = self;
  201. collectionView.delegate = self;
  202. collectionView.translatesAutoresizingMaskIntoConstraints = NO;
  203. [self.view insertSubview:collectionView atIndex:0];
  204. self.photoListView = collectionView;
  205. [collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  206. make.left.mas_equalTo(0);
  207. make.right.mas_equalTo(0);
  208. make.bottom.mas_equalTo(-(60 + safeArea));
  209. make.top.equalTo(self.navBarBGView.mas_bottom).offset(0.f);
  210. }];
  211. }
  212. /**
  213. * 照片列表
  214. */
  215. - (void)setupUploadFileBottomView
  216. {
  217. uploadFileBottomView *bottomView = [[uploadFileBottomView alloc] init];
  218. [self.view insertSubview:bottomView atIndex:0];
  219. self.uploadFileBottomV = bottomView;
  220. [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
  221. make.left.mas_equalTo(0);
  222. make.right.mas_equalTo(0);
  223. make.bottom.mas_equalTo(0);
  224. make.height.mas_equalTo(60 + safeArea);
  225. }];
  226. KWeakSelf
  227. bottomView.didClickUploadFile = ^{
  228. [weakSelf gotoUploadFileRecordFun];
  229. };
  230. bottomView.didClickbottomFun = ^{
  231. [weakSelf gotofileTransferPathCheckVCFun];
  232. };
  233. }
  234. /**
  235. * 相册
  236. */
  237. - (void)setupGroupView {
  238. AJPhotoGroupView *photoGroupView = [[AJPhotoGroupView alloc] init];
  239. photoGroupView.my_delegate = self;
  240. photoGroupView.isPhotoType = _isPhotoType;
  241. [self.view insertSubview:photoGroupView belowSubview:self.navBarBGView];
  242. self.photoGroupView = photoGroupView;
  243. photoGroupView.hidden = YES;
  244. photoGroupView.translatesAutoresizingMaskIntoConstraints = NO;
  245. [self.photoGroupView setupGroup];
  246. [self delayedSetPhotoGroupViewFrameFun];
  247. }
  248. #pragma mark 延时设置photoGroupView frame
  249. - (void)delayedSetPhotoGroupViewFrameFun
  250. {
  251. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  252. NSInteger maxCount = 6;
  253. if(self.photoGroupView.albumGroups.count < maxCount){
  254. maxCount = self.photoGroupView.albumGroups.count;
  255. }
  256. [self.photoGroupView mas_remakeConstraints:^(MASConstraintMaker *make) {
  257. make.left.mas_equalTo(0);
  258. make.right.mas_equalTo(0);
  259. make.height.mas_equalTo(60.0 * maxCount);
  260. make.top.equalTo(self.navBarBGView.mas_bottom).offset(0.f);
  261. }];
  262. });
  263. }
  264. #pragma mark - 相册切换
  265. - (void)selectGroupAction:(UIButton *)sender {
  266. //无权限
  267. if (self.isNotAllowed) {
  268. return;
  269. }
  270. if (self.photoGroupView.hidden) {
  271. [self bgMaskView];
  272. self.bgMaskView.hidden = NO;
  273. self.photoGroupView.hidden = NO;
  274. [UIView animateWithDuration:0.3 animations:^{
  275. CGRect rect = self.photoGroupView.frame;
  276. rect.origin.y = CGRectGetMaxY(self.navBarBGView.frame);
  277. self.photoGroupView.frame = rect;
  278. self.selectTip.transform = CGAffineTransformMakeRotation(M_PI);
  279. }];
  280. } else {
  281. [self hidenGroupView];
  282. }
  283. }
  284. - (void)hidenGroupView {
  285. //[self.bgMaskView removeFromSuperview];
  286. self.bgMaskView.hidden = YES;
  287. [UIView animateWithDuration:0.3 animations:^{
  288. CGRect rect = self.photoGroupView.frame;
  289. rect.origin.y = -SCREEN_H;
  290. self.photoGroupView.frame = rect;
  291. self.selectTip.transform = CGAffineTransformIdentity;
  292. }completion:^(BOOL finished) {
  293. self.photoGroupView.hidden = YES;
  294. }];
  295. }
  296. #pragma mark - 遮罩背景
  297. - (UIView *)bgMaskView {
  298. if (_bgMaskView == nil) {
  299. UIView *bgMaskView = [[UIView alloc] init];
  300. bgMaskView.alpha = 0.5;
  301. bgMaskView.translatesAutoresizingMaskIntoConstraints = NO;
  302. bgMaskView.backgroundColor = [UIColor blackColor];
  303. //[self.view insertSubview:bgMaskView aboveSubview:self.photoListView];
  304. [self.view insertSubview:bgMaskView belowSubview:self.photoGroupView];
  305. bgMaskView.userInteractionEnabled = YES;
  306. [bgMaskView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapBgMaskView:)]];
  307. _bgMaskView = bgMaskView;
  308. [bgMaskView mas_makeConstraints:^(MASConstraintMaker *make) {
  309. make.left.mas_equalTo(0);
  310. make.right.mas_equalTo(0);
  311. make.bottom.mas_equalTo(0);
  312. make.top.equalTo(self.navBarBGView.mas_bottom).offset(0.f);
  313. }];
  314. }
  315. return _bgMaskView;
  316. }
  317. - (void)tapBgMaskView:(UITapGestureRecognizer *)sender {
  318. if (!self.photoGroupView.hidden) {
  319. [self hidenGroupView];
  320. }
  321. }
  322. #pragma mark - BoPhotoGroupViewProtocol
  323. - (void)didSelectGroup:(TZAlbumModel *)model {
  324. [self loadAssets:model];
  325. [self setTitleLabelText:model.name];
  326. [self hidenGroupView];
  327. }
  328. //加载图片
  329. - (void)loadAssets:(TZAlbumModel *)model {
  330. [self.indexPathsForSelectedItems removeAllObjects];
  331. [self.assets removeAllObjects];
  332. [[TZImageManager manager] getAssetsFromFetchResult:model.result completion:^(NSArray<TZAssetModel *> *models) {
  333. self->_assets = [NSMutableArray arrayWithArray:models];
  334. [self.photoListView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:YES];
  335. [self.photoListView reloadData];
  336. }];
  337. }
  338. #pragma mark - uicollectionDelegate
  339. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  340. return self.assets.count;
  341. }
  342. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  343. static NSString *cellIdentifer = @"cell";
  344. AJPhotoListCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifer forIndexPath:indexPath];
  345. BOOL isSelected = [self.indexPathsForSelectedItems containsObject:self.assets[indexPath.row]];
  346. [cell bind:self.assets[indexPath.row] selectionFilter:self.selectionFilter isSelected:isSelected];
  347. KWeakSelf
  348. cell.didClckSelectBut = ^(BOOL isSelect) {
  349. [weakSelf handlCellSelectFunBy:indexPath];
  350. };
  351. return cell;
  352. }
  353. - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
  354. return UIEdgeInsetsMake(5, 5, 5, 5);
  355. }
  356. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  357. CGFloat wh = (collectionView.bounds.size.width - 20)/3.0;
  358. return CGSizeMake(wh, wh);
  359. }
  360. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
  361. return 5.0;
  362. }
  363. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
  364. return 5.0;
  365. }
  366. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  367. PhotoPreviewViewController *vc =[PhotoPreviewViewController new];
  368. vc.assets = _assets;
  369. vc.currentIndex = indexPath.row;
  370. vc.indexPathsForSelectedItems = _indexPathsForSelectedItems;
  371. vc.maximumNumberOfSelection = _maximumNumberOfSelection;
  372. vc.minimumNumberOfSelection = _minimumNumberOfSelection;
  373. vc.availableStorage = self.uploadFileBottomV.availableStorage;
  374. [self.navigationController pushViewController:vc animated:YES];
  375. KWeakSelf
  376. vc.changeSelectIndex = ^(NSMutableArray * _Nonnull indexPathsForSelectedItems) {
  377. [weakSelf refreshDataAndUIFunWith:indexPathsForSelectedItems];
  378. };
  379. }
  380. #pragma mark 从详情页回来 刷新数据和UI
  381. - (void)refreshDataAndUIFunWith:(NSMutableArray *)indexPathsForSelectedItems
  382. {
  383. self.indexPathsForSelectedItems = indexPathsForSelectedItems;
  384. [self refreshAllDataFun];
  385. }
  386. #pragma mark 刷新所有数据
  387. - (void)refreshAllDataFun
  388. {
  389. [self setDataToBottomViewFun];
  390. [self.photoListView reloadData];
  391. }
  392. #pragma mark 处理点击选中相关
  393. - (void)handlCellSelectFunBy:(NSIndexPath *)indexPath
  394. {
  395. AJPhotoListCell *cell = (AJPhotoListCell *)[self.photoListView cellForItemAtIndexPath:indexPath];
  396. TZAssetModel *model = self.assets[indexPath.row];
  397. //超出最大限制
  398. if (self.indexPathsForSelectedItems.count >= self.maximumNumberOfSelection ) {
  399. return;
  400. }
  401. //取消选中
  402. if ([self.indexPathsForSelectedItems containsObject:model]) {
  403. [self.indexPathsForSelectedItems removeObject:model];
  404. model.isSelected = NO;
  405. [cell isSelected:NO];
  406. }
  407. else
  408. {//选中
  409. [self didSelectModel:model isLastModel:NO];
  410. [cell isSelected:YES];
  411. }
  412. [self setDataToBottomViewFun];
  413. }
  414. #pragma mark 选中某个cell
  415. - (void)didSelectModel:(TZAssetModel *)model isLastModel:(BOOL)isLast
  416. {//选中
  417. [self.indexPathsForSelectedItems addObject:model];
  418. model.isSelected = YES;
  419. if(!model.totalBytes)
  420. {
  421. [[PHImageManager defaultManager] requestImageDataForAsset:model.asset options:nil resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
  422. // 直接得到最终的 NSData 数据
  423. if (imageData) {
  424. //model.imageData = imageData;
  425. model.totalBytes = [imageData length];
  426. }
  427. if(model.type != TZAssetModelMediaTypeVideo){
  428. [self setDataToBottomViewFun];
  429. }
  430. if(isLast){
  431. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  432. [SVProgressHUD dismiss];
  433. });
  434. }
  435. }];
  436. if(model.type == TZAssetModelMediaTypeVideo){
  437. PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
  438. options.version = PHVideoRequestOptionsVersionOriginal;
  439. [[PHImageManager defaultManager] requestAVAssetForVideo:model.asset options:options resultHandler:^(AVAsset *asset, AVAudioMix *audioMix, NSDictionary *info) {
  440. if ([asset isKindOfClass:[AVURLAsset class]]) {
  441. AVURLAsset* urlAsset = (AVURLAsset*)asset;
  442. //NSData *videoData = [NSData dataWithContentsOfURL:urlAsset.URL];
  443. NSNumber *size;
  444. [urlAsset.URL getResourceValue:&size forKey:NSURLFileSizeKey error:nil];
  445. //NSLog(@"size is %f",[size floatValue]/(1024.0*1024.0));
  446. //model.videoData = videoData;
  447. //model.totalBytes = [videoData length];
  448. model.totalBytes = size.longLongValue;
  449. [self setDataToBottomViewFun];
  450. }
  451. if(isLast){
  452. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  453. [SVProgressHUD dismiss];
  454. });
  455. }
  456. }];
  457. }
  458. }
  459. else{
  460. if(isLast){
  461. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  462. [SVProgressHUD dismiss];
  463. });
  464. }
  465. }
  466. }
  467. #pragma mark 同步数据到底部
  468. - (void)setDataToBottomViewFun
  469. {
  470. mainBlock(^{
  471. self.uploadFileBottomV.indexPathsForSelectedItems = self.indexPathsForSelectedItems;
  472. });
  473. }
  474. #pragma mark - getter/setter
  475. - (NSMutableArray *)assets {
  476. if (!_assets) {
  477. _assets = [[NSMutableArray alloc] init];
  478. }
  479. return _assets;
  480. }
  481. - (NSMutableArray *)indexPathsForSelectedItems {
  482. if (!_indexPathsForSelectedItems) {
  483. _indexPathsForSelectedItems = [[NSMutableArray alloc] init];
  484. }
  485. return _indexPathsForSelectedItems;
  486. }
  487. #pragma mark 跳转上传记录
  488. - (void)gotoUploadFileRecordFun
  489. {
  490. uploadFileRecordViewController *vc = [uploadFileRecordViewController new];
  491. [self.navigationController pushViewController:vc animated:YES];
  492. vc.isUploadingType = YES;
  493. [vc gotoUploadFile:_indexPathsForSelectedItems];
  494. }
  495. - (void)getCouldPhoneBaseInfoFun:(NSNotification*)not
  496. {
  497. baseInfoModel = [not object];
  498. //HLog(@"%@",baseInfoModel);
  499. [self handelAfterGetBaseInfoModelData];
  500. }
  501. - (void)handelAfterGetBaseInfoModelData
  502. {
  503. if(!baseInfoModel || ![baseInfoModel isKindOfClass:[couldPhoneBaseInfoModel class]]){
  504. return;
  505. }
  506. NSString * uploadDefaultPath = [HWDataManager getStringWithKey:stringKeyAddSn(Const_photo_upload_default_path)];
  507. BOOL isExtraFileType = NO;
  508. BOOL isExtraPathFind = NO;
  509. if(uploadDefaultPath){
  510. if(![uploadDefaultPath containsString:@"sdcard/"]){
  511. isExtraFileType = YES;
  512. }
  513. }
  514. if(uploadDefaultPath && ksharedAppDelegate.cloudPhoneExtraFileListMod){
  515. NSArray*arr = ksharedAppDelegate.cloudPhoneExtraFileListMod.data;
  516. for (cloudPhoneExtraFileModel*model in arr) {
  517. if([uploadDefaultPath containsString:model.extraPath]){
  518. NSString * availableStorage = @"";
  519. NSInteger totalSize_k = model.extraAvableSize / 1024;
  520. if(totalSize_k < 1024){
  521. availableStorage = [[NSString alloc] initWithFormat:@"%ldKB",totalSize_k];
  522. }
  523. else if( totalSize_k >= 1024 && totalSize_k < 1024*1024){
  524. availableStorage = [[NSString alloc] initWithFormat:@"%.1fMB",totalSize_k/1024.0];
  525. }
  526. else{
  527. availableStorage = [[NSString alloc] initWithFormat:@"%.2fG",totalSize_k/1024.0/1024.0];
  528. }
  529. self.uploadFileBottomV.availableStorage = availableStorage;
  530. self.uploadFileBottomV.available = model.extraAvableSize;
  531. isExtraPathFind = YES;
  532. break;
  533. }
  534. }
  535. }
  536. if(!isExtraFileType){
  537. self.uploadFileBottomV.availableStorage = baseInfoModel.data.availableStorage;
  538. self.uploadFileBottomV.available = baseInfoModel.data.available;
  539. }
  540. if(isExtraFileType && !isExtraPathFind){
  541. self.uploadFileBottomV.isExtraFileAndNotFindPathType = YES;
  542. }
  543. else{
  544. self.uploadFileBottomV.isExtraFileAndNotFindPathType = NO;
  545. }
  546. [self setDataToBottomViewFun];
  547. }
  548. - (void)gotofileTransferPathCheckVCFun
  549. {
  550. fileTransferPathCheckViewController *vc = [fileTransferPathCheckViewController new];
  551. vc.curType = 1;
  552. [self.navigationController pushViewController:vc animated:YES];
  553. KWeakSelf
  554. vc.didChangeSavePathFun = ^{
  555. [weakSelf.uploadFileBottomV setSavePathDataFun];
  556. [weakSelf handelAfterGetBaseInfoModelData];
  557. };
  558. }
  559. @end