-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from DRosadoYew/master
Add 'Save to Pocket' feature.
- Loading branch information
Showing
28 changed files
with
3,724 additions
and
13 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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,13 @@ | ||
// | ||
// DRPocketActivity.h | ||
// HackerNews | ||
// | ||
// Created by Daniel Rosado on 09/11/13. | ||
// Copyright (c) 2013 Benjamin Gordon. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@interface DRPocketActivity : UIActivity | ||
|
||
@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,66 @@ | ||
// | ||
// DRPocketActivity.m | ||
// HackerNews | ||
// | ||
// Created by Daniel Rosado on 09/11/13. | ||
// Copyright (c) 2013 Benjamin Gordon. All rights reserved. | ||
// | ||
|
||
#import "PocketAPI.h" | ||
#import "DRPocketActivity.h" | ||
#import "SVProgressHUD.h" | ||
#import "LoadingHUDViewController.h" | ||
|
||
@implementation DRPocketActivity { | ||
NSURL *_URL; | ||
} | ||
|
||
- (NSString *)activityType { | ||
return NSStringFromClass([self class]); | ||
} | ||
|
||
- (NSString *)activityTitle { | ||
return NSLocalizedStringFromTable(@"Save to Pocket", @"DRPocketActivity", nil); | ||
} | ||
|
||
- (UIImage *)activityImage { | ||
return [UIImage imageNamed:@"PocketActivity.png"]; | ||
} | ||
|
||
- (BOOL)canPerformWithActivityItems:(NSArray *)activityItems { | ||
for (id activityItem in activityItems) { | ||
if ([activityItem isKindOfClass:[NSURL class]] && [[UIApplication sharedApplication] canOpenURL:activityItem]) { | ||
return YES; | ||
} | ||
} | ||
|
||
return NO; | ||
} | ||
|
||
- (void)prepareWithActivityItems:(NSArray *)activityItems { | ||
for (id activityItem in activityItems) { | ||
if ([activityItem isKindOfClass:[NSURL class]]) { | ||
_URL = ((NSURL*)activityItem).absoluteURL; | ||
} | ||
} | ||
} | ||
|
||
- (UIViewController *)activityViewController | ||
{ | ||
[self performSelector:@selector(saveToPocket) withObject:nil afterDelay:0]; | ||
return [[LoadingHUDViewController alloc] initWithLoadingStatus:@"Saving..."]; | ||
} | ||
|
||
- (void)saveToPocket { | ||
[[PocketAPI sharedAPI] saveURL:_URL handler: ^(PocketAPI *API, NSURL *URL, NSError *error) { | ||
BOOL activityCompletedSuccessfully = error ? NO : YES; | ||
|
||
double delayInSeconds = 0.5; | ||
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)); | ||
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ | ||
[self activityDidFinish:activityCompletedSuccessfully]; | ||
}); | ||
}]; | ||
} | ||
|
||
@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,15 @@ | ||
// | ||
// LoadingHUDViewController.h | ||
// HackerNews | ||
// | ||
// Created by Daniel Rosado on 09/11/13. | ||
// Copyright (c) 2013 Benjamin Gordon. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@interface LoadingHUDViewController : UIViewController | ||
|
||
- (instancetype)initWithLoadingStatus:(NSString*)string; | ||
|
||
@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,36 @@ | ||
// | ||
// LoadingHUDViewController.m | ||
// HackerNews | ||
// | ||
// Created by Daniel Rosado on 09/11/13. | ||
// Copyright (c) 2013 Benjamin Gordon. All rights reserved. | ||
// | ||
|
||
#import "LoadingHUDViewController.h" | ||
#import "SVProgressHUD.h" | ||
|
||
@implementation LoadingHUDViewController | ||
{ | ||
NSString *_loadingString; | ||
} | ||
|
||
- (instancetype)initWithLoadingStatus:(NSString*)string | ||
{ | ||
self = [super initWithNibName:nil bundle:nil]; | ||
if (self) { | ||
_loadingString = string; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
- (void)loadView | ||
{ | ||
UIView *vw = [[UIView alloc] initWithFrame:[UIApplication sharedApplication].keyWindow.bounds]; | ||
vw.backgroundColor = [UIColor clearColor]; | ||
self.view = vw; | ||
|
||
[SVProgressHUD showWithStatus:_loadingString maskType:SVProgressHUDMaskTypeGradient]; | ||
} | ||
|
||
@end |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,18 @@ | ||
// | ||
// HNPostURL.h | ||
// HackerNews | ||
// | ||
// Created by Daniel Rosado on 09/11/13. | ||
// Copyright (c) 2013 Benjamin Gordon. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface HNPostURL : NSURL | ||
|
||
- (id)initWithString:(NSString *)URLString andMobileFriendlyString:(NSString*)mFriendlyURLString; | ||
|
||
@property (nonatomic, readonly, strong) NSString *mobileFriendlyAbsoluteString; | ||
@property (nonatomic, readonly, strong) NSURL *mobileFriendlyAbsoluteURL; | ||
|
||
@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,44 @@ | ||
// | ||
// HNPostURL.m | ||
// HackerNews | ||
// | ||
// Created by Daniel Rosado on 09/11/13. | ||
// Copyright (c) 2013 Benjamin Gordon. All rights reserved. | ||
// | ||
|
||
#import "HNPostURL.h" | ||
|
||
@interface HNPostURL () | ||
|
||
@property (nonatomic, readwrite, strong) NSString *mobileFriendlyAbsoluteString; | ||
@property (nonatomic, readwrite, strong) NSURL *mobileFriendlyAbsoluteURL; | ||
|
||
@end | ||
|
||
|
||
@implementation HNPostURL | ||
|
||
#pragma mark - Designated initializer | ||
- (id)initWithString:(NSString *)URLString andMobileFriendlyString:(NSString*)mFriendlyURLString | ||
{ | ||
self = [super initWithString:URLString]; | ||
if (self) { | ||
_mobileFriendlyAbsoluteString = mFriendlyURLString; | ||
_mobileFriendlyAbsoluteURL = [[NSURL alloc] initWithString:mFriendlyURLString]; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
#pragma mark - Mobile friendly getters | ||
- (NSString*)mobileFriendlyAbsoluteString | ||
{ | ||
return _mobileFriendlyAbsoluteString; | ||
} | ||
|
||
- (NSURL*)mobileFriendlyAbsoluteURL | ||
{ | ||
return _mobileFriendlyAbsoluteURL; | ||
} | ||
|
||
@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
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
Oops, something went wrong.