RQExerciseAnswerCell.m 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. //
  2. // RQExerciseAnswerCell.m
  3. // JSJP
  4. //
  5. // Created by 张嵘 on 2021/8/16.
  6. //
  7. #import "RQExerciseAnswerCell.h"
  8. @interface RQExerciseAnswerCell ()
  9. @property (nonatomic, readwrite, strong) RQExerciseAnswerItemViewModel *viewModel;
  10. @property (weak, nonatomic) IBOutlet UILabel *answerLabel;
  11. @property (weak, nonatomic) IBOutlet QMUIButton *lookSkillBtn;
  12. @property (weak, nonatomic) IBOutlet YYLabel *skillLabel;
  13. @property (weak, nonatomic) IBOutlet UIImageView *coverImageView;
  14. @property (weak, nonatomic) IBOutlet UIView *tryseeView;
  15. @property (weak, nonatomic) IBOutlet UILabel *trycount_label;
  16. @property (weak, nonatomic) IBOutlet UILabel *jqmd_label;
  17. @property (weak, nonatomic) IBOutlet QMUIButton *trylookSkillBtn;
  18. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *skill_bottom_layout;
  19. @end
  20. @implementation RQExerciseAnswerCell
  21. #pragma mark - PublicMethods
  22. + (instancetype)cellWithTableView:(UITableView *)tableView {
  23. static NSString *ID = @"RQExerciseAnswerCell";
  24. RQExerciseAnswerCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
  25. if (!cell) {
  26. cell = [self rq_viewFromXib];
  27. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  28. }
  29. return cell;
  30. }
  31. - (void)bindViewModel:(RQExerciseAnswerItemViewModel *)viewModel {
  32. _viewModel = viewModel;
  33. @weakify(self)
  34. self.skillLabel.userInteractionEnabled = YES;
  35. RAC(self.answerLabel, text) = [[RACObserve(viewModel, answerString) takeUntil:self.rac_prepareForReuseSignal] deliverOnMainThread];
  36. [[[[RACObserve(viewModel, skillHeight) takeUntil:self.rac_prepareForReuseSignal] deliverOnMainThread] distinctUntilChanged] subscribeNext:^(id _Nullable x) {
  37. @strongify(self)
  38. // self.coverImageView.image = [UIImage imageWithGradualChangingColor:^(QQGradualChangingColor *graColor) {
  39. // graColor.fromColor = [UIColor colorWithHexString:@"#F2F3F5" alpha:0.2];
  40. // graColor.toColor = [UIColor colorWithHexString:@"#F2F3F5" alpha:1.f];
  41. // graColor.type = QQGradualChangeTypeLeftToRight;
  42. // } size:CGSizeMake(RQ_SCREEN_WIDTH - 32.f - 16.f - RQ_FIT_HORIZONTAL(128.f) + 30.f, viewModel.skillHeight) cornerRadius:QQRadiusZero];
  43. self.coverImageView.image = [UIImage imageNamed:@"背景遮罩"];
  44. }];
  45. RAC(self.skillLabel, attributedText) = [[RACObserve(viewModel, skillString) takeUntil:self.rac_prepareForReuseSignal] deliverOnMainThread];
  46. int count = 0;
  47. if(RQ_USER_MANAGER.tryLookCount>0){
  48. count = RQ_USER_MANAGER.tryLookCount-1;
  49. }
  50. self.trycount_label.text = [NSString stringWithFormat:@"%d",count];//试看次数
  51. [[[[RACObserve(viewModel, ydtJSModel) takeUntil:self.rac_prepareForReuseSignal] deliverOnMainThread] distinctUntilChanged] subscribeNext:^(RQYDTJSModel *ydtJSModel) {
  52. @strongify(self)
  53. if (RQ_YDTQuestion_Module.subject == RQHomePageSubjectType_SubjectOne) {
  54. if (RQ_VIP_Module.isSubject1Vip) {
  55. self.coverImageView.hidden = YES;
  56. self.lookSkillBtn.hidden = YES;
  57. self.jqmd_label.hidden = YES;
  58. self.tryseeView.hidden = YES;
  59. } else if(RQ_USER_MANAGER.tryLookCount>0){//是否试看
  60. self.coverImageView.hidden = YES;
  61. self.lookSkillBtn.hidden = YES;
  62. self.jqmd_label.hidden = YES;
  63. self.tryseeView.hidden = NO;
  64. } else {
  65. self.coverImageView.hidden = RQObjectIsNil(ydtJSModel);
  66. self.lookSkillBtn.hidden = RQObjectIsNil(ydtJSModel);
  67. self.jqmd_label.hidden = RQObjectIsNil(ydtJSModel);
  68. self.tryseeView.hidden = YES;
  69. }
  70. } else if (RQ_YDTQuestion_Module.subject == RQHomePageSubjectType_SubjectFour) {
  71. if (RQ_VIP_Module.isSubject4Vip) {
  72. self.coverImageView.hidden = YES;
  73. self.lookSkillBtn.hidden = YES;
  74. self.jqmd_label.hidden = YES;
  75. self.tryseeView.hidden = YES;
  76. } else if(RQ_USER_MANAGER.tryLookCount>0){//是否试看
  77. self.coverImageView.hidden = YES;
  78. self.lookSkillBtn.hidden = YES;
  79. self.jqmd_label.hidden = YES;
  80. self.tryseeView.hidden = NO;
  81. } else {
  82. self.coverImageView.hidden = RQObjectIsNil(ydtJSModel);
  83. self.lookSkillBtn.hidden = RQObjectIsNil(ydtJSModel);
  84. self.jqmd_label.hidden = RQObjectIsNil(ydtJSModel);
  85. self.tryseeView.hidden = YES;
  86. }
  87. } else {
  88. self.coverImageView.hidden = YES;
  89. self.lookSkillBtn.hidden = YES;
  90. self.jqmd_label.hidden = YES;
  91. self.tryseeView.hidden = YES;
  92. }
  93. self.skillLabel.hidden = RQObjectIsNil(ydtJSModel);
  94. }];
  95. }
  96. #pragma mark - SystemMethods
  97. - (void)awakeFromNib {
  98. [super awakeFromNib];
  99. @weakify(self)
  100. dispatch_async(dispatch_get_main_queue(), ^{
  101. @strongify(self)
  102. self.lookSkillBtn.imagePosition = QMUIButtonImagePositionRight;
  103. [self.lookSkillBtn setBackgroundImage:[UIImage imageWithGradualChangingColor:^(QQGradualChangingColor *graColor) {
  104. graColor.fromColor = [UIColor qmui_colorWithHexString:@"#FF7E4D"];
  105. graColor.toColor = [UIColor qmui_colorWithHexString:@"#FF4D53"];
  106. graColor.type = QQGradualChangeTypeLeftToRight;
  107. } size:CGSizeMake(RQ_FIT_HORIZONTAL(128.f), RQ_FIT_HORIZONTAL(34.f)) cornerRadius:QQRadiusMakeSame(RQ_FIT_HORIZONTAL(34.f) / 2.f)] forState:UIControlStateNormal];
  108. self.trylookSkillBtn.imagePosition = QMUIButtonImagePositionRight;
  109. [self.trylookSkillBtn setBackgroundImage:[UIImage imageWithGradualChangingColor:^(QQGradualChangingColor *graColor) {
  110. graColor.fromColor = [UIColor qmui_colorWithHexString:@"#FF7E4D"];
  111. graColor.toColor = [UIColor qmui_colorWithHexString:@"#FF4D53"];
  112. graColor.type = QQGradualChangeTypeLeftToRight;
  113. } size:CGSizeMake(RQ_FIT_HORIZONTAL(128.f), RQ_FIT_HORIZONTAL(34.f)) cornerRadius:QQRadiusMakeSame(RQ_FIT_HORIZONTAL(34.f) / 2.f)] forState:UIControlStateNormal];
  114. 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));
  115. self.skill_bottom_layout.constant = 16.f;
  116. if(RQ_USER_MANAGER.tryLookCount>0 && line == 1){//是否试看
  117. line = 0;
  118. self.skill_bottom_layout.constant = 56.f;
  119. }
  120. self.skillLabel.numberOfLines = line;
  121. [self layoutIfNeeded];
  122. });
  123. }
  124. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  125. [super setSelected:selected animated:animated];
  126. // Configure the view for the selected state
  127. }
  128. - (IBAction)showSkillAction:(id)sender {
  129. [RQ_VIP_Module gotoBuyVipWithVipPageType:RQVIPPageType_Full];
  130. }
  131. @end