Skip to content
This repository has been archived by the owner on Dec 10, 2022. It is now read-only.

Commit

Permalink
to remove "My Photo Stream" from the image picker, which are difficul…
Browse files Browse the repository at this point in the history
…t to be loaded from the network
  • Loading branch information
Simon Xie committed Aug 16, 2015
1 parent 9883fdd commit d0ba378
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 3 deletions.
11 changes: 11 additions & 0 deletions src/wpp/qt/ELCAlbumPickerController+RemoveMyPhotoStream.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef __ELCAlbumPickerController__REMOVE_MY_PHOTO_STREAM__H__
#define __ELCAlbumPickerController__REMOVE_MY_PHOTO_STREAM__H__

#import <UIKit/UIKit.h>
#import "ELCImagePicker/ELCAlbumPickerController.h"

@interface ELCAlbumPickerController (RemoveMyPhotoStream)
@end


#endif
83 changes: 83 additions & 0 deletions src/wpp/qt/ELCAlbumPickerController+RemoveMyPhotoStream.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#import "ELCAlbumPickerController+RemoveMyPhotoStream.h"
//#include <wpp/qt/Wpp.h>

@interface ELCAlbumPickerController (RemoveMyPhotoStream)

@property (nonatomic, strong) ALAssetsLibrary *library;

@end

@implementation ELCAlbumPickerController (RemoveMyPhotoStream)

- (void)viewDidLoad
{
[super viewDidLoad];
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];

[self.navigationItem setTitle:NSLocalizedString(@"Loading...", nil)];

UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self.parent action:@selector(cancelImagePicker)];
[self.navigationItem setRightBarButtonItem:cancelButton];

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

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
NSUInteger groupTypes = ALAssetsGroupAlbum | ALAssetsGroupEvent | ALAssetsGroupFaces | ALAssetsGroupSavedPhotos;

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

}
});

}

@end
6 changes: 5 additions & 1 deletion src/wpp/qt/ImagePicker.mm
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,12 @@ - (void)processImages:(NSArray *)info
{
//NSLog(@"asset=%@", asset);
ALAssetRepresentation *repr = [asset defaultRepresentation];

NSLog(@"asset defaultRepresentation=%@", [asset defaultRepresentation]);
CGImageRef cgImg = [repr fullResolutionImage];

NSLog(@"fname=%@", [repr filename]);
NSString *fname = [repr filename];
NSLog(@"fname=%@", fname);
//NSString* fileName = asset.defaultRepresentation.filename;
NSURL* fileUrl = [[[[NSFileManager defaultManager]
URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask]lastObject]URLByAppendingPathComponent:fname];
Expand Down Expand Up @@ -534,6 +537,7 @@ - (void)elcImagePickerControllerDidCancel:(ELCImagePickerController *)picker
UIViewController *qtController = [[view window] rootViewController];
qDebug() << __FUNCTION__ << ":...2";


// Create a new image picker controller to show on top of Qt's view controller:
ELCImagePickerController *imageController = [(__bridge id)m_delegate createImagePickerController];
/*ELCImagePickerController *imageController = [[ELCImagePickerController alloc] initImagePicker];
Expand Down
6 changes: 4 additions & 2 deletions wpp.pri
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,15 @@ OBJECTIVE_SOURCES += \
$$PWD/src/wpp/qt/IOS.mm \
$$PWD/src/wpp/qt/NativeDateTimePicker.mm \
$$PWD/src/wpp/qt/IOSTimeZonePicker.mm \
$$PWD/src/wpp/qt/QIOSViewController+Rotate.mm
$$PWD/src/wpp/qt/QIOSViewController+Rotate.mm \
$$PWD/src/wpp/qt/ELCAlbumPickerController+RemoveMyPhotoStream.mm

OBJECTIVE_HEADERS += \
$$PWD/src/wpp/qt/AddressBookObjC.h
HEADERS += \
$$PWD/src/wpp/qt/IOS.h \
$$PWD/src/wpp/qt/QIOSViewController+Rotate.h
$$PWD/src/wpp/qt/QIOSViewController+Rotate.h \
$$PWD/src/wpp/qt/ELCAlbumPickerController+RemoveMyPhotoStream.h


LIBS += -framework AddressBook -framework MapKit -framework MessageUI -framework AudioToolbox \
Expand Down

0 comments on commit d0ba378

Please sign in to comment.