// // RQExerciseAnswerCell.m // JSJP // // Created by 张嵘 on 2021/8/16. // #import "RQExerciseAnswerCell.h" @interface RQExerciseAnswerCell () @property (nonatomic, readwrite, strong) RQExerciseAnswerItemViewModel *viewModel; @property (weak, nonatomic) IBOutlet UILabel *answerLabel; @property (weak, nonatomic) IBOutlet QMUIButton *lookSkillBtn; @property (weak, nonatomic) IBOutlet YYLabel *skillLabel; @property (weak, nonatomic) IBOutlet UIImageView *coverImageView; @property (weak, nonatomic) IBOutlet UIView *tryseeView; @property (weak, nonatomic) IBOutlet UILabel *trycount_label; @property (weak, nonatomic) IBOutlet UILabel *jqmd_label; @property (weak, nonatomic) IBOutlet QMUIButton *trylookSkillBtn; @property (weak, nonatomic) IBOutlet NSLayoutConstraint *skill_bottom_layout; @end @implementation RQExerciseAnswerCell #pragma mark - PublicMethods + (instancetype)cellWithTableView:(UITableView *)tableView { static NSString *ID = @"RQExerciseAnswerCell"; RQExerciseAnswerCell *cell = [tableView dequeueReusableCellWithIdentifier:ID]; if (!cell) { cell = [self rq_viewFromXib]; cell.selectionStyle = UITableViewCellSelectionStyleNone; } return cell; } - (void)bindViewModel:(RQExerciseAnswerItemViewModel *)viewModel { _viewModel = viewModel; @weakify(self) self.skillLabel.userInteractionEnabled = YES; RAC(self.answerLabel, text) = [[RACObserve(viewModel, answerString) takeUntil:self.rac_prepareForReuseSignal] deliverOnMainThread]; [[[[RACObserve(viewModel, skillHeight) takeUntil:self.rac_prepareForReuseSignal] deliverOnMainThread] distinctUntilChanged] subscribeNext:^(id _Nullable x) { @strongify(self) // self.coverImageView.image = [UIImage imageWithGradualChangingColor:^(QQGradualChangingColor *graColor) { // graColor.fromColor = [UIColor colorWithHexString:@"#F2F3F5" alpha:0.2]; // graColor.toColor = [UIColor colorWithHexString:@"#F2F3F5" alpha:1.f]; // graColor.type = QQGradualChangeTypeLeftToRight; // } size:CGSizeMake(RQ_SCREEN_WIDTH - 32.f - 16.f - RQ_FIT_HORIZONTAL(128.f) + 30.f, viewModel.skillHeight) cornerRadius:QQRadiusZero]; self.coverImageView.image = [UIImage imageNamed:@"背景遮罩"]; }]; RAC(self.skillLabel, attributedText) = [[RACObserve(viewModel, skillString) takeUntil:self.rac_prepareForReuseSignal] deliverOnMainThread]; int count = 0; if(RQ_USER_MANAGER.tryLookCount>0){ count = RQ_USER_MANAGER.tryLookCount-1; } self.trycount_label.text = [NSString stringWithFormat:@"%d",count];//试看次数 [[[[RACObserve(viewModel, ydtJSModel) takeUntil:self.rac_prepareForReuseSignal] deliverOnMainThread] distinctUntilChanged] subscribeNext:^(RQYDTJSModel *ydtJSModel) { @strongify(self) if (RQ_YDTQuestion_Module.subject == RQHomePageSubjectType_SubjectOne) { if (RQ_VIP_Module.isSubject1Vip) { self.coverImageView.hidden = YES; self.lookSkillBtn.hidden = YES; self.jqmd_label.hidden = YES; self.tryseeView.hidden = YES; } else if(RQ_USER_MANAGER.tryLookCount>0){//是否试看 self.coverImageView.hidden = YES; self.lookSkillBtn.hidden = YES; self.jqmd_label.hidden = YES; self.tryseeView.hidden = NO; } else { self.coverImageView.hidden = RQObjectIsNil(ydtJSModel); self.lookSkillBtn.hidden = RQObjectIsNil(ydtJSModel); self.jqmd_label.hidden = RQObjectIsNil(ydtJSModel); self.tryseeView.hidden = YES; } } else if (RQ_YDTQuestion_Module.subject == RQHomePageSubjectType_SubjectFour) { if (RQ_VIP_Module.isSubject4Vip) { self.coverImageView.hidden = YES; self.lookSkillBtn.hidden = YES; self.jqmd_label.hidden = YES; self.tryseeView.hidden = YES; } else if(RQ_USER_MANAGER.tryLookCount>0){//是否试看 self.coverImageView.hidden = YES; self.lookSkillBtn.hidden = YES; self.jqmd_label.hidden = YES; self.tryseeView.hidden = NO; } else { self.coverImageView.hidden = RQObjectIsNil(ydtJSModel); self.lookSkillBtn.hidden = RQObjectIsNil(ydtJSModel); self.jqmd_label.hidden = RQObjectIsNil(ydtJSModel); self.tryseeView.hidden = YES; } } else { self.coverImageView.hidden = YES; self.lookSkillBtn.hidden = YES; self.jqmd_label.hidden = YES; self.tryseeView.hidden = YES; } self.skillLabel.hidden = RQObjectIsNil(ydtJSModel); }]; } #pragma mark - SystemMethods - (void)awakeFromNib { [super awakeFromNib]; @weakify(self) dispatch_async(dispatch_get_main_queue(), ^{ @strongify(self) self.lookSkillBtn.imagePosition = QMUIButtonImagePositionRight; [self.lookSkillBtn setBackgroundImage:[UIImage imageWithGradualChangingColor:^(QQGradualChangingColor *graColor) { graColor.fromColor = [UIColor qmui_colorWithHexString:@"#FF7E4D"]; graColor.toColor = [UIColor qmui_colorWithHexString:@"#FF4D53"]; graColor.type = QQGradualChangeTypeLeftToRight; } size:CGSizeMake(RQ_FIT_HORIZONTAL(128.f), RQ_FIT_HORIZONTAL(34.f)) cornerRadius:QQRadiusMakeSame(RQ_FIT_HORIZONTAL(34.f) / 2.f)] forState:UIControlStateNormal]; self.trylookSkillBtn.imagePosition = QMUIButtonImagePositionRight; [self.trylookSkillBtn setBackgroundImage:[UIImage imageWithGradualChangingColor:^(QQGradualChangingColor *graColor) { graColor.fromColor = [UIColor qmui_colorWithHexString:@"#FF7E4D"]; graColor.toColor = [UIColor qmui_colorWithHexString:@"#FF4D53"]; graColor.type = QQGradualChangeTypeLeftToRight; } size:CGSizeMake(RQ_FIT_HORIZONTAL(128.f), RQ_FIT_HORIZONTAL(34.f)) cornerRadius:QQRadiusMakeSame(RQ_FIT_HORIZONTAL(34.f) / 2.f)] forState:UIControlStateNormal]; NSInteger line = RQ_COMMON_MANAGER.APP_SWITCH? 0 : ((RQ_VIP_Module.isSubject1Vip && RQ_YDTQuestion_Module.subject == RQHomePageSubjectType_SubjectOne)? 0 : ((RQ_VIP_Module.isSubject4Vip && RQ_YDTQuestion_Module.subject == RQHomePageSubjectType_SubjectFour)? 0 : 1)); self.skill_bottom_layout.constant = 16.f; if(RQ_USER_MANAGER.tryLookCount>0 && line == 1){//是否试看 line = 0; self.skill_bottom_layout.constant = 56.f; } self.skillLabel.numberOfLines = line; [self layoutIfNeeded]; }); } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } - (IBAction)showSkillAction:(id)sender { [RQ_VIP_Module gotoBuyVipWithVipPageType:RQVIPPageType_Full]; } @end