123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879 |
- //
- // RQExerciseSubViewController.m
- // SDJK
- //
- // Created by 张嵘 on 2021/8/12.
- //
- #import "RQExerciseSubViewController.h"
- #import "HWPanModal.h"
- @interface RQExerciseSubViewController () <DZMCoverControllerDelegate>
- /// 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<self.questionArr.count-1 ?_firstNum+1:(int)self.questionArr.count-1;
- // [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithInt:popNum] forKey:@"QUESTIONNUM"];
- // [[NSUserDefaults standardUserDefaults] synchronize];
- }
- - (void)dealloc {
- [RQ_Exercise_Module cancleAutoReadQuestion];
- [RQNotificationCenter removeObserver:self name:RQAnswerResultsNotification object:nil];
- }
- - (void)updateQuestionArr {
- [self.view removeAllSubviews];
- [self rq_setup];
- }
- #pragma mark - PrivateMethods
- /// 初始化
- - (void)rq_setup {
- @weakify(self)
- if (self.viewModel.homeSubPageType == RQHomeSubPageType_WrongTopicAndCollection) {
- [self getQuestionArrayWithComplete:^(NSArray *getQuestionArr) {
- self.questionArr = getQuestionArr.mutableCopy;
- dispatch_async(dispatch_get_main_queue(), ^{
- [self creatCoverVC];
- [self creatToolsBar];
- });
- }];
- /// 错题·收藏题的随机练习和背题模式得单独对数组进行处理
- self.number = self.viewModel.number;
-
- [[[RQNotificationCenter rac_addObserverForName:RQCancelCollectNotification object:nil] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSNotification * note) {
- @strongify(self);
- RQExerciseModel *exerciseModel = note.userInfo[RQCancelCollectExerciseModelKey];
- [[self mutableArrayValueForKey:@"questionArr"] removeObject:exerciseModel];
- [self.coverVC.view removeFromSuperview];
- 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;
- _exerciseToolBarView.errorOptionNumLabel.text = @"0";
- _exerciseToolBarView.correctOptionNumLabel.text = @"0";
- } else {
- self.number = (self.questionArr.count == 1)? 0 : ((self.number == 0)? 0 : self.number - 1);
- [self creatCoverVC];
- [self.view bringSubviewToFront:self.exerciseToolBarView];
- _exerciseToolBarView.errorOptionNumLabel.text = [NSString stringWithFormat:@"%lu",(unsigned long)self.errorArr.count];
- _exerciseToolBarView.correctOptionNumLabel.text = [NSString stringWithFormat:@"%lu",(unsigned long)self.correctArr.count];
- }
- }];
-
- } /*else if (self.viewModel.homeSubPageType == RQHomeSubPageType_MockExamination && self.viewModel.questionArr) {
- self.questionArr = [NSMutableArray arrayWithArray:self.viewModel.questionArr];
- [self creatCoverVC];
- [self creatToolsBar];
- }*/ else {
- if (RQObjectIsNil(self.viewModel.questionArr)) {
- ///获取数据
- if (self.questionArr.count==0) {
- self.number = 0;
- [self changeCityQuestion];
- } else {
- self.number = 0;
- [self creatCoverVC];
- [self creatToolsBar];
- }
- } else {
- if (self.viewModel.questionArr.count > 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<RACSubscriber> 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<RACSubscriber> 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
|