| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- //
- // DetailTopicCellTableViewCell.m
- // iShop
- //
- // Created by Rui Zhang on 2/26/24.
- //
- #import "const.h"
- #import "DetailTopicCell.h"
- #import "CatalogCellSmall.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"];
- //
- //
- //
- //
- //
-
- NSString* value=@"";
- unsigned long color = strtoul([value UTF8String],0,16);
- static NSString * CellIdentifier = @"RelatedModelCell";
- CatalogCellSmall * 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.nameLabel.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 = UIColor.lightGrayColor.CGColor;//UIColorFromRGB(color).CGColor;
- cell.layer.borderWidth = 0.4;
- //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
|