Browse Source

1.相册全选功能

huangxiaodong 2 years ago
parent
commit
fa6f4d0e15

+ 1 - 0
创维盒子/双子星云手机/Class/Set/uploadFile/model/TZAssetModel+imageData.h

@@ -14,6 +14,7 @@ NS_ASSUME_NONNULL_BEGIN
 @interface TZAssetModel (imageData)
 @property (nonatomic, retain) NSData *imageData;
 @property (nonatomic, retain) NSData *videoData;
+//@property (nonatomic, assign)  long totalBytes;//总字节数
 @end
 
 NS_ASSUME_NONNULL_END

+ 10 - 0
创维盒子/双子星云手机/Class/Set/uploadFile/model/TZAssetModel+imageData.m

@@ -23,4 +23,14 @@
 - (NSString *)videoData {
     return objc_getAssociatedObject(self, @selector(videoData));
 }
+
+//static const NSString* ReplacedKeyWhenCreatingKeyValuesKey = @"totalBytes";
+//
+//- (void)setTotalBytes:(long)totalBytes {
+//    objc_setAssociatedObject(self, @selector(totalBytes), ReplacedKeyWhenCreatingKeyValuesKey, OBJC_ASSOCIATION_ASSIGN);
+//}
+//- (long)totalBytes {
+//    return objc_getAssociatedObject(self, @selector(ReplacedKeyWhenCreatingKeyValuesKey));
+//}
+
 @end

+ 85 - 36
创维盒子/双子星云手机/Class/Set/uploadFile/uploadImageOrVideoViewController.m

@@ -112,7 +112,23 @@
         make.height.mas_equalTo(30);
     }];
     
-    [self setTitleLabelText:@"所有相片"];
+    [self setTitleLabelText:@""];
+    
+    UIButton *rightBut = [[UIButton alloc] init];
+    [rightBut setTitle:NSLocalizedString(@"File_upload_Record_select_all",nil) forState:UIControlStateNormal];
+    [rightBut setTitle:NSLocalizedString(@"File_upload_cancel_select_all",nil) forState:UIControlStateSelected];
+    [rightBut setTitleColor:[UIColor hwColor:@"#01B7EA" alpha:1.0] forState:UIControlStateNormal];
+    rightBut.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
+    [rightBut addTarget:self action:@selector(didClickSelectAllButton:) forControlEvents:UIControlEventTouchUpInside];
+    
+    [self.navBarBGView addSubview:rightBut];
+    
+    [rightBut mas_makeConstraints:^(MASConstraintMaker *make) {
+        make.right.mas_equalTo(-20);
+        make.centerY.mas_equalTo(self.backBtn.mas_centerY);
+        make.width.mas_equalTo(100);
+        make.height.mas_equalTo(30);
+    }];
 }
 
 #pragma mark 设置相册标题
@@ -140,6 +156,28 @@
     }];
 }
 
+#pragma mark 点击全选
+- (void)didClickSelectAllButton:(UIButton*)but
+{
+    but.selected = !but.selected;
+    
+    if(but.selected){
+        [self.indexPathsForSelectedItems removeAllObjects];
+        
+        for (TZAssetModel *model in self.assets) {
+            [self didSelectModel:model];
+        }
+    }
+    else{
+        for (TZAssetModel *model in self.assets) {
+             model.isSelected = NO;
+        }
+        [self.indexPathsForSelectedItems removeAllObjects];
+    }
+    
+    [self refreshAllDataFun];
+}
+
 #pragma mark 判断手机相册权限
 - (void)checkVideoAccessFun
 {
@@ -399,8 +437,13 @@
 - (void)refreshDataAndUIFunWith:(NSMutableArray *)indexPathsForSelectedItems
 {
     self.indexPathsForSelectedItems = indexPathsForSelectedItems;
+    [self refreshAllDataFun];
+}
+
+#pragma mark 刷新所有数据
+- (void)refreshAllDataFun
+{
     [self setDataToBottomViewFun];
-    
     [self.photoListView reloadData];
 }
 
@@ -422,49 +465,55 @@
         model.isSelected = NO;
         [cell isSelected:NO];
     }
-    else{//选中
-        [self.indexPathsForSelectedItems addObject:model];
-        model.isSelected = YES;
+    else
+    {//选中
+        [self didSelectModel:model];
         [cell isSelected:YES];
-        
-        if(!model.imageData)
-        {
-            [[PHImageManager defaultManager] requestImageDataForAsset:model.asset options:nil resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
-                    // 直接得到最终的 NSData 数据
-                    if (imageData) {
-                        model.imageData = imageData;
-                    }
-                if(model.type != TZAssetModelMediaTypeVideo){
-                    [self setDataToBottomViewFun];
+    }
+    
+    [self setDataToBottomViewFun];
+}
+
+#pragma mark  选中某个cell
+- (void)didSelectModel:(TZAssetModel *)model
+{//选中
+    [self.indexPathsForSelectedItems addObject:model];
+    model.isSelected = YES;
+    
+    if(!model.imageData)
+    {
+        [[PHImageManager defaultManager] requestImageDataForAsset:model.asset options:nil resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
+                // 直接得到最终的 NSData 数据
+                if (imageData) {
+                    model.imageData = imageData;
                 }
-            }];
+            if(model.type != TZAssetModelMediaTypeVideo){
+                [self setDataToBottomViewFun];
+            }
+        }];
+        
+        if(model.type == TZAssetModelMediaTypeVideo){
             
-            if(model.type == TZAssetModelMediaTypeVideo){
-                
-                PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
-                options.version = PHVideoRequestOptionsVersionOriginal;
-                [[PHImageManager defaultManager] requestAVAssetForVideo:model.asset options:options resultHandler:^(AVAsset *asset, AVAudioMix *audioMix, NSDictionary *info) {
-                    if ([asset isKindOfClass:[AVURLAsset class]]) {
-                        
-                        AVURLAsset* urlAsset = (AVURLAsset*)asset;
-                        NSData *videoData = [NSData dataWithContentsOfURL:urlAsset.URL];
+            PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
+            options.version = PHVideoRequestOptionsVersionOriginal;
+            [[PHImageManager defaultManager] requestAVAssetForVideo:model.asset options:options resultHandler:^(AVAsset *asset, AVAudioMix *audioMix, NSDictionary *info) {
+                if ([asset isKindOfClass:[AVURLAsset class]]) {
+                    
+                    AVURLAsset* urlAsset = (AVURLAsset*)asset;
+                    NSData *videoData = [NSData dataWithContentsOfURL:urlAsset.URL];
 //                        NSNumber *size;
 //                        [urlAsset.URL getResourceValue:&size forKey:NSURLFileSizeKey error:nil];
 //                        NSLog(@"size is %f",[size floatValue]/(1024.0*1024.0));
-                     
-                        
-                        model.videoData = videoData;
-                        [self setDataToBottomViewFun];
-                 }
-                }];
-
-            }
+                 
+                    
+                    model.videoData = videoData;
+                    [self setDataToBottomViewFun];
+             }
+            }];
 
         }
+
     }
-    
-    
-    [self setDataToBottomViewFun];
 }
 
 #pragma mark 同步数据到底部

+ 1 - 1
创维盒子/双子星云手机/CloudPlayer/View/PlayerView.m

@@ -71,7 +71,7 @@ ShowImageViewDelegate>{
                   inRect:CGRectMake(0, 0, glkshowImageView.drawableWidth, glkshowImageView.drawableHeight)
                 fromRect:[ciImage extent]];
     
-    [self->glkshowImageView display];
+    //[self->glkshowImageView display];
 }
 
 - (void)showIMage

+ 1 - 0
创维盒子/双子星云手机/zh-Hans.lproj/Localizable.strings

@@ -271,6 +271,7 @@
 "File_upload_Record_clear_fail_Tip_msg"   = "清空所选已失败的任务?";
 "File_upload_Record_clear_uploading_Tip_msg"   = "任务未完成,确定删除选中的任务?";
 "File_upload_Record_select_all"   = "全选";
+"File_upload_cancel_select_all"   = "取消全选";
 "File_upload_Record_delete"   = "删除";
 "File_upload_fail"   = "文件上传失败";
 "File_upload_success"   = "文件上传成功";