This repository has been archived by the owner on Mar 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 78
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 #541 from artsy/apphub_switcher
[Dev] Support loading Emission from AppHub
- Loading branch information
Showing
10 changed files
with
206 additions
and
132 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#import "ARRootViewController.h" | ||
|
||
@class ARSectionData; | ||
@interface ARRootViewController(AppHub) | ||
|
||
- (ARSectionData *)appHubSectionData; | ||
|
||
@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,79 @@ | ||
#import "ARRootViewController+AppHub.h" | ||
#import "NSDateFormatter+TimeAgo.h" | ||
|
||
#import <AppHub/AppHub.h> | ||
#import <ARGenericTableViewController/ARGenericTableViewController.h> | ||
|
||
@implementation ARRootViewController(AppHub) | ||
|
||
- (ARSectionData *)appHubSectionData; | ||
{ | ||
ARSectionData *section = [[ARSectionData alloc] initWithCellDataArray: @[ | ||
[self appHubBuildChooser], | ||
[self appHubMetadata], | ||
[self showPRForBuild] | ||
]]; | ||
section.headerTitle = [@"AppHub" uppercaseString]; | ||
return section; | ||
} | ||
|
||
- (ARCellData *)appHubMetadata | ||
{ | ||
ARCellData *cellData = [[ARCellData alloc] initWithIdentifier:AROptionCell]; | ||
cellData.cellConfigurationBlock = ^(UITableViewCell *cell) { | ||
AHBuild *build = [[AppHub buildManager] currentBuild]; | ||
if (!build) { | ||
cell.textLabel.text = @"Not downloaded yet"; | ||
} if (build && !build.creationDate) { | ||
cell.textLabel.text = @"Current Build: Bundled with Emission"; | ||
} else { | ||
|
||
NSString *timeString = [NSDateFormatter timeAgoFromDate:build.creationDate]; | ||
cell.textLabel.text = [NSString stringWithFormat:@"Current Build: From %@", timeString]; | ||
} | ||
}; | ||
return cellData; | ||
} | ||
|
||
- (ARCellData *)showPRForBuild | ||
{ | ||
ARCellData *cellData = [[ARCellData alloc] initWithIdentifier:AROptionCell]; | ||
AHBuild *build = [[AppHub buildManager] currentBuild]; | ||
NSString *pr = nil; | ||
|
||
if (build && build.buildDescription) { | ||
pr = [[build.buildDescription componentsSeparatedByString:@"- #"] lastObject]; | ||
} | ||
|
||
cellData.cellConfigurationBlock = ^(UITableViewCell *cell) { | ||
if (!pr) { | ||
cell.textLabel.text = @"Not on an AppHub build..."; | ||
} else { | ||
cell.textLabel.text = [NSString stringWithFormat:@"Link to PR %@", pr]; | ||
} | ||
}; | ||
|
||
cellData.cellSelectionBlock = ^(UITableView *tableView, NSIndexPath *indexPath) { | ||
if(pr) { | ||
NSString *prAddresss = [NSString stringWithFormat:@"https://github.com/artsy/emission/pull/%@", pr]; | ||
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:prAddresss]]; | ||
} | ||
}; | ||
return cellData; | ||
} | ||
|
||
- (ARCellData *)appHubBuildChooser | ||
{ | ||
ARCellData *cellData = [[ARCellData alloc] initWithIdentifier:AROptionCell]; | ||
cellData.cellConfigurationBlock = ^(UITableViewCell *cell) { | ||
cell.textLabel.text = @"Choose an RN build"; | ||
}; | ||
cellData.cellSelectionBlock = ^(UITableView *tableView, NSIndexPath *indexPath) { | ||
[AppHub presentSelectorOnViewController:self withBuildHandler:^(AHBuild *build, NSError *error) { | ||
[self.tableView reloadData]; | ||
}]; | ||
}; | ||
return cellData; | ||
} | ||
|
||
@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
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,10 @@ | ||
#import <Foundation/Foundation.h> | ||
|
||
// Based on an implmentation in | ||
// http://stackoverflow.com/questions/902950/iphone-convert-date-string-to-a-relative-time-stamp | ||
|
||
@interface NSDateFormatter (Extras) | ||
|
||
+ (NSString *)timeAgoFromDate:(NSDate *)date; | ||
|
||
@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,45 @@ | ||
#import "NSDateFormatter+TimeAgo.h" | ||
|
||
@implementation NSDateFormatter (Extras) | ||
|
||
+ (NSString *)timeAgoFromDate:(NSDate *)date | ||
{ | ||
NSDate *now = [NSDate date]; | ||
|
||
NSTimeInterval time = [date timeIntervalSinceDate:now]; | ||
time *= -1; | ||
|
||
if(time < 1) { | ||
return @"-"; | ||
|
||
} else if (time < 60) { | ||
return @"less than a minute ago"; | ||
|
||
} else if (time < 3600) { | ||
NSInteger diff = round(time / 60); | ||
if (diff == 1) return @"1 minute ago"; | ||
|
||
return [NSString stringWithFormat:@"%@ minutes ago", @(diff)]; | ||
|
||
} else if (time < 86400) { | ||
NSInteger diff = round(time / 60 / 60); | ||
if (diff == 1) return @"1 hour ago"; | ||
|
||
return [NSString stringWithFormat:@"%@ hours ago", @(diff)]; | ||
|
||
} else if (time < 604800) { | ||
NSInteger diff = round(time / 60 / 60 / 24); | ||
if (diff == 1) return @"yesterday"; | ||
if (diff == 7) return @"last week"; | ||
|
||
return [NSString stringWithFormat:@"%@ days ago", @(diff)]; | ||
|
||
} else { | ||
NSInteger diff = round(time / 60 / 60 / 24 / 7); | ||
if (diff == 1) return @"last week"; | ||
|
||
return [NSString stringWithFormat:@"%@ weeks ago", @(diff)]; | ||
} | ||
} | ||
|
||
@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
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