aboutsummaryrefslogtreecommitdiffstats
path: root/iphone/FixMyStreet/Classes
diff options
context:
space:
mode:
Diffstat (limited to 'iphone/FixMyStreet/Classes')
-rw-r--r--iphone/FixMyStreet/Classes/FixMyStreetAppDelegate.h5
-rw-r--r--iphone/FixMyStreet/Classes/FixMyStreetAppDelegate.m73
-rw-r--r--iphone/FixMyStreet/Classes/InputTableViewController.h1
-rw-r--r--iphone/FixMyStreet/Classes/InputTableViewController.m11
4 files changed, 55 insertions, 35 deletions
diff --git a/iphone/FixMyStreet/Classes/FixMyStreetAppDelegate.h b/iphone/FixMyStreet/Classes/FixMyStreetAppDelegate.h
index de34ca1c5..0c67e845a 100644
--- a/iphone/FixMyStreet/Classes/FixMyStreetAppDelegate.h
+++ b/iphone/FixMyStreet/Classes/FixMyStreetAppDelegate.h
@@ -23,6 +23,9 @@
NSString* name;
NSString* email;
NSString* phone;
+
+ UIView *uploading;
+ NSMutableData* returnData;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@@ -36,7 +39,7 @@
@property (nonatomic, retain) NSString* email;
@property (nonatomic, retain) NSString* phone;
--(BOOL)uploadReport;
+-(void)uploadReport;
@end
diff --git a/iphone/FixMyStreet/Classes/FixMyStreetAppDelegate.m b/iphone/FixMyStreet/Classes/FixMyStreetAppDelegate.m
index 3704c441b..01b742de2 100644
--- a/iphone/FixMyStreet/Classes/FixMyStreetAppDelegate.m
+++ b/iphone/FixMyStreet/Classes/FixMyStreetAppDelegate.m
@@ -95,24 +95,19 @@
}
// Report stuff
--(BOOL)uploadReport {
- // Not yet working - do something spinny here
+-(void)uploadReport {
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
-// struct CGRect rect = [UIHardware fullScreenApplicationContentRect];
-// rect.origin.x = rect.origin.y = 0.0f;
-// UIWindow *window = [[UIWindow alloc] initWithContentRect: rect];
-// [window orderFront: self];
-// [window makeKey: self];
-// [window setContentView: imgView];
-//
-// id HUD = [[UIProgressHUD alloc] initWithWindow:window];
-// [HUD setText:@"Downloading now..."];
-// [HUD show:YES];
-
- // UIActivityIndicatorView *spinny = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
- // [spinny startAnimating];
- // [spinny release];
+ uploading = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
+ UIColor *bg = [[UIColor alloc] initWithRed:0 green:0 blue:0 alpha:0.5];
+ uploading.backgroundColor = bg;
+ [bg release];
+ UIActivityIndicatorView *spinny = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
+ spinny.center = CGPointMake(160, 160);
+ [uploading addSubview:spinny];
+ [spinny startAnimating];
+ [self.navigationController.view addSubview:uploading];
+ [spinny release];
// Get the phone's unique ID
UIDevice *dev = [UIDevice currentDevice];
@@ -179,22 +174,40 @@
[request setHTTPBody: postBody];
- NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
- NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSASCIIStringEncoding];
+ returnData = [[NSMutableData alloc] init];
+ [NSURLConnection connectionWithRequest:request delegate:self];
+// NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
+}
+
+- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
+ [returnData appendData:data];
+}
+-(void)connectionDidFinishLoading:(NSURLConnection *)connection {
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
-// [HUD show:NO];
-
- // For now, just pop up alert box with return data
- UIAlertView *v = [[UIAlertView alloc] initWithTitle:@"Return" message:returnString delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
- [v show];
- [v release];
-// NSLog(@"Returned string is: %s", returnString);
-
- // Assuming success, remove the stuff
- subject = nil;
- self.image = nil;
- return YES;
+ [uploading removeFromSuperview];
+
+ NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSASCIIStringEncoding];
+
+ if ([returnString isEqualToString:@"SUCCESS"]) {
+ subject = nil;
+ self.image = nil;
+ [(InputTableViewController*)self.navigationController.visibleViewController reportUploaded:YES];
+ UIAlertView *v = [[UIAlertView alloc] initWithTitle:@"Your report has been received" message:@"Check your email for the next step" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
+ [v show];
+ [v release];
+ } else {
+ // Pop up alert box with return error(s)
+ NSArray *errors = [returnString componentsSeparatedByString:@"ERROR:"];
+ NSString *errorString = [[NSString alloc] init];
+ for (int i=1; i<[errors count]; i++) {
+ NSString *error = [errors objectAtIndex:i];
+ errorString = [errorString stringByAppendingFormat:@"\xE2\x80\xA2 %@", error];
+ }
+ UIAlertView *v = [[UIAlertView alloc] initWithTitle:@"Upload failed" message:errorString delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
+ [v show];
+ [v release];
+ }
}
@end
diff --git a/iphone/FixMyStreet/Classes/InputTableViewController.h b/iphone/FixMyStreet/Classes/InputTableViewController.h
index 64bc1d13f..a7b994676 100644
--- a/iphone/FixMyStreet/Classes/InputTableViewController.h
+++ b/iphone/FixMyStreet/Classes/InputTableViewController.h
@@ -26,6 +26,7 @@
-(void)enableSubmissionButton;
-(void)uploadReport;
+-(void)reportUploaded:(BOOL)success;
-(IBAction)addPhoto:(id) sender;
-(IBAction)gotoSettings:(id)sender firstTime:(BOOL)firstTime;
diff --git a/iphone/FixMyStreet/Classes/InputTableViewController.m b/iphone/FixMyStreet/Classes/InputTableViewController.m
index 1f2769590..6515e3e75 100644
--- a/iphone/FixMyStreet/Classes/InputTableViewController.m
+++ b/iphone/FixMyStreet/Classes/InputTableViewController.m
@@ -306,12 +306,15 @@
if (!delegate.name || !delegate.email) {
[self gotoSettings:nil firstTime:YES];
} else {
- BOOL success = [delegate uploadReport];
- if (success)
- imageView.image = nil;
- [self enableSubmissionButton];
+ [delegate uploadReport];
}
}
+-(void)reportUploaded:(BOOL)success {
+ if (success)
+ imageView.image = nil;
+ [self enableSubmissionButton];
+}
+
@end