HomeWeiCousreCell.m 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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)setDataWithModel:(HomeSubItemModel *)model
  96. {
  97. [self.imgV sd_setImageWithURL:[NSURL URLWithString:model.ImageUrls] placeholderImage:IMG(@"img_placeHolder")];
  98. self.titleL.text = model.Title;
  99. CGFloat height = [self.titleL sizeThatFits:CGSizeMake(SCREEN_WIDTH - 175, 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)setDataVideoModel:(BookChanelRightModel *)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.playTimeL.text = model.Duration;
  122. self.numL.text = [NSString stringWithFormat:@"%ld",model.ReadCount];
  123. }
  124. - (void)setDataRightModel:(BookChanelRightModel *)model
  125. {
  126. self.titleL.text = model.Name;
  127. self.subTitleL.text = model.ExpandName;
  128. }
  129. - (void)setCollData
  130. {
  131. self.collectionView.delegate = self;
  132. self.collectionView.dataSource = self;
  133. self.collectionView.showsVerticalScrollIndicator = NO;
  134. self.collectionView.showsHorizontalScrollIndicator = NO;
  135. [self.collectionView registerNib:[UINib nibWithNibName:@"HomeWeiCousreCollectCell" bundle:nil] forCellWithReuseIdentifier:@"HomeWeiCousreCollectCell"];
  136. UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc]init];
  137. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  138. layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
  139. [self.collectionView setCollectionViewLayout:layout];
  140. [self.collectionView setContentOffset:CGPointZero animated:NO];
  141. // [self setArray];
  142. [self.collectionView reloadData];
  143. }
  144. - (void)setCollDataArray:(NSArray *)array
  145. {
  146. self.collectionView.delegate = self;
  147. self.collectionView.dataSource = self;
  148. self.collectionView.showsVerticalScrollIndicator = NO;
  149. self.collectionView.showsHorizontalScrollIndicator = NO;
  150. [self.collectionView registerNib:[UINib nibWithNibName:@"HomeWeiCousreCollectCell" bundle:nil] forCellWithReuseIdentifier:@"HomeWeiCousreCollectCell"];
  151. UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc]init];
  152. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  153. layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
  154. [self.collectionView setCollectionViewLayout:layout];
  155. [self.collectionView setContentOffset:CGPointZero animated:NO];
  156. [self setArray:array];
  157. [self.collectionView reloadData];
  158. }
  159. - (void)setArray:(NSArray *)array
  160. {
  161. self.dataArray = array.modelCopy;
  162. }
  163. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
  164. {
  165. return 15.f;
  166. }
  167. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
  168. {
  169. return 15.f;
  170. }
  171. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  172. {
  173. return self.dataArray.count;
  174. }
  175. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
  176. {
  177. return 1;
  178. }
  179. -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  180. {
  181. return CGSizeMake(135, 80);
  182. }
  183. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  184. {
  185. HomeWeiCousreCollectCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeWeiCousreCollectCell" forIndexPath:indexPath];
  186. BookListenSubModel * model = [self.dataArray objectAtIndex:indexPath.row];
  187. [cell setDataWithTitle:model.Name isSelect:model.isSelect];
  188. return cell;
  189. }
  190. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  191. {
  192. [collectionView deselectItemAtIndexPath:indexPath animated:YES];
  193. WS(weakSelf);
  194. BookListenSubModel * model = [self.dataArray objectAtIndex:indexPath.row];
  195. for (BookListenSubModel * smodel in self.dataArray) {
  196. smodel.isSelect = NO;
  197. }
  198. model.isSelect = YES;
  199. [self.collectionView reloadData];
  200. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  201. [weakSelf.collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionLeft animated:YES];
  202. });
  203. if (self.ClickItemBlock) {
  204. self.ClickItemBlock(model);
  205. }
  206. }
  207. @end