Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bugs found by static analyzer: calling super implementations of ... #105

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
158 changes: 106 additions & 52 deletions Classes/ELCImagePicker/ELCAlbumPickerController.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ @interface ELCAlbumPickerController ()

@implementation ELCAlbumPickerController

- (NSInteger)maximumImagesCount
{
return self.parent.maximumImagesCount;
}

//Using auto synthesizers

#pragma mark -
Expand All @@ -34,72 +39,121 @@ - (void)viewDidLoad
[self.navigationItem setRightBarButtonItem:cancelButton];

NSMutableArray *tempArray = [[NSMutableArray alloc] init];
self.assetGroups = tempArray;
self.assetGroups = nil;

ALAssetsLibrary *assetLibrary = [[ALAssetsLibrary alloc] init];
self.library = assetLibrary;

// Load Albums into assetGroups
dispatch_async(dispatch_get_main_queue(), ^
{
@autoreleasepool {

// Group enumerator Block
void (^assetGroupEnumerator)(ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop)
{
if (group == nil) {
return;
}

// added fix for camera albums order
NSString *sGroupPropertyName = (NSString *)[group valueForProperty:ALAssetsGroupPropertyName];
NSUInteger nType = [[group valueForProperty:ALAssetsGroupPropertyType] intValue];

if ([[sGroupPropertyName lowercaseString] isEqualToString:@"camera roll"] && nType == ALAssetsGroupSavedPhotos) {
[self.assetGroups insertObject:group atIndex:0];
}
else {
[self.assetGroups addObject:group];
}

// Reload albums
[self performSelectorOnMainThread:@selector(reloadTableView) withObject:nil waitUntilDone:YES];
};

// Group Enumerator Failure Block
void (^assetGroupEnumberatorFailure)(NSError *) = ^(NSError *error) {

if ([ALAssetsLibrary authorizationStatus] == ALAuthorizationStatusDenied) {
NSString *errorMessage = NSLocalizedString(@"This app does not have access to your photos or videos. You can enable access in Privacy Settings.", nil);
[[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Access Denied", nil) message:errorMessage delegate:nil cancelButtonTitle:NSLocalizedString(@"Ok", nil) otherButtonTitles:nil] show];

} else {
NSString *errorMessage = [NSString stringWithFormat:@"Album Error: %@ - %@", [error localizedDescription], [error localizedRecoverySuggestion]];
[[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Error", nil) message:errorMessage delegate:nil cancelButtonTitle:NSLocalizedString(@"Ok", nil) otherButtonTitles:nil] show];
}

[self.navigationItem setTitle:nil];
NSLog(@"A problem occured %@", [error description]);
};

// Enumerate Albums
[self.library enumerateGroupsWithTypes:ALAssetsGroupAll
usingBlock:assetGroupEnumerator
failureBlock:assetGroupEnumberatorFailure];

}
@autoreleasepool {

// Group enumerator Block
void (^assetGroupEnumerator)(ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop)
{
if (group) {
[tempArray addObject:group];
} else {
// finished adding groups.
// now sort them and put them into the table
NSDictionary *typeOrderReplacements = @{
@(ALAssetsGroupSavedPhotos) : @(-3),
@(ALAssetsGroupPhotoStream) : @(-2),
@(ALAssetsGroupEvent) : @(-1)
};
[tempArray sortUsingComparator:^NSComparisonResult(ALAssetsGroup *group1, ALAssetsGroup *group2) {
NSNumber *originalType1 = [group1 valueForProperty:ALAssetsGroupPropertyType];
NSNumber *type1 = typeOrderReplacements[originalType1];
if (!type1) {
type1 = originalType1;
}
NSNumber *originalType2 = [group2 valueForProperty:ALAssetsGroupPropertyType];
NSNumber *type2 = typeOrderReplacements[originalType2];
if (!type2) {
type2 = originalType2;
}
// first, we sort by album type (SavedPhotos, PhotoStream, Event, Library, Album, Faces, unknown, ...)
NSComparisonResult result = [type1 compare:type2];
if (result == NSOrderedSame) {
// second, we sort by album name.
// When sorting PhotoStream albums, we prefix the name with underscore when having "stream" in it;
// this should put the main photo stream to the top (assuming it is named something like "stream" in the current language).
NSString *name1 = [group1 valueForProperty:ALAssetsGroupPropertyName];
if ([originalType1 intValue] == ALAssetsGroupPhotoStream && [name1 rangeOfString:@"stream" options:NSCaseInsensitiveSearch].location != NSNotFound) {
name1 = [@"_" stringByAppendingString:name1];
}
NSString *name2 = [group2 valueForProperty:ALAssetsGroupPropertyName];
if ([originalType2 intValue] == ALAssetsGroupPhotoStream && [name2 rangeOfString:@"stream" options:NSCaseInsensitiveSearch].location != NSNotFound) {
name2 = [@"_" stringByAppendingString:name2];
}
result = [name1 caseInsensitiveCompare:name2];
if (result == NSOrderedSame) {
// the last fallback is to sort by pointer comparison.
if (group1 < group2) {
result = NSOrderedAscending;
} else if (group1 > group2) {
result = NSOrderedDescending;
}
}
}
return result;
}];

self.assetGroups = tempArray;
// Reload albums
[self performSelectorOnMainThread:@selector(reloadTableView) withObject:nil waitUntilDone:YES];
}
};

// Group Enumerator Failure Block
void (^assetGroupEnumberatorFailure)(NSError *) = ^(NSError *error) {

if ([ALAssetsLibrary authorizationStatus] == ALAuthorizationStatusDenied) {
NSString *appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"];
NSString *errorMessage = [NSString stringWithFormat:NSLocalizedString(@"This app does not have access to your photos or videos. You can enable access in Privacy Settings.", nil), appName];
UIAlertController *alert = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Access Denied", nil)
message:errorMessage
preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"Ok", nil)
style:UIAlertActionStyleCancel
handler:nil]];
[self presentViewController:alert animated:YES completion:nil];
} else {
NSString *errorMessage = [NSString stringWithFormat:@"Album Error: %@ - %@", [error localizedDescription], [error localizedRecoverySuggestion]];
UIAlertController *alert = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Error", nil)
message:errorMessage
preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"Ok", nil)
style:UIAlertActionStyleCancel
handler:nil]];
[self presentViewController:alert animated:YES completion:nil];
}

[self.navigationItem setTitle:nil];
NSLog(@"A problem occured %@", [error description]);
};

// Enumerate Albums
[self.library enumerateGroupsWithTypes:ALAssetsGroupAll
usingBlock:assetGroupEnumerator
failureBlock:assetGroupEnumberatorFailure];

}
});

}

- (void)viewWillAppear:(BOOL)animated {

- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadTableView) name:ALAssetsLibraryChangedNotification object:nil];
[self.tableView reloadData];
}

- (void)viewWillDisappear:(BOOL)animated {

- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self name:ALAssetsLibraryChangedNotification object:nil];
}

Expand Down
35 changes: 20 additions & 15 deletions Classes/ELCImagePicker/ELCAssetCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#import "ELCConsole.h"
#import "ELCOverlayImageView.h"

#import "ELCStreetspotrOverlay.h" // custom drawn overlay

@interface ELCAssetCell ()

@property (nonatomic, strong) NSArray *rowAssets;
Expand Down Expand Up @@ -69,7 +71,7 @@ - (void)setAssets:(NSArray *)assets
overlayView.labIndex.text = [NSString stringWithFormat:@"%d", asset.index + 1];
} else {
if (overlayImage == nil) {
overlayImage = [UIImage imageNamed:@"Overlay.png"];
overlayImage = [UIImage streetspotrELCOverlayImage];
}
ELCOverlayImageView *overlayView = [[ELCOverlayImageView alloc] initWithImage:overlayImage];
[_overlayViewArray addObject:overlayView];
Expand All @@ -96,20 +98,23 @@ - (void)cellTapped:(UITapGestureRecognizer *)tapRecognizer

for (int i = 0; i < [_rowAssets count]; ++i) {
if (CGRectContainsPoint(frame, point)) {
ELCAsset *asset = [_rowAssets objectAtIndex:i];
asset.selected = !asset.selected;
ELCOverlayImageView *overlayView = [_overlayViewArray objectAtIndex:i];
overlayView.hidden = !asset.selected;
if (asset.selected) {
asset.index = [[ELCConsole mainConsole] numOfSelectedElements];
[overlayView setIndex:asset.index+1];
[[ELCConsole mainConsole] addIndex:asset.index];
}
else
{
int lastElement = [[ELCConsole mainConsole] numOfSelectedElements] - 1;
[[ELCConsole mainConsole] removeIndex:lastElement];
}
ELCAsset *asset = [_rowAssets objectAtIndex:i];
BOOL oldSelected = asset.selected;
asset.selected = !asset.selected;
if (!asset.selected != !oldSelected) { // need this test; elsewise we may accidently remove a still used index from ELCConsole
ELCOverlayImageView *overlayView = [_overlayViewArray objectAtIndex:i];
overlayView.hidden = !asset.selected;
if (asset.selected) {
asset.index = [[ELCConsole mainConsole] numOfSelectedElements];
[overlayView setIndex:asset.index+1];
[[ELCConsole mainConsole] addIndex:asset.index];
}
else
{
int lastElement = [[ELCConsole mainConsole] numOfSelectedElements] - 1;
[[ELCConsole mainConsole] removeIndex:lastElement];
}
}
break;
}
frame.origin.x = frame.origin.x + frame.size.width + 4;
Expand Down
2 changes: 2 additions & 0 deletions Classes/ELCImagePicker/ELCAssetSelectionDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

@protocol ELCAssetSelectionDelegate <NSObject>

@property (nonatomic, readonly) NSInteger maximumImagesCount;

- (void)selectedAssets:(NSArray *)assets;
- (BOOL)shouldSelectAsset:(ELCAsset *)asset previousCount:(NSUInteger)previousCount;
- (BOOL)shouldDeselectAsset:(ELCAsset *)asset previousCount:(NSUInteger)previousCount;
Expand Down
23 changes: 15 additions & 8 deletions Classes/ELCImagePicker/ELCAssetTablePicker.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,17 @@ - (id)init

- (void)viewDidLoad
{
[super viewDidLoad];

[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
[self.tableView setAllowsSelection:NO];

NSMutableArray *tempArray = [[NSMutableArray alloc] init];
self.elcAssets = tempArray;


self.singleSelection = (self.parent.maximumImagesCount == 1);
self.immediateReturn = (self.parent.maximumImagesCount == 1);

if (self.immediateReturn) {

} else {
Expand Down Expand Up @@ -67,16 +72,18 @@ - (void)viewWillDisappear:(BOOL)animated
[[NSNotificationCenter defaultCenter] removeObserver:self name:ALAssetsLibraryChangedNotification object:nil];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return YES;
- (BOOL)shouldAutorotate {
return YES;
}

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
[super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
self.columns = self.view.bounds.size.width / 80;
[self.tableView reloadData];
[coordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
#pragma unused(context)
self.columns = self.view.bounds.size.width / 80;
[self.tableView reloadData];
}];
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
}

- (void)preparePhotos
Expand Down
2 changes: 1 addition & 1 deletion Classes/ELCImagePicker/ELCConsole.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ - (int)currIndex

- (int)numOfSelectedElements {

return [myIndex count];
return (int)[myIndex count];
}

@end
4 changes: 3 additions & 1 deletion Classes/ELCImagePicker/ELCImagePickerController.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#import <UIKit/UIKit.h>
#import "ELCAssetSelectionDelegate.h"

extern NSString *const ELCIImagePickerControllerAsset; // added by Streetspotr; key for returned ALAsset

@class ELCImagePickerController;
@class ELCAlbumPickerController;

Expand All @@ -18,7 +20,7 @@
* Called with the picker the images were selected from, as well as an array of dictionary's
* containing keys for ALAssetPropertyLocation, ALAssetPropertyType,
* UIImagePickerControllerOriginalImage, and UIImagePickerControllerReferenceURL.
* @param picker
* @param picker The ELCImagePickerController instance
* @param info An NSArray containing dictionary's with the key UIImagePickerControllerOriginalImage, which is a rotated, and sized for the screen 'default representation' of the image selected. If you want to get the original image, use the UIImagePickerControllerReferenceURL key.
*/
- (void)elcImagePickerController:(ELCImagePickerController *)picker didFinishPickingMediaWithInfo:(NSArray *)info;
Expand Down
34 changes: 18 additions & 16 deletions Classes/ELCImagePicker/ELCImagePickerController.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#import <MobileCoreServices/UTCoreTypes.h>
#import "ELCConsole.h"

NSString *const ELCIImagePickerControllerAsset = @"ELCIImagePickerControllerAsset"; // added by Streetspotr; key for returned ALAsset

@implementation ELCImagePickerController

//Using auto synthesizers
Expand Down Expand Up @@ -71,13 +73,15 @@ - (BOOL)shouldSelectAsset:(ELCAsset *)asset previousCount:(NSUInteger)previousCo
{
BOOL shouldSelect = previousCount < self.maximumImagesCount;
if (!shouldSelect) {
NSString *title = [NSString stringWithFormat:NSLocalizedString(@"Only %d photos please!", nil), self.maximumImagesCount];
NSString *message = [NSString stringWithFormat:NSLocalizedString(@"You can only send %d photos at a time.", nil), self.maximumImagesCount];
[[[UIAlertView alloc] initWithTitle:title
message:message
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:NSLocalizedString(@"Okay", nil), nil] show];
NSString *title = [NSString stringWithFormat:NSLocalizedString(@"Only %d photos please!", nil), (int)self.maximumImagesCount];
NSString *message = [NSString stringWithFormat:NSLocalizedString(@"You can only send %d photos at a time.", nil), (int)self.maximumImagesCount];
UIAlertController *alert = [UIAlertController alertControllerWithTitle:title
message:message
preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"Okay", nil)
style:UIAlertActionStyleDefault
handler:nil]];
[self presentViewController:alert animated:YES completion:nil];
}
return shouldSelect;
}
Expand Down Expand Up @@ -118,18 +122,20 @@ - (void)selectedAssets:(NSArray *)assets

if (_returnsOriginalImage) {
imgRef = [assetRep fullResolutionImage];
orientation = [assetRep orientation];
orientation = (UIImageOrientation)[assetRep orientation];
} else {
imgRef = [assetRep fullScreenImage];
}
UIImage *img = [UIImage imageWithCGImage:imgRef
scale:1.0f
orientation:orientation];
[workingDictionary setObject:img forKey:UIImagePickerControllerOriginalImage];
}
} else {
[workingDictionary setObject:asset forKey:ELCIImagePickerControllerAsset]; // added by Streetspotr, because getting Asset from URL of photo stream images is not possible for some reason
}

[workingDictionary setObject:[[asset valueForProperty:ALAssetPropertyURLs] valueForKey:[[[asset valueForProperty:ALAssetPropertyURLs] allKeys] objectAtIndex:0]] forKey:UIImagePickerControllerReferenceURL];

[returnArray addObject:workingDictionary];
}

Expand All @@ -141,13 +147,9 @@ - (void)selectedAssets:(NSArray *)assets
}
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
- (BOOL)shouldAutorotate
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
return YES;
} else {
return toInterfaceOrientation != UIInterfaceOrientationPortraitUpsideDown;
}
return YES;
}

- (BOOL)onOrder
Expand Down
Loading