DetailTopicCell.m 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. //
  2. // DetailTopicCellTableViewCell.m
  3. // iShop
  4. //
  5. // Created by Rui Zhang on 2/26/24.
  6. //
  7. #import "const.h"
  8. #import "DetailTopicCell.h"
  9. #import "CatalogCellSmall.h"
  10. //#import "DetailViewController.h"
  11. //#import "DefaultAppearance.h"
  12. #import "AppDelegate.h"
  13. #import "FileCache.h"
  14. @implementation DetailTopicCell
  15. @synthesize itemdelegate;
  16. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  17. {
  18. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  19. if (self) {
  20. // Initialization code
  21. }
  22. return self;
  23. }
  24. - (void)awakeFromNib
  25. {
  26. // Initialization code
  27. [super awakeFromNib];
  28. self.refreshLabel.layer.borderColor = [UIColor darkGrayColor].CGColor;
  29. self.refreshLabel.layer.borderWidth = 2.0;
  30. self.refreshLabel.layer.cornerRadius=15;
  31. self.refreshLabel.layer.masksToBounds=true;
  32. }
  33. -(void) begin_refresh
  34. {
  35. self.topicCollectionView.hidden=true;
  36. self.refreshLabel.hidden=false;
  37. }
  38. -(void) end_refresh
  39. {
  40. self.topicCollectionView.hidden=false;
  41. self.refreshLabel.hidden=true;
  42. }
  43. - (void)setSelected:(BOOL)selected animated:(BOOL)animated
  44. {
  45. [super setSelected:selected animated:animated];
  46. // Configure the view for the selected state
  47. }
  48. #pragma mark -- UICollectionViewDataSource
  49. -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  50. {
  51. // 每个Section的item个数
  52. int count =[[self.related_data valueForKey:@"count"] intValue];
  53. return count;
  54. }
  55. -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
  56. {
  57. return 1;
  58. }
  59. -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  60. {
  61. //
  62. //
  63. // NSString* value =[DefaultAppearance get_noneappearance_value:@"CategoryViewController" valuename:@"cell_border_color"];
  64. //
  65. //
  66. //
  67. //
  68. //
  69. NSString* value=@"";
  70. unsigned long color = strtoul([value UTF8String],0,16);
  71. static NSString * CellIdentifier = @"RelatedModelCell";
  72. CatalogCellSmall * cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
  73. cell.cellImageView.contentMode = UIViewContentModeScaleAspectFit;
  74. NSDictionary * item_json =[self.related_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  75. NSString* img_url =[item_json valueForKey:@"picture_path"];
  76. NSString* description =[item_json valueForKey:@"fash_name"];
  77. // NSString* old_price =[item_json valueForKey:@"old_price"];
  78. // NSString* price =[item_json valueForKey:@"price"];
  79. cell.nameLabel.text = description;
  80. // cell.oldPrice.text = old_price;
  81. // cell.Price.text = price;
  82. NSString *loading = @"loading_s";
  83. NSString * notFound = @"notfound_s";
  84. cell.imageName = img_url;
  85. cell.cellImageView.image = [UIImage imageNamed:loading];
  86. NSString* file_name=[img_url lastPathComponent];
  87. NSData* img_data=[FileCache load_cached_img:file_name loadFrom:img_url];
  88. if(img_data!=nil)
  89. {
  90. UIImage * img =[UIImage imageWithData:img_data];
  91. cell.cellImageView.image = img;
  92. }
  93. else
  94. {
  95. // BOOL offline = NO;
  96. //#ifdef OFFLINE_MODE
  97. // AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  98. // offline = appDelegate.offline_mode;
  99. //#endif
  100. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  101. NSData* downloadimg_data = nil;
  102. //离线模式不会主动下载图片,避免同名图片覆盖离线图片。
  103. // if (!offline) {
  104. downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  105. // }
  106. dispatch_async(dispatch_get_main_queue(), ^{
  107. if(downloadimg_data!=nil)
  108. {
  109. [FileCache cache_img:downloadimg_data filename:file_name saveTo:img_url];
  110. UIImage * img =[UIImage imageWithData:downloadimg_data];
  111. cell.cellImageView.image = img;
  112. }
  113. else
  114. cell.cellImageView.image = [UIImage imageNamed:notFound];
  115. });
  116. });
  117. }
  118. // if (![cell.imageName isEqualToString:img_url]) {
  119. // cell.imageName = img_url;
  120. // cell.cellImageView.image = [UIImage imageNamed:@"loading_s"];
  121. // NSString* file_name=[img_url lastPathComponent];
  122. // NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  123. // if(img_data!=nil)
  124. // {
  125. //
  126. // UIImage * img =[UIImage imageWithData:img_data];
  127. // cell.cellImageView.image = img;
  128. // }
  129. // else
  130. // {
  131. //
  132. //
  133. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  134. //
  135. // NSData* downloadimg_data = nil;
  136. // BOOL offline = NO;
  137. //#ifdef OFFLINE_MODE
  138. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  139. // offline = appDelegate.offline_mode;
  140. //#endif
  141. // if (!offline) {
  142. // downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  143. // }
  144. // dispatch_async(dispatch_get_main_queue(), ^{
  145. //
  146. //
  147. //
  148. // if(downloadimg_data!=nil)
  149. // {
  150. //
  151. // [FileCache cache_img:downloadimg_data filename:file_name saveTo:img_url];
  152. //
  153. // UIImage * img =[UIImage imageWithData:downloadimg_data];
  154. // cell.cellImageView.image = img;
  155. // }
  156. // else
  157. // cell.cellImageView.image = [UIImage imageNamed:@"notfound_s"];
  158. //
  159. // });
  160. // });
  161. //
  162. //
  163. // }
  164. // }
  165. cell.layer.borderColor = UIColor.lightGrayColor.CGColor;//UIColorFromRGB(color).CGColor;
  166. cell.layer.borderWidth = 0.4;
  167. //cell.layer.cornerRadius=15;
  168. cell.layer.masksToBounds=true;
  169. return cell;
  170. }
  171. #pragma mark --UICollectionViewDelegateFlowLayout
  172. ////定义每个UICollectionView 的大小
  173. //- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  174. //{
  175. // return CGSizeMake(96, 100);
  176. //}
  177. //定义每个UICollectionView 的 margin
  178. -(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
  179. {
  180. return UIEdgeInsetsMake(10, 10, 10, 10);
  181. }
  182. #pragma mark --UICollectionViewDelegate
  183. //UICollectionView被选中时调用的方法
  184. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  185. {
  186. NSDictionary* json=[self.related_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  187. NSString* product_id = [json valueForKey:@"product_id"];
  188. NSString* category = [json valueForKey:@"category"];
  189. [itemdelegate TopicItemClicked : product_id category:category];
  190. }
  191. @end