From be09e467f27e84167e7e06e98bd10c01f9f72591 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=CC=81rgio=20Este=CC=82va=CC=83o?= Date: Wed, 29 Apr 2015 21:19:56 +1000 Subject: [PATCH 1/7] Update selected assets on reload. --- Pod/Classes/WPMediaCollectionViewController.m | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Pod/Classes/WPMediaCollectionViewController.m b/Pod/Classes/WPMediaCollectionViewController.m index 4038a82f..82cb5fd7 100644 --- a/Pod/Classes/WPMediaCollectionViewController.m +++ b/Pod/Classes/WPMediaCollectionViewController.m @@ -182,7 +182,13 @@ - (BOOL)isShowingCaptureCell - (void)loadData { [self.assets removeAllObjects]; - + + NSMutableSet *selectedAssetsSet = [NSMutableSet set]; + NSMutableSet *stillExistingSeletedAsssets = [NSMutableSet set]; + for (ALAsset *asset in self.selectedAssets) { + [selectedAssetsSet addObject:[asset valueForProperty:ALAssetPropertyAssetURL] ]; + } + if (!self.assetsGroup) { [self.assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) { if(!group){ @@ -206,12 +212,28 @@ - (void)loadData usingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) { if (result){ [self.assets addObject:result]; + NSURL *assetURL = [result valueForProperty:ALAssetPropertyAssetURL]; + if ([selectedAssetsSet containsObject:assetURL]) { + [stillExistingSeletedAsssets addObject:assetURL]; + } } else { + [selectedAssetsSet minusSet:stillExistingSeletedAsssets]; + NSSet *missingAsset = [NSSet setWithSet:selectedAssetsSet]; + NSMutableArray *assetsToRemove = [NSMutableArray array]; + for (ALAsset *selectedAsset in self.selectedAssets){ + if ([missingAsset containsObject:[selectedAsset valueForProperty:ALAssetPropertyAssetURL]]){ + [assetsToRemove addObject:selectedAsset]; + } + } + [self.selectedAssets removeObjectsInArray:assetsToRemove]; + // Add live data cell if ([self isShowingCaptureCell]){ NSInteger insertPosition = self.showMostRecentFirst ? 0 : self.assets.count; [self.assets insertObject:self.liveAsset atIndex:insertPosition]; } + // Make sure we reload the collection view [self.collectionView reloadData]; + // Scroll to the correct position NSInteger sectionToScroll = 0; NSInteger itemToScroll = self.showMostRecentFirst ? 0 :self.assets.count-1; [self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:itemToScroll inSection:sectionToScroll] atScrollPosition:UICollectionViewScrollPositionBottom animated:NO]; @@ -319,6 +341,7 @@ - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPa } [self.selectedAssets addObject:asset]; + WPMediaCollectionViewCell *cell = (WPMediaCollectionViewCell *)[self.collectionView cellForItemAtIndexPath:indexPath]; [cell setPosition:self.selectedAssets.count]; [self animateCellSelection:cell completion:^{ From fda752247e115a7a4dba4b4daa59bcc8ee713ddb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=CC=81rgio=20Este=CC=82va=CC=83o?= Date: Wed, 29 Apr 2015 21:20:23 +1000 Subject: [PATCH 2/7] Test with live asset on the end. --- Example/WPMediaPicker/DemoViewController.m | 1 - 1 file changed, 1 deletion(-) diff --git a/Example/WPMediaPicker/DemoViewController.m b/Example/WPMediaPicker/DemoViewController.m index 324dce28..6de24022 100644 --- a/Example/WPMediaPicker/DemoViewController.m +++ b/Example/WPMediaPicker/DemoViewController.m @@ -88,7 +88,6 @@ - (void) showPicker:(id) sender { WPMediaPickerViewController * mediaPicker = [[WPMediaPickerViewController alloc] init]; mediaPicker.delegate = self; - mediaPicker.showMostRecentFirst = YES; [self presentViewController:mediaPicker animated:YES completion:nil]; } From 71c3845d38f65ec412239bd462ef6ae46f5a5254 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=CC=81rgio=20Este=CC=82va=CC=83o?= Date: Wed, 29 Apr 2015 21:59:24 +1000 Subject: [PATCH 3/7] Assume that assets that belong to another group are still present when deletions happen. --- Pod/Classes/WPMediaCollectionViewController.m | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/Pod/Classes/WPMediaCollectionViewController.m b/Pod/Classes/WPMediaCollectionViewController.m index 82cb5fd7..a29c3d06 100644 --- a/Pod/Classes/WPMediaCollectionViewController.m +++ b/Pod/Classes/WPMediaCollectionViewController.m @@ -14,6 +14,7 @@ @interface WPMediaCollectionViewController () Date: Wed, 29 Apr 2015 22:08:21 +1000 Subject: [PATCH 4/7] Fix cast type --- Pod/Classes/WPMediaCollectionViewController.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Pod/Classes/WPMediaCollectionViewController.m b/Pod/Classes/WPMediaCollectionViewController.m index a29c3d06..2f4ead74 100644 --- a/Pod/Classes/WPMediaCollectionViewController.m +++ b/Pod/Classes/WPMediaCollectionViewController.m @@ -190,7 +190,7 @@ - (void)loadData NSURL *currentGroupURL = [self.assetsGroup valueForProperty:ALAssetsGroupPropertyURL]; for (int i =0; i < self.selectedAssets.count; i++) { ALAsset *asset = (ALAsset *)self.selectedAssets[i]; - NSURL *assetURL = (ALAsset *)[asset valueForProperty:ALAssetPropertyAssetURL]; + NSURL *assetURL = (NSURL *)[asset valueForProperty:ALAssetPropertyAssetURL]; [selectedAssetsSet addObject:assetURL]; ALAssetsGroup *assetGroup = (ALAssetsGroup *)self.selectedAssetsGroup[i]; From 4158c166f752cc80184c7482eded3672787175f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=CC=81rgio=20Este=CC=82va=CC=83o?= Date: Wed, 29 Apr 2015 22:08:32 +1000 Subject: [PATCH 5/7] Relayout code. --- Pod/Classes/WPMediaCollectionViewController.m | 62 ++++++++++--------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/Pod/Classes/WPMediaCollectionViewController.m b/Pod/Classes/WPMediaCollectionViewController.m index 2f4ead74..6d5f224e 100644 --- a/Pod/Classes/WPMediaCollectionViewController.m +++ b/Pod/Classes/WPMediaCollectionViewController.m @@ -218,38 +218,40 @@ - (void)loadData NSString *title = [NSString stringWithFormat:@"%@ %@", (NSString *)[self.assetsGroup valueForProperty:ALAssetsGroupPropertyName], ArrowDown]; [self.titleButton setTitle:title forState:UIControlStateNormal]; [self.titleButton sizeToFit]; + [self.assetsGroup setAssetsFilter:self.assetsFilter]; + ALAssetsGroupEnumerationResultsBlock assetEnumerationBlock = ^(ALAsset *result, NSUInteger index, BOOL *stop) { + if (result){ + [self.assets addObject:result]; + NSURL *assetURL = [result valueForProperty:ALAssetPropertyAssetURL]; + if ([selectedAssetsSet containsObject:assetURL]) { + [stillExistingSeletedAssets addObject:assetURL]; + } + } else { + [selectedAssetsSet minusSet:stillExistingSeletedAssets]; + NSSet *missingAsset = [NSSet setWithSet:selectedAssetsSet]; + NSMutableArray *assetsToRemove = [NSMutableArray array]; + for (ALAsset *selectedAsset in self.selectedAssets){ + if ([missingAsset containsObject:[selectedAsset valueForProperty:ALAssetPropertyAssetURL]]){ + [assetsToRemove addObject:selectedAsset]; + } + } + [self.selectedAssets removeObjectsInArray:assetsToRemove]; + // Add live data cell + if ([self isShowingCaptureCell]){ + NSInteger insertPosition = self.showMostRecentFirst ? 0 : self.assets.count; + [self.assets insertObject:self.liveAsset atIndex:insertPosition]; + } + // Make sure we reload the collection view + [self.collectionView reloadData]; + // Scroll to the correct position + NSInteger sectionToScroll = 0; + NSInteger itemToScroll = self.showMostRecentFirst ? 0 :self.assets.count-1; + [self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:itemToScroll inSection:sectionToScroll] atScrollPosition:UICollectionViewScrollPositionBottom animated:NO]; + } + }; [self.assetsGroup enumerateAssetsWithOptions:self.showMostRecentFirst ? NSEnumerationReverse : 0 - usingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) { - if (result){ - [self.assets addObject:result]; - NSURL *assetURL = [result valueForProperty:ALAssetPropertyAssetURL]; - if ([selectedAssetsSet containsObject:assetURL]) { - [stillExistingSeletedAssets addObject:assetURL]; - } - } else { - [selectedAssetsSet minusSet:stillExistingSeletedAssets]; - NSSet *missingAsset = [NSSet setWithSet:selectedAssetsSet]; - NSMutableArray *assetsToRemove = [NSMutableArray array]; - for (ALAsset *selectedAsset in self.selectedAssets){ - if ([missingAsset containsObject:[selectedAsset valueForProperty:ALAssetPropertyAssetURL]]){ - [assetsToRemove addObject:selectedAsset]; - } - } - [self.selectedAssets removeObjectsInArray:assetsToRemove]; - // Add live data cell - if ([self isShowingCaptureCell]){ - NSInteger insertPosition = self.showMostRecentFirst ? 0 : self.assets.count; - [self.assets insertObject:self.liveAsset atIndex:insertPosition]; - } - // Make sure we reload the collection view - [self.collectionView reloadData]; - // Scroll to the correct position - NSInteger sectionToScroll = 0; - NSInteger itemToScroll = self.showMostRecentFirst ? 0 :self.assets.count-1; - [self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:itemToScroll inSection:sectionToScroll] atScrollPosition:UICollectionViewScrollPositionBottom animated:NO]; - } - }]; + usingBlock:assetEnumerationBlock]; } - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView From 658dd9dca60cd858d6103d31adb0ef9ea9dca2e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=CC=81rgio=20Este=CC=82va=CC=83o?= Date: Wed, 29 Apr 2015 22:51:23 +1000 Subject: [PATCH 6/7] Reload live cell after its moved. --- Pod/Classes/WPMediaCollectionViewController.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Pod/Classes/WPMediaCollectionViewController.m b/Pod/Classes/WPMediaCollectionViewController.m index 6d5f224e..a2cac2ec 100644 --- a/Pod/Classes/WPMediaCollectionViewController.m +++ b/Pod/Classes/WPMediaCollectionViewController.m @@ -550,6 +550,10 @@ - (void)addAsset:(ALAsset *)asset [self.collectionView performBatchUpdates:^{ [self.collectionView insertItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:insertPosition inSection:0]]]; } completion:^(BOOL finished) { + if ( ![self showMostRecentFirst] ){ + NSUInteger reloadPosition = self.assets.count - 1; + [self.collectionView reloadItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:reloadPosition inSection:0]]]; + } self.ignoreMediaNotifications = NO; }]; if (!willBeSelected) { From d728bdebc1c9e540bcfb5a130f30152d8b4a2e82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=CC=81rgio=20Este=CC=82va=CC=83o?= Date: Wed, 29 Apr 2015 23:03:30 +1000 Subject: [PATCH 7/7] Bump pod version. --- Example/Podfile.lock | 4 ++-- WPMediaPicker.podspec | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Example/Podfile.lock b/Example/Podfile.lock index e958a3fe..ec2bd4ae 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -1,5 +1,5 @@ PODS: - - WPMediaPicker (0.3.2) + - WPMediaPicker (0.3.3) DEPENDENCIES: - WPMediaPicker (from `../`) @@ -9,6 +9,6 @@ EXTERNAL SOURCES: :path: ../ SPEC CHECKSUMS: - WPMediaPicker: aec400d4a62eb2d215cdb264e1fd2bc12c656081 + WPMediaPicker: 3397de209862de5ae02a36d2ed5b8c57a4300f9d COCOAPODS: 0.36.4 diff --git a/WPMediaPicker.podspec b/WPMediaPicker.podspec index 0ee96a44..b4e8262a 100644 --- a/WPMediaPicker.podspec +++ b/WPMediaPicker.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "WPMediaPicker" - s.version = "0.3.2" + s.version = "0.3.3" s.summary = "WPMediaPicker is an iOS controller that allows capture and picking of media assets." s.description = <<-DESC WPMediaPicker is an iOS controller that allows capture and picking of media assets.