Skip to content
This repository was archived by the owner on Jun 19, 2025. It is now read-only.

Commit 4cee383

Browse files
committed
Merge branch 'release/0.7.1'
2 parents d0595d2 + 242c2bd commit 4cee383

File tree

5 files changed

+81
-52
lines changed

5 files changed

+81
-52
lines changed

.travis.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1+
osx_image: xcode7.1
12
sudo: false
23
language: objective-c
3-
cache: cocoapods
44
podfile: Example/Podfile
5-
install:
6-
- gem install cocoapods
7-
- gem install xcpretty --no-rdoc --no-ri --no-document --quiet
85
before_script:
96
- cd Example && pod install && cd -
107
script:

Example/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
PODS:
2-
- WPMediaPicker (0.7.0)
2+
- WPMediaPicker (0.7.1)
33

44
DEPENDENCIES:
55
- WPMediaPicker (from `../`)
@@ -9,6 +9,6 @@ EXTERNAL SOURCES:
99
:path: ../
1010

1111
SPEC CHECKSUMS:
12-
WPMediaPicker: f721cacd4113c6e718a1c7296083b9fd4a040536
12+
WPMediaPicker: d3d46adfbc9f34a4350f0f2defdafb04f32701f2
1313

1414
COCOAPODS: 0.39.0

Pod/Classes/WPMediaCollectionViewCell.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ - (void)prepareForReuse
3535
[self setImage:nil];
3636
[self setCaption:@""];
3737
[self setPosition:NSNotFound];
38+
[self setSelected:NO];
3839
}
3940

4041
- (void)commonInit

Pod/Classes/WPMediaCollectionViewController.m

Lines changed: 76 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,12 @@ - (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(
188188
return UIModalPresentationNone;
189189
}
190190

191+
- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller
192+
traitCollection:(UITraitCollection *)traitCollection
193+
{
194+
return UIModalPresentationNone;
195+
}
196+
191197
- (void)cancelPicker:(UIBarButtonItem *)sender
192198
{
193199
if ([self.picker.delegate respondsToSelector:@selector(mediaPickerControllerDidCancel:)]) {
@@ -237,6 +243,9 @@ - (void)refreshData
237243
[self.collectionView setContentOffset:CGPointMake(0, - [[self topLayoutGuide] length] - (self.refreshControl.frame.size.height)) animated:YES];
238244
[self.refreshControl beginRefreshing];
239245
}
246+
// NOTE: Sergio Estevao (2015-11-19)
247+
// Clean all assets and refresh collection view when the group was changed
248+
// This avoid to see data from previous group while the new one is loading.
240249
[self.collectionView reloadData];
241250
}
242251
self.collectionView.allowsSelection = NO;
@@ -268,39 +277,59 @@ - (void)refreshData
268277
} failure:^(NSError *error) {
269278
__typeof__(self) strongSelf = weakSelf;
270279
dispatch_async(dispatch_get_main_queue(), ^{
271-
[strongSelf refreshTitle];
272-
[strongSelf.refreshControl endRefreshing];
273-
strongSelf.collectionView.allowsSelection = YES;
274-
strongSelf.collectionView.scrollEnabled = YES;
275-
[strongSelf.collectionView reloadData];
276-
if (error.domain == WPMediaPickerErrorDomain &&
277-
error.code == WPMediaErrorCodePermissionsFailed) {
278-
NSString *otherButtonTitle = nil;
279-
if ([[self class] isiOS8OrAbove]) {
280-
otherButtonTitle = NSLocalizedString(@"Open Settings", @"Go to the settings app");
281-
}
282-
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Media Library", @"Title for alert when access to the media library is not granted by the user")
283-
message:NSLocalizedString(@"This app needs permission to access your device media library in order to add photos and/or video to your posts. Please change the privacy settings if you wish to allow this.", @"Explaining to the user why the app needs access to the device media library.")
284-
delegate:self
285-
cancelButtonTitle:NSLocalizedString(@"OK", "")
286-
otherButtonTitles:otherButtonTitle,nil];
287-
alertView.tag = WPMediaCollectionAlertMediaLibraryPermissionsNeeded;
288-
alertView.delegate = strongSelf;
289-
[alertView show];
290-
return;
291-
}
292-
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Media Library", @"Title for alert when a generic error happened when loading media")
293-
message:NSLocalizedString(@"There was a problem when trying to access your media. Please try again later.", @"Explaining to the user there was an generic error accesing media.")
294-
delegate:self
295-
cancelButtonTitle:NSLocalizedString(@"OK", "")
296-
otherButtonTitles:nil];
297-
alertView.tag = WPMediaCollectionAlertOtherError;
298-
alertView.delegate = strongSelf;
299-
[alertView show];
280+
[strongSelf showError:error];
300281
});
301282
}];
302283
}
303284

285+
- (void)showError:(NSError *)error {
286+
[self refreshTitle];
287+
[self.refreshControl endRefreshing];
288+
self.collectionView.allowsSelection = YES;
289+
self.collectionView.scrollEnabled = YES;
290+
[self.collectionView reloadData];
291+
NSString *title = NSLocalizedString(@"Media Library", @"Title for alert when a generic error happened when loading media");
292+
NSString *message = NSLocalizedString(@"There was a problem when trying to access your media. Please try again later.", @"Explaining to the user there was an generic error accesing media.");
293+
NSString *cancelText = NSLocalizedString(@"OK", "");
294+
NSString *otherButtonTitle = nil;
295+
NSInteger tag = WPMediaCollectionAlertOtherError;
296+
if (error.domain == WPMediaPickerErrorDomain &&
297+
error.code == WPMediaErrorCodePermissionsFailed) {
298+
if ([[self class] isiOS8OrAbove]) {
299+
otherButtonTitle = NSLocalizedString(@"Open Settings", @"Go to the settings app");
300+
}
301+
title = NSLocalizedString(@"Media Library", @"Title for alert when access to the media library is not granted by the user");
302+
message = NSLocalizedString(@"This app needs permission to access your device media library in order to add photos and/or video to your posts. Please change the privacy settings if you wish to allow this.", @"Explaining to the user why the app needs access to the device media library.");
303+
tag = WPMediaCollectionAlertMediaLibraryPermissionsNeeded;
304+
}
305+
if ([[self class] isiOS8OrAbove]) {
306+
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
307+
UIAlertAction *okAction = [UIAlertAction actionWithTitle:cancelText style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
308+
if ([self.picker.delegate respondsToSelector:@selector(mediaPickerControllerDidCancel:)]) {
309+
[self.picker.delegate mediaPickerControllerDidCancel:self.picker];
310+
}
311+
}];
312+
[alertController addAction:okAction];
313+
314+
if (otherButtonTitle) {
315+
UIAlertAction *otherAction = [UIAlertAction actionWithTitle:otherButtonTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
316+
NSURL *settingsURL = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
317+
[[UIApplication sharedApplication] openURL:settingsURL];
318+
}];
319+
[alertController addAction:otherAction];
320+
[self presentViewController:alertController animated:YES completion:nil];
321+
}
322+
} else {
323+
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title
324+
message:message
325+
delegate:self
326+
cancelButtonTitle:cancelText
327+
otherButtonTitles:otherButtonTitle, nil];
328+
alertView.tag = tag;
329+
[alertView show];
330+
}
331+
}
332+
304333
- (void)refreshSelection
305334
{
306335
NSArray *selectedAssets = [NSArray arrayWithArray:self.selectedAssets];
@@ -657,13 +686,15 @@ - (void)showAlertAboutMediaCapturePermission
657686

658687
- (void)processMediaCaptured:(NSDictionary *)info
659688
{
689+
NSInteger mediaItemsBefore = [self.dataSource numberOfAssets];
660690
self.ignoreMediaTimestamp = [NSDate timeIntervalSinceReferenceDate];
661691
WPMediaAddedBlock completionBlock = ^(id<WPMediaAsset> media, NSError *error) {
662692
if (error || !media) {
663-
NSLog(@"%@", error);
693+
NSLog(@"Adding media failed: %@", [error localizedDescription]);
664694
return;
665695
}
666-
[self addMedia:media];
696+
NSInteger mediaItemsAfter = [self.dataSource numberOfAssets];
697+
[self addMedia:media animated:mediaItemsAfter != mediaItemsBefore];
667698
};
668699
if ([info[UIImagePickerControllerMediaType] isEqual:(NSString *)kUTTypeImage]) {
669700
UIImage *image = (UIImage *)info[UIImagePickerControllerOriginalImage];
@@ -675,7 +706,7 @@ - (void)processMediaCaptured:(NSDictionary *)info
675706
}
676707
}
677708

678-
- (void)addMedia:(id<WPMediaAsset>)asset
709+
- (void)addMedia:(id<WPMediaAsset>)asset animated:(BOOL)animated
679710
{
680711
BOOL willBeSelected = YES;
681712
if ([self.picker.delegate respondsToSelector:@selector(mediaPickerController:shouldSelectAsset:)]) {
@@ -687,21 +718,21 @@ - (void)addMedia:(id<WPMediaAsset>)asset
687718
} else {
688719
[self.selectedAssets addObject:asset];
689720
}
690-
691721
NSUInteger insertPosition = [self showMostRecentFirst] ? 1 : [self.dataSource numberOfAssets]-1;
722+
if (animated){
723+
[self.collectionView insertItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:insertPosition inSection:0]]];
692724

693-
[self.collectionView insertItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:insertPosition inSection:0]]];
694-
695-
if ( ![self showMostRecentFirst] ){
696-
NSUInteger reloadPosition = [self.dataSource numberOfAssets];
697-
[self.collectionView reloadItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:reloadPosition inSection:0]]];
698-
} else {
699-
NSUInteger reloadPosition = MIN([self.dataSource numberOfAssets], 2);
700-
[self.collectionView reloadItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:reloadPosition inSection:0]]];
701-
}
702-
if (!self.showMostRecentFirst) {
703-
[self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:[self.dataSource numberOfAssets] inSection:0]
704-
atScrollPosition:UICollectionViewScrollPositionBottom animated:YES];
725+
if ( ![self showMostRecentFirst] ){
726+
NSUInteger reloadPosition = [self.dataSource numberOfAssets];
727+
[self.collectionView reloadItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:reloadPosition inSection:0]]];
728+
} else {
729+
NSUInteger reloadPosition = MIN([self.dataSource numberOfAssets], 2);
730+
[self.collectionView reloadItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:reloadPosition inSection:0]]];
731+
}
732+
if (!self.showMostRecentFirst) {
733+
[self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:[self.dataSource numberOfAssets] inSection:0]
734+
atScrollPosition:UICollectionViewScrollPositionBottom animated:YES];
735+
}
705736
}
706737

707738
if (!willBeSelected) {

WPMediaPicker.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "WPMediaPicker"
3-
s.version = "0.7.0"
3+
s.version = "0.7.1"
44
s.summary = "WPMediaPicker is an iOS controller that allows capture and picking of media assets."
55
s.description = <<-DESC
66
WPMediaPicker is an iOS controller that allows capture and picking of media assets.

0 commit comments

Comments
 (0)