add selected management
This commit is contained in:
parent
960b34a73a
commit
fb571a7442
|
@ -117,7 +117,7 @@ static NSString * const CellReuseIdentifier = @"Cell";
|
||||||
allPhotosOptions.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:YES]];
|
allPhotosOptions.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:YES]];
|
||||||
|
|
||||||
if ([albumName caseInsensitiveCompare:@"all photos"] == NSOrderedSame || !albumName || [albumName isEqualToString:@""]) {
|
if ([albumName caseInsensitiveCompare:@"all photos"] == NSOrderedSame || !albumName || [albumName isEqualToString:@""]) {
|
||||||
// self.assetsCollection = [PHAsset fetchAssetsWithOptions:allPhotosOptions];
|
// self.assetsCollection = [PHAsset fetchAssetsWithOptions:allPhotosOptions];
|
||||||
PHFetchResult *allPhotosFetchResults = [PHAsset fetchAssetsWithOptions:allPhotosOptions];
|
PHFetchResult *allPhotosFetchResults = [PHAsset fetchAssetsWithOptions:allPhotosOptions];
|
||||||
self.galleryData = [[GalleryData alloc] initWithFetchResults:allPhotosFetchResults];
|
self.galleryData = [[GalleryData alloc] initWithFetchResults:allPhotosFetchResults];
|
||||||
|
|
||||||
|
@ -132,7 +132,6 @@ static NSString * const CellReuseIdentifier = @"Cell";
|
||||||
|
|
||||||
if ([collection.localizedTitle isEqualToString:albumName]) {
|
if ([collection.localizedTitle isEqualToString:albumName]) {
|
||||||
|
|
||||||
// self.assetsCollection = [PHAsset fetchAssetsInAssetCollection:collection options:nil];
|
|
||||||
PHFetchResult *collectionFetchResults = [PHAsset fetchAssetsInAssetCollection:collection options:nil];
|
PHFetchResult *collectionFetchResults = [PHAsset fetchAssetsInAssetCollection:collection options:nil];
|
||||||
self.galleryData = [[GalleryData alloc] initWithFetchResults:collectionFetchResults];
|
self.galleryData = [[GalleryData alloc] initWithFetchResults:collectionFetchResults];
|
||||||
[self.collectionView reloadData];
|
[self.collectionView reloadData];
|
||||||
|
@ -156,6 +155,8 @@ static NSString * const CellReuseIdentifier = @"Cell";
|
||||||
PHAsset *asset = assetDictionary[@"asset"];
|
PHAsset *asset = assetDictionary[@"asset"];
|
||||||
|
|
||||||
CKGalleryCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellReuseIdentifier forIndexPath:indexPath];
|
CKGalleryCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellReuseIdentifier forIndexPath:indexPath];
|
||||||
|
cell.isSelected = ((NSNumber*)assetDictionary[@"isSelected"]).boolValue;
|
||||||
|
|
||||||
cell.representedAssetIdentifier = asset.localIdentifier;
|
cell.representedAssetIdentifier = asset.localIdentifier;
|
||||||
|
|
||||||
[self.imageManager requestImageForAsset:asset
|
[self.imageManager requestImageForAsset:asset
|
||||||
|
@ -179,9 +180,10 @@ static NSString * const CellReuseIdentifier = @"Cell";
|
||||||
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
|
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
|
||||||
|
|
||||||
id selectedCell =[collectionView cellForItemAtIndexPath:indexPath];
|
id selectedCell =[collectionView cellForItemAtIndexPath:indexPath];
|
||||||
NSDictionary *assetDictionary = (NSDictionary*)self.galleryData.data[indexPath.row];
|
NSMutableDictionary *assetDictionary = (NSMutableDictionary*)self.galleryData.data[indexPath.row];
|
||||||
PHAsset *asset = assetDictionary[@"asset"];
|
PHAsset *asset = assetDictionary[@"asset"];
|
||||||
NSNumber *isSelectedNumber = assetDictionary[@"isSelected"];
|
NSNumber *isSelectedNumber = assetDictionary[@"isSelected"];
|
||||||
|
assetDictionary[@"isSelected"] = [NSNumber numberWithBool:!(isSelectedNumber.boolValue)];
|
||||||
|
|
||||||
if ([selectedCell isKindOfClass:[CKGalleryCollectionViewCell class]]) {
|
if ([selectedCell isKindOfClass:[CKGalleryCollectionViewCell class]]) {
|
||||||
CKGalleryCollectionViewCell *ckCell = (CKGalleryCollectionViewCell*)selectedCell;
|
CKGalleryCollectionViewCell *ckCell = (CKGalleryCollectionViewCell*)selectedCell;
|
||||||
|
@ -189,7 +191,6 @@ static NSString * const CellReuseIdentifier = @"Cell";
|
||||||
|
|
||||||
[self.selectedAssets removeObject:asset];
|
[self.selectedAssets removeObject:asset];
|
||||||
|
|
||||||
|
|
||||||
if (ckCell.isSelected) {
|
if (ckCell.isSelected) {
|
||||||
if (asset) {
|
if (asset) {
|
||||||
[self.selectedAssets addObject:asset];
|
[self.selectedAssets addObject:asset];
|
||||||
|
@ -261,7 +262,7 @@ RCT_EXPORT_METHOD(getSelectedImages:(RCTPromiseResolveBlock)resolve
|
||||||
|
|
||||||
float imageSize = imageData.length;
|
float imageSize = imageData.length;
|
||||||
assetInfoDict[@"size"] = [NSNumber numberWithFloat:imageSize];
|
assetInfoDict[@"size"] = [NSNumber numberWithFloat:imageSize];
|
||||||
|
|
||||||
NSURL *fileURL = [directoryURL URLByAppendingPathComponent:fileName];
|
NSURL *fileURL = [directoryURL URLByAppendingPathComponent:fileName];
|
||||||
NSError *error = nil;
|
NSError *error = nil;
|
||||||
[imageData writeToURL:fileURL options:NSDataWritingAtomic error:&error];
|
[imageData writeToURL:fileURL options:NSDataWritingAtomic error:&error];
|
||||||
|
|
|
@ -35,8 +35,11 @@
|
||||||
NSMutableArray *array = [[NSMutableArray alloc] init];
|
NSMutableArray *array = [[NSMutableArray alloc] init];
|
||||||
|
|
||||||
for (PHAsset *asset in fetchResults) {
|
for (PHAsset *asset in fetchResults) {
|
||||||
NSDictionary *assetDictionary = @{@"asset": asset,
|
NSMutableDictionary *assetDictionary = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
|
||||||
@"isSelected:": @NO};
|
asset, @"asset",
|
||||||
|
[NSNumber numberWithBool:NO], @"isSelected",
|
||||||
|
nil];
|
||||||
|
|
||||||
[array addObject:assetDictionary];
|
[array addObject:assetDictionary];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue