RQExerciseAnswerCell.m 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. @end
  15. @implementation RQExerciseAnswerCell
  16. #pragma mark - PublicMethods
  17. + (instancetype)cellWithTableView:(UITableView *)tableView {
  18. static NSString *ID = @"RQExerciseAnswerCell";
  19. RQExerciseAnswerCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
  20. if (!cell) {
  21. cell = [self rq_viewFromXib];
  22. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  23. }
  24. return cell;
  25. }
  26. - (void)bindViewModel:(RQExerciseAnswerItemViewModel *)viewModel {
  27. _viewModel = viewModel;
  28. @weakify(self)
  29. RAC(self.answerLabel, text) = [[RACObserve(viewModel, answerString) takeUntil:self.rac_prepareForReuseSignal] deliverOnMainThread];
  30. [[[[RACObserve(viewModel, skillHeight) takeUntil:self.rac_prepareForReuseSignal] deliverOnMainThread] distinctUntilChanged] subscribeNext:^(id _Nullable x) {
  31. @strongify(self)
  32. self.coverImageView.image = [UIImage imageWithGradualChangingColor:^(QQGradualChangingColor *graColor) {
  33. graColor.fromColor = [UIColor colorWithHexString:@"#F2F3F5" alpha:0.2];
  34. graColor.toColor = [UIColor colorWithHexString:@"#F2F3F5" alpha:1.f];
  35. graColor.type = QQGradualChangeTypeLeftToRight;
  36. } size:CGSizeMake(RQ_SCREEN_WIDTH - 32.f - 16.f - RQ_FIT_HORIZONTAL(128.f) + 30.f, viewModel.skillHeight) cornerRadius:QQRadiusZero];
  37. }];
  38. RAC(self.skillLabel, attributedText) = [[RACObserve(viewModel, skillString) takeUntil:self.rac_prepareForReuseSignal] deliverOnMainThread];
  39. [[[[RACObserve(viewModel, ydtJSModel) takeUntil:self.rac_prepareForReuseSignal] deliverOnMainThread] distinctUntilChanged] subscribeNext:^(RQYDTJSModel *ydtJSModel) {
  40. @strongify(self)
  41. if (RQ_YDTQuestion_Module.subject == RQHomePageSubjectType_SubjectOne) {
  42. if (RQ_VIP_Module.isSubject1Vip) {
  43. self.coverImageView.hidden = YES;
  44. self.lookSkillBtn.hidden = YES;
  45. } else {
  46. self.coverImageView.hidden = RQObjectIsNil(ydtJSModel);
  47. self.lookSkillBtn.hidden = RQObjectIsNil(ydtJSModel);
  48. }
  49. } else if (RQ_YDTQuestion_Module.subject == RQHomePageSubjectType_SubjectFour) {
  50. if (RQ_VIP_Module.isSubject4Vip) {
  51. self.coverImageView.hidden = YES;
  52. self.lookSkillBtn.hidden = YES;
  53. } else {
  54. self.coverImageView.hidden = RQObjectIsNil(ydtJSModel);
  55. self.lookSkillBtn.hidden = RQObjectIsNil(ydtJSModel);
  56. }
  57. } else {
  58. self.coverImageView.hidden = YES;
  59. self.lookSkillBtn.hidden = YES;
  60. }
  61. self.skillLabel.hidden = RQObjectIsNil(ydtJSModel);
  62. }];
  63. }
  64. #pragma mark - SystemMethods
  65. - (void)awakeFromNib {
  66. [super awakeFromNib];
  67. @weakify(self)
  68. dispatch_async(dispatch_get_main_queue(), ^{
  69. @strongify(self)
  70. self.lookSkillBtn.imagePosition = QMUIButtonImagePositionRight;
  71. [self.lookSkillBtn setBackgroundImage:[UIImage imageWithGradualChangingColor:^(QQGradualChangingColor *graColor) {
  72. graColor.fromColor = [UIColor qmui_colorWithHexString:@"#FF7E4D"];
  73. graColor.toColor = [UIColor qmui_colorWithHexString:@"#FF4D53"];
  74. graColor.type = QQGradualChangeTypeLeftToRight;
  75. } size:CGSizeMake(RQ_FIT_HORIZONTAL(128.f), RQ_FIT_HORIZONTAL(34.f)) cornerRadius:QQRadiusMakeSame(RQ_FIT_HORIZONTAL(34.f) / 2.f)] forState:UIControlStateNormal];
  76. 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));
  77. self.skillLabel.numberOfLines = line;
  78. });
  79. }
  80. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  81. [super setSelected:selected animated:animated];
  82. // Configure the view for the selected state
  83. }
  84. - (IBAction)showSkillAction:(id)sender {
  85. [RQ_VIP_Module gotoBuyVipWithVipPageType:RQVIPPageType_Full];
  86. }
  87. @end