123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- //
- // RQExerciseOptionItemViewModel.m
- // SDJK
- //
- // Created by 张嵘 on 2021/8/12.
- //
- #import "RQExerciseOptionItemViewModel.h"
- @interface RQExerciseOptionItemViewModel ()
- @property (nonatomic, readwrite, strong) RQExerciseModel *exerciseModel;
- @property (nonatomic, readwrite, assign) RQExerciseOptionItemType exerciseOptionItemType;
- @property (nonatomic, readwrite, strong) NSMutableAttributedString *optsString;
- @property (nonatomic, readwrite, assign) RQExerciseType exerciseType;
- @end
- @implementation RQExerciseOptionItemViewModel
- /// init
- - (instancetype)initWithRQExerciseModel:(RQExerciseModel *)exerciseModel opts:(NSString *)opts RQExerciseOptionItemType:(RQExerciseOptionItemType)exerciseOptionItemType exerciseType:(RQExerciseType)exerciseType {
- if (self = [super init]) {
- self.exerciseModel = exerciseModel;
- self.exerciseOptionItemType = exerciseOptionItemType;
- self.exerciseType = exerciseType;
- opts = [opts containsString:@"×"]? @"错误" : ([opts containsString:@"√"]? @"正确" : opts);
- self.optsString = [[NSMutableAttributedString alloc] initWithString:opts];
- UIColor *noKeywordColor = RQ_MAIN_LINE_COLOR_1;
- switch (exerciseOptionItemType) {
- case RQExerciseOptionItemType_Correct_CorrectOption:
- case RQExerciseOptionItemType_Error_CorrectOption:{
- noKeywordColor = RQ_MAIN_TEXT_COLOR_GREEN;
- }
- break;
-
- case RQExerciseOptionItemType_Correct_ErrorOption:
- case RQExerciseOptionItemType_Error_ErrorOption:{
- noKeywordColor = RQ_MAIN_TEXT_COLOR_RED;
- }
- break;
-
- case RQExerciseOptionItemType_Multiple_Primary: {
- noKeywordColor = RQ_MAIN_COLOR;
- }
- break;
-
- default: {
- noKeywordColor = RQ_MAIN_TEXT_COLOR_1;
- }
- break;
- }
-
- if (RQStringIsNotEmpty(exerciseModel.answerkeyword) && exerciseModel.isShowSkillExplanation) {
- [[[exerciseModel.answerkeyword componentsSeparatedByString:@"-"].rac_sequence.signal deliverOnMainThread] subscribeNext:^(NSString * _Nullable answerkeyword) {
- NSRange targetRange = NSMakeRange(0, opts.length);
- NSRange range = targetRange;
- [_optsString addAttribute:NSForegroundColorAttributeName value:noKeywordColor range:range];
- while (true) {
- range = [opts rangeOfString:answerkeyword options:NSLiteralSearch range:targetRange];
- if (range.location != NSNotFound) {
- targetRange = NSMakeRange(NSMaxRange(range), opts.length-NSMaxRange(range));
-
- [_optsString addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:RQ_Exercise_Module.exerciseFontSize + 2] range:range];
- [_optsString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:RQ_Exercise_Module.exerciseFontSize] range:targetRange];
- [_optsString addAttribute:NSForegroundColorAttributeName value:(exerciseModel.answerResultsType != RQAnswerResultsType_Unanswered)? noKeywordColor : RQ_MAIN_TEXT_COLOR_RED range:range];
- [_optsString addAttribute:NSForegroundColorAttributeName value:noKeywordColor range:targetRange];
-
- } else {
- break;
- }
- }
-
- } completed:^{
-
- }];
- } else {
- [_optsString addAttribute:NSForegroundColorAttributeName value:noKeywordColor range:NSMakeRange(0, opts.length)];
- }
- }
-
-
-
-
- return self;
- }
- - (NSString *)itemClassName {
- return @"RQExerciseOptionCell";
- }
- @end
|