Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Refactored code into a method
  • Loading branch information
galonsky committed Apr 9, 2011
1 parent 4e18298 commit 80076dc
Showing 1 changed file with 21 additions and 23 deletions.
44 changes: 21 additions & 23 deletions Classes/Controllers/BrowserController.m
Expand Up @@ -122,22 +122,6 @@ - (void)submitInstapaperRequest {
[request addItemWithURL:currentURL];
}

- (void)instapaperRequestDidAddItem:(InstapaperRequest *)request {
[hud hide:YES];
}

- (void)instapaperRequest:(InstapaperRequest *)request didFailToAddItemWithError:(NSError *)error {
[hud hide:NO];

hud = [[MBProgressHUD alloc] initWithView:[[self navigationController] view]];
[hud setDelegate:self];
[hud setCustomView:[[UIView alloc] initWithFrame:CGRectZero]];
[hud setMode:MBProgressHUDModeCustomView];
[hud setLabelText:@"Failed to Send to Instpaper"];
[[[self navigationController] view] addSubview:hud];
[hud showWhileExecuting:@selector(sleepFor:) onTarget:self withObject:[NSNumber numberWithInt:1] animated:YES];
}

- (void)readability {
[webview stringByEvaluatingJavaScriptFromString:kReadabilityJavascript];
}
Expand All @@ -156,10 +140,30 @@ - (void)loginControllerDidCancel:(LoginController *)controller {
[controller dismissModalViewControllerAnimated:YES];
}

- (void)showHUDMessage:(NSString *)message duration:(NSTimeInterval)duration {
hud = [[MBProgressHUD alloc] initWithView:[[self navigationController] view]];
[hud setDelegate:self];
[hud setCustomView:[[UIView alloc] initWithFrame:CGRectZero]];
[hud setMode:MBProgressHUDModeCustomView];
[hud setLabelText:message];
[[[self navigationController] view] addSubview:hud];
[hud showWhileExecuting:@selector(sleepFor:) onTarget:self withObject:[NSNumber numberWithDouble:duration] animated:YES];
}

- (void)sleepFor: (NSNumber *) seconds {
[NSThread sleepForTimeInterval:[seconds doubleValue]];
}

- (void)instapaperRequestDidAddItem:(InstapaperRequest *)request {
[hud hide:YES];
}

- (void)instapaperRequest:(InstapaperRequest *)request didFailToAddItemWithError:(NSError *)error {
[hud hide:NO];
[self showHUDMessage:@"Failed to Send to Instapaper" duration:.5];
}


- (void)actionSheet:(UIActionSheet *)action clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == [action cancelButtonIndex]) return;

Expand All @@ -170,13 +174,7 @@ - (void)actionSheet:(UIActionSheet *)action clickedButtonAtIndex:(NSInteger)butt
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
[pasteboard setURL:currentURL];
[pasteboard setString:[currentURL absoluteString]];
hud = [[MBProgressHUD alloc] initWithView:[[self navigationController] view]];
[hud setDelegate:self];
[hud setCustomView:[[UIView alloc] initWithFrame:CGRectZero]];
[hud setMode:MBProgressHUDModeCustomView];
[hud setLabelText:@"Copied to Clipboard"];
[[[self navigationController] view] addSubview:hud];
[hud showWhileExecuting:@selector(sleepFor:) onTarget:self withObject:[NSNumber numberWithDouble:.5] animated:YES];
[self showHUDMessage:@"Copied to Clipboard" duration:.5];
} else if (buttonIndex == first + 2) {
if ([InstapaperSession currentSession] != nil) {
[self submitInstapaperRequest];
Expand Down

0 comments on commit 80076dc

Please sign in to comment.