Permalink
Browse files

Fixed CRASH and loading of Activities

no more duplicate and sorted latest first
  • Loading branch information...
1 parent 8a6eba4 commit 8a4de3ca406a2414877fa626c1d4ddf0508d4da1 @jovhenni19 committed Dec 9, 2013
@@ -235,7 +235,6 @@ - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)
- (void)connection:(NSURLConnection*)connection didReceiveResponse:(NSURLResponse *)response
{
- [self.buttonDescription setTitle:@"" forState:UIControlStateNormal];
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
self.dataReceived = nil;
@@ -404,6 +403,10 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
}
}
+ else {
+
+ [self.buttonDescription setTitle:@"Save" forState:UIControlStateNormal];
+ }
// Do something with responseData
}
@@ -210,18 +210,19 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
// [self dismissOverlay];
-// NSLog(@"Did Finish:%@", json);
if(connection == self.urlConnectionActivity) {
NSError *error = nil;
- NSDictionary *json = [NSJSONSerialization JSONObjectWithData:self.dataReceived options:NSJSONReadingAllowFragments error:&error];
+ NSDictionary *jsonActivities = [NSJSONSerialization JSONObjectWithData:self.dataReceived options:NSJSONReadingAllowFragments error:&error];
- if ([[json objectForKey:@"data"] count]) {
+ if ([[jsonActivities objectForKey:@"data"] count]) {
+// NSLog(@"Did Finish:%@", json);
// NSLog(@"total:%i",[[json objectForKey:@"data"] count]);
- for (NSDictionary *entry in [json objectForKey:@"data"]) {
- if ([[entry valueForKey:@"activity_type"] integerValue] == 25) {
- NSString *parameters = [NSString stringWithFormat:@"?user_id=%@&activities_id=%@", self.loginDetail.user_id, [entry valueForKey:@"activities_id"]];
+ for (NSDictionary *entryActivities in [jsonActivities objectForKey:@"data"]) {
+
+ if ([[entryActivities valueForKey:@"activity_type"] integerValue] == 25) {
+ NSString *parameters = [NSString stringWithFormat:@"?user_id=%@&activities_id=%@", self.loginDetail.user_id, [entryActivities valueForKey:@"activities_id"]];
// NSLog(@"(%i)parameters:%@",[[json objectForKey:@"data"] indexOfObject:entry],parameters);
NSString *urlString = [NSString stringWithFormat:@"http://keydiscoveryinc.com/agent_bridge/webservice/getactivity-25.php%@",parameters];
@@ -237,7 +238,7 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection
NSData *responseData = [request responseData];
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingAllowFragments error:&errorData];
if ([[json objectForKey:@"data"] count]) {
-
+// NSLog(@"25 Did Finish:%@", json);
// dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSManagedObjectContext *context = ((ABridge_AppDelegate *)[[UIApplication sharedApplication] delegate]).managedObjectContext;
// for (NSDictionary *entry in [json objectForKey:@"data"]) {
@@ -262,16 +263,26 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection
}
else {
if (self.arrayOfActivity == nil) {
- self.arrayOfActivity = [[NSMutableArray alloc] init];
+ self.arrayOfActivity = [NSMutableArray array];
+ for(int i = 0; i<[[jsonActivities objectForKey:@"data"] count]; i++)
+ [self.arrayOfActivity addObject: [NSNull null]];
}
- [self.arrayOfActivity addObject:activity];
+// [self.arrayOfActivity addObject:activity];
+ [self.arrayOfActivity replaceObjectAtIndex:[[jsonActivities objectForKey:@"data"] indexOfObject:entryActivities] withObject:activity];
}
// NSLog(@"25 Did Finish:%i [%i] %i", [self.arrayOfURL_25 count], [self.arrayOfActivity count], self.index_25);
// dispatch_async(dispatch_get_main_queue(), ^{
-
+
+ NSSortDescriptor *sortDescriptor;
+ sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"date"
+ ascending:NO];
+ NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
+ NSArray *sortedArray;
+ sortedArray = [self.arrayOfActivity sortedArrayUsingDescriptors:sortDescriptors];
+
self.numberOfActivity = [self.arrayOfActivity count];
self.labelNumberOfActivity.text = [NSString stringWithFormat:@"My Activity (%li)",(long)self.numberOfActivity];
[self.labelNumberOfActivity sizeToFit];
@@ -280,7 +291,7 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection
frame.origin.x = self.labelNumberOfActivity.frame.origin.x + self.labelNumberOfActivity.frame.size.width + 10.0f;
self.activityIndicator.frame = frame;
- if (self.pageController == nil) {
+ if (self.pageController == nil && ![[self.arrayOfActivity objectAtIndex:0] isEqual:[NSNull null]]) {
[self reloadPages];
}
// });
@@ -302,8 +313,8 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection
}
- else if ([[entry valueForKey:@"activity_type"] integerValue] == 11) {
- NSString *parameters = [NSString stringWithFormat:@"?user_id=%@&activities_id=%@", self.loginDetail.user_id, [entry valueForKey:@"activities_id"]];
+ else if ([[entryActivities valueForKey:@"activity_type"] integerValue] == 11) {
+ NSString *parameters = [NSString stringWithFormat:@"?user_id=%@&activities_id=%@", self.loginDetail.user_id, [entryActivities valueForKey:@"activities_id"]];
// NSLog(@"[%i]parameters:%@",[[json objectForKey:@"data"] indexOfObject:entry],parameters);
NSString *urlString = [NSString stringWithFormat:@"http://keydiscoveryinc.com/agent_bridge/webservice/getactivity-11.php%@",parameters];
@@ -319,7 +330,7 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection
NSData *responseData = [request responseData];
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingAllowFragments error:&errorData];
if ([[json objectForKey:@"data"] count]) {
-
+// NSLog(@"11 Did Finish:%@", json);
// dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSManagedObjectContext *context = ((ABridge_AppDelegate *)[[UIApplication sharedApplication] delegate]).managedObjectContext;
// for (NSDictionary *entry in [json objectForKey:@"data"]) {
@@ -342,18 +353,29 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection
if (![context save:&error]) {
NSLog(@"Error on saving Activity:%@",[error localizedDescription]);
}
- else {
- if (self.arrayOfActivity == nil) {
- self.arrayOfActivity = [[NSMutableArray alloc] init];
- }
-
- [self.arrayOfActivity addObject:activity];
+ else {
+ if (self.arrayOfActivity == nil) {
+ self.arrayOfActivity = [NSMutableArray array];
+ for(int i = 0; i<[[jsonActivities objectForKey:@"data"] count]; i++)
+ [self.arrayOfActivity addObject: [NSNull null]];
+ }
+
+// [self.arrayOfActivity addObject:activity];
+
+ [self.arrayOfActivity replaceObjectAtIndex:[[jsonActivities objectForKey:@"data"] indexOfObject:entryActivities] withObject:activity];
}
// NSLog(@"25 Did Finish:%i [%i] %i", [self.arrayOfURL_25 count], [self.arrayOfActivity count], self.index_25);
// dispatch_async(dispatch_get_main_queue(), ^{
-
+
+ NSSortDescriptor *sortDescriptor;
+ sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"date"
+ ascending:NO];
+ NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
+ NSArray *sortedArray;
+ sortedArray = [self.arrayOfActivity sortedArrayUsingDescriptors:sortDescriptors];
+
self.numberOfActivity = [self.arrayOfActivity count];
self.labelNumberOfActivity.text = [NSString stringWithFormat:@"My Activity (%li)",(long)self.numberOfActivity];
[self.labelNumberOfActivity sizeToFit];
@@ -362,7 +384,7 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection
frame.origin.x = self.labelNumberOfActivity.frame.origin.x + self.labelNumberOfActivity.frame.size.width + 10.0f;
self.activityIndicator.frame = frame;
- if (self.pageController == nil) {
+ if (self.pageController == nil && ![[self.arrayOfActivity objectAtIndex:0] isEqual:[NSNull null]]) {
[self reloadPages];
}
// });
@@ -400,6 +422,7 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection
[self showOverlayWithMessage:@"You currently don't have any Activities." withIndicator:NO];
}
+
}
[self.activityIndicator stopAnimating];
@@ -72,7 +72,9 @@ - (void)viewDidLoad
executeFetchRequest:fetchRequest error:&error];
self.loginDetail = (LoginDetails*)[fetchedObjects firstObject];
- [self.delegate hideSaveButton:NO];
+ if ([self.delegate respondsToSelector:@selector(hideSaveButton:)]) {
+ [self.delegate hideSaveButton:NO];
+ }
self.labelZip.font = FONT_OPENSANS_REGULAR(FONT_SIZE_REGULAR);
self.labelPrice.font = FONT_OPENSANS_BOLD(FONT_SIZE_REGULAR);
@@ -498,7 +500,9 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection
self.labelDescription.text = [NSString stringWithFormat:@"This POPs™ is restricted to %@'s Network members only",self.propertyDetails.name];
[self.buttonDescription setTitle:@"Pending" forState:UIControlStateNormal];
- [self.delegate hideSaveButton:YES];
+ if ([self.delegate respondsToSelector:@selector(hideSaveButton:)]) {
+ [self.delegate hideSaveButton:YES];
+ }
}
}
else {
@@ -508,7 +512,9 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection
self.labelDescription.text = [NSString stringWithFormat:@"This POPs™ is restricted to %@'s Network members only",self.propertyDetails.name];
[self.buttonDescription setTitle:@"Request To View" forState:UIControlStateNormal];
- [self.delegate hideSaveButton:YES];
+ if ([self.delegate respondsToSelector:@selector(hideSaveButton:)]) {
+ [self.delegate hideSaveButton:YES];
+ }
}
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
@@ -524,7 +530,9 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
- [self.delegate hideSaveButton:YES];
+ if ([self.delegate respondsToSelector:@selector(hideSaveButton:)]) {
+ [self.delegate hideSaveButton:YES];
+ }
}
}
@@ -569,7 +577,9 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection
self.labelDescription.text = @"This POPs™ is restricted to private";
[self.buttonDescription setTitle:@"Pending" forState:UIControlStateNormal];
- [self.delegate hideSaveButton:YES];
+ if ([self.delegate respondsToSelector:@selector(hideSaveButton:)]) {
+ [self.delegate hideSaveButton:YES];
+ }
}
}
@@ -580,7 +590,9 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection
self.labelDescription.text = [NSString stringWithFormat:@"This POPs™ is restricted to %@'s Network members only",self.propertyDetails.name];
[self.buttonDescription setTitle:@"Request To View" forState:UIControlStateNormal];
- [self.delegate hideSaveButton:YES];
+ if ([self.delegate respondsToSelector:@selector(hideSaveButton:)]) {
+ [self.delegate hideSaveButton:YES];
+ }
}
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
@@ -595,7 +607,9 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
- [self.delegate hideSaveButton:YES];
+ if ([self.delegate respondsToSelector:@selector(hideSaveButton:)]) {
+ [self.delegate hideSaveButton:YES];
+ }
}
}
// Do something with responseData
@@ -21,7 +21,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
- <string>1.0.14</string>
+ <string>1.0.15</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIAppFonts</key>

0 comments on commit 8a4de3c

Please sign in to comment.