// // RQExerciseSubViewController.m // SDJK // // Created by 张嵘 on 2021/8/12. // #import "RQExerciseSubViewController.h" #import "HWPanModal.h" @interface RQExerciseSubViewController () /// viewModel @property (nonatomic, readonly, strong) RQExerciseSubViewModel *viewModel; @property (nonatomic, copy) void(^scrollCallback)(UIScrollView *scrollView); @property (nonatomic, readwrite, weak) DZMCoverController *coverVC; @property (nonatomic, readwrite, assign) NSInteger firstNum;///再次进来的第一题 //@property (nonatomic, readwrite, retain) FMDatabase *db; @property (nonatomic, readwrite, retain) FMDatabaseQueue *dbQueue; @property (nonatomic, readwrite, strong) RQExerciseToolBarView *exerciseToolBarView; @property (nonatomic, readwrite, strong) RQErrorExerciseToolBarView *errorExerciseToolBarView; @property (nonatomic, readwrite, strong) RQHandInThePaperView *handInThePaperView; @property (nonatomic, readwrite, strong) NSMutableArray *correctArr; @property (nonatomic, readwrite, strong) NSMutableArray *errorArr; @end @implementation RQExerciseSubViewController @dynamic viewModel; #pragma mark - SystemMethod - (void)viewDidLoad { [super viewDidLoad]; /// 初始化 [self rq_setup]; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; // int popNum = _firstNum 0) { self.questionArr = [NSMutableArray arrayWithArray:self.viewModel.questionArr]; self.number = 0; [self creatCoverVC]; [self creatToolsBar]; } else { ///获取数据 if (self.questionArr.count==0) { self.number = 0; [self changeCityQuestion]; } else { self.number = 0; [self creatCoverVC]; [self creatToolsBar]; } } } } /// 答题结果 [RQNotificationCenter addObserver:self selector:@selector(dealWithAnswerResults:) name:RQAnswerResultsNotification object:nil]; } - (void)getQuestionArrayWithComplete:(VoidBlock_id)complete { @weakify(self) switch (self.viewModel.homeSubPageType) { case RQHomeSubPageType_WrongTopicAndCollection: { if (self.viewModel.homeSubEditListType == RQHomeSubEditListType_WrongTopic) { NSArray *questionIdArr = [RQ_SDJK_DB_MANAGER queryWrongModelQuestionIdArrWithSubjectType:self.viewModel.homePageSubjectType]; [RQ_QUESTION_DB_MANAGER getQuestionsWithQuestionIdArr:questionIdArr complete:^(NSArray *modelArray) { @strongify(self) if (self.viewModel.exerciseType == RQExerciseType_Random) { complete([NSMutableArray arrayWithArray:[modelArray rq_randomArray]]); } else if (self.viewModel.exerciseType == RQExerciseType_Recitation) { complete([modelArray.rac_sequence.signal map:^id _Nullable(RQExerciseModel *exerciseModel) { exerciseModel.userAnswer = exerciseModel.answer; return exerciseModel; }].toArray.mutableCopy); } else { complete(modelArray.mutableCopy); } }]; } else if (self.viewModel.homeSubEditListType == RQHomeSubEditListType_Collection) { NSArray *questionIdArr = [RQ_SDJK_DB_MANAGER queryCollectionModelQuestionIdArrWithSubjectType:self.viewModel.homePageSubjectType]; [RQ_QUESTION_DB_MANAGER getQuestionsWithQuestionIdArr:questionIdArr complete:^(NSArray *modelArray) { @strongify(self) if (self.viewModel.exerciseType == RQExerciseType_Random) { complete([NSMutableArray arrayWithArray:[modelArray rq_randomArray]]); } else if (self.viewModel.exerciseType == RQExerciseType_Recitation) { complete([modelArray.rac_sequence.signal map:^id _Nullable(RQExerciseModel *exerciseModel) { exerciseModel.userAnswer = exerciseModel.answer; return exerciseModel; }].toArray.mutableCopy); } else { complete(modelArray.mutableCopy); } }]; } break; } default: break; } } - (void)dealWithAnswerResults:(NSNotification *)note { RQExerciseModel *exerciseModel = note.userInfo[RQAnswerResultsKey]; RQHomePageCarType notifiCarType = [note.userInfo[RQHomePageCarTypeKey] integerValue]; RQHomePageSubjectType notifiSubjectType = [note.userInfo[RQHomePageSubjectTypeKey] integerValue]; RQExerciseDoType exerciseDoType = [note.userInfo[RQExerciseDoTypeKey] integerValue]; if (notifiCarType != self.viewModel.homePageCarType || notifiSubjectType != self.viewModel.homePageSubjectType) { NSLog(@"重复推送"); return; } [self saveTheAnswerRecordActionWithRQExerciseModel:exerciseModel]; switch (exerciseModel.answerResultsType) { case RQAnswerResultsType_Correct: { if (![self.correctArr containsObject:exerciseModel]) { if (self.viewModel.exerciseType != RQExerciseType_Recitation) { [self.correctArr addObject:exerciseModel]; if (exerciseDoType == RQExerciseDoType_Default && !RQ_Exercise_Module.isAutoRead) { /// 非自动读题 做对自动跳下一题 /// 延时 if (RQ_Exercise_Module.isRightAutoJumpToNext) { [[[RACSignal createSignal:^RACDisposable *(id subscriber) { [subscriber sendNext:@"延时0.5秒"]; return nil; }] delay:.5f] subscribeNext:^(id x) { [self jumpNextQuestion]; NSLog(@"-->%@",x); }]; } } } } else { } if (self.viewModel.exerciseType != RQExerciseType_Test && self.viewModel.exerciseType != RQExerciseType_Exam) { if (self.viewModel.homeSubEditListType == RQHomeSubEditListType_WrongTopic) { _errorExerciseToolBarView.correctOptionNumLabel.text = [NSString stringWithFormat:@"%lu",(unsigned long)self.correctArr.count]; } else { _exerciseToolBarView.correctOptionNumLabel.text = [NSString stringWithFormat:@"%lu",(unsigned long)self.correctArr.count]; } } if (RQ_Exercise_Module.isAutoRead) { if (!exerciseModel.isAuto) { ///自动读题模式下: 当前题目结束自动读题 2秒后自动跳到下一题 //延时 [[[RACSignal createSignal:^RACDisposable *(id subscriber) { [subscriber sendNext:@"延时2秒"]; return nil; }] delay:2] subscribeNext:^(id x) { [self jumpNextQuestion]; NSLog(@"-->%@",x); }]; } else { /// 自动读题模式下: 当前题目正在自动读题 暂不自动跳到下一题 NSLog(@"自动读题模式下: 当前题目正在自动读题 暂不自动跳到下一题"); } } } break; case RQAnswerResultsType_Error: { if ([self.errorArr indexOfObject:exerciseModel] == NSNotFound && ![self.errorArr containsObject:exerciseModel]) { [_errorArr addObject:exerciseModel]; if (self.viewModel.exerciseType != RQExerciseType_Recitation && self.viewModel.exerciseType != RQExerciseType_Test && self.viewModel.exerciseType != RQExerciseType_Exam) { [RQ_Exercise_Module rq_showSkillExplanationAlertWithMessage:exerciseModel.explain_jq skillkeyword:exerciseModel.skillkeyword explainGifUrl:exerciseModel.explain_gif mp3Url:exerciseModel.explain_mp3 completeBlock:nil]; } RQWrongModel *wrongModel = [[RQWrongModel alloc] init]; wrongModel.questionId = exerciseModel._id==0?exerciseModel.idYdt:exerciseModel._id; wrongModel.km = RQ_COMMON_MANAGER.subjectStr; wrongModel.createTime = [NSDate rq_currentTimeSSSInterval]; wrongModel.userId = RQ_USER_MANAGER.currentUserId; // [[RQ_HTTP_Service queryAddWrongRecordWithQuestionId:exerciseModel._id carType:notifiCarType subject:notifiSubjectType] subscribeNext:^(id _Nullable x) { // [RQ_SDJK_DB_MANAGER addWrongRecordWithRQWrongModel:wrongModel]; // [RQ_SDJK_DB_MANAGER getAllWrongModelsCount]; // NSLog(@"%@",x); // }]; [RQ_SDJK_DB_MANAGER addWrongRecordWithRQWrongModel:wrongModel]; [RQ_SDJK_DB_MANAGER getAllWrongModelsCount]; } if (self.viewModel.exerciseType != RQExerciseType_Test && self.viewModel.exerciseType != RQExerciseType_Exam) { if (self.viewModel.homeSubEditListType == RQHomeSubEditListType_WrongTopic) { _errorExerciseToolBarView.errorOptionNumLabel.text = [NSString stringWithFormat:@"%lu",(unsigned long)self.errorArr.count]; } else { _exerciseToolBarView.errorOptionNumLabel.text = [NSString stringWithFormat:@"%lu",(unsigned long)self.errorArr.count]; } } } break; default: break; } switch (exerciseDoType) { case RQExerciseDoType_Default: { break; } case RQExerciseDoType_Auto: { break; } case RQExerciseDoType_SkillExplanation: { [RQ_Exercise_Module rq_showSkillExplanationAlertWithMessage:exerciseModel.explain_jq skillkeyword:exerciseModel.skillkeyword explainGifUrl:exerciseModel.explain_gif mp3Url:exerciseModel.explain_mp3 completeBlock:nil]; break; } case RQExerciseDoType_ReadAndAnswer: { // [RQ_MUSIC_MANAGER rq_resetStreamerWithURLString:exerciseModel.explainjsmp3]; break; } default: break; } } - (void)creatCoverVC { if (self.questionArr.count <= 0) { return; } if (self.number > self.questionArr.count) { return; } DZMCoverController *coverVC = [[DZMCoverController alloc] init]; coverVC.delegate = self; [self.view addSubview:coverVC.view]; [self addChildViewController:coverVC]; self.coverVC = coverVC; [self.coverVC setController:[self creatSubVC]]; } - (RQTestQuestionsViewController *)creatSubVC { @weakify(self) RQExerciseModel *exerciseModel = self.questionArr[self.number]; exerciseModel.num = self.number; exerciseModel.allNum = self.questionArr.count; exerciseModel.isShowSkillExplanation = NO; RQTestQuestionsViewModel *testQuestionsViewModel = [[RQTestQuestionsViewModel alloc] initWithServices:self.viewModel.services params:@{ RQViewModelUtilKey : exerciseModel, RQExerciseTypeKey : @(self.viewModel.exerciseType), RQHomePageCarTypeKey : @(self.viewModel.homePageCarType), RQHomePageSubjectTypeKey: @(self.viewModel.homePageSubjectType), }]; testQuestionsViewModel.lastQuestionCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id _Nullable input) { @strongify(self) [self jumpLastQuestion]; return [RACSignal empty]; }]; testQuestionsViewModel.nextQuestionCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id _Nullable input) { @strongify(self) [self jumpNextQuestion]; return [RACSignal empty]; }]; testQuestionsViewModel.showCatalogueCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id _Nullable input) { @strongify(self) [self showCatalogue]; return [RACSignal empty]; }]; RQTestQuestionsViewController *vc = [[RQTestQuestionsViewController alloc] initWithViewModel:testQuestionsViewModel]; __weak typeof(vc) weakController = vc; return weakController; } /// 根据车型取题 - (void)changeCityQuestion { if (self.viewModel.homeSubPageType == RQHomeSubPageType_MockExamination && self.viewModel.exerciseType == RQExerciseType_Exam) { //模拟考从网络获取考题 @weakify(self) /// 默认为轿车 cart,bus,truck NSString *carTypeStr = @"cart"; switch (self.viewModel.homePageCarType) { case RQHomePageCarType_Car: carTypeStr = @"cart"; break; case RQHomePageCarType_Bus: carTypeStr = @"bus"; break; case RQHomePageCarType_Truck: carTypeStr = @"truck"; break; case RQHomePageCarType_Motorcycle: carTypeStr = @"mtc"; break; default: break; } /// 默认科目一 NSString *subjectTypeStr = @"1"; switch (self.viewModel.homePageSubjectType) { case RQHomePageSubjectType_SubjectOne: subjectTypeStr = @"1"; break; case RQHomePageSubjectType_SubjectTwo: subjectTypeStr = @"2"; break; case RQHomePageSubjectType_SubjectThree: subjectTypeStr = @"3"; break; case RQHomePageSubjectType_SubjectFour: subjectTypeStr = @"4"; break; default: break; } [[[RQ_HTTP_Service getSelectTestK14QuestionInfoList:carTypeStr subject:subjectTypeStr] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSArray *array) { //获取考题 @strongify(self) self.questionArr = array.mutableCopy; [self setup_dataarray]; } error:^(NSError * _Nullable error) { }]; return; } self.questionArr = [RQ_QUESTION_DB_MANAGER getQuestionWithCarType:self.viewModel.homePageCarType subject:self.viewModel.homePageSubjectType pageType:self.viewModel.homeSubPageType name:self.viewModel.titleStr exerciseType:self.viewModel.exerciseType].mutableCopy; [self setup_dataarray]; } - (void)setup_dataarray{ NSString *titleStr = [self.viewModel.title componentsSeparatedByString:@"/"].lastObject; RQHistoryModel *history = [RQ_SDJK_DB_MANAGER queryHistoryModelWithCarType:self.viewModel.homePageCarType subjectType:self.viewModel.homePageSubjectType homeSubPageTyp:self.viewModel.homeSubPageType titleStr:titleStr]; if (!RQObjectIsNil(history)) { NSInteger historyIndex = [[self.viewModel.questionArr.rac_sequence.signal map:^id _Nullable(RQExerciseModel *exerciseModel) { return @(exerciseModel._id); }].toArray indexOfObject:@(history.questionId)] + 1; if (historyIndex > 1) { self.number = historyIndex; } } // if (arr && arr.count > 0) { // NSInteger questionId = [arr.firstObject intValue]; // NSArray *arr1 = [self.questionArr.rac_sequence filter:^BOOL(RQExerciseModel *exerciseModel) { // return exerciseModel._id == questionId; // }].array; // if (arr1 && arr1.count > 0) { // RQExerciseModel *exerciseModel = (RQExerciseModel *)arr1.firstObject; // NSInteger historyNum = [self.questionArr indexOfObject:exerciseModel]; // self.number = historyNum; // } // } // [self searchExamRecord]; //顺序练习 // if (self.number > 0) { // [NSObject rq_showAlertViewWithTitle:@"温馨提示" message:[NSString stringWithFormat:@"检测到您上次做到第%ld题,是否跳转?",self.number] confirmTitle:@"确定" cancelTitle:@"取消" confirmAction:^{ // @strongify(self) // [self jumpQuestionWithIndex:self.number]; // } cancelAction:nil]; // } if (self.questionArr.count > 0) { [self creatCoverVC]; [self creatToolsBar]; } } /// 查看答题记录 - (void)searchExamRecord { // FMResultSet *RightresultSet = [_db executeQuery:@"select * from dt_practice_record where course = 1 and mode = 1 and cert_type = 1"]; // // 逐行读取数据 // while ( [ RightresultSet next ] ) // { // NSInteger ID = [RightresultSet intForColumn:@"_id"]; // for (RQExerciseModel *item in self.questionArr) { // if (item._id == ID) { // item.answer = [RightresultSet stringForColumn:@"answer"]; // if ([item.userAnswer isEqualToString:item.answer]) { // item.answerResultsType=1;//答对 // }else{ // item.answerResultsType=2;//答错 // } // } // } // // } } /// 保存更新答题记录 ,如果没有打完自动跳转到下一题 ,model:1顺序2随机3专项4答对5打错6未答7收藏8模拟9考试纪录10章节 . */ - (void)saveTheAnswerRecordActionWithRQExerciseModel:(RQExerciseModel *_Nullable)exerciseModel { /* *自动跳转到下一题 */ _firstNum = self.number; NSString *seque_issue_name = @""; NSString *class_issue_name = @""; NSString *place_issue_name = @""; NSString *excell_issue_name = @""; NSString *titleStr = [self.viewModel.title componentsSeparatedByString:@"/"].lastObject; switch (self.viewModel.homeSubPageType) { case RQHomeSubPageType_SequentialPractice: seque_issue_name = titleStr; break; case RQHomeSubPageType_LocalTopics: place_issue_name = titleStr; break; case RQHomeSubPageType_ClassificationExercise: class_issue_name = titleStr; break; case RQHomeSubPageType_SelectedTestQuestions: excell_issue_name = titleStr; break; default: break; } RQHistoryModel *historyModel = [[RQHistoryModel alloc] init]; historyModel.questionId = exerciseModel._id; historyModel.userId = RQ_USER_MANAGER.currentUserId; historyModel.km = [RQ_COMMON_MANAGER getSubjectTypeStrWithSubjectType:self.viewModel.homePageSubjectType]; historyModel.carType = [RQ_COMMON_MANAGER getCarTypeStrWithCarType:self.viewModel.homePageCarType]; historyModel.seque_issue_name = seque_issue_name; historyModel.place_issue_name = place_issue_name; historyModel.class_issue_name = class_issue_name; historyModel.excell_issue_name = excell_issue_name; [RQ_SDJK_DB_MANAGER addHistoryRecordWithRQHistoryModel:historyModel]; } - (void)jumpNextQuestion { if (self.number + 1 >= self.questionArr.count) { return; } self.number += 1; NSLog(@"$$$-下一页:%zd",self.number); [self.coverVC setController:[self creatSubVC] animated:YES isAbove:NO]; if (self.viewModel.exerciseType != RQExerciseType_Test && self.viewModel.exerciseType != RQExerciseType_Exam) { if (self.viewModel.homeSubEditListType == RQHomeSubEditListType_WrongTopic) { [self.view bringSubviewToFront:self.errorExerciseToolBarView]; } else { [self.view bringSubviewToFront:self.exerciseToolBarView]; } } else { [self.view bringSubviewToFront:self.handInThePaperView]; } } - (void)jumpLastQuestion{ if (self.number == 0) { return; } self.number -= 1; NSLog(@"$$$-上一页:%zd",self.number); [self.coverVC setController:[self creatSubVC] animated:YES isAbove:YES]; if (self.viewModel.exerciseType != RQExerciseType_Test && self.viewModel.exerciseType != RQExerciseType_Exam) { if (self.viewModel.homeSubEditListType == RQHomeSubEditListType_WrongTopic) { [self.view bringSubviewToFront:self.errorExerciseToolBarView]; } else { [self.view bringSubviewToFront:self.exerciseToolBarView]; } } else { [self.view bringSubviewToFront:self.handInThePaperView]; } } - (void)jumpQuestionWithIndex:(NSUInteger)index { self.number = (int)index; [self.coverVC setController:[self creatSubVC] animated:NO isAbove:NO]; if (self.viewModel.exerciseType != RQExerciseType_Test && self.viewModel.exerciseType != RQExerciseType_Exam) { if (self.viewModel.homeSubEditListType == RQHomeSubEditListType_WrongTopic) { [self.view bringSubviewToFront:self.errorExerciseToolBarView]; } else { [self.view bringSubviewToFront:self.exerciseToolBarView]; } } else { [self.view bringSubviewToFront:self.handInThePaperView]; } } - (void)creatToolsBar { if (self.viewModel.exerciseType != RQExerciseType_Test && self.viewModel.exerciseType != RQExerciseType_Exam) { if (self.viewModel.homeSubEditListType == RQHomeSubEditListType_WrongTopic) { [self.view addSubview:self.errorExerciseToolBarView]; [_errorExerciseToolBarView mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.mas_equalTo(self.view); make.bottom.mas_equalTo(self.view).mas_offset(-(RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT + RQ_APPLICATION_NAV_BAR_HEIGHT)); make.size.mas_equalTo(CGSizeMake(RQ_SCREEN_WIDTH, 50)); }]; } else { [self.view addSubview:self.exerciseToolBarView]; [_exerciseToolBarView mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.mas_equalTo(self.view); make.bottom.mas_equalTo(self.view).mas_offset(-(RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT + RQ_APPLICATION_NAV_BAR_HEIGHT)); make.size.mas_equalTo(CGSizeMake(RQ_SCREEN_WIDTH, 50)); }]; } } else { [self.view addSubview:self.handInThePaperView]; [_handInThePaperView mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.mas_equalTo(self.view); make.bottom.mas_equalTo(self.view).mas_offset(-(RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT + RQ_APPLICATION_NAV_BAR_HEIGHT)); make.size.mas_equalTo(CGSizeMake(RQ_SCREEN_WIDTH, 8.f + RQ_FIT_HORIZONTAL(54.f) + 8.f + 50.f + 8.f)); }]; } } - (void)showCatalogue { @weakify(self) if (self.questionArr.count == 0) { return; } RQCatalogueViewModel *catalogueViewModel = [[RQCatalogueViewModel alloc] initWithServices:self.viewModel.services params:@{ RQViewModelIDKey : @(self.number), RQViewModelUtilKey : self.questionArr, RQViewCommonValueKey : @(self.correctArr.count), RQViewModelRequestKey : @(self.errorArr.count), }]; RQCatalogueViewController *catalogueViewController = [[RQCatalogueViewController alloc] initWithViewModel:catalogueViewModel]; [catalogueViewController initCompletionWithSelectIndexBlock:^(NSInteger index) { @strongify(self) [self jumpQuestionWithIndex:index]; }]; [self presentPanModal:catalogueViewController]; } #pragma mark - DZMCoverControllerDelegate /// 切换结果 - (void)coverController:(DZMCoverController *)coverController currentController:(UIViewController *)currentController finish:(BOOL)isFinish { if (!isFinish) { // 切换失败 // RQTestQuestionsViewController *vc = (RQTestQuestionsViewController *)currentController; } } /// 上一个控制器 - (UIViewController *)coverController:(DZMCoverController *)coverController getAboveControllerWithCurrentController:(UIViewController *)currentController { if (self.number == 0) { return nil; } self.number -= 1; return [self creatSubVC]; } /// 下一个控制器 - (UIViewController *)coverController:(DZMCoverController *)coverController getBelowControllerWithCurrentController:(UIViewController *)currentController { if (self.number==self.questionArr.count-1) { return nil; } self.number += 1; return [self creatSubVC]; } #pragma mark - UITableViewDataSource, UITableViewDelegate - (void)scrollViewDidScroll:(UIScrollView *)scrollView { !self.scrollCallback ?: self.scrollCallback(scrollView); } #pragma mark - JXPagingViewListViewDelegate - (UIView *)listView { return self.view; } - (UIScrollView *)listScrollView { return self.tableView; } - (void)listViewDidScrollCallback:(void (^)(UIScrollView *))callback { self.scrollCallback = callback; } #pragma mark - LazyLoad - (NSMutableArray *)questionArr { if (!_questionArr) { _questionArr = @[].mutableCopy; } return _questionArr; } - (RQExerciseToolBarView *)exerciseToolBarView { if (!_exerciseToolBarView) { _exerciseToolBarView = [RQExerciseToolBarView exerciseToolBarView]; @weakify(self,_exerciseToolBarView); // [RACObserve(self, number) subscribeNext:^(id _Nullable x) { // @strongify(self,_exerciseToolBarView) // _exerciseToolBarView.totalNumberOfQuestionsLabel.text = [NSString stringWithFormat:@"%ld/%lu",[x integerValue] + 1,(unsigned long)self.questionArr.count]; // }]; RAC(_exerciseToolBarView.totalNumberOfQuestionsLabel, text) = [RACSignal combineLatest:@[RACObserve(self, number), RACObserve(self, questionArr)] reduce:^id (NSNumber *num, NSArray *selectArr){ @strongify(self) return [NSString stringWithFormat:@"%ld/%lu",(self.questionArr.count == 0)? 0 : [num integerValue] + 1,(unsigned long)self.questionArr.count]; }]; [_exerciseToolBarView.lastQuestionView setTapActionWithBlock:^(UITapGestureRecognizer *tap) { @strongify(self) _exerciseToolBarView.lastQuestionView.userInteractionEnabled = NO; [self jumpLastQuestion]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.6f *NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ _exerciseToolBarView.lastQuestionView.userInteractionEnabled = YES; }); }]; [_exerciseToolBarView.nextQuestionView setTapActionWithBlock:^(UITapGestureRecognizer *tap) { @strongify(self) _exerciseToolBarView.nextQuestionView.userInteractionEnabled = NO; [self jumpNextQuestion]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.6f *NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ _exerciseToolBarView.nextQuestionView.userInteractionEnabled = YES; }); }]; [_exerciseToolBarView.totalNumberOfQuestionsView setTapActionWithBlock:^(UITapGestureRecognizer *tap) { @strongify(self) [self showCatalogue]; }]; [_exerciseToolBarView.officialInterpretationView setTapActionWithBlock:^(UITapGestureRecognizer *tap) { @strongify(self) if (self.questionArr.count == 0) { return; } RQExerciseModel *exerciseModel = self.questionArr[self.number]; if (RQ_Exercise_Module.isAutoRead) RQ_Exercise_Module.isAutoRead = NO; [RQ_Exercise_Module rq_showOfficialInterpretationAlertWithMessage:exerciseModel.explain_js mp3Url:exerciseModel.explainjsmp3]; }]; } return _exerciseToolBarView; } - (RQErrorExerciseToolBarView *)errorExerciseToolBarView { if (!_errorExerciseToolBarView) { _errorExerciseToolBarView = [RQErrorExerciseToolBarView errorExerciseToolBarView]; @weakify(self); RAC(_errorExerciseToolBarView.totalNumberOfQuestionsLabel, text) = [RACSignal combineLatest:@[RACObserve(self, number), RACObserve(self, questionArr)] reduce:^id (NSNumber *num, NSArray *selectArr){ @strongify(self) return [NSString stringWithFormat:@"%ld/%lu",(self.questionArr.count == 0)? 0 : [num integerValue] + 1,(unsigned long)self.questionArr.count]; }]; // [RACObserve(self, number) subscribeNext:^(id _Nullable x) { // @strongify(self,_errorExerciseToolBarView) // _errorExerciseToolBarView.totalNumberOfQuestionsLabel.text = [NSString stringWithFormat:@"%ld/%lu",(self.questionArr.count == 0)? 0 : [x integerValue] + 1,(unsigned long)self.questionArr.count]; // }]; [_errorExerciseToolBarView.deleteView setTapActionWithBlock:^(UITapGestureRecognizer *tap) { @strongify(self) if (self.questionArr.count == 0) { return; } RQExerciseModel *exerciseModel = self.questionArr[self.number]; // [[RQ_HTTP_Service queryDeleteWrongRecordWithQuestionId:[NSString qmui_stringWithNSInteger:exerciseModel._id]] subscribeNext:^(id _Nullable x) { // @strongify(self) // [RQ_SDJK_DB_MANAGER deleteWrongRecordWithQuestionId:exerciseModel._id]; // [[self mutableArrayValueForKey:@"questionArr"] removeObject:exerciseModel]; // [MBProgressHUD rq_showTips:@"删除成功"]; // [self.coverVC.view removeFromSuperview]; // [RQ_SDJK_DB_MANAGER getAllWrongModelsCount]; // if ([self.errorArr containsObject:exerciseModel]) { // [self.errorArr removeObject:exerciseModel]; // } else if ([self.correctArr containsObject:exerciseModel]) { // [self.correctArr removeObject:exerciseModel]; // } // // if (self.questionArr.count == 0) { // self.number = 0; // _errorExerciseToolBarView.errorOptionNumLabel.text = @"0"; // _errorExerciseToolBarView.correctOptionNumLabel.text = @"0"; // } else { // self.number = (self.questionArr.count == 1)? 0 : ((self.number == 0)? 0 : self.number - 1); // [self creatCoverVC]; // [self.view bringSubviewToFront:self.errorExerciseToolBarView]; // _errorExerciseToolBarView.errorOptionNumLabel.text = [NSString stringWithFormat:@"%lu",(unsigned long)self.errorArr.count]; // _errorExerciseToolBarView.correctOptionNumLabel.text = [NSString stringWithFormat:@"%lu",(unsigned long)self.correctArr.count]; // } // } error:^(NSError * _Nullable error) { // [MBProgressHUD rq_showErrorTips:error]; // }]; BOOL isDelete = [RQ_SDJK_DB_MANAGER deleteWrongRecordWithQuestionId:exerciseModel._id]; if (isDelete) { [[self mutableArrayValueForKey:@"questionArr"] removeObject:exerciseModel]; [MBProgressHUD rq_showTips:@"删除成功"]; [self.coverVC.view removeFromSuperview]; [RQ_SDJK_DB_MANAGER getAllWrongModelsCount]; if ([self.errorArr containsObject:exerciseModel]) { [self.errorArr removeObject:exerciseModel]; } else if ([self.correctArr containsObject:exerciseModel]) { [self.correctArr removeObject:exerciseModel]; } if (self.questionArr.count == 0) { self.number = 0; self.errorExerciseToolBarView.errorOptionNumLabel.text = @"0"; self.errorExerciseToolBarView.correctOptionNumLabel.text = @"0"; } else { self.number = (self.questionArr.count == 1)? 0 : ((self.number == 0)? 0 : self.number - 1); [self creatCoverVC]; [self.view bringSubviewToFront:self.errorExerciseToolBarView]; self.errorExerciseToolBarView.errorOptionNumLabel.text = [NSString stringWithFormat:@"%lu",(unsigned long)self.errorArr.count]; self.errorExerciseToolBarView.correctOptionNumLabel.text = [NSString stringWithFormat:@"%lu",(unsigned long)self.correctArr.count]; } } else { [MBProgressHUD rq_showTips:@"删除失败"]; } }]; [_errorExerciseToolBarView.totalNumberOfQuestionsView setTapActionWithBlock:^(UITapGestureRecognizer *tap) { @strongify(self) [self showCatalogue]; }]; [_errorExerciseToolBarView.officialInterpretationView setTapActionWithBlock:^(UITapGestureRecognizer *tap) { @strongify(self) if (self.questionArr.count == 0) { return; } RQExerciseModel *exerciseModel = self.questionArr[self.number]; if (RQ_Exercise_Module.isAutoRead) RQ_Exercise_Module.isAutoRead = NO; [RQ_Exercise_Module rq_showOfficialInterpretationAlertWithMessage:exerciseModel.explain_js mp3Url:exerciseModel.explainjsmp3]; }]; } return _errorExerciseToolBarView; } - (RQHandInThePaperView *)handInThePaperView { if (!_handInThePaperView) { @weakify(self) _handInThePaperView = [RQHandInThePaperView handInThePaperView]; [_handInThePaperView.handInThePaperBtn setTapActionWithBlock:^(UITapGestureRecognizer *tap) { @strongify(self) NSInteger score = (self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectOne && (self.viewModel.homePageCarType == RQHomePageCarType_Car || self.viewModel.homePageCarType == RQHomePageCarType_Bus || self.viewModel.homePageCarType == RQHomePageCarType_Truck))? self.correctArr.count : self.correctArr.count * 2; RQTestResultsViewModel *testResultsViewModel = [[RQTestResultsViewModel alloc] initWithServices:self.viewModel.services params:@{ RQHomePageCarTypeKey : @(self.viewModel.homePageCarType), RQHomePageSubjectTypeKey : @(self.viewModel.homePageSubjectType), RQHomeSubPageTypeKey : @(self.viewModel.homeSubPageType), RQExerciseTypeKey : @(self.viewModel.exerciseType), RQViewModelIDKey : @(score), RQViewCommonValueKey : @(self.count), RQViewModelUtilKey : self.questionArr, }]; [self.viewModel.services pushViewModel:testResultsViewModel animated:YES]; }]; [_handInThePaperView.lastQuestionBtn setTapActionWithBlock:^(UITapGestureRecognizer *tap) { @strongify(self) _handInThePaperView.lastQuestionBtn.enabled = NO; [self jumpLastQuestion]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.6f *NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ _handInThePaperView.lastQuestionBtn.enabled = YES; }); }]; [_handInThePaperView.nextQuestionBtn setTapActionWithBlock:^(UITapGestureRecognizer *tap) { @strongify(self) _handInThePaperView.nextQuestionBtn.enabled = NO; [self jumpNextQuestion]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.6f *NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ _handInThePaperView.nextQuestionBtn.enabled = YES; }); }]; [_handInThePaperView.totalNumberOfQuestionsBtn setTapActionWithBlock:^(UITapGestureRecognizer *tap) { @strongify(self) [self showCatalogue]; }]; RAC(_handInThePaperView.totalNumberOfQuestionsBtn.titleLabel, text) = [RACSignal combineLatest:@[RACObserve(self, number), RACObserve(self, questionArr)] reduce:^id (NSNumber *num, NSArray *selectArr){ @strongify(self) [self.handInThePaperView.totalNumberOfQuestionsBtn setTitleNormal:[NSString stringWithFormat:@"%ld/%lu",(self.questionArr.count == 0)? 0 : [num integerValue] + 1,(unsigned long)self.questionArr.count]]; return [NSString stringWithFormat:@"%ld/%lu",(self.questionArr.count == 0)? 0 : [num integerValue] + 1,(unsigned long)self.questionArr.count]; }]; } return _handInThePaperView; } - (NSMutableArray *)correctArr { if (!_correctArr) { _correctArr = @[].mutableCopy; } return _correctArr; } - (NSMutableArray *)errorArr { if (!_errorArr) { _errorArr = @[].mutableCopy; } return _errorArr; } @end