Skip to content

Commit

Permalink
ARC
Browse files Browse the repository at this point in the history
  • Loading branch information
dongle committed Sep 14, 2012
1 parent 25620b3 commit 4936f9b
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 127 deletions.
14 changes: 1 addition & 13 deletions DIYAssetPicker/DIYAssetPickerController.h
Expand Up @@ -44,21 +44,9 @@ typedef enum {
NSString *const DIYAssetPickerThumbnail;

@interface DIYAssetPickerController : UIViewController <UITableViewDataSource, UITableViewDelegate>
{
@private ALAssetsLibrary *_assetsLibrary;
@private NSMutableArray *_assetsArray;
@private UITableView *_assetsTable;
@private UINavigationBar *_header;

@private NSMutableDictionary *_videoInfo;
@private AVAssetExportSession *_exporter;
@private NSTimer *_exportDisplayTimer;
@private UIView *_exportDisplay;
@private UIProgressView *_exportDisplayProgress;
}

#pragma mark - Delegate
@property (assign) NSObject<DIYAssetPickerControllerDelegate> *delegate;
@property (weak) NSObject<DIYAssetPickerControllerDelegate> *delegate;

#pragma mark - Options
@property (nonatomic, assign) DIYAssetPickerControllerAssetType assetType;
Expand Down
59 changes: 18 additions & 41 deletions DIYAssetPicker/DIYAssetPickerController.m
Expand Up @@ -9,16 +9,16 @@
#import "DIYAssetPickerController.h"

@interface DIYAssetPickerController ()
@property (nonatomic, retain) ALAssetsLibrary *assetsLibrary;
@property (nonatomic, retain) NSMutableArray *assetsArray;
@property (nonatomic, retain) UITableView *assetsTable;
@property (nonatomic, retain) UINavigationBar *header;

@property (nonatomic, retain) NSMutableDictionary *videoInfo;
@property (nonatomic, retain) AVAssetExportSession *exporter;
@property (nonatomic, assign) NSTimer *exportDisplayTimer;
@property (nonatomic, retain) UIView *exportDisplay;
@property (nonatomic, retain) UIProgressView *exportDisplayProgress;
@property ALAssetsLibrary *assetsLibrary;
@property NSMutableArray *assetsArray;
@property UITableView *assetsTable;
@property UINavigationBar *header;

@property NSMutableDictionary *videoInfo;
@property AVAssetExportSession *exporter;
@property (weak) NSTimer *exportDisplayTimer;
@property UIView *exportDisplay;
@property UIProgressView *exportDisplayProgress;
@end

NSString *const DIYAssetPickerThumbnail = @"DIYAssetPickerThumbnail";
Expand All @@ -36,13 +36,13 @@ - (void)_setup
[self setTitle:@"Library"];

// Asset library & array
self.assetsLibrary = [[[ALAssetsLibrary alloc] init] autorelease];
self.assetsLibrary = [[ALAssetsLibrary alloc] init];

_assetsArray = [[NSMutableArray alloc] init];
[self getAssetsArray];

// Header
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelPicking)] autorelease];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelPicking)];

_header = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)];
self.header.autoresizingMask = UIViewAutoresizingFlexibleWidth;
Expand Down Expand Up @@ -127,7 +127,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

for (UIView *view in cell.contentView.subviews){
Expand Down Expand Up @@ -161,7 +161,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
- (UIView *)tableView:(UITableView *)tableView viewForIndexPath:(NSIndexPath *)indexPath
{
// This is the view that will be returned as the contentView for each cell
UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, self.assetsTable.frame.size.width, [self tableView:self.assetsTable heightForRowAtIndexPath:indexPath])] autorelease];
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.assetsTable.frame.size.width, [self tableView:self.assetsTable heightForRowAtIndexPath:indexPath])];

// Layout variables
int initialThumbOffset = ((int)self.assetsTable.frame.size.width+THUMB_SPACING-(THUMB_COUNT_PER_ROW*(THUMB_SIZE+THUMB_SPACING)))/2;
Expand Down Expand Up @@ -191,22 +191,20 @@ - (UIView *)tableView:(UITableView *)tableView viewForIndexPath:(NSIndexPath *)i
[image setUserInteractionEnabled:YES];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(getAssetFromGesture:)];
[image addGestureRecognizer:tap];
[tap release];

// finally add the thumbnail to the view
[view addSubview:image];
[image release];

// Add video info view to video assets
if ([[asset valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypeVideo]) {
// This is the transparent black bar at the bottom of the thumbnail
UIView *videoBar = [[[UIView alloc] initWithFrame:CGRectMake(0, THUMB_SIZE - 18, THUMB_SIZE, 18)] autorelease];
UIView *videoBar = [[UIView alloc] initWithFrame:CGRectMake(0, THUMB_SIZE - 18, THUMB_SIZE, 18)];
videoBar.backgroundColor = [UIColor blackColor];
videoBar.alpha = 0.75f;
[image addSubview:videoBar];

// This is the tiny video icon in the lower left of the thumbnail
UIImageView *videoIcon = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ui_icon_tinyvideo@2x.png"]] autorelease];
UIImageView *videoIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ui_icon_tinyvideo@2x.png"]];
videoIcon.frame = CGRectMake(6, THUMB_SIZE - 13, videoIcon.frame.size.width/2.0f, videoIcon.frame.size.height/2.0f);
[image addSubview:videoIcon];

Expand All @@ -221,7 +219,7 @@ - (UIView *)tableView:(UITableView *)tableView viewForIndexPath:(NSIndexPath *)i
// seconds to appear.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
dispatch_sync(dispatch_get_main_queue(), ^{
UILabel *lengthLabel = [[[UILabel alloc] initWithFrame:CGRectMake(THUMB_SIZE/2.0f, THUMB_SIZE - 14, (THUMB_SIZE/2.0f) - 6, 12)] autorelease];
UILabel *lengthLabel = [[UILabel alloc] initWithFrame:CGRectMake(THUMB_SIZE/2.0f, THUMB_SIZE - 14, (THUMB_SIZE/2.0f) - 6, 12)];
lengthLabel.text = [NSString stringWithFormat:@"%i:%02i", minutes, seconds];
lengthLabel.textAlignment = UITextAlignmentRight;
lengthLabel.font = [UIFont fontWithName:@"HelveticaNeue-Bold" size:11.0f];
Expand Down Expand Up @@ -286,7 +284,6 @@ - (void)getAssetsArray
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
else {
UIAlertView *alert = [[UIAlertView alloc]
Expand All @@ -296,7 +293,6 @@ - (void)getAssetsArray
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}

[self.delegate pickerDidCancel:self];
Expand Down Expand Up @@ -386,7 +382,6 @@ - (void)toggleExportDisplay
blockingView.backgroundColor = [UIColor blackColor];
blockingView.alpha = 0.0f;
[self.view addSubview:blockingView];
[blockingView release];

// Container view for the progressview and the label
_exportDisplay = [[UIView alloc] initWithFrame:exportViewFrame];
Expand All @@ -402,7 +397,6 @@ - (void)toggleExportDisplay
progressLabel.textAlignment = UITextAlignmentCenter;
progressLabel.text = @"Exporting video …";
[self.exportDisplay addSubview:progressLabel];
[progressLabel release];

// Progress view
_exportDisplayProgress = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
Expand All @@ -423,26 +417,9 @@ - (void)toggleExportDisplay

#pragma mark - Dealloc

- (void)releaseObjects
{
_delegate = nil;

[_assetsArray release]; _assetsArray = nil;
[_assetsLibrary release]; _assetsLibrary = nil;
[_assetsTable release]; _assetsTable = nil;
[_header release]; _header = nil;

[_videoInfo release]; _videoInfo = nil;
[_exporter release]; _exporter = nil;
[_exportDisplay release]; _exportDisplay = nil;
[_exportDisplayProgress release]; _exportDisplayProgress = nil;
[_exportDisplayTimer invalidate]; _exportDisplayTimer = nil;
}

- (void)dealloc
{
[self releaseObjects];
[super dealloc];
[_exportDisplayTimer invalidate]; _exportDisplayTimer = nil;
}

@end
2 changes: 2 additions & 0 deletions Example/DIYAssetPicker.xcodeproj/project.pbxproj
Expand Up @@ -260,6 +260,7 @@
DE25878815CA0152002657BD /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_OBJC_ARC = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "DIYAssetPicker/DIYAssetPicker-Prefix.pch";
INFOPLIST_FILE = "DIYAssetPicker/DIYAssetPicker-Info.plist";
Expand All @@ -271,6 +272,7 @@
DE25878915CA0152002657BD /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_OBJC_ARC = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "DIYAssetPicker/DIYAssetPicker-Prefix.pch";
INFOPLIST_FILE = "DIYAssetPicker/DIYAssetPicker-Info.plist";
Expand Down
1 change: 0 additions & 1 deletion Example/DIYAssetPicker/DIYAppDelegate.h
Expand Up @@ -14,6 +14,5 @@

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) DIYViewController *viewController;
//@property (strong, nonatomic) DIYAssetPickerController *assetPicker;

@end
51 changes: 4 additions & 47 deletions Example/DIYAssetPicker/DIYAppDelegate.m
Expand Up @@ -10,59 +10,16 @@

@implementation DIYAppDelegate

@synthesize viewController = _viewController;
//@synthesize assetPicker = _assetPicker;

- (void)dealloc
{
[_viewController release];
// [_assetPicker release];
[_window release];
[super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

self.window.backgroundColor = [UIColor whiteColor];

// _assetPicker = [[DIYAssetPickerController alloc] init];
// self.window.rootViewController = self.assetPicker;


_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
_viewController = [[DIYViewController alloc] init];

self.window.rootViewController = self.viewController;

self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];

return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
25 changes: 0 additions & 25 deletions Example/DIYAssetPicker/DIYViewController.m
Expand Up @@ -12,17 +12,6 @@ @implementation DIYViewController

#pragma mark - View lifecycle

- (void)viewDidLoad
{
[super viewDidLoad];
}

- (void)viewDidUnload
{
[super viewDidUnload];
[self releaseObjects];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return true;
Expand All @@ -41,7 +30,6 @@ -(IBAction)assetPickerButtonSelected:(id)sender
DIYAssetPickerController *picker = [[DIYAssetPickerController alloc] init];
picker.delegate = self;
[self presentModalViewController:picker animated:true];
[picker release];
}

#pragma mark - DIYAssetPickerController protocol
Expand Down Expand Up @@ -87,17 +75,4 @@ - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
[self dismissModalViewControllerAnimated:true];
}

#pragma mark - Dealloc

- (void)releaseObjects
{

}

- (void)dealloc
{
[self releaseObjects];
[super dealloc];
}

@end

0 comments on commit 4936f9b

Please sign in to comment.