Skip to content

Commit

Permalink
Merge branch 'ole-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Ole Zorn committed Jan 31, 2012
2 parents 8037b71 + 96b1c69 commit 0ca422c
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 35 deletions.
6 changes: 6 additions & 0 deletions Classes/DownloadViewController.h
Expand Up @@ -19,13 +19,19 @@
@interface DownloadCell : UITableViewCell {
NSDictionary *_downloadInfo;
DocSetDownload *_download;
UIView *_downloadInfoView;
UIProgressView *_progressView;
UIButton *_cancelDownloadButton;
}

@property (nonatomic, strong) NSDictionary *downloadInfo;
@property (nonatomic, strong) DocSetDownload *download;
@property (nonatomic, strong) UIView *downloadInfoView;
@property (nonatomic, strong) UIProgressView *progressView;
@property (nonatomic, strong) UIButton *cancelDownloadButton;

- (void)setupDownloadInfoView;
- (void)updateStatusLabel;
- (void)cancelDownload:(id)sender;

@end
81 changes: 46 additions & 35 deletions Classes/DownloadViewController.m
Expand Up @@ -97,35 +97,6 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
}
}

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary *downloadInfo = [[[DocSetDownloadManager sharedDownloadManager] availableDownloads] objectAtIndex:indexPath.row];
NSString *name = [downloadInfo objectForKey:@"name"];
BOOL downloaded = [[[DocSetDownloadManager sharedDownloadManager] downloadedDocSetNames] containsObject:name];
if (downloaded) {
return NO;
}
DocSetDownload *download = [[DocSetDownloadManager sharedDownloadManager] downloadForURL:[downloadInfo objectForKey:@"URL"]];
if (!download) {
return NO;
} else if (download.status == DocSetDownloadStatusDownloading || download.status == DocSetDownloadStatusWaiting || download.status == DocSetDownloadStatusExtracting) {
return YES;
}
return NO;
}

- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
return NSLocalizedString(@"Stop", nil);
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary *downloadInfo = [[[DocSetDownloadManager sharedDownloadManager] availableDownloads] objectAtIndex:indexPath.row];
DocSetDownload *download = [[DocSetDownloadManager sharedDownloadManager] downloadForURL:[downloadInfo objectForKey:@"URL"]];
[[DocSetDownloadManager sharedDownloadManager] stopDownload:download];
}

- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
Expand All @@ -137,21 +108,52 @@ - (void)dealloc

@implementation DownloadCell

@synthesize downloadInfo=_downloadInfo, download=_download, progressView=_progressView;
@synthesize downloadInfo=_downloadInfo, download=_download, downloadInfoView=_downloadInfoView, progressView=_progressView, cancelDownloadButton=_cancelDownloadButton;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadStarted:) name:DocSetDownloadManagerStartedDownloadNotification object:nil];
_progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
CGRect pFrame = _progressView.frame;
pFrame.size.width = ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) ? 120 : 70;
_progressView.frame = pFrame;
[self setupDownloadInfoView];

}
return self;
}

- (void)setupDownloadInfoView
{
CGFloat progressViewWidth = ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) ? 120 : 70;
CGFloat cancelButtonWidth = 30;
CGFloat cancelButtonHeight = 29;
CGFloat margin = 10;

_progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];

_cancelDownloadButton = [UIButton buttonWithType:UIButtonTypeCustom];
_cancelDownloadButton.frame = CGRectMake(progressViewWidth + margin, 0, cancelButtonWidth, cancelButtonHeight);
[_cancelDownloadButton setImage:[UIImage imageNamed:@"Cancel.png"] forState:UIControlStateNormal];
[_cancelDownloadButton setImage:[UIImage imageNamed:@"Cancel-Pressed.png"] forState:UIControlStateHighlighted];
[_cancelDownloadButton setImage:[UIImage imageNamed:@"Cancel-Pressed.png"] forState:UIControlStateSelected];
[_cancelDownloadButton addTarget:self action:@selector(cancelDownload:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)layoutSubviews
{
[super layoutSubviews];
if (!self.download) {
return;
}
DocSetDownloadStatus status = self.download.status;
if (status == DocSetDownloadStatusWaiting || status == DocSetDownloadStatusDownloading || status == DocSetDownloadStatusExtracting) {
self.progressView.frame = CGRectMake(60, CGRectGetMidY(self.contentView.bounds) - self.progressView.bounds.size.height * 0.5, CGRectGetWidth(self.contentView.bounds) - 70, self.progressView.frame.size.height);
CGRect textLabelFrame = self.textLabel.frame;
self.textLabel.frame = CGRectMake(textLabelFrame.origin.x, 3, textLabelFrame.size.width, textLabelFrame.size.height);
CGRect detailLabelFrame = self.detailTextLabel.frame;
self.detailTextLabel.frame = CGRectMake(detailLabelFrame.origin.x, self.contentView.bounds.size.height - CGRectGetHeight(detailLabelFrame) - 3, detailLabelFrame.size.width, detailLabelFrame.size.height);
}
}

- (void)downloadStarted:(NSNotification *)notification
{
if (!self.download) {
Expand Down Expand Up @@ -197,10 +199,14 @@ - (void)setDownload:(DocSetDownload *)download
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadFinished:) name:DocSetDownloadFinishedNotification object:_download];

if (_download) {
self.textLabel.font = [UIFont boldSystemFontOfSize:15.0];
self.progressView.progress = self.download.progress;
self.accessoryView = self.progressView;
self.accessoryView = self.cancelDownloadButton;
[self.contentView addSubview:self.progressView];
} else {
self.textLabel.font = [UIFont boldSystemFontOfSize:18.0];
self.accessoryView = nil;
[self.progressView removeFromSuperview];
}
[self updateStatusLabel];
}
Expand Down Expand Up @@ -247,6 +253,11 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
}
}

- (void)cancelDownload:(id)sender
{
[[DocSetDownloadManager sharedDownloadManager] stopDownload:self.download];
}

- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
Expand Down
24 changes: 24 additions & 0 deletions DocSets.xcodeproj/project.pbxproj
Expand Up @@ -13,6 +13,10 @@
2804200B108E984D000629CD /* RootViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 28042008108E984D000629CD /* RootViewController.m */; };
2804200C108E984D000629CD /* DetailViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2804200A108E984D000629CD /* DetailViewController.m */; };
2892E4100DC94CBA00A64D0F /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2892E40F0DC94CBA00A64D0F /* CoreGraphics.framework */; };
5D892D8A14D73C5A005B3273 /* Cancel-Pressed.png in Resources */ = {isa = PBXBuildFile; fileRef = 5D892D8614D73C5A005B3273 /* Cancel-Pressed.png */; };
5D892D8B14D73C5A005B3273 /* Cancel-Pressed@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 5D892D8714D73C5A005B3273 /* Cancel-Pressed@2x.png */; };
5D892D8C14D73C5A005B3273 /* Cancel.png in Resources */ = {isa = PBXBuildFile; fileRef = 5D892D8814D73C5A005B3273 /* Cancel.png */; };
5D892D8D14D73C5A005B3273 /* Cancel@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 5D892D8914D73C5A005B3273 /* Cancel@2x.png */; };
7F1D426314D0708F00A85CB3 /* Icon72.png in Resources */ = {isa = PBXBuildFile; fileRef = 7F1D426214D0708F00A85CB3 /* Icon72.png */; };
7F1D426514D071D500A85CB3 /* Icon114.png in Resources */ = {isa = PBXBuildFile; fileRef = 7F1D426414D071D500A85CB3 /* Icon114.png */; };
7F1D426714D0721700A85CB3 /* Icon57.png in Resources */ = {isa = PBXBuildFile; fileRef = 7F1D426614D0721700A85CB3 /* Icon57.png */; };
Expand Down Expand Up @@ -114,6 +118,10 @@
28042009108E984D000629CD /* DetailViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DetailViewController.h; sourceTree = "<group>"; };
2804200A108E984D000629CD /* DetailViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DetailViewController.m; sourceTree = "<group>"; };
2892E40F0DC94CBA00A64D0F /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
5D892D8614D73C5A005B3273 /* Cancel-Pressed.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Cancel-Pressed.png"; sourceTree = "<group>"; };
5D892D8714D73C5A005B3273 /* Cancel-Pressed@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Cancel-Pressed@2x.png"; sourceTree = "<group>"; };
5D892D8814D73C5A005B3273 /* Cancel.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Cancel.png; sourceTree = "<group>"; };
5D892D8914D73C5A005B3273 /* Cancel@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Cancel@2x.png"; sourceTree = "<group>"; };
7F1D426214D0708F00A85CB3 /* Icon72.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Icon72.png; sourceTree = "<group>"; };
7F1D426414D071D500A85CB3 /* Icon114.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Icon114.png; sourceTree = "<group>"; };
7F1D426614D0721700A85CB3 /* Icon57.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Icon57.png; sourceTree = "<group>"; };
Expand Down Expand Up @@ -325,6 +333,17 @@
name = Frameworks;
sourceTree = "<group>";
};
5D892D8E14D73C72005B3273 /* Buttons */ = {
isa = PBXGroup;
children = (
5D892D8814D73C5A005B3273 /* Cancel.png */,
5D892D8914D73C5A005B3273 /* Cancel@2x.png */,
5D892D8614D73C5A005B3273 /* Cancel-Pressed.png */,
5D892D8714D73C5A005B3273 /* Cancel-Pressed@2x.png */,
);
name = Buttons;
sourceTree = "<group>";
};
7F1D431114D163EC00A85CB3 /* Backgrounds */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -448,6 +467,7 @@
7F1D434914D18ADA00A85CB3 /* Launch Images */,
7F1D431114D163EC00A85CB3 /* Backgrounds */,
7FCAE4C312B70FCE00F529FF /* Toolbar Icons */,
5D892D8E14D73C72005B3273 /* Buttons */,
7FCAE4C412B70FFE00F529FF /* Document Icons */,
7FF70B4912AD14B2001FF09F /* Token Icons */,
);
Expand Down Expand Up @@ -624,6 +644,10 @@
7F1D434814D18AD600A85CB3 /* Default-Landscape~ipad.png in Resources */,
7F1D435014D1C28B00A85CB3 /* OutlineDisclosureButton.png in Resources */,
7F1D435414D1CF0900A85CB3 /* OutlineDisclosureButton@2x.png in Resources */,
5D892D8A14D73C5A005B3273 /* Cancel-Pressed.png in Resources */,
5D892D8B14D73C5A005B3273 /* Cancel-Pressed@2x.png in Resources */,
5D892D8C14D73C5A005B3273 /* Cancel.png in Resources */,
5D892D8D14D73C5A005B3273 /* Cancel@2x.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Binary file added Images/Cancel-Pressed.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/Cancel-Pressed@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/Cancel.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/Cancel@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0ca422c

Please sign in to comment.