HomeWeiCousreCell.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. //
  2. // HomeWeiCousreCell.m
  3. // smartRhino
  4. //
  5. // Created by niuzhen on 2020/5/16.
  6. // Copyright © 2020 tederen. All rights reserved.
  7. //
  8. #import "HomeWeiCousreCell.h"
  9. #import "HomeWeiCousreCollectCell.h"
  10. #import "BookAlertModel.h"
  11. #import "NSDate+Extension.h"
  12. @implementation HomeWeiCousreCell
  13. - (void)awakeFromNib {
  14. [super awakeFromNib];
  15. self.imgV.layer.cornerRadius = 2.5f;
  16. self.imgV.layer.masksToBounds = YES;
  17. }
  18. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  19. [super setSelected:selected animated:animated];
  20. // Configure the view for the selected state
  21. }
  22. + (HomeWeiCousreCell *)configCell0:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{
  23. static NSString *cellIdentifer = @"HomeWeiCousreCell0";
  24. HomeWeiCousreCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer];
  25. if (cell == nil) {
  26. cell = [[[NSBundle mainBundle] loadNibNamed:@"HomeWeiCousreCell" owner:nil options:nil] objectAtIndex:0];
  27. }
  28. return cell;
  29. }
  30. + (HomeWeiCousreCell *)configCell1:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{
  31. static NSString *cellIdentifer = @"HomeWeiCousreCell1";
  32. HomeWeiCousreCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer];
  33. if (cell == nil) {
  34. cell = [[[NSBundle mainBundle] loadNibNamed:@"HomeWeiCousreCell" owner:nil options:nil] objectAtIndex:1];
  35. }
  36. return cell;
  37. }
  38. + (HomeWeiCousreCell *)configCell2:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{
  39. static NSString *cellIdentifer = @"HomeWeiCousreCell2";
  40. HomeWeiCousreCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer];
  41. if (cell == nil) {
  42. cell = [[[NSBundle mainBundle] loadNibNamed:@"HomeWeiCousreCell" owner:nil options:nil] objectAtIndex:2];
  43. }
  44. return cell;
  45. }
  46. + (HomeWeiCousreCell *)configCell3:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{
  47. static NSString *cellIdentifer = @"HomeWeiCousreCell3";
  48. HomeWeiCousreCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer];
  49. if (cell == nil) {
  50. cell = [[[NSBundle mainBundle] loadNibNamed:@"HomeWeiCousreCell" owner:nil options:nil] objectAtIndex:3];
  51. }
  52. return cell;
  53. }
  54. + (HomeWeiCousreCell *)configCell4:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{
  55. static NSString *cellIdentifer = @"HomeWeiCousreCell4";
  56. HomeWeiCousreCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer];
  57. if (cell == nil) {
  58. cell = [[[NSBundle mainBundle] loadNibNamed:@"HomeWeiCousreCell" owner:nil options:nil] objectAtIndex:4];
  59. }
  60. return cell;
  61. }
  62. - (void)setDataWithDetailModel:(BookListenModel *)model
  63. {
  64. self.timeL.text = [NSDate getTimeStringAutoShort2:model.AddDate];
  65. self.titleL.text = model.Title;
  66. self.nameL.text = model.Author;
  67. self.numL.text = [NSString stringWithFormat:@"%ld人已学习",model.ReadCount];
  68. }
  69. - (void)setDataWithSubModel:(BookListenSubModel *)model
  70. {
  71. [self.imgV sd_setImageWithURL:[NSURL URLWithString:model.VideoImage] placeholderImage:IMG(@"img_placeHolder")];
  72. self.titleL.text = model.Name;
  73. self.timeL.text = model.Duration;
  74. self.playTimeL.text = model.Duration;
  75. // self.subTitleL.text = model.SectionName;
  76. self.nameL.text = model.Author;
  77. // self.numL.text = [NSString stringWithFormat:@"%ld",model.ReadCount];
  78. }
  79. - (void)setDataWithRecommendModel:(BookRecommendModel *)model
  80. {
  81. [self.imgV sd_setImageWithURL:[NSURL URLWithString:model.ImageUrls] placeholderImage:IMG(@"img_placeHolder")];
  82. self.titleL.text = model.Title;
  83. CGFloat height = [self.titleL sizeThatFits:CGSizeMake(SCREEN_WIDTH - 175, MAXFLOAT)].height;
  84. if (height > 30) {
  85. self.subTitleL.numberOfLines = 1;
  86. }else{
  87. self.subTitleL.numberOfLines = 2;
  88. }
  89. self.timeL.text = [NSDate getTimeStringAutoShort3:model.CreatedDate];
  90. self.playTimeL.text = model.Duration;
  91. self.subTitleL.text = model.Summary;
  92. self.nameL.text = model.Author;
  93. self.numL.text = [NSString stringWithFormat:@"%ld",model.ReadCount];
  94. }
  95. - (void)setDataWithIndexModel:(HomeSubItemModel *)model searchText:(NSString *)text
  96. {
  97. [self.imgV sd_setImageWithURL:[NSURL URLWithString:model.ImageUrls] placeholderImage:IMG(@"img_placeHolder")];
  98. self.titleL.attributedText = [ZYCTool checkOfString:model.Title withSearchText:text withColor:UIColorHex(0xFF5252)];
  99. CGFloat height = [self.titleL sizeThatFits:CGSizeMake(SCREEN_WIDTH - 205, MAXFLOAT)].height;
  100. if (height > 30) {
  101. self.subTitleL.numberOfLines = 1;
  102. }else{
  103. self.subTitleL.numberOfLines = 2;
  104. }
  105. self.subTitleL.text = model.Summary;
  106. self.nameL.text = model.Author;
  107. self.numL.text = [NSString stringWithFormat:@"%ld",model.ReadCount];
  108. }
  109. - (void)setDataWithModel:(HomeSubItemModel *)model
  110. {
  111. [self.imgV sd_setImageWithURL:[NSURL URLWithString:model.ImageUrls] placeholderImage:IMG(@"img_placeHolder")];
  112. self.titleL.text = model.Title;
  113. CGFloat height = [self.titleL sizeThatFits:CGSizeMake(SCREEN_WIDTH - 175, MAXFLOAT)].height;
  114. if (height > 30) {
  115. self.subTitleL.numberOfLines = 1;
  116. }else{
  117. self.subTitleL.numberOfLines = 2;
  118. }
  119. self.subTitleL.text = model.Summary;
  120. self.nameL.text = model.Author;
  121. self.numL.text = [NSString stringWithFormat:@"%ld",model.ReadCount];
  122. }
  123. - (void)setDataVideoModel:(BookChanelRightModel *)model
  124. {
  125. [self.imgV sd_setImageWithURL:[NSURL URLWithString:model.ImageUrls] placeholderImage:IMG(@"img_placeHolder")];
  126. self.titleL.text = model.Title;
  127. CGFloat height = [self.titleL sizeThatFits:CGSizeMake(SCREEN_WIDTH - 175, MAXFLOAT)].height;
  128. if (height > 30) {
  129. self.subTitleL.numberOfLines = 1;
  130. }else{
  131. self.subTitleL.numberOfLines = 2;
  132. }
  133. self.subTitleL.text = model.Summary;
  134. self.nameL.text = model.Author;
  135. self.playTimeL.text = model.Duration;
  136. self.numL.text = [NSString stringWithFormat:@"%ld",model.ReadCount];
  137. }
  138. - (void)setDataRightModel:(BookChanelRightModel *)model
  139. {
  140. self.titleL.text = model.Name;
  141. self.subTitleL.text = model.ExpandName;
  142. }
  143. - (void)setCollData
  144. {
  145. self.collectionView.delegate = self;
  146. self.collectionView.dataSource = self;
  147. self.collectionView.showsVerticalScrollIndicator = NO;
  148. self.collectionView.showsHorizontalScrollIndicator = NO;
  149. [self.collectionView registerNib:[UINib nibWithNibName:@"HomeWeiCousreCollectCell" bundle:nil] forCellWithReuseIdentifier:@"HomeWeiCousreCollectCell"];
  150. UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc]init];
  151. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  152. layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
  153. [self.collectionView setCollectionViewLayout:layout];
  154. [self.collectionView setContentOffset:CGPointZero animated:NO];
  155. // [self setArray];
  156. [self.collectionView reloadData];
  157. }
  158. - (void)setCollDataArray:(NSArray *)array
  159. {
  160. self.collectionView.delegate = self;
  161. self.collectionView.dataSource = self;
  162. self.collectionView.showsVerticalScrollIndicator = NO;
  163. self.collectionView.showsHorizontalScrollIndicator = NO;
  164. [self.collectionView registerNib:[UINib nibWithNibName:@"HomeWeiCousreCollectCell" bundle:nil] forCellWithReuseIdentifier:@"HomeWeiCousreCollectCell"];
  165. UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc]init];
  166. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  167. layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
  168. [self.collectionView setCollectionViewLayout:layout];
  169. [self.collectionView setContentOffset:CGPointZero animated:NO];
  170. [self setArray:array];
  171. [self.collectionView reloadData];
  172. NSInteger item = 0;
  173. for (NSInteger i = 0; i < array.count; i ++) {
  174. BookListenSubModel * model = array[i];
  175. if (model.isSelect) {
  176. item = i;
  177. }
  178. }
  179. WS(weakSelf);
  180. NSIndexPath * indexPath = [NSIndexPath indexPathForItem:item inSection:0];
  181. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  182. [weakSelf.collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionLeft animated:YES];
  183. });
  184. }
  185. - (void)setArray:(NSArray *)array
  186. {
  187. self.dataArray = array.modelCopy;
  188. }
  189. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
  190. {
  191. return 15.f;
  192. }
  193. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
  194. {
  195. return 15.f;
  196. }
  197. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  198. {
  199. return self.dataArray.count;
  200. }
  201. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
  202. {
  203. return 1;
  204. }
  205. -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  206. {
  207. return CGSizeMake(135, 80);
  208. }
  209. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  210. {
  211. HomeWeiCousreCollectCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeWeiCousreCollectCell" forIndexPath:indexPath];
  212. BookListenSubModel * model = [self.dataArray objectAtIndex:indexPath.item];
  213. [cell setDataWithTitle:model.Name isSelect:model.isSelect];
  214. return cell;
  215. }
  216. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  217. {
  218. WS(weakSelf);
  219. [collectionView deselectItemAtIndexPath:indexPath animated:YES];
  220. BookListenSubModel * model = [self.dataArray objectAtIndex:indexPath.item];
  221. for (BookListenSubModel * smodel in self.dataArray) {
  222. smodel.isSelect = NO;
  223. }
  224. model.isSelect = YES;
  225. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  226. [weakSelf.collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionLeft animated:YES];
  227. });
  228. [self.collectionView reloadData];
  229. if (self.ClickItemBlock) {
  230. self.ClickItemBlock(model);
  231. }
  232. }
  233. @end