uploadImageOrVideoViewController.m 29 KB

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