RQExerciseAnswerItemViewModel.m 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //
  2. // RQExerciseAnswerItemViewModel.m
  3. // JSJP
  4. //
  5. // Created by 张嵘 on 2021/8/16.
  6. //
  7. #import "RQExerciseAnswerItemViewModel.h"
  8. @interface RQExerciseAnswerItemViewModel ()
  9. @property (nonatomic, readwrite, strong) NSString *answerString;
  10. @property (nonatomic, readwrite, strong) RQYDTJSModel *ydtJSModel;
  11. @property (nonatomic, readwrite, assign) CGFloat skillHeight;
  12. @property (nonatomic, readwrite, strong) YYLabel *yyLabel;
  13. @property (nonatomic, readwrite, strong) NSMutableAttributedString *skillString;
  14. @end
  15. @implementation RQExerciseAnswerItemViewModel
  16. - (instancetype)initWithRQExerciseModel:(RQExerciseModel *)exerciseModel {
  17. if (self = [super init]) {
  18. @weakify(self)
  19. dispatch_async(dispatch_get_main_queue(), ^{
  20. @strongify(self)
  21. NSArray *allOptionsArr = @[@"A",@"B",@"C",@"D"];
  22. NSMutableArray *answerOptionArr = @[].mutableCopy;
  23. for (int i = 0; i < exerciseModel.ydtQuestionModel.AnswerTrue.length; i ++) {
  24. NSRange range;
  25. range.location = i;
  26. range.length = 1;
  27. NSString *indexStr = [exerciseModel.ydtQuestionModel.AnswerTrue substringWithRange:range];
  28. [answerOptionArr addObject:[allOptionsArr objectAtIndex:indexStr.integerValue - 1]];
  29. }
  30. self.ydtJSModel = [RQ_YDT_JS_Question_Module getQuestionJSWithQuestionId:exerciseModel.ydtQuestionModel.ID];
  31. //ning 2023-5-24 一点通db 解题答案数据有异常-新整jq库进行修正。
  32. self.ydtJSModel.qb_read_analyse = [YN_YDT_JQ_Question_Module getQuestionKTJQWithQuestionId:exerciseModel.ydtQuestionModel.ID];
  33. self.answerString = [NSString stringWithFormat:@"答案 %@",[answerOptionArr.mutableCopy componentsJoinedByString:@" "]];
  34. __block CGFloat space = 0.f;
  35. if (RQObjectIsNil(self.ydtJSModel)) {
  36. self.skillHeight = 0.f;
  37. space = 0.f;
  38. } else {
  39. NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"解题技巧讲解:%@",self.ydtJSModel.qb_read_analyse]];
  40. text.yy_font = [UIFont boldSystemFontOfSize:RQ_Exercise_Module.exerciseFontSize];
  41. text.yy_lineSpacing = 8;
  42. text.yy_color = RQ_MAIN_TEXT_COLOR_1;
  43. self.skillString = text;
  44. 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));
  45. CGFloat height = (line == 0)? [self getMessageHeightWithAttributedStr:text andLabel:self.yyLabel] : RQ_FIT_HORIZONTAL(34.f);
  46. self.skillHeight = height;
  47. space = 6.f;
  48. }
  49. self.rowHeight = [_answerString heightForFont:[UIFont boldSystemFontOfSize:19] width:RQ_SCREEN_WIDTH - (16 * 2) - (8 * 2)] + (8 * 2) + (16 * 2) + space + self.skillHeight;
  50. });
  51. }
  52. return self;
  53. }
  54. - (CGFloat)getMessageHeightWithAttributedStr:(NSMutableAttributedString *)attributedStr andLabel:(YYLabel *)lb {
  55. lb.attributedText = attributedStr;
  56. CGSize introSize = CGSizeMake(RQ_SCREEN_WIDTH - (16 * 2) - (8 * 2), CGFLOAT_MAX);
  57. YYTextLayout *layout = [YYTextLayout layoutWithContainerSize:introSize text:attributedStr];
  58. lb.textLayout = layout;
  59. CGFloat introHeight = layout.textBoundingSize.height+10;
  60. return introHeight;
  61. }
  62. - (YYLabel *)yyLabel {
  63. if (!_yyLabel) {
  64. _yyLabel = [[YYLabel alloc] init];
  65. }
  66. return _yyLabel;
  67. }
  68. - (NSString *)itemClassName {
  69. return @"RQExerciseAnswerCell";
  70. }
  71. @end