2
0

Update Google+ integration.

[UPDATED]   Google+ SDK to 1.1.0.
This commit is contained in:
Maarten Billemont
2013-01-31 16:22:37 -05:00
parent cc015ada1b
commit 6c23134e47
74 changed files with 3383 additions and 2012 deletions

View File

@@ -18,6 +18,7 @@
#import "GooglePlusSampleMasterViewController.h"
#import "GooglePlusSampleAppDelegate.h"
#import "GooglePlusSampleShareViewController.h"
#import "GooglePlusSampleSignInViewController.h"
#import "GooglePlusSampleMomentsViewController.h"
@@ -25,10 +26,19 @@
static const int kNumViewControllers = 3;
static NSString * const kMenuOptions[kNumViewControllers] = {
@"Sign In", @"Share", @"Moments" };
static NSString * const kUnselectableMenuOptions[kNumViewControllers] = {
@"", @"", @"Sign in to use moments" };
static NSString * const kNibNames[kNumViewControllers] = {
@"GooglePlusSampleSignInViewController",
@"GooglePlusSampleShareViewController",
@"GooglePlusSampleMomentsViewController" };
static const int kMomentsIndex = 2;
@interface GooglePlusSampleMasterViewController () {
NSIndexPath *momentsIndexPath_;
}
- (BOOL)isSelectable:(NSIndexPath *)indexPath;
@end
@implementation GooglePlusSampleMasterViewController
@@ -47,6 +57,11 @@ static NSString * const kNibNames[kNumViewControllers] = {
return self;
}
- (void)dealloc {
[momentsIndexPath_ release];
[super dealloc];
}
#pragma mark - View lifecycle
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)
@@ -58,6 +73,15 @@ static NSString * const kNibNames[kNumViewControllers] = {
return YES;
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if (momentsIndexPath_) {
[self.tableView
reloadRowsAtIndexPaths:[NSArray arrayWithObject:momentsIndexPath_]
withRowAnimation:UITableViewRowAnimationFade];
}
}
#pragma mark - UITableViewDelegate/UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
@@ -71,22 +95,32 @@ static NSString * const kNibNames[kNumViewControllers] = {
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString * const kCellIdentifier = @"Cell";
BOOL selectable = [self isSelectable:indexPath];
NSString * const kCellIdentifier = selectable ? @"Cell" : @"GreyCell";
UITableViewCell *cell =
[tableView dequeueReusableCellWithIdentifier:kCellIdentifier];
if (cell == nil) {
cell =
[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:kCellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
if (selectable) {
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
} else {
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textLabel.textColor = [UIColor lightGrayColor];
}
}
cell.textLabel.text = (selectable ? kMenuOptions : kUnselectableMenuOptions)
[indexPath.row];
cell.textLabel.text = kMenuOptions[indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (![self isSelectable:indexPath]) {
return;
}
Class nibClass = NSClassFromString(kNibNames[indexPath.row]);
UIViewController *controller =
[[[nibClass alloc] initWithNibName:nil bundle:nil] autorelease];
@@ -95,4 +129,19 @@ static NSString * const kNibNames[kNumViewControllers] = {
[self.navigationController pushViewController:controller animated:YES];
}
#pragma mark - Helper methods
- (BOOL)isSelectable:(NSIndexPath *)indexPath {
if (indexPath.row == kMomentsIndex) {
if (!momentsIndexPath_) {
momentsIndexPath_ = [indexPath retain];
}
// To use Google+ History API, you need to sign in.
GooglePlusSampleAppDelegate *appDelegate = (GooglePlusSampleAppDelegate *)
[[UIApplication sharedApplication] delegate];
return appDelegate.auth && appDelegate.plusMomentsWriteScope;
}
return YES;
}
@end