// // DetailRelatedCell.m // RedAnt ERP Mobile // // Created by Ray on 14-7-31. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved. // #import "DetailTopicCell.h" #import "CategoryCellSmall.h" #import "DetailViewController.h" #import "DefaultAppearance.h" #import "AppDelegate.h" #import "FileCache.h" @implementation DetailTopicCell @synthesize itemdelegate; - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { // Initialization code } return self; } - (void)awakeFromNib { // Initialization code [super awakeFromNib]; self.refreshLabel.layer.borderColor = [UIColor darkGrayColor].CGColor; self.refreshLabel.layer.borderWidth = 2.0; self.refreshLabel.layer.cornerRadius=15; self.refreshLabel.layer.masksToBounds=true; } -(void) begin_refresh { self.topicCollectionView.hidden=true; self.refreshLabel.hidden=false; } -(void) end_refresh { self.topicCollectionView.hidden=false; self.refreshLabel.hidden=true; } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } #pragma mark -- UICollectionViewDataSource -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { // 每个Section的item个数 int count =[[self.related_data valueForKey:@"count"] intValue]; return count; } -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 1; } -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { NSString* value =[DefaultAppearance get_noneappearance_value:@"CategoryViewController" valuename:@"cell_border_color"]; if(value==nil) value=@""; unsigned long color = strtoul([value UTF8String],0,16); static NSString * CellIdentifier = @"RelatedModelCell"; CategoryCellSmall * cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath]; cell.cellImageView.contentMode = UIViewContentModeScaleAspectFit; NSDictionary * item_json =[self.related_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]]; NSString* img_url =[item_json valueForKey:@"picture_path"]; NSString* description =[item_json valueForKey:@"fash_name"]; // NSString* old_price =[item_json valueForKey:@"old_price"]; // NSString* price =[item_json valueForKey:@"price"]; cell.cellDescription.text = description; // cell.oldPrice.text = old_price; // cell.Price.text = price; NSString *loading = @"loading_s"; NSString * notFound = @"notfound_s"; cell.imageName = img_url; cell.cellImageView.image = [UIImage imageNamed:loading]; NSString* file_name=[img_url lastPathComponent]; NSData* img_data=[FileCache load_cached_img:file_name loadFrom:img_url]; if(img_data!=nil) { UIImage * img =[UIImage imageWithData:img_data]; cell.cellImageView.image = img; } else { // BOOL offline = NO; //#ifdef OFFLINE_MODE // AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate; // offline = appDelegate.offline_mode; //#endif dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSData* downloadimg_data = nil; //离线模式不会主动下载图片,避免同名图片覆盖离线图片。 // if (!offline) { downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]]; // } dispatch_async(dispatch_get_main_queue(), ^{ if(downloadimg_data!=nil) { [FileCache cache_img:downloadimg_data filename:file_name saveTo:img_url]; UIImage * img =[UIImage imageWithData:downloadimg_data]; cell.cellImageView.image = img; } else cell.cellImageView.image = [UIImage imageNamed:notFound]; }); }); } // if (![cell.imageName isEqualToString:img_url]) { // cell.imageName = img_url; // cell.cellImageView.image = [UIImage imageNamed:@"loading_s"]; // NSString* file_name=[img_url lastPathComponent]; // NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url]; // if(img_data!=nil) // { // // UIImage * img =[UIImage imageWithData:img_data]; // cell.cellImageView.image = img; // } // else // { // // // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ // // NSData* downloadimg_data = nil; // BOOL offline = NO; //#ifdef OFFLINE_MODE // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; // offline = appDelegate.offline_mode; //#endif // if (!offline) { // downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]]; // } // dispatch_async(dispatch_get_main_queue(), ^{ // // // // if(downloadimg_data!=nil) // { // // [FileCache cache_img:downloadimg_data filename:file_name saveTo:img_url]; // // UIImage * img =[UIImage imageWithData:downloadimg_data]; // cell.cellImageView.image = img; // } // else // cell.cellImageView.image = [UIImage imageNamed:@"notfound_s"]; // // }); // }); // // // } // } cell.layer.borderColor = UIColorFromRGB(color).CGColor; cell.layer.borderWidth = 0.5; //cell.layer.cornerRadius=15; cell.layer.masksToBounds=true; return cell; } #pragma mark --UICollectionViewDelegateFlowLayout ////定义每个UICollectionView 的大小 //- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath //{ // return CGSizeMake(96, 100); //} //定义每个UICollectionView 的 margin -(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section { return UIEdgeInsetsMake(10, 10, 10, 10); } #pragma mark --UICollectionViewDelegate //UICollectionView被选中时调用的方法 -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { NSDictionary* json=[self.related_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]]; NSString* product_id = [json valueForKey:@"product_id"]; NSString* category = [json valueForKey:@"category"]; [itemdelegate TopicItemClicked : product_id category:category]; } @end