Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the Build List UI #35

Merged
merged 3 commits into from Sep 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion AppHub/AppHub/AHBuildManager+Private.h
Expand Up @@ -10,7 +10,6 @@
@interface AHBuildManager ()

@property (nonatomic, getter=isFetchingBuild) BOOL fetchingBuild;
@property (nonatomic, copy, readonly) NSString *installedAppVersion;
@property (nonatomic, readonly, strong) NSMutableString *logs;
@property (nonatomic, strong) NSTimer *pollingTimer;
@property (nonatomic, strong) NSMutableArray *completionHandlers;
Expand Down
10 changes: 10 additions & 0 deletions AppHub/AppHub/AHBuildManager.h
Expand Up @@ -82,6 +82,16 @@ extern NSString *const AHBuildManagerBuildKey;
*/
@property (nonatomic, assign, getter=areCellularDownloadsEnabled) BOOL cellularDownloadsEnabled;


/**
* By default, the AppHub SDK will use the version of your application to ensure that AppHub builds match
* your application. If the version of your AppHub build is different to your application's then
* you can use this setting to have AppHub look for a specific version.
*
* Defaults to `NSBundle mainBundle`'s CFBundleShortVersionString.
*/
@property (nonatomic, copy, readwrite) NSString *installedAppVersion;

///---------------------
/// @name Fetching Builds Manually (Advanced)
///---------------------
Expand Down
2 changes: 2 additions & 0 deletions AppHub/AppHub/AHBuildManager.m
Expand Up @@ -56,6 +56,8 @@ - (instancetype)_init __attribute__((objc_method_family(init)))

- (NSString *)installedAppVersion
{
if (_installedAppVersion) { return _installedAppVersion; }

NSBundle *mainBundle = [NSBundle mainBundle];
return mainBundle.infoDictionary[@"CFBundleShortVersionString"];
}
Expand Down
1 change: 1 addition & 0 deletions AppHub/AppHub/AHBuildsListViewController.h
Expand Up @@ -11,6 +11,7 @@

@interface AHBuildsListViewController : UITableViewController


- (instancetype)initWithBuildsResultsHandler:(AHBuildResultBlock)block;

@end
57 changes: 44 additions & 13 deletions AppHub/AppHub/AHBuildsListViewController.m
Expand Up @@ -17,16 +17,16 @@

@implementation AHBuildsListViewController
{
NSArray *_builds;
NSArray *_buildSections;
NSDateFormatter *_dateFormatter;
AHBuildResultBlock _resultsHandler;
}

- (instancetype)initWithBuildsResultsHandler:(AHBuildResultBlock)block
{
if ((self = [super initWithStyle:UITableViewStylePlain])) {
if ((self = [super initWithStyle:UITableViewStyleGrouped])) {
_resultsHandler = block;
self.tableView.contentInset = UIEdgeInsetsMake(20, 0, 0, 0);
_buildSections = @[];
}

return self;
Expand All @@ -35,6 +35,7 @@ - (instancetype)initWithBuildsResultsHandler:(AHBuildResultBlock)block
- (void)viewDidLoad
{
[super viewDidLoad];
self.tableView.contentInset = UIEdgeInsetsMake(20, 0, 0, 0);
[self fetchBuilds];
}

Expand All @@ -53,18 +54,37 @@ - (void)fetchBuilds
}

NSDictionary *listBuildsJson = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];

_builds = [listBuildsJson[@"data"] arrayByAddingObject:@{
AHBuildDataNameKey: @"Local Build",
AHBuildDataDescriptionKey: @"This build is loaded locally from the device."
}];
_buildSections = [self createBuildList: listBuildsJson[@"data"]];

[self.tableView reloadData];
});
}];
[task resume];
}

- (NSArray *)createBuildList:(NSArray *)builds
{
NSMutableArray *sections = [NSMutableArray array];

NSSortDescriptor *createdSortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"created" ascending:NO];
NSArray *sortedBuilds = [builds sortedArrayUsingDescriptors:@[createdSortDescriptor]];
[sections addObject:sortedBuilds];

[sections addObject:@[
@{
AHBuildDataNameKey: @"Local Build",
AHBuildDataDescriptionKey: @"This build is loaded locally from the device."
}
]];
return [sections copy];
}


- (NSDictionary *)buildAtIndexPath:(NSIndexPath *)path
{
return _buildSections[path.section][path.row];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *const BuildCellIdentifier = @"BuildCell";
Expand All @@ -73,7 +93,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:BuildCellIdentifier];
}

NSDictionary *item = _builds[indexPath.row];
NSDictionary *item = [self buildAtIndexPath:indexPath];
NSString *createdTime = item[AHBuildDataCreatedAtKey];
NSDate *createdDate = createdTime ? [NSDate dateWithTimeIntervalSince1970:createdTime.doubleValue / 1000.0] : [NSDate date];

Expand All @@ -85,28 +105,39 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
NSString *createdString = [_dateFormatter stringFromDate:createdDate];

cell.textLabel.text = [NSString stringWithFormat:@"%@ - %@", item[AHBuildDataNameKey], createdString];
cell.detailTextLabel.text = item[AHBuildDataDescriptionKey];
NSString *subtitle = [[item[AHBuildDataCompatibleIOSVersionsKey] allValues] componentsJoinedByString:@", "];
cell.detailTextLabel.text = subtitle ?: item[AHBuildDataDescriptionKey];

return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row + 1 == _builds.count) {
if (indexPath.section + 1 == _buildSections.count) {
// Return the default build.
AHBuild *defaultBuild = [[AHBuild alloc] initWithBundle:[NSBundle mainBundle] info:nil];
_resultsHandler(defaultBuild, nil);
return;
}

NSDictionary *buildJSON = _builds[indexPath.row];
NSDictionary *buildJSON = [self buildAtIndexPath:indexPath];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[[AppHub buildManager] downloadFromJSON:buildJSON resultsHandler:_resultsHandler];
}

- (nullable NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return (section + 1 == _buildSections.count) ? @"Local Build" : @"AppHub Builds";
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
{
return [_buildSections count];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [_builds count];
return [_buildSections[section] count];
}

@end