#import "NotificationViewController.h" | |
#import "CoreDataManager.h" | |
#import "NotificationEntity.h" | |
#import "NotificationViewCell.h" | |
#import "PeopleDetailViewController.h" | |
#import "PlaceDetailViewController.h" | |
@interface NotificationViewController () | |
@end | |
@implementation NotificationViewController | |
@synthesize tableView1; | |
@synthesize noticListArr; | |
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
// Do any additional setup after loading the view from its nib. | |
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:navigationBarBGSmall] forBarMetrics:UIBarMetricsDefault];//bgNavBarDetail_1.png | |
self.title=NSLocalizedString(@"notification", nil); | |
// noticListArr=[[NSMutableArray alloc]init]; | |
dispatch_queue_t downloadQueue = dispatch_queue_create("noticaitong login", NULL); | |
dispatch_async(downloadQueue, ^{ | |
NSManagedObjectContext *managedObjectContext =[self getManagedObjectContext]; | |
self.noticListArr=[[CoreDataManager sharedInstance] readEvent:@"NotificationEntity" SortDescriptor:nil managedObjectContext:managedObjectContext]; | |
NSLog(@"noticListArr.count:%d ",noticListArr.count); | |
}); | |
dispatch_async(dispatch_get_main_queue(), ^{ | |
[self.tableView1 reloadData]; | |
}); | |
dispatch_release(downloadQueue); | |
} | |
-(void)refreshData{ | |
dispatch_queue_t downloadQueue = dispatch_queue_create("socket login", NULL); | |
dispatch_async(downloadQueue, ^{ | |
NSManagedObjectContext *managedObjectContext =[self getManagedObjectContext]; | |
self.noticListArr=[[CoreDataManager sharedInstance] readEvent:@"NotificationEntity" SortDescriptor:nil managedObjectContext:managedObjectContext]; | |
NSLog(@"refreshData.count:%d ",noticListArr.count); | |
for(int i=0;i<noticListArr.count;i++){ | |
NotificationEntity *notificationEntity=[noticListArr objectAtIndex:i]; | |
NSLog(@"notificationEntity.name:%@ ",notificationEntity.name); | |
NSLog(@"notificationEntity.describeString:%@ ",notificationEntity.describeString); | |
NSLog(@"notificationEntity.source:%@", notificationEntity.source); | |
} | |
}); | |
dispatch_async(dispatch_get_main_queue(), ^{ | |
[self.tableView1 reloadData]; | |
}); | |
dispatch_release(downloadQueue); | |
} | |
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ | |
return 60; | |
} | |
#pragma mark - | |
#pragma mark Table view data source | |
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { | |
// Return the number of sections. | |
return 1; | |
} | |
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { | |
// Return the number of rows in the section. | |
return [ self.noticListArr count]; | |
} | |
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { | |
static NSString *CellIdentifier = @"NotificationViewCell"; | |
// NotificationEntity *notificationEntity = [[NotificationEntity alloc]initWithEntity:[NSEntityDescription entityForName:@"NotificationEntity" inManagedObjectContext:[self getManagedObjectContext]]insertIntoManagedObjectContext:[self getManagedObjectContext]]; | |
NotificationViewCell *cell = (NotificationViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; | |
NotificationEntity *notificationEntity=(NotificationEntity *)[ self.noticListArr objectAtIndex:indexPath.row]; | |
NSLog(@"tableViewnoticListArr.count:%d ",noticListArr.count); | |
NSLog(@"indexPath.row:%d ",indexPath.row); | |
NSLog(@"notificationTable.avatarsmall:%@", notificationEntity.avatarsmall); | |
NSLog(@"notificationTable.source:%@", notificationEntity.source); | |
NSLog(@"notificationTable.name:%@", notificationEntity.name); | |
NSLog(@"notificationTable.describeString:%@ ",notificationEntity.describeString); | |
if (cell == nil) | |
{ | |
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"NotificationViewCell" owner:self options:nil]; | |
for (id oneObject in nib) | |
if ([oneObject isKindOfClass:[NotificationViewCell class]]) { | |
cell = (NotificationViewCell *)oneObject; | |
break; | |
} | |
} | |
//set the cell with people info | |
if (![GlobalVariable isBlankString:notificationEntity.name]) | |
{ | |
cell.titleLabel.text = notificationEntity.name; | |
} | |
if (![GlobalVariable isBlankString:notificationEntity.describeString]) | |
{ | |
cell.describeLabel.text = notificationEntity.describeString; | |
} | |
if (![GlobalVariable isBlankString:notificationEntity.avatarsmall] && ![notificationEntity.avatarsmall isEqualToString:@"token_expire"]) | |
{ | |
AsyncImageView *imageView = (AsyncImageView *)[cell viewWithTag:106]; | |
[[AsyncImageLoader sharedLoader] cancelLoadingImagesForTarget:imageView]; | |
if([notificationEntity.subtype isEqualToString:@"beFollowed"] ||[notificationEntity.subtype isEqualToString:@"beFriends"]||[notificationEntity.subtype isEqualToString:@"nearby"]||[notificationEntity.subtype isEqualToString:@"yuanfen"]){ | |
imageView.imageURL = [NSURL URLWithString:notificationEntity.avatarsmall]; | |
}else if ([notificationEntity.subtype isEqualToString:@"poi"]){ | |
imageView.image=[UIImage imageNamed:[ModelClass returnPlacImage:notificationEntity.avatarsmall]]; | |
} | |
}else if([notificationEntity.avatarsmall isEqualToString:@"token_expire"]){ | |
AsyncImageView *imageView = (AsyncImageView *)[cell viewWithTag:106]; | |
imageView.image=[UIImage imageNamed:@"system_message.gif"]; | |
} | |
else { | |
AsyncImageView *imageView = (AsyncImageView *)[cell viewWithTag:106]; | |
imageView.image=[UIImage imageNamed:@"default_user.png"]; | |
} | |
if([GlobalVariable isBlankString:notificationEntity.source]) | |
{ | |
cell.sourceImage.hidden=YES; | |
}else{ | |
cell.sourceImage.hidden=NO; | |
cell.sourceImage.image=[UIImage imageNamed:[ModelClass returnimage_source:notificationEntity.source]]; | |
} | |
if (![GlobalVariable isBlankString:notificationEntity.when]) { | |
cell.distanceLabel.hidden=NO; | |
cell.distanceLabel.text =[GlobalVariable intervalSinceNow:notificationEntity.when]; | |
if ([GlobalVariable isBlankString:notificationEntity.distance] || [notificationEntity.distance intValue]<=0) { | |
// cell.distanceLabel.hidden=YES; | |
}else{ | |
cell.distanceLabel.text=[cell.distanceLabel.text stringByAppendingString:@"|"] ; | |
NSString *dis=[NSString stringWithFormat:@"%@",notificationEntity.distance]; | |
cell.distanceLabel.text=[cell.distanceLabel.text stringByAppendingString:dis]; | |
cell.distanceLabel.text=[cell.distanceLabel.text stringByAppendingString:@"m"]; | |
} | |
} | |
else { | |
if ([GlobalVariable isBlankString:notificationEntity.distance]) { | |
cell.distanceLabel.hidden=YES; | |
}else{ | |
NSString *dis=[NSString stringWithFormat:@"%@",notificationEntity.distance]; | |
cell.distanceLabel.text=dis; | |
} | |
} | |
return cell; | |
} | |
#pragma mark - | |
#pragma mark Table view delegate | |
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { | |
NotificationEntity *notificationEntity=[noticListArr objectAtIndex:indexPath.row]; | |
if([notificationEntity.subtype isEqualToString:@"authExp"]){ | |
if([notificationEntity.source isEqualToString:@"netease"]){ | |
} | |
}else if ([notificationEntity.subtype isEqualToString:@"beFollowed"] ||[notificationEntity.subtype isEqualToString:@"beFriends"]||[notificationEntity.subtype isEqualToString:@"nearby"]|| | |
[notificationEntity.subtype isEqualToString:@"yuanfen"]){ | |
NSLog(@"noticationHistory:didSelectRowAtIndexPath"); | |
[self JumpDetailView:notificationEntity]; | |
}else if ([notificationEntity.subtype isEqualToString:@"version"]){ | |
NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary]; | |
NSString* versionNum =[infoDict objectForKey:@"CFBundleVersion"]; | |
//这里要注意 为了简单 source 代表版本 forend 代表link | |
if( ![notificationEntity.source isEqualToString:versionNum]){ | |
versionLink=notificationEntity.foreignId; | |
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:NSLocalizedString(@"version_update", nil) | |
message:NSLocalizedString(@"version_message", nil) | |
delegate:self | |
cancelButtonTitle:NSLocalizedString(@"ok", nil) | |
otherButtonTitles:NSLocalizedString(@"cancel", nil),nil]; | |
[alert show]; | |
} | |
}else if([notificationEntity.subtype isEqualToString:@"poi"]){ | |
[self JumpPlaceDetailView:notificationEntity]; | |
}else if([notificationEntity.subtype isEqualToString:@"specials"]){ | |
[self JumpPlaceDetailView:notificationEntity]; | |
} | |
[tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
} | |
-(void)JumpDetailView:(NotificationEntity*)notificationEntity{ | |
PeopleDetailViewController *controller=[[PeopleDetailViewController alloc]init]; | |
UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:controller]; | |
controller.people_source=notificationEntity.source; | |
controller.people_foreignId=notificationEntity.foreignId; | |
controller.people_distance=notificationEntity.distance; | |
controller.people_lastActivity=@""; | |
[self.navigationController presentModalViewController:nav animated:NO]; | |
} | |
-(void)JumpPlaceDetailView:(NotificationEntity*)notificationEntity{ | |
PlaceDetailViewController *controller=[[PlaceDetailViewController alloc]init]; | |
controller.poiId=notificationEntity.foreignId; | |
controller.strTitle=notificationEntity.name; | |
UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:controller]; | |
[self.navigationController presentModalViewController:nav animated:NO]; | |
} | |
- (void)viewDidUnload | |
{ | |
[super viewDidUnload]; | |
} | |
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation | |
{ | |
return (interfaceOrientation == UIInterfaceOrientationPortrait); | |
} | |
////////////////////////////// | |
-(NSManagedObjectContext *)getManagedObjectContext{ | |
return [[CoreDataManager sharedInstance] managedObjectContext:@"PushNoticationModal.sqlite" managedObjectContext:[CoreDataManager sharedInstance].managedObjectContext]; | |
} | |
//version update | |
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex | |
{ | |
if (buttonIndex == 0) { | |
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:versionLink]]; | |
} | |
} | |
- (void)viewWillDisappear:(BOOL)animated | |
{ | |
[[CoreDataManager sharedInstance] saveContextWithmanagedObjectContext:[CoreDataManager sharedInstance].managedObjectContext]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment