Skip to content

Commit

Permalink
Show intersection/city name at the top of the game list.
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronpk committed Sep 8, 2011
1 parent 5e6501a commit efc2413
Show file tree
Hide file tree
Showing 6 changed files with 360 additions and 96 deletions.
6 changes: 5 additions & 1 deletion Classes/GameListViewController.h
Expand Up @@ -23,14 +23,18 @@
@property (nonatomic, retain) IBOutlet UIButton *reloadBtn;
@property (nonatomic, retain) IBOutlet UIButton *logoutBtn;
@property (nonatomic, retain) IBOutlet UITableView *tableView;
@property (nonatomic, retain) IBOutlet UIView *loadingView;
@property (nonatomic, retain) IBOutlet UILabel *loadingStatus;
@property (nonatomic, retain) IBOutlet UILabel *gamesNearLabel;
@property (nonatomic, retain) IBOutlet GameCell *gameCell;
@property (nonatomic, retain) IBOutlet UIView *loadingView;
@property (nonatomic, retain) IBOutlet UIView *noGamesView;
@property (nonatomic, retain) IBOutlet UIActivityIndicatorView *spinnerView;
@property (nonatomic, retain) NSMutableArray *games;
@property (nonatomic, retain) NSIndexPath *selectedIndex;

- (IBAction)reloadBtnPressed;
- (IBAction)logoutBtnPressed;
- (IBAction)emailBtnPressed;
- (void)refreshNearbyLayers;

@end
64 changes: 49 additions & 15 deletions Classes/GameListViewController.m
Expand Up @@ -13,14 +13,16 @@

@implementation GameListViewController

@synthesize reloadBtn, logoutBtn, tableView, gameCell, games, selectedIndex, loadingView, loadingStatus;
@synthesize reloadBtn, logoutBtn, tableView, noGamesView, gameCell, games, selectedIndex, loadingView, loadingStatus, spinnerView, gamesNearLabel;

- (void)dealloc {
[games release];
[gameCell release];
[selectedIndex release];
[tableView release];
[loadingView release];
[noGamesView release];
[spinnerView release];
[reloadBtn release];
[logoutBtn release];
[locationManager release];
Expand Down Expand Up @@ -60,9 +62,18 @@ - (IBAction)logoutBtnPressed {
[[LQClient single] logout];
}

- (IBAction)emailBtnPressed {
NSLog(@"email tapped");
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto:games@mapattack.org"]];
}

- (void)refreshNearbyLayers {
self.loadingStatus.text = @"Finding your location...";
self.loadingView.alpha = 0.75;
self.loadingView.alpha = 0.85;
self.noGamesView.hidden = YES;
self.spinnerView.hidden = NO;
self.loadingStatus.hidden = NO;
self.gamesNearLabel.text = @"";

if (!locationManager) {
#ifdef FAKE_CORE_LOCATION
Expand All @@ -82,19 +93,42 @@ - (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation {

self.loadingStatus.text = @"Finding nearby games...";

[[LQClient single] getNearbyLayers:newLocation withCallback:^(NSError *error, NSDictionary *response){
self.games = [response objectForKey:@"nearby"];
NSLog(@"Found games: %@", self.games);
self.loadingStatus.text = @"Reticulating splines...";

[UIView beginAnimations:@"alpha" context:nil];
[UIView setAnimationDuration:0.4];
[self.loadingView setAlpha:0.0];
[UIView commitAnimations];

[self.tableView reloadData];
[[LQClient single] getPlaceContext:newLocation withCallback:^(NSError *error, NSDictionary *response){
NSLog(@"Found place context: %@", response);
if([response objectForKey:@"best_name"] != nil) {
self.gamesNearLabel.text = [NSString stringWithFormat:@"Games near %@", [response objectForKey:@"best_name"]];
} else {
self.gamesNearLabel.text = @"";
}

self.loadingStatus.text = @"Finding nearby games...";

[[LQClient single] getNearbyLayers:newLocation withCallback:^(NSError *error, NSDictionary *response){
if([response objectForKey:@"nearby"] != nil)
self.games = [response objectForKey:@"nearby"];
else
self.games = nil;

NSLog(@"Found games: %@", self.games);

if(self.games == nil || [self.games count] == 0) {
self.noGamesView.hidden = NO;
self.spinnerView.hidden = YES;
self.loadingStatus.hidden = YES;
[UIView beginAnimations:@"alpha" context:nil];
[UIView setAnimationDuration:0.3];
[self.noGamesView setAlpha:1.0];
[UIView commitAnimations];
} else {
self.loadingStatus.text = @"Reticulating splines...";
[UIView beginAnimations:@"alpha" context:nil];
[UIView setAnimationDuration:0.4];
[self.loadingView setAlpha:0.0];
[UIView commitAnimations];
}

[self.tableView reloadData];
}];
}];

[locationManager stopUpdatingLocation];
Expand Down
59 changes: 14 additions & 45 deletions Classes/HowToPlay.xib
Expand Up @@ -40,31 +40,6 @@
<object class="IBUIView" id="191373211">
<reference key="NSNextResponder"/>
<int key="NSvFlags">274</int>
<object class="NSMutableArray" key="NSSubviews">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBUILabel" id="1002673755">
<reference key="NSNextResponder" ref="191373211"/>
<int key="NSvFlags">292</int>
<string key="NSFrame">{{122, 152}, {54, 21}}</string>
<reference key="NSSuperview" ref="191373211"/>
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClipsSubviews">YES</bool>
<int key="IBUIContentMode">7</int>
<bool key="IBUIUserInteractionEnabled">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<string key="IBUIText">Yeah!!!</string>
<object class="NSColor" key="IBUITextColor">
<int key="NSColorSpace">1</int>
<bytes key="NSRGB">MCAwIDAAA</bytes>
</object>
<object class="NSColor" key="IBUIHighlightedColor">
<int key="NSColorSpace">3</int>
<bytes key="NSWhite">MQA</bytes>
</object>
<int key="IBUIBaselineAdjustment">1</int>
<float key="IBUIMinimumFontSize">10</float>
</object>
</object>
<string key="NSFrameSize">{320, 460}</string>
<reference key="NSSuperview"/>
<object class="NSColor" key="IBUIBackgroundColor">
Expand All @@ -89,14 +64,6 @@
</object>
<int key="connectionID">3</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">test</string>
<reference key="source" ref="372490531"/>
<reference key="destination" ref="1002673755"/>
</object>
<int key="connectionID">5</int>
</object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
Expand All @@ -112,7 +79,6 @@
<reference key="object" ref="191373211"/>
<object class="NSMutableArray" key="children">
<bool key="EncodedWithXMLCoder">YES</bool>
<reference ref="1002673755"/>
</object>
<reference key="parent" ref="0"/>
</object>
Expand All @@ -127,11 +93,6 @@
<reference key="object" ref="975951072"/>
<reference key="parent" ref="0"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">4</int>
<reference key="object" ref="1002673755"/>
<reference key="parent" ref="191373211"/>
</object>
</object>
</object>
<object class="NSMutableDictionary" key="flattenedProperties">
Expand All @@ -142,19 +103,13 @@
<string>-2.CustomClassName</string>
<string>1.IBEditorWindowLastContentRect</string>
<string>1.IBPluginDependency</string>
<string>4.IBPluginDependency</string>
<string>4.IBViewBoundsToFrameTransform</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>HowToPlay</string>
<string>UIResponder</string>
<string>{{341, 230}, {320, 480}}</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<object class="NSAffineTransform">
<bytes key="NSTransformStruct">P4AAAL+AAABC0AAAwykAAA</bytes>
</object>
</object>
</object>
<object class="NSMutableDictionary" key="unlocalizedProperties">
Expand Down Expand Up @@ -270,6 +225,20 @@
<string key="minorKey">Foundation.framework/Headers/NSURLConnection.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">NSObject</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBFrameworkSource</string>
<string key="minorKey">QuartzCore.framework/Headers/CAAnimation.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">NSObject</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBFrameworkSource</string>
<string key="minorKey">QuartzCore.framework/Headers/CALayer.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">NSObject</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
Expand Down
1 change: 1 addition & 0 deletions Classes/LQClient.h
Expand Up @@ -36,6 +36,7 @@ typedef void (^LQHTTPRequestCallback)(NSError *error, NSDictionary *response);
// - (NSString *)refreshToken;
- (void)sendPushToken:(NSString *)token withCallback:(LQHTTPRequestCallback)callback;
- (void)getNearbyLayers:(CLLocation *)location withCallback:(LQHTTPRequestCallback)callback;
- (void)getPlaceContext:(CLLocation *)location withCallback:(LQHTTPRequestCallback)callback;
- (void)createNewAccountWithEmail:(NSString *)email initials:(NSString *)initials callback:(LQHTTPRequestCallback)callback;
- (void)joinGame:(NSString *)layer_id withToken:(NSString *)group_token;
- (void)logout;
Expand Down
13 changes: 13 additions & 0 deletions Classes/LQClient.m
Expand Up @@ -272,6 +272,19 @@ - (void)getNearbyLayers:(CLLocation *)location withCallback:(LQHTTPRequestCallba
[self runRequest:request callback:callback];
}

- (void)getPlaceContext:(CLLocation *)location withCallback:(LQHTTPRequestCallback)callback {
NSURL *url = [self urlWithPath:[NSString stringWithFormat:@"location/context?latitude=%f&longitude=%f",
//45.5246, -122.6843, MapAttackAppID]];
location.coordinate.latitude, location.coordinate.longitude]];
__block ASIHTTPRequest *request;
if([self isLoggedIn]) {
request = [self userRequestWithURL:url];
} else {
request = [self appRequestWithURL:url];
}
[self runRequest:request callback:callback];
}

- (void)logout {
[[NSUserDefaults standardUserDefaults] removeObjectForKey:LQAuthEmailAddressKey];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:LQAuthInitialsKey];
Expand Down

0 comments on commit efc2413

Please sign in to comment.