// // RQVideoDetailSubPageCell.m // JSJP // // Created by 张嵘 on 2021/11/5. // #import "RQVideoDetailSubPageCell.h" @interface RQVideoDetailSubPageCell () @property (nonatomic, readwrite, strong) RQVideoDetailSubPageItemViewModel *viewModel; @property (weak, nonatomic) IBOutlet UIView *topLine; @property (weak, nonatomic) IBOutlet UILabel *indexLabel; @property (weak, nonatomic) IBOutlet UIView *bottomLine; @property (weak, nonatomic) IBOutlet UIButton *stateBtn; @property (weak, nonatomic) IBOutlet UILabel *titleLabel; @property (weak, nonatomic) IBOutlet UILabel *subTitleLabel; @property (weak, nonatomic) IBOutlet UIImageView *videoImageView; @property (weak, nonatomic) IBOutlet UIButton *isLearningBtn; @property (weak, nonatomic) IBOutlet QMUIButton *tryLookBtn; @property (weak, nonatomic) IBOutlet UIButton *vipBtn; @property (nonatomic, readwrite, strong) RQVideoPermissionStateModel *videoPermissionStateModel; @end @implementation RQVideoDetailSubPageCell #pragma mark - PublicMethods + (instancetype)cellWithTableView:(UITableView *)tableView { static NSString *ID = @"RQVideoDetailSubPageCell"; RQVideoDetailSubPageCell *cell = [tableView dequeueReusableCellWithIdentifier:ID]; if (!cell) { cell = [self rq_viewFromXib]; cell.selectionStyle = UITableViewCellSelectionStyleNone; [cell.stateBtn borderColor:RQ_MAIN_COLOR width:1 cornorRadius:8]; [cell.stateBtn setTitleColor:RQ_MAIN_COLOR forState:UIControlStateNormal]; cell.indexLabel.textColor = RQ_MAIN_COLOR; } return cell; } - (void)bindViewModel:(RQVideoDetailSubPageItemViewModel *)viewModel { @weakify(self) _viewModel = viewModel; _indexLabel.text = [NSString stringWithFormat:@"%ld",viewModel.videosItem.index]; _topLine.hidden = viewModel.videosItem.index == 1; _bottomLine.hidden = viewModel.videosItem.totalNum == viewModel.videosItem.index; _titleLabel.text = viewModel.videosItem.title; _subTitleLabel.text = viewModel.videosItem.videoDescribe? : @""; [_videoImageView yy_setImageWithURL:[NSURL URLWithString:viewModel.videosItem.coverFileUrl] placeholder:RQWebVideoImagePlaceholder()]; [[RACObserve(viewModel.videosItem, isPlaying) takeUntil:self.rac_prepareForReuseSignal] subscribeNext:^(id _Nullable x) { @strongify(self) if (viewModel.videosItem.isPlaying) { self.isLearningBtn.hidden = NO; self.titleLabel.textColor = RQ_MAIN_COLOR; self.subTitleLabel.textColor = RQ_MAIN_COLOR; } else { self.isLearningBtn.hidden = YES; self.titleLabel.textColor = RQ_MAIN_TEXT_COLOR_1; self.subTitleLabel.textColor = RQ_MAIN_TEXT_COLOR_3; } }]; if (!RQ_COMMON_MANAGER.APP_SWITCH) { [[RACSignal combineLatest:@[RACObserve(RQ_VIP_Module, isSubject2Vip), RACObserve(RQ_VIP_Module, isSubject3Vip)] reduce:^id (NSNumber *isSubjectTwoVip, NSNumber *isSubjectThreeVip) { @strongify(self) if ((viewModel.videosItem.subject == 1 && RQ_VIP_Module.isSubject2Vip) || (viewModel.videosItem.subject == 2 && RQ_VIP_Module.isSubject3Vip)) { self.videoPermissionStateModel.tryLookShow = NO; self.videoPermissionStateModel.vipShow = NO; } else { self.videoPermissionStateModel.tryLookShow = (viewModel.videosItem.permission == 1); self.videoPermissionStateModel.vipShow = (viewModel.videosItem.permission == 2); } return self.videoPermissionStateModel; }] subscribeNext:^(RQVideoPermissionStateModel *videoPermissionStateModel) { @strongify(self) self.tryLookBtn.hidden = !videoPermissionStateModel.tryLookShow; self.vipBtn.hidden = !videoPermissionStateModel.vipShow; }]; } [[[RACObserve(viewModel.videosItem.placeVideoListModel, permission) deliverOnMainThread] takeUntil:self.rac_prepareForReuseSignal] subscribeNext:^(id _Nullable x) { @strongify(self) self.vipBtn.hidden = NO; if ([viewModel.videosItem.placeVideoListModel.permission isEqualToString:@"0"]) { self.vipBtn.hidden = YES; self.tryLookBtn.hidden = YES; } else if ([viewModel.videosItem.placeVideoListModel.permission isEqualToString:@"1"]) { self.vipBtn.hidden = YES; self.tryLookBtn.hidden = NO; } else if ([viewModel.videosItem.placeVideoListModel.permission isEqualToString:@"2"]) { self.vipBtn.hidden = NO; self.tryLookBtn.hidden = YES; } else { self.vipBtn.hidden = YES; self.tryLookBtn.hidden = YES; } if (viewModel.videosItem.placeVideoListModel.placeListModel.isCheckVip) { self.vipBtn.hidden = YES; self.tryLookBtn.hidden = YES; } }]; } #pragma mark - SystemMethods - (void)awakeFromNib { [super awakeFromNib]; _tryLookBtn.spacingBetweenImageAndTitle = 3; [_tryLookBtn setBackgroundColor:[UIColor rq_colorGradientChangeWithFrame:_tryLookBtn.frame startPoint:CGPointMake(0, 0.5) endPoint:CGPointMake(1, 0.5) startColor:RQColorFromHexString(@"#FF4C52") endColor:RQColorFromHexString(@"#FC8269")]]; } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } #pragma mark - LazyLoad - (RQVideoPermissionStateModel *)videoPermissionStateModel { if (!_videoPermissionStateModel) { _videoPermissionStateModel = [[RQVideoPermissionStateModel alloc] init]; } return _videoPermissionStateModel; } @end