// // RQExerciseAnswerItemViewModel.m // JSJP // // Created by 张嵘 on 2021/8/16. // #import "RQExerciseAnswerItemViewModel.h" @interface RQExerciseAnswerItemViewModel () @property (nonatomic, readwrite, strong) NSString *answerString; @property (nonatomic, readwrite, strong) RQYDTJSModel *ydtJSModel; @property (nonatomic, readwrite, assign) CGFloat skillHeight; @property (nonatomic, readwrite, strong) YYLabel *yyLabel; @property (nonatomic, readwrite, strong) NSMutableAttributedString *skillString; @end @implementation RQExerciseAnswerItemViewModel - (instancetype)initWithRQExerciseModel:(RQExerciseModel *)exerciseModel { if (self = [super init]) { @weakify(self) dispatch_async(dispatch_get_main_queue(), ^{ @strongify(self) NSArray *allOptionsArr = @[@"A",@"B",@"C",@"D"]; NSMutableArray *answerOptionArr = @[].mutableCopy; for (int i = 0; i < exerciseModel.ydtQuestionModel.AnswerTrue.length; i ++) { NSRange range; range.location = i; range.length = 1; NSString *indexStr = [exerciseModel.ydtQuestionModel.AnswerTrue substringWithRange:range]; [answerOptionArr addObject:[allOptionsArr objectAtIndex:indexStr.integerValue - 1]]; } self.ydtJSModel = [RQ_YDT_JS_Question_Module getQuestionJSWithQuestionId:exerciseModel.ydtQuestionModel.ID]; //ning 2023-5-24 一点通db 解题答案数据有异常-新整jq库进行修正。 self.ydtJSModel.qb_read_analyse = [YN_YDT_JQ_Question_Module getQuestionKTJQWithQuestionId:exerciseModel.ydtQuestionModel.ID]; self.answerString = [NSString stringWithFormat:@"答案 %@",[answerOptionArr.mutableCopy componentsJoinedByString:@" "]]; __block CGFloat space = 0.f; if (RQObjectIsNil(self.ydtJSModel)) { self.skillHeight = 0.f; space = 0.f; } else { NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"解题技巧讲解:%@",self.ydtJSModel.qb_read_analyse]]; text.yy_font = [UIFont boldSystemFontOfSize:RQ_Exercise_Module.exerciseFontSize]; text.yy_lineSpacing = 8; text.yy_color = RQ_MAIN_TEXT_COLOR_1; self.skillString = text; 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)); CGFloat height = (line == 0)? [self getMessageHeightWithAttributedStr:text andLabel:self.yyLabel] : RQ_FIT_HORIZONTAL(34.f); self.skillHeight = height; space = 6.f; } self.rowHeight = [_answerString heightForFont:[UIFont boldSystemFontOfSize:19] width:RQ_SCREEN_WIDTH - (16 * 2) - (8 * 2)] + (8 * 2) + (16 * 2) + space + self.skillHeight; }); } return self; } - (CGFloat)getMessageHeightWithAttributedStr:(NSMutableAttributedString *)attributedStr andLabel:(YYLabel *)lb { lb.attributedText = attributedStr; CGSize introSize = CGSizeMake(RQ_SCREEN_WIDTH - (16 * 2) - (8 * 2), CGFLOAT_MAX); YYTextLayout *layout = [YYTextLayout layoutWithContainerSize:introSize text:attributedStr]; lb.textLayout = layout; CGFloat introHeight = layout.textBoundingSize.height+10; return introHeight; } - (YYLabel *)yyLabel { if (!_yyLabel) { _yyLabel = [[YYLabel alloc] init]; } return _yyLabel; } - (NSString *)itemClassName { return @"RQExerciseAnswerCell"; } @end