DetailTopicCell.m 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. //
  2. // DetailRelatedCell.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 14-7-31.
  6. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "DetailTopicCell.h"
  9. #import "CategoryCellSmall.h"
  10. #import "iSalesDB.h"
  11. #import "DetailViewController.h"
  12. #import "DefaultAppearance.h"
  13. #import "AppDelegate.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. NSString* value =[DefaultAppearance get_noneappearance_value:@"CategoryViewController" valuename:@"cell_border_color"];
  62. if(value==nil)
  63. value=@"";
  64. unsigned long color = strtoul([value UTF8String],0,16);
  65. static NSString * CellIdentifier = @"RelatedModelCell";
  66. CategoryCellSmall * cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
  67. cell.cellImageView.contentMode = UIViewContentModeScaleAspectFit;
  68. NSDictionary * item_json =[self.related_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  69. NSString* img_url =[item_json valueForKey:@"picture_path"];
  70. NSString* description =[item_json valueForKey:@"fash_name"];
  71. // NSString* old_price =[item_json valueForKey:@"old_price"];
  72. // NSString* price =[item_json valueForKey:@"price"];
  73. cell.cellDescription.text = description;
  74. // cell.oldPrice.text = old_price;
  75. // cell.Price.text = price;
  76. NSString *loading = @"loading_s";
  77. NSString * notFound = @"notfound_s";
  78. cell.imageName = img_url;
  79. cell.cellImageView.image = [UIImage imageNamed:loading];
  80. NSString* file_name=[img_url lastPathComponent];
  81. NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  82. if(img_data!=nil)
  83. {
  84. UIImage * img =[UIImage imageWithData:img_data];
  85. cell.cellImageView.image = img;
  86. }
  87. else
  88. {
  89. // BOOL offline = NO;
  90. //#ifdef OFFLINE_MODE
  91. // AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  92. // offline = appDelegate.offline_mode;
  93. //#endif
  94. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  95. NSData* downloadimg_data = nil;
  96. //离线模式不会主动下载图片,避免同名图片覆盖离线图片。
  97. // if (!offline) {
  98. downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  99. // }
  100. dispatch_async(dispatch_get_main_queue(), ^{
  101. if(downloadimg_data!=nil)
  102. {
  103. [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
  104. UIImage * img =[UIImage imageWithData:downloadimg_data];
  105. cell.cellImageView.image = img;
  106. }
  107. else
  108. cell.cellImageView.image = [UIImage imageNamed:notFound];
  109. });
  110. });
  111. }
  112. // if (![cell.imageName isEqualToString:img_url]) {
  113. // cell.imageName = img_url;
  114. // cell.cellImageView.image = [UIImage imageNamed:@"loading_s"];
  115. // NSString* file_name=[img_url lastPathComponent];
  116. // NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  117. // if(img_data!=nil)
  118. // {
  119. //
  120. // UIImage * img =[UIImage imageWithData:img_data];
  121. // cell.cellImageView.image = img;
  122. // }
  123. // else
  124. // {
  125. //
  126. //
  127. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  128. //
  129. // NSData* downloadimg_data = nil;
  130. // BOOL offline = NO;
  131. //#ifdef OFFLINE_MODE
  132. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  133. // offline = appDelegate.offline_mode;
  134. //#endif
  135. // if (!offline) {
  136. // downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  137. // }
  138. // dispatch_async(dispatch_get_main_queue(), ^{
  139. //
  140. //
  141. //
  142. // if(downloadimg_data!=nil)
  143. // {
  144. //
  145. // [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
  146. //
  147. // UIImage * img =[UIImage imageWithData:downloadimg_data];
  148. // cell.cellImageView.image = img;
  149. // }
  150. // else
  151. // cell.cellImageView.image = [UIImage imageNamed:@"notfound_s"];
  152. //
  153. // });
  154. // });
  155. //
  156. //
  157. // }
  158. // }
  159. cell.layer.borderColor = UIColorFromRGB(color).CGColor;
  160. cell.layer.borderWidth = 0.5;
  161. //cell.layer.cornerRadius=15;
  162. cell.layer.masksToBounds=true;
  163. return cell;
  164. }
  165. #pragma mark --UICollectionViewDelegateFlowLayout
  166. ////定义每个UICollectionView 的大小
  167. //- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  168. //{
  169. // return CGSizeMake(96, 100);
  170. //}
  171. //定义每个UICollectionView 的 margin
  172. -(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
  173. {
  174. return UIEdgeInsetsMake(10, 10, 10, 10);
  175. }
  176. #pragma mark --UICollectionViewDelegate
  177. //UICollectionView被选中时调用的方法
  178. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  179. {
  180. NSDictionary* json=[self.related_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  181. NSString* product_id = [json valueForKey:@"product_id"];
  182. NSString* category = [json valueForKey:@"category"];
  183. [itemdelegate TopicItemClicked : product_id category:category];
  184. }
  185. @end