forked from brightsoftdev/photo-picker-plus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master'
- Loading branch information
Showing
124 changed files
with
22,748 additions
and
6 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
iOS/PhotoPickerPlus/Chute SDK/Categories/GC_UIImage+Extras.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// | ||
// GC_UIImage+Extras.h | ||
// | ||
// Created by Achal Aggarwal on 11/09/11. | ||
// Copyright 2011 Chute Corporation. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface UIImage (Extras) | ||
- (UIImage *)imageByScalingProportionallyToSize:(CGSize)targetSize; | ||
@end; |
74 changes: 74 additions & 0 deletions
74
iOS/PhotoPickerPlus/Chute SDK/Categories/GC_UIImage+Extras.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// | ||
// GC_UIImage+Extras.m | ||
// KitchenSink | ||
// | ||
// Created by Achal Aggarwal on 11/09/11. | ||
// Copyright 2011 Chute Corporation. All rights reserved. | ||
// | ||
|
||
#import "GC_UIImage+Extras.h" | ||
|
||
@implementation UIImage (Extras) | ||
|
||
- (UIImage *)imageByScalingProportionallyToSize:(CGSize)targetSize { | ||
|
||
UIImage *sourceImage = self; | ||
UIImage *newImage = nil; | ||
|
||
CGSize imageSize = sourceImage.size; | ||
CGFloat width = imageSize.width; | ||
CGFloat height = imageSize.height; | ||
|
||
CGFloat targetWidth = targetSize.width; | ||
CGFloat targetHeight = targetSize.height; | ||
|
||
CGFloat scaleFactor = 0.0; | ||
CGFloat scaledWidth = targetWidth; | ||
CGFloat scaledHeight = targetHeight; | ||
|
||
CGPoint thumbnailPoint = CGPointMake(0.0,0.0); | ||
|
||
if (CGSizeEqualToSize(imageSize, targetSize) == NO) { | ||
|
||
CGFloat widthFactor = targetWidth / width; | ||
CGFloat heightFactor = targetHeight / height; | ||
|
||
if (widthFactor < heightFactor) | ||
scaleFactor = widthFactor; | ||
else | ||
scaleFactor = heightFactor; | ||
|
||
scaledWidth = width * scaleFactor; | ||
scaledHeight = height * scaleFactor; | ||
|
||
// center the image | ||
|
||
if (widthFactor < heightFactor) { | ||
thumbnailPoint.y = (targetHeight - scaledHeight) * 0.5; | ||
} else if (widthFactor > heightFactor) { | ||
thumbnailPoint.x = (targetWidth - scaledWidth) * 0.5; | ||
} | ||
} | ||
|
||
|
||
// this is actually the interesting part: | ||
|
||
UIGraphicsBeginImageContext(targetSize); | ||
|
||
CGRect thumbnailRect = CGRectZero; | ||
thumbnailRect.origin = thumbnailPoint; | ||
thumbnailRect.size.width = scaledWidth; | ||
thumbnailRect.size.height = scaledHeight; | ||
|
||
[sourceImage drawInRect:thumbnailRect]; | ||
|
||
newImage = UIGraphicsGetImageFromCurrentImageContext(); | ||
UIGraphicsEndImageContext(); | ||
|
||
if(newImage == nil) NSLog(@"could not scale image"); | ||
|
||
|
||
return newImage ; | ||
} | ||
|
||
@end; |
22 changes: 22 additions & 0 deletions
22
iOS/PhotoPickerPlus/Chute SDK/Classes/Core/GCAssetUploader.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// GCAssetUploader.h | ||
// | ||
// Created by Achal Aggarwal on 08/09/11. | ||
// Copyright 2011 Chute Corporation. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import "GetChute.h" | ||
|
||
@interface GCAssetUploader : NSObject | ||
|
||
@property (nonatomic, retain) NSMutableSet *queue; | ||
|
||
+ (GCAssetUploader *)sharedUploader; | ||
|
||
- (void) addAsset:(GCAsset *) anAsset; | ||
- (void) removeAsset:(GCAsset *) anAsset; | ||
|
||
- (GCResponse *) createParcelWithAssets:(NSArray *) assets andChutes:(NSArray *) chutes; | ||
|
||
@end |
132 changes: 132 additions & 0 deletions
132
iOS/PhotoPickerPlus/Chute SDK/Classes/Core/GCAssetUploader.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
// | ||
// GCAssetUploader.m | ||
// | ||
// Created by Achal Aggarwal on 08/09/11. | ||
// Copyright 2011 Chute Corporation. All rights reserved. | ||
// | ||
|
||
#import "GCAssetUploader.h" | ||
|
||
static GCAssetUploader *sharedAssetUploader = nil; | ||
|
||
@implementation GCAssetUploader | ||
|
||
@synthesize queue; | ||
|
||
#pragma mark - Step 1 - Make Parcel with Assets and Chutes | ||
- (GCResponse *) createParcelWithAssets:(NSArray *) assets andChutes:(NSArray *) chutes { | ||
NSMutableArray *_assetsUniqueDescription = [[NSMutableArray alloc] init]; | ||
for (GCAsset *_asset in assets) { | ||
[_assetsUniqueDescription addObject:[_asset uniqueRepresentation]]; | ||
} | ||
|
||
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys: | ||
[_assetsUniqueDescription JSONRepresentation], @"files", | ||
[chutes JSONRepresentation], @"chutes", | ||
nil]; | ||
|
||
[_assetsUniqueDescription release]; | ||
|
||
NSString *_path = [[NSString alloc] initWithFormat:@"%@%@", API_URL, @"parcels"]; | ||
|
||
GCRequest *gcRequest = [[GCRequest alloc] init]; | ||
GCResponse *response = [[gcRequest postRequestWithPath:_path andParams:(NSMutableDictionary *)params] retain]; | ||
|
||
[gcRequest release]; | ||
[_path release]; | ||
return [response autorelease]; | ||
} | ||
|
||
#pragma mark - Step 2 - Remove already uploaded assets from the queue | ||
|
||
#pragma mark - Step 3 - Generate token for Assets in the queue | ||
|
||
#pragma mark - Step 4 - Upload assets to Amazon S3 using the token from previous request | ||
|
||
#pragma mark - Step 5 - Send completion request for a particular asset | ||
|
||
|
||
#pragma mark - | ||
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { | ||
if ([keyPath isEqualToString:@"queue"]) { | ||
//Check for GCAssets with status new and start uploading them... or reset a timer... if a new asset is added to the queue. | ||
|
||
} else { | ||
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; | ||
} | ||
} | ||
|
||
#pragma mark - Instance Methods | ||
|
||
//TODO: Reset timer to 0 everytime addAsset is called. This delay will allow us to add more assets together | ||
- (void) addAsset:(GCAsset *) anAsset { | ||
[[self queue] addObject:anAsset]; | ||
} | ||
|
||
- (void) removeAsset:(GCAsset *) anAsset { | ||
[[self queue] removeObject:anAsset]; | ||
} | ||
|
||
- (void) assetUpdated:(NSNotification *) notification { | ||
if ([[notification object] status] == GCAssetStateFinished) { | ||
[self removeAsset:[notification object]]; | ||
} | ||
} | ||
|
||
#pragma mark - Methods for Singleton class | ||
+ (GCAssetUploader *)sharedUploader | ||
{ | ||
if (sharedAssetUploader == nil) { | ||
static dispatch_once_t onceToken; | ||
dispatch_once(&onceToken, ^{ | ||
sharedAssetUploader = [[super allocWithZone:NULL] init]; | ||
}); | ||
} | ||
return sharedAssetUploader; | ||
} | ||
|
||
+ (id)allocWithZone:(NSZone *)zone | ||
{ | ||
return [[self sharedUploader] retain]; | ||
} | ||
|
||
- (id) init { | ||
self = [super init]; | ||
if (self) { | ||
queue = [[NSMutableSet alloc] init]; | ||
[self addObserver:self forKeyPath:@"queue" options:0 context:nil]; | ||
} | ||
return self; | ||
} | ||
|
||
- (id)copyWithZone:(NSZone *)zone | ||
{ | ||
return self; | ||
} | ||
|
||
- (id)retain | ||
{ | ||
return self; | ||
} | ||
|
||
- (NSUInteger)retainCount | ||
{ | ||
return NSUIntegerMax; | ||
} | ||
|
||
- (oneway void)release; | ||
{ | ||
//nothing | ||
} | ||
|
||
- (id)autorelease | ||
{ | ||
return self; | ||
} | ||
|
||
- (void) dealloc { | ||
[queue release]; | ||
[super dealloc]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// | ||
// GCError.h | ||
// | ||
// Created by Achal Aggarwal on 02/09/11. | ||
// Copyright 2011 Chute Corporation. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface GCError : NSError | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// | ||
// GCError.m | ||
// | ||
// Created by Achal Aggarwal on 02/09/11. | ||
// Copyright 2011 Chute Corporation. All rights reserved. | ||
// | ||
|
||
#import "GCError.h" | ||
|
||
@implementation GCError | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// | ||
// GCMacros.h | ||
// | ||
// Created by Achal Aggarwal on 26/08/11. | ||
// Copyright 2011 Chute Corporation. All rights reserved. | ||
// | ||
#ifndef ChuteMacros_h | ||
#define ChuteMacros_h | ||
|
||
//Comment this line to stop debug log on the debugger console. | ||
//#define DEBUG | ||
|
||
@class GCResponse; | ||
|
||
typedef void(^GCBasicBlock)(void); | ||
typedef void(^GCBoolBlock)(BOOL value); | ||
typedef void(^GCBoolErrorBlock)(BOOL value, NSError *error); | ||
typedef void(^GCErrorBlock)(NSError *error); | ||
typedef void(^GCResponseBlock)(GCResponse *response); | ||
|
||
#define kJSONResponse 1 | ||
|
||
#define DO_IN_BACKGROUND(action, responseBlock) \ | ||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^(void) {\ | ||
id _response = action;\ | ||
dispatch_async(dispatch_get_main_queue(), ^(void) {\ | ||
if (responseBlock) {\ | ||
responseBlock(_response);\ | ||
}\ | ||
});\ | ||
}); | ||
|
||
#define DO_IN_BACKGROUND_BOOL(action, responseBlock) \ | ||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^(void) {\ | ||
BOOL _response = action;\ | ||
dispatch_async(dispatch_get_main_queue(), ^(void) {\ | ||
if (responseBlock) {\ | ||
responseBlock(_response);\ | ||
}\ | ||
});\ | ||
}); | ||
|
||
#define DO_IN_BACKGROUND_BOOL_ERROR(action, responseBlock) \ | ||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^(void) {\ | ||
id _response = action;\ | ||
dispatch_async(dispatch_get_main_queue(), ^(void) {\ | ||
if (responseBlock) {\ | ||
responseBlock([_response isSuccessful], [_response error]);\ | ||
}\ | ||
});\ | ||
}); | ||
|
||
//////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
#ifdef DEBUG | ||
#define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__); | ||
#else | ||
#define DLog(...) | ||
#endif | ||
|
||
#define ALog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__); | ||
|
||
#define IS_NULL(x) ((nil == x) || ([x isEqual: [NSNull null]])) | ||
|
||
//////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
#endif | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// | ||
// GCRequest.h | ||
// | ||
// Created by Achal Aggarwal on 26/08/11. | ||
// Copyright 2011 Chute Corporation. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import "GCMacros.h" | ||
#import "GCConstants.h" | ||
#import "ASIHTTPRequest.h" | ||
#import "SBJson.h" | ||
#import "GCResponse.h" | ||
#import "GCError.h" | ||
|
||
@interface GCRequest : NSObject | ||
|
||
- (NSMutableDictionary *)headers; | ||
|
||
- (GCResponse *)getRequestWithPath:(NSString *)path; | ||
|
||
- (GCResponse *)postRequestWithPath:(NSString *)path | ||
andParams:(NSMutableDictionary *)params; | ||
|
||
- (GCResponse *)postRequestWithPath:(NSString *)path | ||
andParams:(NSMutableDictionary *)params | ||
andMethod:(NSString *)method; | ||
|
||
- (GCResponse *)putRequestWithPath:(NSString *)path | ||
andParams:(NSMutableDictionary *)params; | ||
|
||
- (GCResponse *)deleteRequestWithPath:(NSString *)path | ||
andParams:(NSMutableDictionary *)params; | ||
|
||
//Background Calls | ||
- (void)getRequestInBackgroundWithPath:(NSString *)path | ||
withResponse:(GCResponseBlock)aResponseBlock; | ||
|
||
- (void)postRequestInBackgroundWithPath:(NSString *)path | ||
andParams:(NSMutableDictionary *)params | ||
withResponse:(GCResponseBlock)aResponseBlock; | ||
|
||
- (void)putRequestInBackgroundWithPath:(NSString *)path | ||
andParams:(NSMutableDictionary *)params | ||
withResponse:(GCResponseBlock)aResponseBlock; | ||
|
||
- (void)deleteRequestInBackgroundWithPath:(NSString *)path | ||
andParams:(NSMutableDictionary *)params | ||
withResponse:(GCResponseBlock)aResponseBlock; | ||
@end |
Oops, something went wrong.