Skip to content

Commit

Permalink
Merge branch 'release/0.3.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioEstevao committed Apr 29, 2015
2 parents 80eb218 + d728bde commit 45d2658
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 19 deletions.
4 changes: 2 additions & 2 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- WPMediaPicker (0.3.2)
- WPMediaPicker (0.3.3)

DEPENDENCIES:
- WPMediaPicker (from `../`)
Expand All @@ -9,6 +9,6 @@ EXTERNAL SOURCES:
:path: ../

SPEC CHECKSUMS:
WPMediaPicker: aec400d4a62eb2d215cdb264e1fd2bc12c656081
WPMediaPicker: 3397de209862de5ae02a36d2ed5b8c57a4300f9d

COCOAPODS: 0.36.4
1 change: 0 additions & 1 deletion Example/WPMediaPicker/DemoViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

Expand Down
74 changes: 59 additions & 15 deletions Pod/Classes/WPMediaCollectionViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ @interface WPMediaCollectionViewController () <UIImagePickerControllerDelegate,
@property (nonatomic, strong) ALAssetsGroup *assetsGroup;
@property (nonatomic, strong) NSMutableArray *assets;
@property (nonatomic, strong) NSMutableArray *selectedAssets;
@property (nonatomic, strong) NSMutableArray *selectedAssetsGroup;
@property (nonatomic, strong) ALAsset *liveAsset;
@property (nonatomic, strong) WPMediaCaptureCollectionViewCell *captureCell;
@property (nonatomic, strong) UIButton *titleButton;
Expand Down Expand Up @@ -43,6 +44,7 @@ - (instancetype)init
_layout = layout;
_assets = [[NSMutableArray alloc] init];
_selectedAssets = [[NSMutableArray alloc] init];
_selectedAssetsGroup = [[NSMutableArray alloc] init];
_allowCaptureOfMedia = YES;
_showMostRecentFirst = NO;
_liveAsset = [[ALAsset alloc] init];
Expand Down Expand Up @@ -182,7 +184,22 @@ - (BOOL)isShowingCaptureCell
- (void)loadData
{
[self.assets removeAllObjects];


NSMutableSet *selectedAssetsSet = [NSMutableSet set];
NSMutableSet *stillExistingSeletedAssets = [NSMutableSet set];
NSURL *currentGroupURL = [self.assetsGroup valueForProperty:ALAssetsGroupPropertyURL];
for (int i =0; i < self.selectedAssets.count; i++) {
ALAsset *asset = (ALAsset *)self.selectedAssets[i];
NSURL *assetURL = (NSURL *)[asset valueForProperty:ALAssetPropertyAssetURL];
[selectedAssetsSet addObject:assetURL];

ALAssetsGroup *assetGroup = (ALAssetsGroup *)self.selectedAssetsGroup[i];
NSURL *assetGroupURL = [assetGroup valueForProperty:ALAssetsGroupPropertyURL];
if ( ![assetGroupURL isEqual:currentGroupURL]) {
[stillExistingSeletedAssets addObject:assetURL];
}
}

if (!self.assetsGroup) {
[self.assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
if(!group){
Expand All @@ -201,22 +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];
} else {
if ([self isShowingCaptureCell]){
NSInteger insertPosition = self.showMostRecentFirst ? 0 : self.assets.count;
[self.assets insertObject:self.liveAsset atIndex:insertPosition];
}
[self.collectionView reloadData];
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
Expand Down Expand Up @@ -319,6 +354,8 @@ - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPa
}

[self.selectedAssets addObject:asset];
[self.selectedAssetsGroup addObject:self.assetsGroup];

WPMediaCollectionViewCell *cell = (WPMediaCollectionViewCell *)[self.collectionView cellForItemAtIndexPath:indexPath];
[cell setPosition:self.selectedAssets.count];
[self animateCellSelection:cell completion:^{
Expand Down Expand Up @@ -360,6 +397,7 @@ - (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndex
NSUInteger deselectPosition = [self findAsset:asset];
if (deselectPosition != NSNotFound) {
[self.selectedAssets removeObjectAtIndex:deselectPosition];
[self.selectedAssetsGroup removeObjectAtIndex:deselectPosition];
}

WPMediaCollectionViewCell *cell = (WPMediaCollectionViewCell *)[self.collectionView cellForItemAtIndexPath:indexPath];
Expand Down Expand Up @@ -498,18 +536,24 @@ - (void)addAsset:(ALAsset *)asset
if ([self.picker.delegate respondsToSelector:@selector(mediaPickerController:shouldSelectAsset:)]) {
if ([self.picker.delegate mediaPickerController:self.picker shouldSelectAsset:asset]) {
[self.selectedAssets addObject:asset];
[self.selectedAssetsGroup addObject:self.assetsGroup];
} else {
willBeSelected = NO;
}
} else {
[self.selectedAssets addObject:asset];
[self.selectedAssetsGroup addObject:self.assetsGroup];
}

NSUInteger insertPosition = [self showMostRecentFirst] ? 1 : self.assets.count - 1;
[self.assets insertObject:asset atIndex:insertPosition];
[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) {
Expand Down
2 changes: 1 addition & 1 deletion WPMediaPicker.podspec
Original file line number Diff line number Diff line change
@@ -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.
Expand Down

0 comments on commit 45d2658

Please sign in to comment.