RQVideoDetailSubPageCell.m 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. //
  2. // RQVideoDetailSubPageCell.m
  3. // JSJP
  4. //
  5. // Created by 张嵘 on 2021/11/5.
  6. //
  7. #import "RQVideoDetailSubPageCell.h"
  8. @interface RQVideoDetailSubPageCell ()
  9. @property (nonatomic, readwrite, strong) RQVideoDetailSubPageItemViewModel *viewModel;
  10. @property (weak, nonatomic) IBOutlet UIView *topLine;
  11. @property (weak, nonatomic) IBOutlet UILabel *indexLabel;
  12. @property (weak, nonatomic) IBOutlet UIView *bottomLine;
  13. @property (weak, nonatomic) IBOutlet UIButton *stateBtn;
  14. @property (weak, nonatomic) IBOutlet UILabel *titleLabel;
  15. @property (weak, nonatomic) IBOutlet UILabel *subTitleLabel;
  16. @property (weak, nonatomic) IBOutlet UIImageView *videoImageView;
  17. @property (weak, nonatomic) IBOutlet UIButton *isLearningBtn;
  18. @property (weak, nonatomic) IBOutlet QMUIButton *tryLookBtn;
  19. @property (weak, nonatomic) IBOutlet UIButton *vipBtn;
  20. @property (nonatomic, readwrite, strong) RQVideoPermissionStateModel *videoPermissionStateModel;
  21. @end
  22. @implementation RQVideoDetailSubPageCell
  23. #pragma mark - PublicMethods
  24. + (instancetype)cellWithTableView:(UITableView *)tableView {
  25. static NSString *ID = @"RQVideoDetailSubPageCell";
  26. RQVideoDetailSubPageCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
  27. if (!cell) {
  28. cell = [self rq_viewFromXib];
  29. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  30. [cell.stateBtn borderColor:RQ_MAIN_COLOR width:1 cornorRadius:8];
  31. [cell.stateBtn setTitleColor:RQ_MAIN_COLOR forState:UIControlStateNormal];
  32. cell.indexLabel.textColor = RQ_MAIN_COLOR;
  33. }
  34. return cell;
  35. }
  36. - (void)bindViewModel:(RQVideoDetailSubPageItemViewModel *)viewModel {
  37. @weakify(self)
  38. _viewModel = viewModel;
  39. _indexLabel.text = [NSString stringWithFormat:@"%ld",viewModel.videosItem.index];
  40. _topLine.hidden = viewModel.videosItem.index == 1;
  41. _bottomLine.hidden = viewModel.videosItem.totalNum == viewModel.videosItem.index;
  42. _titleLabel.text = viewModel.videosItem.title;
  43. _subTitleLabel.text = viewModel.videosItem.videoDescribe? : @"";
  44. [_videoImageView yy_setImageWithURL:[NSURL URLWithString:viewModel.videosItem.coverFileUrl] placeholder:RQWebVideoImagePlaceholder()];
  45. [[RACObserve(viewModel.videosItem, isPlaying) takeUntil:self.rac_prepareForReuseSignal] subscribeNext:^(id _Nullable x) {
  46. @strongify(self)
  47. if (viewModel.videosItem.isPlaying) {
  48. self.isLearningBtn.hidden = NO;
  49. self.titleLabel.textColor = RQ_MAIN_COLOR;
  50. self.subTitleLabel.textColor = RQ_MAIN_COLOR;
  51. } else {
  52. self.isLearningBtn.hidden = YES;
  53. self.titleLabel.textColor = RQ_MAIN_TEXT_COLOR_1;
  54. self.subTitleLabel.textColor = RQ_MAIN_TEXT_COLOR_3;
  55. }
  56. }];
  57. if (!RQ_COMMON_MANAGER.APP_SWITCH) {
  58. [[RACSignal combineLatest:@[RACObserve(RQ_VIP_Module, isSubject2Vip), RACObserve(RQ_VIP_Module, isSubject3Vip)] reduce:^id (NSNumber *isSubjectTwoVip, NSNumber *isSubjectThreeVip) {
  59. @strongify(self)
  60. if ((viewModel.videosItem.subject == 1 && RQ_VIP_Module.isSubject2Vip) || (viewModel.videosItem.subject == 2 && RQ_VIP_Module.isSubject3Vip)) {
  61. self.videoPermissionStateModel.tryLookShow = NO;
  62. self.videoPermissionStateModel.vipShow = NO;
  63. } else {
  64. self.videoPermissionStateModel.tryLookShow = (viewModel.videosItem.permission == 1);
  65. self.videoPermissionStateModel.vipShow = (viewModel.videosItem.permission == 2);
  66. }
  67. return self.videoPermissionStateModel;
  68. }] subscribeNext:^(RQVideoPermissionStateModel *videoPermissionStateModel) {
  69. @strongify(self)
  70. self.tryLookBtn.hidden = !videoPermissionStateModel.tryLookShow;
  71. self.vipBtn.hidden = !videoPermissionStateModel.vipShow;
  72. }];
  73. }
  74. [[[RACObserve(viewModel.videosItem.placeVideoListModel, permission) deliverOnMainThread] takeUntil:self.rac_prepareForReuseSignal] subscribeNext:^(id _Nullable x) {
  75. @strongify(self)
  76. self.vipBtn.hidden = NO;
  77. if ([viewModel.videosItem.placeVideoListModel.permission isEqualToString:@"0"]) {
  78. self.vipBtn.hidden = YES;
  79. self.tryLookBtn.hidden = YES;
  80. } else if ([viewModel.videosItem.placeVideoListModel.permission isEqualToString:@"1"]) {
  81. self.vipBtn.hidden = YES;
  82. self.tryLookBtn.hidden = NO;
  83. } else if ([viewModel.videosItem.placeVideoListModel.permission isEqualToString:@"2"]) {
  84. self.vipBtn.hidden = NO;
  85. self.tryLookBtn.hidden = YES;
  86. } else {
  87. self.vipBtn.hidden = YES;
  88. self.tryLookBtn.hidden = YES;
  89. }
  90. if (viewModel.videosItem.placeVideoListModel.placeListModel.isCheckVip) {
  91. self.vipBtn.hidden = YES;
  92. self.tryLookBtn.hidden = YES;
  93. }
  94. }];
  95. }
  96. #pragma mark - SystemMethods
  97. - (void)awakeFromNib {
  98. [super awakeFromNib];
  99. _tryLookBtn.spacingBetweenImageAndTitle = 3;
  100. [_tryLookBtn setBackgroundColor:[UIColor rq_colorGradientChangeWithFrame:_tryLookBtn.frame startPoint:CGPointMake(0, 0.5) endPoint:CGPointMake(1, 0.5) startColor:RQColorFromHexString(@"#FF4C52") endColor:RQColorFromHexString(@"#FC8269")]];
  101. }
  102. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  103. [super setSelected:selected animated:animated];
  104. // Configure the view for the selected state
  105. }
  106. #pragma mark - LazyLoad
  107. - (RQVideoPermissionStateModel *)videoPermissionStateModel {
  108. if (!_videoPermissionStateModel) {
  109. _videoPermissionStateModel = [[RQVideoPermissionStateModel alloc] init];
  110. }
  111. return _videoPermissionStateModel;
  112. }
  113. @end