Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Network Request implemented

  • Loading branch information...
commit 37ae35ae9a10f9347ca98989dd6b35489d19a396 1 parent 6a5a8b6
@jovhenni19 authored
View
BIN  ...j/project.xcworkspace/xcuserdata/host24_iosdev.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown
View
114 AgentBridge/ABridge_ActivityPagesViewController.m
@@ -133,8 +133,6 @@ - (void)viewDidLoad
NSString *pops_link = [NSString stringWithFormat:@"<a href='http://pops/%@'>%@</a>",self.activityDetail.listing_id, self.activityDetail.property_name];
- NSLog(@"pops:%@",self.activityDetail.listing_id);
-
message = [NSString stringWithFormat:@"Your POPs™, %@, is a match to your buyer, %@", pops_link, buyer_name];
}
else {
@@ -221,27 +219,123 @@ - (void)viewDidLoad
message = [NSString stringWithFormat:@"%@ is requesting to view your private POPs™, %@.",self.activityDetail.user_name, pops_link];
}
- else if ([self.activityDetail.activity_type integerValue] == 28 || [self.activityDetail.activity_type integerValue] == 8) {
- // NSLog(@"listing:%@",self.activityDetail.listing_id);
+ else if ([self.activityDetail.activity_type integerValue] == 8) {
+
+// NSLog(@"[8]%@ user:%@ - %@ --- %@",self.loginDetail.user_id,self.activityDetail.user_id, self.activityDetail.other_user_id, self.activityDetail.user_name);
+
+ if ([self.activityDetail.user_id integerValue] == [self.loginDetail.user_id integerValue]) {
+
+ message = [NSString stringWithFormat:@"%@ is requesting to view your public POPs™.",self.activityDetail.user_name];
+ }
+ else {
+ message = [NSString stringWithFormat:@"You have requested to view %@'s public POPs™.",self.activityDetail.user_name];
+ }
dispatch_async(dispatch_get_main_queue(), ^{
self.labelActivityName.text = @"Request Network Access";
self.labelDateTime.text = self.activityDetail.date;
- NSLog(@"status:%@",self.activityDetail.network_status);
- if (self.activityDetail.network_status == nil) {
+
+ if ([self.activityDetail.user_id integerValue] == [self.loginDetail.user_id integerValue]) {
+ self.viewForDescription.hidden = NO;
self.labelDescription.text = @"";
self.buttonDescription.hidden = NO;
[self.buttonDescription setTitle:@"Accept" forState:UIControlStateNormal];
+
+
+ if ([self.activityDetail.network_status integerValue] == 1) {
+ self.viewForDescription.hidden = NO;
+ self.labelDescription.text = [NSString stringWithFormat:@"You have accepted this request. %@ is now part of your Network.",self.activityDetail.user_name];
+ self.buttonDescription.hidden = YES;
+ }
+ else if ([self.activityDetail.network_status integerValue] == 2) {
+ self.viewForDescription.hidden = NO;
+ self.labelDescription.text = @"You have declined this request. ";
+ self.buttonDescription.hidden = YES;
+ }
}
else {
- self.labelDescription.text = [NSString stringWithFormat:@"You have accepted this request. %@ is now part of your Network.",self.activityDetail.user_name];
- self.buttonDescription.hidden = YES;
+ self.viewForDescription.hidden = YES;
+
+
+ if ([self.activityDetail.network_status integerValue] == 1) {
+ self.viewForDescription.hidden = NO;
+ self.labelDescription.text = [NSString stringWithFormat:@" %@ has accepted this request. You are now able to view %@'s POPs™.",self.activityDetail.user_name,self.activityDetail.user_name];
+ self.buttonDescription.hidden = YES;
+ }
+ else if ([self.activityDetail.network_status integerValue] == 2) {
+ self.viewForDescription.hidden = NO;
+ self.labelDescription.text = [NSString stringWithFormat:@"%@ has declined this request.",self.activityDetail.user_name];
+ self.buttonDescription.hidden = NO;
+ [self.buttonDescription setTitle:@"Request to View" forState:UIControlStateNormal];
+ }
+ else if ([self.activityDetail.network_status integerValue] == 0) {
+ self.viewForDescription.hidden = NO;
+ self.labelDescription.text = @"Pending Approval";
+ self.buttonDescription.hidden = YES;
+ }
}
- self.viewForDescription.hidden = NO;
+
});
- message = [NSString stringWithFormat:@"%@ is requesting to join your Network. If you accept this request, %@ will be able to view your public POPs™.",self.activityDetail.user_name,self.activityDetail.user_name];
+
+ }
+ else if ([self.activityDetail.activity_type integerValue] == 28) {
+
+// NSLog(@"[28]%@ user:%@ - %@ --- %@",self.loginDetail.user_id,self.activityDetail.user_id, self.activityDetail.other_user_id, self.activityDetail.user_name);
+
+ if ([self.activityDetail.user_id integerValue] == [self.loginDetail.user_id integerValue]) {
+
+ message = [NSString stringWithFormat:@"You have been invited to join %@'s Network. If you accept this request, you will be able to view %@'s public POPs™.",self.activityDetail.user_name,self.activityDetail.user_name];
+ }
+ else {
+ message = [NSString stringWithFormat:@"%@ is now added to your Network and will be able to view your public POPs™.",self.activityDetail.user_name];
+ }
+
+ dispatch_async(dispatch_get_main_queue(), ^{
+ self.labelActivityName.text = @"Request Network Access";
+ self.labelDateTime.text = self.activityDetail.date;
+
+ if ([self.activityDetail.user_id integerValue] == [self.loginDetail.user_id integerValue]) {
+ self.viewForDescription.hidden = NO;
+ self.labelDescription.text = @"";
+ self.buttonDescription.hidden = NO;
+ [self.buttonDescription setTitle:@"Accept" forState:UIControlStateNormal];
+
+ if ([self.activityDetail.network_status integerValue] == 1) {
+ self.viewForDescription.hidden = NO;
+ self.labelDescription.text = [NSString stringWithFormat:@"You have accepted this request. You are now part of %@'s Network.",self.activityDetail.user_name];
+ self.buttonDescription.hidden = YES;
+ }
+ else if ([self.activityDetail.network_status integerValue] == 2) {
+ self.viewForDescription.hidden = NO;
+ self.labelDescription.text = @"You have declined this request.";
+ self.buttonDescription.hidden = YES;
+ }
+ }
+ else {
+ self.viewForDescription.hidden = YES;
+
+ if ([self.activityDetail.network_status integerValue] == 1) {
+ self.viewForDescription.hidden = NO;
+ self.labelDescription.text = [NSString stringWithFormat:@"%@ has accepted this request and is now part of your Network.",self.activityDetail.user_name];
+ self.buttonDescription.hidden = YES;
+ }
+ else if ([self.activityDetail.network_status integerValue] == 2) {
+ self.viewForDescription.hidden = NO;
+ self.labelDescription.text = [NSString stringWithFormat:@"%@ has declined this request.",self.activityDetail.user_name];
+ self.buttonDescription.hidden = NO;
+ [self.buttonDescription setTitle:@"Request to View" forState:UIControlStateNormal];
+ }
+ else if ([self.activityDetail.network_status integerValue] == 0) {
+ self.viewForDescription.hidden = NO;
+ self.labelDescription.text = @"Pending Approval";
+ self.buttonDescription.hidden = YES;
+ }
+ }
+
+
+ });
}
View
894 AgentBridge/ABridge_ActivityViewController.m
@@ -197,405 +197,486 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection
-// NSString *parameters = [NSString stringWithFormat:@"?user_id=%@&activities_id=%@", self.loginDetail.user_id, [entryActivities valueForKey:@"activities_id"]];
-// // NSLog(@"25 parameters:%@",parameters);
-// NSString *urlString = [NSString stringWithFormat:@"http://keydiscoveryinc.com/agent_bridge/webservice/getactivity-%@.php%@", [entryActivities valueForKey:@"activity_type"], parameters];
-//
-//// NSLog(@"url:%@",urlString);
-// self.activityIndicator.hidden = NO;
-// [self.activityIndicator startAnimating];
-// __block NSError *errorData = nil;
-// __block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:urlString]];
-// [request setCompletionBlock:^{
-// // Use when fetching text data
-// // NSString *responseString = [request responseString];
-// // Use when fetching binary data
-// NSData *responseData = [request responseData];
-// NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingAllowFragments error:&errorData];
-// if ([[json objectForKey:@"data"] count]) {
-// // NSLog(@"25 Did Finish:%i", [[json objectForKey:@"data"] count]);
-// // 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"]) {
-// NSDictionary *entry = [[json objectForKey:@"data"] firstObject];
-// Activity *activity = nil;
-//
-// NSPredicate * predicate = [NSPredicate predicateWithFormat:@"activities_id == %@", [entry objectForKey:@"activities_id"]];
-// NSArray *result = [self fetchObjectsWithEntityName:@"Activity" andPredicate:predicate];
-// if ([result count]) {
-// activity = (Activity*)[result firstObject];
-// }
-// else {
-// activity = [NSEntityDescription insertNewObjectForEntityForName: @"Activity" inManagedObjectContext: context];
+ NSString *parameters = [NSString stringWithFormat:@"?user_id=%@&activities_id=%@", self.loginDetail.user_id, [entryActivities valueForKey:@"activities_id"]];
+ // NSLog(@"25 parameters:%@",parameters);
+ NSString *urlString = [NSString stringWithFormat:@"http://keydiscoveryinc.com/agent_bridge/webservice/getactivity-%@.php%@", [entryActivities valueForKey:@"activity_type"], parameters];
+
+// NSLog(@"url:%@",urlString);
+ self.activityIndicator.hidden = NO;
+ [self.activityIndicator startAnimating];
+ __block NSError *errorData = nil;
+ __block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:urlString]];
+ [request setCompletionBlock:^{
+ // Use when fetching text data
+ // NSString *responseString = [request responseString];
+ // Use when fetching binary data
+ NSData *responseData = [request responseData];
+ NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingAllowFragments error:&errorData];
+ if ([[json objectForKey:@"data"] count]) {
+ NSManagedObjectContext *context = ((ABridge_AppDelegate *)[[UIApplication sharedApplication] delegate]).managedObjectContext;
+
+ NSDictionary *entry = [[json objectForKey:@"data"] firstObject];
+ Activity *activity = nil;
+
+ NSPredicate * predicate = [NSPredicate predicateWithFormat:@"activities_id == %@", [entry objectForKey:@"activities_id"]];
+ NSArray *result = [self fetchObjectsWithEntityName:@"Activity" andPredicate:predicate];
+ if ([result count]) {
+ activity = (Activity*)[result firstObject];
+ }
+ else {
+ activity = [NSEntityDescription insertNewObjectForEntityForName: @"Activity" inManagedObjectContext: context];
+ }
+
+ if ([[entryActivities valueForKey:@"activity_type"] integerValue] == 11) {
+ if ([result count]) {
+
+ if (![self compareLatestStatusFrom:[entry valueForKey:@"referral_status"] To:[activity valueForKey:@"referral_status"]]) {
+ [activity setValuesForKeysWithDictionary:entry];
+ }
+ }
+ else {
+ [activity setValuesForKeysWithDictionary:entry];
+ }
+ }
+ else {
+ [activity setValuesForKeysWithDictionary:entry];
+ }
+
+ NSError *error = nil;
+ if (![context save:&error]) {
+ NSLog(@"Error on saving Activity:%@",[error localizedDescription]);
+ }
+ 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];
+ }
+
+ 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];
+
+ CGRect frame = self.activityIndicator.frame;
+ frame.origin.x = self.labelNumberOfActivity.frame.origin.x + self.labelNumberOfActivity.frame.size.width + 10.0f;
+ self.activityIndicator.frame = frame;
+
+ if (![[[self.arrayOfActivity objectAtIndex:0] class] isSubclassOfClass:[NSNull class]]) {
+ [self reloadPages];
+ }
+ }
+
+
+ [self.activityIndicator stopAnimating];
+ self.activityIndicator.hidden = YES;
+
+ }];
+ [request setFailedBlock:^{
+ NSError *error = [request error];
+ NSLog(@"error:%@",error);
+ [self.activityIndicator stopAnimating];
+ self.activityIndicator.hidden = YES;
+ }];
+ [request startAsynchronous];
+
+
+// if ([[entryActivities valueForKey:@"activity_type"] integerValue] == 25) {
+// NSString *parameters = [NSString stringWithFormat:@"?user_id=%@&activities_id=%@", self.loginDetail.user_id, [entryActivities valueForKey:@"activities_id"]];
+//// NSLog(@"25 parameters:%@",parameters);
+// NSString *urlString = [NSString stringWithFormat:@"http://keydiscoveryinc.com/agent_bridge/webservice/getactivity-25.php%@",parameters];
+//
+//
+// self.activityIndicator.hidden = NO;
+// [self.activityIndicator startAnimating];
+// __block NSError *errorData = nil;
+// __block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:urlString]];
+// [request setCompletionBlock:^{
+// // Use when fetching text data
+//// NSString *responseString = [request responseString];
+// // Use when fetching binary data
+// NSData *responseData = [request responseData];
+// NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingAllowFragments error:&errorData];
+// if ([[json objectForKey:@"data"] count]) {
+//// NSLog(@"25 Did Finish:%i", [[json objectForKey:@"data"] count]);
+//// 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"]) {
+// NSDictionary *entry = [[json objectForKey:@"data"] firstObject];
+// Activity *activity = nil;
+//
+// NSPredicate * predicate = [NSPredicate predicateWithFormat:@"activities_id == %@", [entry objectForKey:@"activities_id"]];
+// NSArray *result = [self fetchObjectsWithEntityName:@"Activity" andPredicate:predicate];
+// if ([result count]) {
+// activity = (Activity*)[result firstObject];
+// }
+// else {
+// activity = [NSEntityDescription insertNewObjectForEntityForName: @"Activity" inManagedObjectContext: context];
+// }
+//
+// [activity setValuesForKeysWithDictionary:entry];
+//
+// // NSLog(@"activity:%@",activity);
+// NSError *error = nil;
+// if (![context save:&error]) {
+// NSLog(@"Error on saving Activity:%@",[error localizedDescription]);
+// }
+// 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];
+//
+// CGRect frame = self.activityIndicator.frame;
+// frame.origin.x = self.labelNumberOfActivity.frame.origin.x + self.labelNumberOfActivity.frame.size.width + 10.0f;
+// self.activityIndicator.frame = frame;
+//
+//// if (self.pageController == nil/* && ![[self.arrayOfActivity objectAtIndex:0] isEqual:[NSNull null]]*/) {
+//// [self reloadPages];
+//// }
+//// });
+//// });
// }
//
-//// [activity setValuesForKeysWithDictionary:entry];
+// [self.activityIndicator stopAnimating];
+// self.activityIndicator.hidden = YES;
+//
+// }];
+// [request setFailedBlock:^{
+// NSError *error = [request error];
+// NSLog(@"25 error:%@",error);
+// [self.activityIndicator stopAnimating];
+// self.activityIndicator.hidden = YES;
+// }];
+// [request startAsynchronous];
+//
+//
+//
+// }
+// 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(@"11 parameters:%@",parameters);
+//
+// NSString *urlString = [NSString stringWithFormat:@"http://keydiscoveryinc.com/agent_bridge/webservice/getactivity-11.php%@",parameters];
+//
+// self.activityIndicator.hidden = NO;
+// [self.activityIndicator startAnimating];
+// __block NSError *errorData = nil;
+// __block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:urlString]];
+// [request setCompletionBlock:^{
+// // Use when fetching text data
+// // NSString *responseString = [request responseString];
+// // Use when fetching binary data
+// NSData *responseData = [request responseData];
+// NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingAllowFragments error:&errorData];
//
-// if ([[entryActivities valueForKey:@"activity_type"] integerValue] == 11) {
-// if ([result count]) {
+// for (NSDictionary *entry in [json objectForKey:@"data"]) {
+//
+// if ([[json objectForKey:@"data"] count]) {
+//// NSLog(@"11 Did Finish:%i", [[json objectForKey:@"data"] count]);
+// // 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"]) {
+//// NSDictionary *entry = [[json objectForKey:@"data"] firstObject];
+// Activity *activity = nil;
//
-// if (![self compareLatestStatusFrom:[entry valueForKey:@"referral_status"] To:[activity valueForKey:@"referral_status"]]) {
+// NSPredicate * predicate = [NSPredicate predicateWithFormat:@"activities_id == %@", [entry objectForKey:@"activities_id"]];
+// NSArray *result = [self fetchObjectsWithEntityName:@"Activity" andPredicate:predicate];
+// if ([result count]) {
+// activity = (Activity*)[result firstObject];
+// }
+// else {
+// activity = [NSEntityDescription insertNewObjectForEntityForName: @"Activity" inManagedObjectContext: context];
+// }
+//
+//// NSLog(@"status:%@ -- %@",[entry valueForKey:@"referral_status"], [activity valueForKey:@"referral_status"]);
+// if ([result count]) {
+//
+// if (![self compareLatestStatusFrom:[entry valueForKey:@"referral_status"] To:[activity valueForKey:@"referral_status"]]) {
+// [activity setValuesForKeysWithDictionary:entry];
+// }
+// }
+// else {
// [activity setValuesForKeysWithDictionary:entry];
// }
+//
+//
+//
+//// NSLog(@"%i activity:%@",[result count],activity);
+// NSError *error = nil;
+// if (![context save:&error]) {
+// NSLog(@"Error on saving Activity:%@",[error localizedDescription]);
+// }
+// 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];
+//
+// CGRect frame = self.activityIndicator.frame;
+// frame.origin.x = self.labelNumberOfActivity.frame.origin.x + self.labelNumberOfActivity.frame.size.width + 10.0f;
+// self.activityIndicator.frame = frame;
+//
+//// if (self.pageController == nil/* && ![[self.arrayOfActivity objectAtIndex:0] isEqual:[NSNull null]]*/) {
+//// [self reloadPages];
+//// }
+// // });
+// // });
+// }
+// }
+//
+//
+// [self.activityIndicator stopAnimating];
+// self.activityIndicator.hidden = YES;
+// }];
+// [request setFailedBlock:^{
+// NSError *error = [request error];
+// NSLog(@"11 error:%@",error);
+// [self.activityIndicator stopAnimating];
+// self.activityIndicator.hidden = YES;
+// }];
+// [request startAsynchronous];
+//
+//
+// }
+// else if ([[entryActivities valueForKey:@"activity_type"] integerValue] == 6) {
+// NSString *parameters = [NSString stringWithFormat:@"?user_id=%@&activities_id=%@", self.loginDetail.user_id, [entryActivities valueForKey:@"activities_id"]];
+//
+// NSString *urlString = [NSString stringWithFormat:@"http://keydiscoveryinc.com/agent_bridge/webservice/getactivity-6.php%@",parameters];
+//
+//
+// self.activityIndicator.hidden = NO;
+// [self.activityIndicator startAnimating];
+// __block NSError *errorData = nil;
+// __block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:urlString]];
+// [request setCompletionBlock:^{
+// // Use when fetching text data
+// // NSString *responseString = [request responseString];
+// // Use when fetching binary data
+// NSData *responseData = [request responseData];
+// NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingAllowFragments error:&errorData];
+// if ([[json objectForKey:@"data"] count]) {
+// // NSLog(@"25 Did Finish:%i", [[json objectForKey:@"data"] count]);
+// // 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"]) {
+// NSDictionary *entry = [[json objectForKey:@"data"] firstObject];
+// Activity *activity = nil;
+//
+// NSPredicate * predicate = [NSPredicate predicateWithFormat:@"activities_id == %@", [entry objectForKey:@"activities_id"]];
+// NSArray *result = [self fetchObjectsWithEntityName:@"Activity" andPredicate:predicate];
+// if ([result count]) {
+// activity = (Activity*)[result firstObject];
// }
// else {
-// [activity setValuesForKeysWithDictionary:entry];
+// activity = [NSEntityDescription insertNewObjectForEntityForName: @"Activity" inManagedObjectContext: context];
// }
-// }
-// else {
+//
// [activity setValuesForKeysWithDictionary:entry];
-// }
-//
-//// NSLog(@"activity:%@",activity);
-// NSError *error = nil;
-// if (![context save:&error]) {
-// NSLog(@"Error on saving Activity:%@",[error localizedDescription]);
-// }
-// else {
-// if (self.arrayOfActivity == nil) {
-// self.arrayOfActivity = [NSMutableArray array];
-// for(int i = 0; i<[[jsonActivities objectForKey:@"data"] count]; i++)
-// [self.arrayOfActivity addObject: [NSNull null]];
+//
+// // NSLog(@"activity:%@",activity);
+// NSError *error = nil;
+// if (![context save:&error]) {
+// NSLog(@"Error on saving Activity:%@",[error localizedDescription]);
+// }
+// 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];
// }
//
-// // [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];
+//
+// CGRect frame = self.activityIndicator.frame;
+// frame.origin.x = self.labelNumberOfActivity.frame.origin.x + self.labelNumberOfActivity.frame.size.width + 10.0f;
+// self.activityIndicator.frame = frame;
+//
+//// if (self.pageController == nil/* && ![[self.arrayOfActivity objectAtIndex:0] isEqual:[NSNull null]]*/) {
+//// [self reloadPages];
+//// }
+// // });
+// // });
// }
//
-// // NSLog(@"25 Did Finish:%i [%i] %i", [self.arrayOfURL_25 count], [self.arrayOfActivity count], self.index_25);
-//
-// // dispatch_async(dispatch_get_main_queue(), ^{
+// [self.activityIndicator stopAnimating];
+// self.activityIndicator.hidden = YES;
//
-// 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];
+// }];
+// [request setFailedBlock:^{
+// NSError *error = [request error];
+// NSLog(@"25 error:%@",error);
+// [self.activityIndicator stopAnimating];
+// self.activityIndicator.hidden = YES;
+// }];
+// [request startAsynchronous];
+//
+//
+//
+// }
+// else if ([[entryActivities valueForKey:@"activity_type"] integerValue] == 8 || [[entryActivities valueForKey:@"activity_type"] integerValue] == 28) {
+// NSString *parameters = [NSString stringWithFormat:@"?user_id=%@&activities_id=%@", self.loginDetail.user_id, [entryActivities valueForKey:@"activities_id"]];
+//
+// NSString *urlString = [NSString stringWithFormat:@"http://keydiscoveryinc.com/agent_bridge/webservice/getactivity-%@.php%@",[entryActivities valueForKey:@"activity_type"],parameters];
+//
+//// NSLog(@"url:%@",urlString);
+// self.activityIndicator.hidden = NO;
+// [self.activityIndicator startAnimating];
+// __block NSError *errorData = nil;
+// __block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:urlString]];
+// [request setCompletionBlock:^{
+// // Use when fetching text data
+// // NSString *responseString = [request responseString];
+// // Use when fetching binary data
+// NSData *responseData = [request responseData];
+// NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingAllowFragments error:&errorData];
+// if ([[json objectForKey:@"data"] count]) {
+// // NSLog(@"25 Did Finish:%i", [[json objectForKey:@"data"] count]);
+// // 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"]) {
+// NSDictionary *entry = [[json objectForKey:@"data"] firstObject];
+// Activity *activity = nil;
+//
+// NSPredicate * predicate = [NSPredicate predicateWithFormat:@"activities_id == %@", [entry objectForKey:@"activities_id"]];
+// NSArray *result = [self fetchObjectsWithEntityName:@"Activity" andPredicate:predicate];
+// if ([result count]) {
+// activity = (Activity*)[result firstObject];
+// }
+// else {
+// activity = [NSEntityDescription insertNewObjectForEntityForName: @"Activity" inManagedObjectContext: context];
+// }
+//
+// [activity setValuesForKeysWithDictionary:entry];
+//
+// // NSLog(@"activity:%@",activity);
+// NSError *error = nil;
+// if (![context save:&error]) {
+// NSLog(@"Error on saving Activity:%@",[error localizedDescription]);
+// }
+// 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];
+//
+// CGRect frame = self.activityIndicator.frame;
+// frame.origin.x = self.labelNumberOfActivity.frame.origin.x + self.labelNumberOfActivity.frame.size.width + 10.0f;
+// self.activityIndicator.frame = frame;
+//
+//// if (self.pageController == nil/* && ![[self.arrayOfActivity objectAtIndex:0] isEqual:[NSNull null]]*/) {
+//// [self reloadPages];
+//// }
+// // });
+// // });
+// }
//
-// CGRect frame = self.activityIndicator.frame;
-// frame.origin.x = self.labelNumberOfActivity.frame.origin.x + self.labelNumberOfActivity.frame.size.width + 10.0f;
-// self.activityIndicator.frame = frame;
+// [self.activityIndicator stopAnimating];
+// self.activityIndicator.hidden = YES;
//
-//// NSLog(@"self.pageController:%@",[self.arrayOfActivity objectAtIndex:0]);
-// if (self.pageController == nil/* && ![[self.arrayOfActivity objectAtIndex:0] isEqual:[NSNull null]]*/) {
-// [self reloadPages];
-// }
-// // });
-// // });
-// }
+// }];
+// [request setFailedBlock:^{
+// NSError *error = [request error];
+// NSLog(@"25 error:%@",error);
+// [self.activityIndicator stopAnimating];
+// self.activityIndicator.hidden = YES;
+// }];
+// [request startAsynchronous];
//
//
-// [self.activityIndicator stopAnimating];
-// self.activityIndicator.hidden = YES;
//
-// }];
-// [request setFailedBlock:^{
-// NSError *error = [request error];
-// NSLog(@"25 error:%@",error);
-// [self.activityIndicator stopAnimating];
-// self.activityIndicator.hidden = YES;
-// }];
-// [request startAsynchronous];
-
-
-
- if ([[entryActivities valueForKey:@"activity_type"] integerValue] == 25) {
- NSString *parameters = [NSString stringWithFormat:@"?user_id=%@&activities_id=%@", self.loginDetail.user_id, [entryActivities valueForKey:@"activities_id"]];
-// NSLog(@"25 parameters:%@",parameters);
- NSString *urlString = [NSString stringWithFormat:@"http://keydiscoveryinc.com/agent_bridge/webservice/getactivity-25.php%@",parameters];
-
-
- self.activityIndicator.hidden = NO;
- [self.activityIndicator startAnimating];
- __block NSError *errorData = nil;
- __block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:urlString]];
- [request setCompletionBlock:^{
- // Use when fetching text data
-// NSString *responseString = [request responseString];
- // Use when fetching binary data
- NSData *responseData = [request responseData];
- NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingAllowFragments error:&errorData];
- if ([[json objectForKey:@"data"] count]) {
-// NSLog(@"25 Did Finish:%i", [[json objectForKey:@"data"] count]);
-// 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"]) {
- NSDictionary *entry = [[json objectForKey:@"data"] firstObject];
- Activity *activity = nil;
-
- NSPredicate * predicate = [NSPredicate predicateWithFormat:@"activities_id == %@", [entry objectForKey:@"activities_id"]];
- NSArray *result = [self fetchObjectsWithEntityName:@"Activity" andPredicate:predicate];
- if ([result count]) {
- activity = (Activity*)[result firstObject];
- }
- else {
- activity = [NSEntityDescription insertNewObjectForEntityForName: @"Activity" inManagedObjectContext: context];
- }
-
- [activity setValuesForKeysWithDictionary:entry];
-
- // NSLog(@"activity:%@",activity);
- NSError *error = nil;
- if (![context save:&error]) {
- NSLog(@"Error on saving Activity:%@",[error localizedDescription]);
- }
- 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];
-
- CGRect frame = self.activityIndicator.frame;
- frame.origin.x = self.labelNumberOfActivity.frame.origin.x + self.labelNumberOfActivity.frame.size.width + 10.0f;
- self.activityIndicator.frame = frame;
-
- if (self.pageController == nil/* && ![[self.arrayOfActivity objectAtIndex:0] isEqual:[NSNull null]]*/) {
- [self reloadPages];
- }
-// });
-// });
- }
-
- [self.activityIndicator stopAnimating];
- self.activityIndicator.hidden = YES;
-
- }];
- [request setFailedBlock:^{
- NSError *error = [request error];
- NSLog(@"25 error:%@",error);
- [self.activityIndicator stopAnimating];
- self.activityIndicator.hidden = YES;
- }];
- [request startAsynchronous];
-
-
-
- }
- 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(@"11 parameters:%@",parameters);
-
- NSString *urlString = [NSString stringWithFormat:@"http://keydiscoveryinc.com/agent_bridge/webservice/getactivity-11.php%@",parameters];
-
- self.activityIndicator.hidden = NO;
- [self.activityIndicator startAnimating];
- __block NSError *errorData = nil;
- __block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:urlString]];
- [request setCompletionBlock:^{
- // Use when fetching text data
- // NSString *responseString = [request responseString];
- // Use when fetching binary data
- NSData *responseData = [request responseData];
- NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingAllowFragments error:&errorData];
-
- for (NSDictionary *entry in [json objectForKey:@"data"]) {
-
- if ([[json objectForKey:@"data"] count]) {
-// NSLog(@"11 Did Finish:%i", [[json objectForKey:@"data"] count]);
- // 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"]) {
-// NSDictionary *entry = [[json objectForKey:@"data"] firstObject];
- Activity *activity = nil;
-
- NSPredicate * predicate = [NSPredicate predicateWithFormat:@"activities_id == %@", [entry objectForKey:@"activities_id"]];
- NSArray *result = [self fetchObjectsWithEntityName:@"Activity" andPredicate:predicate];
- if ([result count]) {
- activity = (Activity*)[result firstObject];
- }
- else {
- activity = [NSEntityDescription insertNewObjectForEntityForName: @"Activity" inManagedObjectContext: context];
- }
-
-// NSLog(@"status:%@ -- %@",[entry valueForKey:@"referral_status"], [activity valueForKey:@"referral_status"]);
- if ([result count]) {
-
- if (![self compareLatestStatusFrom:[entry valueForKey:@"referral_status"] To:[activity valueForKey:@"referral_status"]]) {
- [activity setValuesForKeysWithDictionary:entry];
- }
- }
- else {
- [activity setValuesForKeysWithDictionary:entry];
- }
-
-
-
-// NSLog(@"%i activity:%@",[result count],activity);
- NSError *error = nil;
- if (![context save:&error]) {
- NSLog(@"Error on saving Activity:%@",[error localizedDescription]);
- }
- 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];
-
- CGRect frame = self.activityIndicator.frame;
- frame.origin.x = self.labelNumberOfActivity.frame.origin.x + self.labelNumberOfActivity.frame.size.width + 10.0f;
- self.activityIndicator.frame = frame;
-
- if (self.pageController == nil/* && ![[self.arrayOfActivity objectAtIndex:0] isEqual:[NSNull null]]*/) {
- [self reloadPages];
- }
- // });
- // });
- }
- }
-
-
- [self.activityIndicator stopAnimating];
- self.activityIndicator.hidden = YES;
- }];
- [request setFailedBlock:^{
- NSError *error = [request error];
- NSLog(@"11 error:%@",error);
- [self.activityIndicator stopAnimating];
- self.activityIndicator.hidden = YES;
- }];
- [request startAsynchronous];
-
-
- }
- else if ([[entryActivities valueForKey:@"activity_type"] integerValue] == 6) {
- NSString *parameters = [NSString stringWithFormat:@"?user_id=%@&activities_id=%@", self.loginDetail.user_id, [entryActivities valueForKey:@"activities_id"]];
-
- NSString *urlString = [NSString stringWithFormat:@"http://keydiscoveryinc.com/agent_bridge/webservice/getactivity-6.php%@",parameters];
-
-
- self.activityIndicator.hidden = NO;
- [self.activityIndicator startAnimating];
- __block NSError *errorData = nil;
- __block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:urlString]];
- [request setCompletionBlock:^{
- // Use when fetching text data
- // NSString *responseString = [request responseString];
- // Use when fetching binary data
- NSData *responseData = [request responseData];
- NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingAllowFragments error:&errorData];
- if ([[json objectForKey:@"data"] count]) {
- // NSLog(@"25 Did Finish:%i", [[json objectForKey:@"data"] count]);
- // 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"]) {
- NSDictionary *entry = [[json objectForKey:@"data"] firstObject];
- Activity *activity = nil;
-
- NSPredicate * predicate = [NSPredicate predicateWithFormat:@"activities_id == %@", [entry objectForKey:@"activities_id"]];
- NSArray *result = [self fetchObjectsWithEntityName:@"Activity" andPredicate:predicate];
- if ([result count]) {
- activity = (Activity*)[result firstObject];
- }
- else {
- activity = [NSEntityDescription insertNewObjectForEntityForName: @"Activity" inManagedObjectContext: context];
- }
-
- [activity setValuesForKeysWithDictionary:entry];
-
- // NSLog(@"activity:%@",activity);
- NSError *error = nil;
- if (![context save:&error]) {
- NSLog(@"Error on saving Activity:%@",[error localizedDescription]);
- }
- 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];
-
- CGRect frame = self.activityIndicator.frame;
- frame.origin.x = self.labelNumberOfActivity.frame.origin.x + self.labelNumberOfActivity.frame.size.width + 10.0f;
- self.activityIndicator.frame = frame;
-
- if (self.pageController == nil/* && ![[self.arrayOfActivity objectAtIndex:0] isEqual:[NSNull null]]*/) {
- [self reloadPages];
- }
- // });
- // });
- }
-
- [self.activityIndicator stopAnimating];
- self.activityIndicator.hidden = YES;
-
- }];
- [request setFailedBlock:^{
- NSError *error = [request error];
- NSLog(@"25 error:%@",error);
- [self.activityIndicator stopAnimating];
- self.activityIndicator.hidden = YES;
- }];
- [request startAsynchronous];
-
-
-
- }
- }
+// }
+
+
+ } //end of for loop
}
else {
@@ -624,33 +705,34 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection
- (void) reloadPages {
- if(![self.arrayOfActivity containsObject:[NSNull null]]){
- dispatch_async(dispatch_get_main_queue(), ^{
-
- [self.pageController.view removeFromSuperview];
- [self.pageController removeFromParentViewController];
- self.pageController = nil;
-
- self.pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
-
- self.pageController.dataSource = self;
- CGRect pageControllerFrame = self.viewForPages.frame;
- pageControllerFrame.origin.x = 0.0f;
- pageControllerFrame.origin.y = 1.0f;
- self.pageController.view.frame = pageControllerFrame;
-
- ABridge_ActivityPagesViewController *initialViewController = [self viewControllerAtIndex:0];
-
- NSArray *viewControllers = [NSArray arrayWithObject:initialViewController];
-
- [self.pageController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
-
- [self addChildViewController:self.pageController];
- [[self viewForPages] addSubview:[self.pageController view]];
- [self.pageController didMoveToParentViewController:self];
-
- });
+ if (self.pageController == nil) {
+ dispatch_async(dispatch_get_main_queue(), ^{
+
+ [self.pageController.view removeFromSuperview];
+ [self.pageController removeFromParentViewController];
+ self.pageController = nil;
+
+ self.pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
+
+ self.pageController.dataSource = self;
+ CGRect pageControllerFrame = self.viewForPages.frame;
+ pageControllerFrame.origin.x = 0.0f;
+ pageControllerFrame.origin.y = 1.0f;
+ self.pageController.view.frame = pageControllerFrame;
+
+ ABridge_ActivityPagesViewController *initialViewController = [self viewControllerAtIndex:0];
+
+ NSArray *viewControllers = [NSArray arrayWithObject:initialViewController];
+
+ [self.pageController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
+
+ [self addChildViewController:self.pageController];
+ [[self viewForPages] addSubview:[self.pageController view]];
+ [self.pageController didMoveToParentViewController:self];
+
+ });
}
+
}
- (void) reloadData {
@@ -669,7 +751,7 @@ - (void) reloadData {
NSString *parameters = [NSString stringWithFormat:@"?user_id=%@", self.loginDetail.user_id];
// NSLog(@"parameters:%@",parameters);
- self.urlConnectionActivity = [self urlConnectionWithURLString:@"http://keydiscoveryinc.com/agent_bridge/webservice/getactivity.php" andParameters:parameters];
+ self.urlConnectionActivity = [self urlConnectionWithURLString:@"http://keydiscoveryinc.com/agent_bridge/webservice/getactivity-test.php" andParameters:parameters];
if (self.urlConnectionActivity) {
[self addURLConnection:self.urlConnectionActivity];
View
1  AgentBridge/ABridge_AgentInvitesViewController.h
@@ -7,6 +7,7 @@
//
#import "ABridge_ParentViewController.h"
+#import "ASIHTTPRequest.h"
@interface ABridge_AgentInvitesViewController : ABridge_ParentViewController
View
68 AgentBridge/ABridge_AgentInvitesViewController.m
@@ -7,6 +7,7 @@
//
#import "ABridge_AgentInvitesViewController.h"
+#import "AgentProfile.h"
@interface ABridge_AgentInvitesViewController ()
@property (weak, nonatomic) IBOutlet UILabel *labelInviteTitle;
@@ -17,9 +18,12 @@ @interface ABridge_AgentInvitesViewController ()
@property (weak, nonatomic) IBOutlet UIButton *buttonSend;
- (IBAction)sendInvite:(id)sender;
+@property (assign, nonatomic) NSInteger numberOfInvites;
+
@end
@implementation ABridge_AgentInvitesViewController
+@synthesize numberOfInvites;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
@@ -51,6 +55,70 @@ - (void)viewDidLoad
[self addPaddingAndBorder:self.textFieldLastname color:[UIColor colorWithRed:178.0f/255.0f green:178.0f/255.0f blue:178.0f/255.0f alpha:1.0f]];
[self addPaddingAndBorder:self.textFieldZipcode color:[UIColor colorWithRed:178.0f/255.0f green:178.0f/255.0f blue:178.0f/255.0f alpha:1.0f]];
+
+ NSManagedObjectContext *context = ((ABridge_AppDelegate *)[[UIApplication sharedApplication] delegate]).managedObjectContext;
+
+ NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
+ NSEntityDescription *entity = [NSEntityDescription entityForName:@"LoginDetails" inManagedObjectContext:context];
+ [fetchRequest setEntity:entity];
+ NSError *error = nil;
+ NSArray *fetchedObjects = [context
+ executeFetchRequest:fetchRequest error:&error];
+
+ fetchRequest = [[NSFetchRequest alloc] init];
+ entity = [NSEntityDescription entityForName:@"AgentProfile"
+ inManagedObjectContext:context];
+ [fetchRequest setEntity:entity];
+
+ error = nil;
+ fetchedObjects = nil;
+ fetchedObjects = [context executeFetchRequest:fetchRequest error:&error];
+
+ AgentProfile *profileData = nil;
+ for (AgentProfile *profile in fetchedObjects) {
+ if ([profile.user_id integerValue] == [[[fetchedObjects firstObject] valueForKey:@"user_id"] integerValue]) {
+ profileData = profile;
+ break;
+ }
+ }
+
+
+ NSString *parameters = [NSString stringWithFormat:@"?profile_id=%@", profileData.profile_id];
+
+ NSString *urlString = [NSString stringWithFormat:@"http://keydiscoveryinc.com/agent_bridge/webservice/getinvites.php%@",parameters];
+
+ __block NSError *errorData = nil;
+ __block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:urlString]];
+ [request setCompletionBlock:^{
+ NSData *responseData = [request responseData];
+ NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingAllowFragments error:&errorData];
+
+ self.numberOfInvites = 10 - [[json objectForKey:@"data"] count];
+
+ if (self.numberOfInvites < 1) {
+ self.labelInviteTitle.text = [NSString stringWithFormat:@"You have used up all your invite credits.",self.numberOfInvites];
+ [self.labelInviteTitle sizeToFit];
+
+ self.textFieldEmail.hidden = YES;
+ self.textFieldFirstname.hidden = YES;
+ self.textFieldLastname.hidden = YES;
+ self.textFieldZipcode.hidden = YES;
+ self.buttonSend.hidden = YES;
+ }
+ else {
+
+ self.labelInviteTitle.text = [NSString stringWithFormat:@"You may sponsor %i agents for membership.",self.numberOfInvites];
+ [self.labelInviteTitle sizeToFit];
+ }
+
+ }];
+ [request setFailedBlock:^{
+ NSError *error = [request error];
+ NSLog(@"25 error:%@",error);
+
+ }];
+ [request startAsynchronous];
+
}
- (void)didReceiveMemoryWarning
View
10 AgentBridge/Main.storyboard
@@ -1187,12 +1187,12 @@
</subviews>
</view>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="Firstname" minimumFontSize="17" id="t22-Gv-DJ8">
- <rect key="frame" x="20" y="124" width="280" height="30"/>
+ <rect key="frame" x="20" y="129" width="280" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
</textField>
- <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="My Invites" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="Tdb-mo-Oa6">
+ <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="Tdb-mo-Oa6">
<rect key="frame" x="20" y="68" width="280" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
@@ -1200,19 +1200,19 @@
<nil key="highlightedColor"/>
</label>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="Lastname" minimumFontSize="17" id="U9W-Yc-JAg">
- <rect key="frame" x="20" y="162" width="280" height="30"/>
+ <rect key="frame" x="20" y="167" width="280" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
</textField>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="Email" minimumFontSize="17" id="vTd-Ar-36N">
- <rect key="frame" x="20" y="200" width="280" height="30"/>
+ <rect key="frame" x="20" y="205" width="280" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
</textField>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="Zipcode" minimumFontSize="17" id="hPM-WY-Zkb">
- <rect key="frame" x="20" y="238" width="126" height="30"/>
+ <rect key="frame" x="20" y="243" width="126" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
Please sign in to comment.
Something went wrong with that request. Please try again.