uploadImageOrVideoViewController.m 29 KB

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