Skip to content

Commit

Permalink
Merge branch 'release/0.24'
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioEstevao committed Nov 1, 2017
2 parents f7232d4 + 2bd95d8 commit 641d34b
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 39 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file.
`WPMediaPicker` adheres to [Semantic Versioning](http://semver.org/).

#### 0.x Releases
- `0.24` Release - [0.24](#24)
- `0.23` Release - [0.23](#23)
- `0.22` Release - [0.22](#22)
- `0.21` Release - [0.21](#21)
Expand All @@ -14,6 +15,15 @@ All notable changes to this project will be documented in this file.
- `0.15` Releases - [0.15](#15)

---
## [0.24](https://github.com/wordpress-mobile/MediaPicker-iOS/releases/tag/0.24)
Released on 2017-11-01. All issues associated with this milestone can be found using this
[filter](https://github.com/wordpress-mobile/MediaPicker-iOS/pulls?utf8=✓&q=is%3Apr%20is%3Aclosed%20milestone%3A0.24).

### Fixed
- Empty albums are filtered out of the album list. #230
- Fix crash on reload when using the same data source. #253
- Fixed display of count and thumbnail of albums when scrolling super quick. #255

## [0.23](https://github.com/wordpress-mobile/MediaPicker-iOS/releases/tag/0.23)
Released on 2017-10-04. All issues associated with this milestone can be found using this
[filter](https://github.com/wordpress-mobile/MediaPicker-iOS/pulls?utf8=✓&q=is%3Apr%20is%3Aclosed%20milestone%3A0.23).
Expand Down
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.23)
- WPMediaPicker (0.24)

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

SPEC CHECKSUMS:
WPMediaPicker: 51dff88157706419e000169b37c3abe0d3017b5f
WPMediaPicker: 5e2db7fd30d8ca497d91b26fbf61e94d6660f1c6

PODFILE CHECKSUM: 7c47e10b39aca62b1f30c3c4260cc99456cf95f8

Expand Down
2 changes: 1 addition & 1 deletion Example/WPMediaPicker/DemoViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ - (void)showPicker:(id) sender
{
self.mediaPicker = [[WPNavigationMediaPickerViewController alloc] initWithOptions:[self selectedOptions]];
self.mediaPicker.delegate = self;
self.pickerDataSource = [[WPPHAssetDataSource alloc] init];
self.pickerDataSource = [WPPHAssetDataSource sharedInstance];
self.mediaPicker.dataSource = self.pickerDataSource;
self.mediaPicker.selectionActionTitle = NSLocalizedString(@"Insert %@", @"");
if (self.mediaInputViewController) {
Expand Down
36 changes: 19 additions & 17 deletions Pod/Classes/WPMediaGroupPickerViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -116,27 +116,29 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
id<WPMediaGroup> group = [self.dataSource groupAtIndex:indexPath.row];

cell.imagePosterView.image = nil;
__block WPMediaRequestID requestKey = 0;
NSString *groupID = group.identifier;
cell.groupIdentifier = groupID;
CGFloat scale = [[UIScreen mainScreen] scale];
CGSize requestSize = CGSizeApplyAffineTransform(CGSizeMake(WPMediaGroupCellHeight, WPMediaGroupCellHeight), CGAffineTransformMakeScale(scale, scale));
requestKey = [group imageWithSize:requestSize
completionHandler:^(UIImage *result, NSError *error)
{
if (error) {
return;
}
dispatch_async(dispatch_get_main_queue(), ^{
if (cell.tag == requestKey){
cell.imagePosterView.image = result;
}
});
}];
cell.tag = requestKey;
[group imageWithSize:requestSize
completionHandler:^(UIImage *result, NSError *error)
{
if (error) {
return;
}
if ([cell.groupIdentifier isEqualToString:groupID]){
dispatch_async(dispatch_get_main_queue(), ^{
cell.imagePosterView.image = result;
});
}
}];
cell.titleLabel.text = [group name];
NSInteger numberOfAssets = [group numberOfAssetsOfType:[self.dataSource mediaTypeFilter] completionHandler:^(NSInteger result, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
cell.countLabel.text = [NSString stringWithFormat:@"%ld", (long)result];
});
if ([cell.groupIdentifier isEqualToString:groupID]){
dispatch_async(dispatch_get_main_queue(), ^{
cell.countLabel.text = [NSString stringWithFormat:@"%ld", (long)result];
});
}
}];
if (numberOfAssets != NSNotFound) {
cell.countLabel.text = [NSString stringWithFormat:@"%ld", (long)numberOfAssets];
Expand Down
1 change: 1 addition & 0 deletions Pod/Classes/WPMediaGroupTableViewCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *countLabel;
@property (nonatomic, strong) UIColor *posterBackgroundColor UI_APPEARANCE_SELECTOR;
@property (nonatomic, strong) NSString *groupIdentifier;

@end
8 changes: 8 additions & 0 deletions Pod/Classes/WPMediaGroupTableViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,12 @@ - (void)setPosterBackgroundColor:(UIColor *)posterBackgroundColor {
_imagePosterView.backgroundColor = posterBackgroundColor;
}

- (void)prepareForReuse {
[super prepareForReuse];
self.imagePosterView.image = nil;
self.titleLabel.text = nil;
self.countLabel.text = nil;
self.groupIdentifier = nil;
}

@end
2 changes: 2 additions & 0 deletions Pod/Classes/WPPHAssetDataSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ NS_CLASS_AVAILABLE_IOS(8_0) @interface WPPHAssetDataSource : NSObject<WPMediaCol
*/
@interface PHAssetCollectionForWPMediaGroup : NSObject<WPMediaGroup>

- (instancetype)initWithCollection:(PHAssetCollection *)collection mediaType:(WPMediaType)mediaType dispatchQueue:(dispatch_queue_t)queue;

- (instancetype)initWithCollection:(PHAssetCollection *)collection mediaType:(WPMediaType)mediaType;

@end
56 changes: 39 additions & 17 deletions Pod/Classes/WPPHAssetDataSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ @interface WPPHAssetDataSource() <PHPhotoLibraryChangeObserver>
@property (nonatomic, strong) PHFetchResult *assetsCollections;
@property (nonatomic, strong) PHFetchResult *assets;
@property (nonatomic, strong) PHFetchResult *albums;
@property (nonatomic, strong) NSMutableArray<PHAssetCollectionForWPMediaGroup *> *cachedCollections;
@property (nonatomic, strong) NSArray<PHAssetCollectionForWPMediaGroup *> *cachedCollections;
@property (nonatomic, assign) WPMediaType mediaTypeFilter;
@property (nonatomic, strong) NSMutableDictionary *observers;
@property (nonatomic, assign) BOOL refreshGroups;
@property (nonatomic, assign) BOOL ascendingOrdering;
@property (nonatomic, strong) dispatch_queue_t imageGenerationQueue;

@end

Expand Down Expand Up @@ -43,6 +44,7 @@ - (instancetype)init
_observers = [[NSMutableDictionary alloc] init];
_refreshGroups = YES;
_cachedCollections = [[NSMutableArray alloc] init];
_imageGenerationQueue = dispatch_queue_create("org.wordpress.wpmediapicker.WPPHAssetDataSource", DISPATCH_QUEUE_SERIAL);
[[PHPhotoLibrary sharedPhotoLibrary] registerChangeObserver:self];
return self;
}
Expand Down Expand Up @@ -178,15 +180,22 @@ - (NSArray *)smartAlbumsToShow {
- (void)loadGroupsWithSuccess:(WPMediaSuccessBlock)successBlock
failure:(WPMediaFailureBlock)failureBlock
{
PHFetchOptions *options = [[PHFetchOptions alloc] init];
options.fetchLimit = 1;
NSMutableArray *collectionsArray=[NSMutableArray array];
for (NSNumber *subType in [self smartAlbumsToShow]) {
PHFetchResult * smartAlbum = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum
subtype:[subType intValue]
options:nil];
options:options];
PHAssetCollection *collection = (PHAssetCollection *)smartAlbum.firstObject;
[collectionsArray addObject:collection];
PHFetchResult *result = [PHAsset fetchAssetsInAssetCollection:collection options:options];
if (result.count > 0) {
[collectionsArray addObject:collection];
}
}


PHFetchOptions *albumOptions = [[PHFetchOptions alloc] init];
albumOptions.predicate = [NSPredicate predicateWithFormat:@"(estimatedAssetCount != 0)"];
self.albums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum
subtype:PHAssetCollectionSubtypeAny
options:nil];
Expand All @@ -195,11 +204,17 @@ - (void)loadGroupsWithSuccess:(WPMediaSuccessBlock)successBlock


PHCollectionList *allAlbums = [PHCollectionList transientCollectionListWithCollections:collectionsArray title:@"Root"];
self.assetsCollections = [PHAssetCollection fetchCollectionsInCollectionList:allAlbums options:nil];
[self.cachedCollections removeAllObjects];
for (PHAssetCollection *assetColletion in self.assetsCollections) {
[self.cachedCollections addObject:[[PHAssetCollectionForWPMediaGroup alloc] initWithCollection:assetColletion mediaType:self.mediaTypeFilter]];
self.assetsCollections = [PHAssetCollection fetchCollectionsInCollectionList:allAlbums options:albumOptions];
NSMutableArray *newCachedAssetCollection = [NSMutableArray new];
for (PHAssetCollection *assetCollection in self.assetsCollections) {
if (assetCollection.estimatedAssetCount == 0) {
continue;
}
[newCachedAssetCollection addObject:[[PHAssetCollectionForWPMediaGroup alloc] initWithCollection:assetCollection
mediaType:self.mediaTypeFilter
dispatchQueue: self.imageGenerationQueue]];
}
self.cachedCollections = newCachedAssetCollection;
if (self.assetsCollections.count > 0){
if (!self.activeAssetsCollection || [self.assetsCollections indexOfObject:self.activeAssetsCollection] == NSNotFound) {
self.activeAssetsCollection = [self.assetsCollections firstObject];
Expand All @@ -213,10 +228,6 @@ - (void)loadGroupsWithSuccess:(WPMediaSuccessBlock)successBlock
}

}

self.albums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum
subtype:PHAssetCollectionSubtypeAny
options:nil];
}

+ (NSPredicate *)predicateForFilterMediaType:(WPMediaType)mediaType
Expand Down Expand Up @@ -276,7 +287,8 @@ - (NSInteger)numberOfGroups
{
if (!_selectedGroup) {
_selectedGroup = [[PHAssetCollectionForWPMediaGroup alloc] initWithCollection:self.activeAssetsCollection
mediaType:self.mediaTypeFilter];
mediaType:self.mediaTypeFilter
dispatchQueue:self.imageGenerationQueue];
}

return _selectedGroup;
Expand Down Expand Up @@ -549,18 +561,23 @@ @interface PHAssetCollectionForWPMediaGroup()
@property(nonatomic, assign) WPMediaType mediaType;
@property(nonatomic, strong) PHFetchResult *fetchResult;
@property(nonatomic, strong) PHFetchResult *posterAssetFetchResult;
@property (nonatomic, strong) dispatch_queue_t imageGenerationQueue;

@end

@implementation PHAssetCollectionForWPMediaGroup

- (instancetype)initWithCollection:(PHAssetCollection *)collection mediaType:(WPMediaType)mediaType
- (instancetype)initWithCollection:(PHAssetCollection *)collection mediaType:(WPMediaType)mediaType {
return [self initWithCollection:collection mediaType:mediaType dispatchQueue:dispatch_get_main_queue()];
}

- (instancetype)initWithCollection:(PHAssetCollection *)collection mediaType:(WPMediaType)mediaType dispatchQueue:(dispatch_queue_t)queue
{
self = [super init];
if (self) {
_collection = collection;
_mediaType = mediaType;

_imageGenerationQueue = queue;
_assetCount = NSNotFound;
_posterAsset = nil;
}
Expand All @@ -575,8 +592,9 @@ - (NSString *)name

- (WPMediaRequestID)imageWithSize:(CGSize)size completionHandler:(WPMediaImageBlock)completionHandler
{
dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{
[self.posterAsset imageWithSize:size completionHandler:completionHandler];
__weak __typeof__(self) weakSelf = self;
dispatch_async(self.imageGenerationQueue, ^{
[weakSelf.posterAsset imageWithSize:size completionHandler:completionHandler];
});
return 0;
}
Expand All @@ -598,6 +616,10 @@ - (NSString *)identifier

- (NSInteger)numberOfAssetsOfType:(WPMediaType)mediaType completionHandler:(WPMediaCountBlock)completionHandler
{
if (_assetCount != NSNotFound) {
completionHandler(self.assetCount, nil);
return self.assetCount;
}
dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{
self.assetCount = [self.fetchResult count];
completionHandler(self.assetCount, nil);
Expand Down
2 changes: 1 addition & 1 deletion Pod/Classes/WPVideoPlayerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ - (void)observeValueForKeyPath:(NSString *)keyPath
AVPlayerItemStatus status;
NSNumber *statusNumber = change[NSKeyValueChangeNewKey];
// Get the status change from the change dictionary
if (statusNumber) {
if (statusNumber != nil) {
status = (AVPlayerItemStatus)[statusNumber intValue];
} else {
status = AVPlayerItemStatusUnknown;
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.23"
s.version = "0.24"
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 641d34b

Please sign in to comment.