RQExerciseSubViewController.m 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808
  1. //
  2. // RQExerciseSubViewController.m
  3. // SDJK
  4. //
  5. // Created by 张嵘 on 2021/8/12.
  6. //
  7. #import "RQExerciseSubViewController.h"
  8. #import "HWPanModal.h"
  9. @interface RQExerciseSubViewController () <DZMCoverControllerDelegate>
  10. /// viewModel
  11. @property (nonatomic, readonly, strong) RQExerciseSubViewModel *viewModel;
  12. @property (nonatomic, copy) void(^scrollCallback)(UIScrollView *scrollView);
  13. @property (nonatomic, readwrite, weak) DZMCoverController *coverVC;
  14. @property (nonatomic, readwrite, assign) NSInteger firstNum;///再次进来的第一题
  15. //@property (nonatomic, readwrite, retain) FMDatabase *db;
  16. @property (nonatomic, readwrite, retain) FMDatabaseQueue *dbQueue;
  17. @property (nonatomic, readwrite, strong) RQExerciseToolBarView *exerciseToolBarView;
  18. @property (nonatomic, readwrite, strong) RQErrorExerciseToolBarView *errorExerciseToolBarView;
  19. @property (nonatomic, readwrite, strong) RQHandInThePaperView *handInThePaperView;
  20. @property (nonatomic, readwrite, strong) NSMutableArray *correctArr;
  21. @property (nonatomic, readwrite, strong) NSMutableArray *errorArr;
  22. @end
  23. @implementation RQExerciseSubViewController
  24. @dynamic viewModel;
  25. #pragma mark - SystemMethod
  26. - (void)viewDidLoad {
  27. [super viewDidLoad];
  28. /// 初始化
  29. [self rq_setup];
  30. }
  31. - (void)viewWillDisappear:(BOOL)animated {
  32. [super viewWillDisappear:animated];
  33. // int popNum = _firstNum<self.questionArr.count-1 ?_firstNum+1:(int)self.questionArr.count-1;
  34. // [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithInt:popNum] forKey:@"QUESTIONNUM"];
  35. // [[NSUserDefaults standardUserDefaults] synchronize];
  36. }
  37. - (void)dealloc {
  38. [RQ_Exercise_Module cancleAutoReadQuestion];
  39. [RQNotificationCenter removeObserver:self name:RQAnswerResultsNotification object:nil];
  40. }
  41. - (void)updateQuestionArr {
  42. [self.view removeAllSubviews];
  43. [self rq_setup];
  44. }
  45. #pragma mark - PrivateMethods
  46. /// 初始化
  47. - (void)rq_setup {
  48. @weakify(self)
  49. if (self.viewModel.homeSubPageType == RQHomeSubPageType_WrongTopicAndCollection) {
  50. [self getQuestionArrayWithComplete:^(NSArray *getQuestionArr) {
  51. self.questionArr = getQuestionArr.mutableCopy;
  52. dispatch_async(dispatch_get_main_queue(), ^{
  53. [self creatCoverVC];
  54. [self creatToolsBar];
  55. });
  56. }];
  57. /// 错题·收藏题的随机练习和背题模式得单独对数组进行处理
  58. self.number = self.viewModel.number;
  59. [[[RQNotificationCenter rac_addObserverForName:RQCancelCollectNotification object:nil] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSNotification * note) {
  60. @strongify(self);
  61. RQExerciseModel *exerciseModel = note.userInfo[RQCancelCollectExerciseModelKey];
  62. [[self mutableArrayValueForKey:@"questionArr"] removeObject:exerciseModel];
  63. [self.coverVC.view removeFromSuperview];
  64. if ([self.errorArr containsObject:exerciseModel]) {
  65. [self.errorArr removeObject:exerciseModel];
  66. } else if ([self.correctArr containsObject:exerciseModel]) {
  67. [self.correctArr removeObject:exerciseModel];
  68. }
  69. if (self.questionArr.count == 0) {
  70. self.number = 0;
  71. _exerciseToolBarView.errorOptionNumLabel.text = @"0";
  72. _exerciseToolBarView.correctOptionNumLabel.text = @"0";
  73. } else {
  74. self.number = (self.questionArr.count == 1)? 0 : ((self.number == 0)? 0 : self.number - 1);
  75. [self creatCoverVC];
  76. [self.view bringSubviewToFront:self.exerciseToolBarView];
  77. _exerciseToolBarView.errorOptionNumLabel.text = [NSString stringWithFormat:@"%lu",(unsigned long)self.errorArr.count];
  78. _exerciseToolBarView.correctOptionNumLabel.text = [NSString stringWithFormat:@"%lu",(unsigned long)self.correctArr.count];
  79. }
  80. }];
  81. } /*else if (self.viewModel.homeSubPageType == RQHomeSubPageType_MockExamination && self.viewModel.questionArr) {
  82. self.questionArr = [NSMutableArray arrayWithArray:self.viewModel.questionArr];
  83. [self creatCoverVC];
  84. [self creatToolsBar];
  85. }*/ else {
  86. if (RQObjectIsNil(self.viewModel.questionArr)) {
  87. ///获取数据
  88. if (self.questionArr.count==0) {
  89. self.number = 0;
  90. [self changeCityQuestion];
  91. } else {
  92. self.number = 0;
  93. [self creatCoverVC];
  94. [self creatToolsBar];
  95. }
  96. } else {
  97. if (self.viewModel.questionArr.count > 0) {
  98. self.questionArr = [NSMutableArray arrayWithArray:self.viewModel.questionArr];
  99. self.number = 0;
  100. [self creatCoverVC];
  101. [self creatToolsBar];
  102. } else {
  103. ///获取数据
  104. if (self.questionArr.count==0) {
  105. self.number = 0;
  106. [self changeCityQuestion];
  107. } else {
  108. self.number = 0;
  109. [self creatCoverVC];
  110. [self creatToolsBar];
  111. }
  112. }
  113. }
  114. }
  115. /// 答题结果
  116. [RQNotificationCenter addObserver:self selector:@selector(dealWithAnswerResults:) name:RQAnswerResultsNotification object:nil];
  117. }
  118. - (void)getQuestionArrayWithComplete:(VoidBlock_id)complete {
  119. @weakify(self)
  120. switch (self.viewModel.homeSubPageType) {
  121. case RQHomeSubPageType_WrongTopicAndCollection: {
  122. if (self.viewModel.homeSubEditListType == RQHomeSubEditListType_WrongTopic) {
  123. NSArray *questionIdArr = [RQ_SDJK_DB_MANAGER queryWrongModelQuestionIdArrWithSubjectType:self.viewModel.homePageSubjectType];
  124. [RQ_QUESTION_DB_MANAGER getQuestionsWithQuestionIdArr:questionIdArr complete:^(NSArray *modelArray) {
  125. @strongify(self)
  126. if (self.viewModel.exerciseType == RQExerciseType_Random) {
  127. complete([NSMutableArray arrayWithArray:[modelArray rq_randomArray]]);
  128. } else if (self.viewModel.exerciseType == RQExerciseType_Recitation) {
  129. complete([modelArray.rac_sequence.signal map:^id _Nullable(RQExerciseModel *exerciseModel) {
  130. exerciseModel.userAnswer = exerciseModel.answer;
  131. return exerciseModel;
  132. }].toArray.mutableCopy);
  133. } else {
  134. complete(modelArray.mutableCopy);
  135. }
  136. }];
  137. } else if (self.viewModel.homeSubEditListType == RQHomeSubEditListType_Collection) {
  138. NSArray *questionIdArr = [RQ_SDJK_DB_MANAGER queryCollectionModelQuestionIdArrWithSubjectType:self.viewModel.homePageSubjectType];
  139. [RQ_QUESTION_DB_MANAGER getQuestionsWithQuestionIdArr:questionIdArr complete:^(NSArray *modelArray) {
  140. @strongify(self)
  141. if (self.viewModel.exerciseType == RQExerciseType_Random) {
  142. complete([NSMutableArray arrayWithArray:[modelArray rq_randomArray]]);
  143. } else if (self.viewModel.exerciseType == RQExerciseType_Recitation) {
  144. complete([modelArray.rac_sequence.signal map:^id _Nullable(RQExerciseModel *exerciseModel) {
  145. exerciseModel.userAnswer = exerciseModel.answer;
  146. return exerciseModel;
  147. }].toArray.mutableCopy);
  148. } else {
  149. complete(modelArray.mutableCopy);
  150. }
  151. }];
  152. }
  153. break;
  154. }
  155. default:
  156. break;
  157. }
  158. }
  159. - (void)dealWithAnswerResults:(NSNotification *)note {
  160. RQExerciseModel *exerciseModel = note.userInfo[RQAnswerResultsKey];
  161. RQHomePageCarType notifiCarType = [note.userInfo[RQHomePageCarTypeKey] integerValue];
  162. RQHomePageSubjectType notifiSubjectType = [note.userInfo[RQHomePageSubjectTypeKey] integerValue];
  163. RQExerciseDoType exerciseDoType = [note.userInfo[RQExerciseDoTypeKey] integerValue];
  164. if (notifiCarType != self.viewModel.homePageCarType || notifiSubjectType != self.viewModel.homePageSubjectType) {
  165. NSLog(@"重复推送");
  166. return;
  167. }
  168. [self saveTheAnswerRecordActionWithRQExerciseModel:exerciseModel];
  169. switch (exerciseModel.answerResultsType) {
  170. case RQAnswerResultsType_Correct: {
  171. if (![self.correctArr containsObject:exerciseModel]) {
  172. if (self.viewModel.exerciseType != RQExerciseType_Recitation) {
  173. [self.correctArr addObject:exerciseModel];
  174. if (exerciseDoType == RQExerciseDoType_Default && !RQ_Exercise_Module.isAutoRead) {
  175. /// 非自动读题 做对自动跳下一题
  176. /// 延时
  177. if (RQ_Exercise_Module.isRightAutoJumpToNext) {
  178. [[[RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
  179. [subscriber sendNext:@"延时0.5秒"];
  180. return nil;
  181. }] delay:.5f] subscribeNext:^(id x) {
  182. [self jumpNextQuestion];
  183. NSLog(@"-->%@",x);
  184. }];
  185. }
  186. }
  187. }
  188. } else {
  189. }
  190. if (self.viewModel.exerciseType != RQExerciseType_Test && self.viewModel.exerciseType != RQExerciseType_Exam) {
  191. if (self.viewModel.homeSubEditListType == RQHomeSubEditListType_WrongTopic) {
  192. _errorExerciseToolBarView.correctOptionNumLabel.text = [NSString stringWithFormat:@"%lu",(unsigned long)self.correctArr.count];
  193. } else {
  194. _exerciseToolBarView.correctOptionNumLabel.text = [NSString stringWithFormat:@"%lu",(unsigned long)self.correctArr.count];
  195. }
  196. }
  197. if (RQ_Exercise_Module.isAutoRead) {
  198. if (!exerciseModel.isAuto) {
  199. ///自动读题模式下: 当前题目结束自动读题 2秒后自动跳到下一题
  200. //延时
  201. [[[RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
  202. [subscriber sendNext:@"延时2秒"];
  203. return nil;
  204. }] delay:2] subscribeNext:^(id x) {
  205. [self jumpNextQuestion];
  206. NSLog(@"-->%@",x);
  207. }];
  208. } else {
  209. /// 自动读题模式下: 当前题目正在自动读题 暂不自动跳到下一题
  210. NSLog(@"自动读题模式下: 当前题目正在自动读题 暂不自动跳到下一题");
  211. }
  212. }
  213. }
  214. break;
  215. case RQAnswerResultsType_Error: {
  216. if ([self.errorArr indexOfObject:exerciseModel] == NSNotFound && ![self.errorArr containsObject:exerciseModel]) {
  217. [_errorArr addObject:exerciseModel];
  218. if (self.viewModel.exerciseType != RQExerciseType_Recitation && self.viewModel.exerciseType != RQExerciseType_Test && self.viewModel.exerciseType != RQExerciseType_Exam) {
  219. [RQ_Exercise_Module rq_showSkillExplanationAlertWithMessage:exerciseModel.explain_jq skillkeyword:exerciseModel.skillkeyword explainGifUrl:exerciseModel.explain_gif mp3Url:exerciseModel.explain_mp3 completeBlock:nil];
  220. }
  221. RQWrongModel *wrongModel = [[RQWrongModel alloc] init];
  222. wrongModel.questionId = exerciseModel._id;
  223. wrongModel.km = RQ_COMMON_MANAGER.subjectStr;
  224. wrongModel.createTime = [NSDate rq_currentTimeSSSInterval];
  225. wrongModel.userId = RQ_USER_MANAGER.currentUserId;
  226. // [[RQ_HTTP_Service queryAddWrongRecordWithQuestionId:exerciseModel._id carType:notifiCarType subject:notifiSubjectType] subscribeNext:^(id _Nullable x) {
  227. // [RQ_SDJK_DB_MANAGER addWrongRecordWithRQWrongModel:wrongModel];
  228. // [RQ_SDJK_DB_MANAGER getAllWrongModelsCount];
  229. // NSLog(@"%@",x);
  230. // }];
  231. [RQ_SDJK_DB_MANAGER addWrongRecordWithRQWrongModel:wrongModel];
  232. [RQ_SDJK_DB_MANAGER getAllWrongModelsCount];
  233. }
  234. if (self.viewModel.exerciseType != RQExerciseType_Test && self.viewModel.exerciseType != RQExerciseType_Exam) {
  235. if (self.viewModel.homeSubEditListType == RQHomeSubEditListType_WrongTopic) {
  236. _errorExerciseToolBarView.errorOptionNumLabel.text = [NSString stringWithFormat:@"%lu",(unsigned long)self.errorArr.count];
  237. } else {
  238. _exerciseToolBarView.errorOptionNumLabel.text = [NSString stringWithFormat:@"%lu",(unsigned long)self.errorArr.count];
  239. }
  240. }
  241. }
  242. break;
  243. default:
  244. break;
  245. }
  246. switch (exerciseDoType) {
  247. case RQExerciseDoType_Default: {
  248. break;
  249. }
  250. case RQExerciseDoType_Auto: {
  251. break;
  252. }
  253. case RQExerciseDoType_SkillExplanation: {
  254. [RQ_Exercise_Module rq_showSkillExplanationAlertWithMessage:exerciseModel.explain_jq skillkeyword:exerciseModel.skillkeyword explainGifUrl:exerciseModel.explain_gif mp3Url:exerciseModel.explain_mp3 completeBlock:nil];
  255. break;
  256. }
  257. case RQExerciseDoType_ReadAndAnswer: {
  258. // [RQ_MUSIC_MANAGER rq_resetStreamerWithURLString:exerciseModel.explainjsmp3];
  259. break;
  260. }
  261. default:
  262. break;
  263. }
  264. }
  265. - (void)creatCoverVC {
  266. if (self.questionArr.count <= 0) {
  267. return;
  268. }
  269. if (self.number > self.questionArr.count) {
  270. return;
  271. }
  272. DZMCoverController *coverVC = [[DZMCoverController alloc] init];
  273. coverVC.delegate = self;
  274. [self.view addSubview:coverVC.view];
  275. [self addChildViewController:coverVC];
  276. self.coverVC = coverVC;
  277. [self.coverVC setController:[self creatSubVC]];
  278. }
  279. - (RQTestQuestionsViewController *)creatSubVC {
  280. @weakify(self)
  281. RQExerciseModel *exerciseModel = self.questionArr[self.number];
  282. exerciseModel.num = self.number;
  283. exerciseModel.allNum = self.questionArr.count;
  284. exerciseModel.isShowSkillExplanation = NO;
  285. RQTestQuestionsViewModel *testQuestionsViewModel = [[RQTestQuestionsViewModel alloc] initWithServices:self.viewModel.services params:@{
  286. RQViewModelUtilKey : exerciseModel,
  287. RQExerciseTypeKey : @(self.viewModel.exerciseType),
  288. RQHomePageCarTypeKey : @(self.viewModel.homePageCarType),
  289. RQHomePageSubjectTypeKey: @(self.viewModel.homePageSubjectType),
  290. }];
  291. testQuestionsViewModel.lastQuestionCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id _Nullable input) {
  292. @strongify(self)
  293. [self jumpLastQuestion];
  294. return [RACSignal empty];
  295. }];
  296. testQuestionsViewModel.nextQuestionCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id _Nullable input) {
  297. @strongify(self)
  298. [self jumpNextQuestion];
  299. return [RACSignal empty];
  300. }];
  301. testQuestionsViewModel.showCatalogueCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id _Nullable input) {
  302. @strongify(self)
  303. [self showCatalogue];
  304. return [RACSignal empty];
  305. }];
  306. RQTestQuestionsViewController *vc = [[RQTestQuestionsViewController alloc] initWithViewModel:testQuestionsViewModel];
  307. __weak typeof(vc) weakController = vc;
  308. return weakController;
  309. }
  310. /// 根据车型取题
  311. - (void)changeCityQuestion {
  312. // @weakify(self)
  313. 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;
  314. NSString *titleStr = [self.viewModel.title componentsSeparatedByString:@"/"].lastObject;
  315. RQHistoryModel *history = [RQ_SDJK_DB_MANAGER queryHistoryModelWithCarType:self.viewModel.homePageCarType subjectType:self.viewModel.homePageSubjectType homeSubPageTyp:self.viewModel.homeSubPageType titleStr:titleStr];
  316. if (!RQObjectIsNil(history)) {
  317. NSInteger historyIndex = [[self.viewModel.questionArr.rac_sequence.signal map:^id _Nullable(RQExerciseModel *exerciseModel) {
  318. return @(exerciseModel._id);
  319. }].toArray indexOfObject:@(history.questionId)] + 1;
  320. if (historyIndex > 1) {
  321. self.number = historyIndex;
  322. }
  323. }
  324. // if (arr && arr.count > 0) {
  325. // NSInteger questionId = [arr.firstObject intValue];
  326. // NSArray *arr1 = [self.questionArr.rac_sequence filter:^BOOL(RQExerciseModel *exerciseModel) {
  327. // return exerciseModel._id == questionId;
  328. // }].array;
  329. // if (arr1 && arr1.count > 0) {
  330. // RQExerciseModel *exerciseModel = (RQExerciseModel *)arr1.firstObject;
  331. // NSInteger historyNum = [self.questionArr indexOfObject:exerciseModel];
  332. // self.number = historyNum;
  333. // }
  334. // }
  335. // [self searchExamRecord]; //顺序练习
  336. // if (self.number > 0) {
  337. // [NSObject rq_showAlertViewWithTitle:@"温馨提示" message:[NSString stringWithFormat:@"检测到您上次做到第%ld题,是否跳转?",self.number] confirmTitle:@"确定" cancelTitle:@"取消" confirmAction:^{
  338. // @strongify(self)
  339. // [self jumpQuestionWithIndex:self.number];
  340. // } cancelAction:nil];
  341. // }
  342. if (self.questionArr.count > 0) {
  343. [self creatCoverVC];
  344. [self creatToolsBar];
  345. }
  346. }
  347. /// 查看答题记录
  348. - (void)searchExamRecord {
  349. // FMResultSet *RightresultSet = [_db executeQuery:@"select * from dt_practice_record where course = 1 and mode = 1 and cert_type = 1"];
  350. // // 逐行读取数据
  351. // while ( [ RightresultSet next ] )
  352. // {
  353. // NSInteger ID = [RightresultSet intForColumn:@"_id"];
  354. // for (RQExerciseModel *item in self.questionArr) {
  355. // if (item._id == ID) {
  356. // item.answer = [RightresultSet stringForColumn:@"answer"];
  357. // if ([item.userAnswer isEqualToString:item.answer]) {
  358. // item.answerResultsType=1;//答对
  359. // }else{
  360. // item.answerResultsType=2;//答错
  361. // }
  362. // }
  363. // }
  364. //
  365. // }
  366. }
  367. /// 保存更新答题记录 ,如果没有打完自动跳转到下一题 ,model:1顺序2随机3专项4答对5打错6未答7收藏8模拟9考试纪录10章节 . */
  368. - (void)saveTheAnswerRecordActionWithRQExerciseModel:(RQExerciseModel *_Nullable)exerciseModel {
  369. /*
  370. *自动跳转到下一题
  371. */
  372. _firstNum = self.number;
  373. NSString *seque_issue_name = @"";
  374. NSString *class_issue_name = @"";
  375. NSString *place_issue_name = @"";
  376. NSString *excell_issue_name = @"";
  377. NSString *titleStr = [self.viewModel.title componentsSeparatedByString:@"/"].lastObject;
  378. switch (self.viewModel.homeSubPageType) {
  379. case RQHomeSubPageType_SequentialPractice:
  380. seque_issue_name = titleStr;
  381. break;
  382. case RQHomeSubPageType_LocalTopics:
  383. place_issue_name = titleStr;
  384. break;
  385. case RQHomeSubPageType_ClassificationExercise:
  386. class_issue_name = titleStr;
  387. break;
  388. case RQHomeSubPageType_SelectedTestQuestions:
  389. excell_issue_name = titleStr;
  390. break;
  391. default:
  392. break;
  393. }
  394. RQHistoryModel *historyModel = [[RQHistoryModel alloc] init];
  395. historyModel.questionId = exerciseModel._id;
  396. historyModel.userId = RQ_USER_MANAGER.currentUserId;
  397. historyModel.km = [RQ_COMMON_MANAGER getSubjectTypeStrWithSubjectType:self.viewModel.homePageSubjectType];
  398. historyModel.carType = [RQ_COMMON_MANAGER getCarTypeStrWithCarType:self.viewModel.homePageCarType];
  399. historyModel.seque_issue_name = seque_issue_name;
  400. historyModel.place_issue_name = place_issue_name;
  401. historyModel.class_issue_name = class_issue_name;
  402. historyModel.excell_issue_name = excell_issue_name;
  403. [RQ_SDJK_DB_MANAGER addHistoryRecordWithRQHistoryModel:historyModel];
  404. }
  405. - (void)jumpNextQuestion {
  406. if (self.number + 1 >= self.questionArr.count) {
  407. return;
  408. }
  409. self.number += 1;
  410. [self.coverVC setController:[self creatSubVC] animated:YES isAbove:NO];
  411. if (self.viewModel.exerciseType != RQExerciseType_Test && self.viewModel.exerciseType != RQExerciseType_Exam) {
  412. if (self.viewModel.homeSubEditListType == RQHomeSubEditListType_WrongTopic) {
  413. [self.view bringSubviewToFront:self.errorExerciseToolBarView];
  414. } else {
  415. [self.view bringSubviewToFront:self.exerciseToolBarView];
  416. }
  417. } else {
  418. [self.view bringSubviewToFront:self.handInThePaperView];
  419. }
  420. }
  421. - (void)jumpLastQuestion{
  422. if (self.number == 0) {
  423. return;
  424. }
  425. self.number -= 1;
  426. [self.coverVC setController:[self creatSubVC] animated:YES isAbove:YES];
  427. if (self.viewModel.exerciseType != RQExerciseType_Test && self.viewModel.exerciseType != RQExerciseType_Exam) {
  428. if (self.viewModel.homeSubEditListType == RQHomeSubEditListType_WrongTopic) {
  429. [self.view bringSubviewToFront:self.errorExerciseToolBarView];
  430. } else {
  431. [self.view bringSubviewToFront:self.exerciseToolBarView];
  432. }
  433. } else {
  434. [self.view bringSubviewToFront:self.handInThePaperView];
  435. }
  436. }
  437. - (void)jumpQuestionWithIndex:(NSUInteger)index {
  438. self.number = (int)index;
  439. [self.coverVC setController:[self creatSubVC] animated:NO isAbove:NO];
  440. if (self.viewModel.exerciseType != RQExerciseType_Test && self.viewModel.exerciseType != RQExerciseType_Exam) {
  441. if (self.viewModel.homeSubEditListType == RQHomeSubEditListType_WrongTopic) {
  442. [self.view bringSubviewToFront:self.errorExerciseToolBarView];
  443. } else {
  444. [self.view bringSubviewToFront:self.exerciseToolBarView];
  445. }
  446. } else {
  447. [self.view bringSubviewToFront:self.handInThePaperView];
  448. }
  449. }
  450. - (void)creatToolsBar {
  451. if (self.viewModel.exerciseType != RQExerciseType_Test && self.viewModel.exerciseType != RQExerciseType_Exam) {
  452. if (self.viewModel.homeSubEditListType == RQHomeSubEditListType_WrongTopic) {
  453. [self.view addSubview:self.errorExerciseToolBarView];
  454. [_errorExerciseToolBarView mas_makeConstraints:^(MASConstraintMaker *make) {
  455. make.centerX.mas_equalTo(self.view);
  456. make.bottom.mas_equalTo(self.view).mas_offset(-(RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT + RQ_APPLICATION_NAV_BAR_HEIGHT));
  457. make.size.mas_equalTo(CGSizeMake(RQ_SCREEN_WIDTH, 50));
  458. }];
  459. } else {
  460. [self.view addSubview:self.exerciseToolBarView];
  461. [_exerciseToolBarView mas_makeConstraints:^(MASConstraintMaker *make) {
  462. make.centerX.mas_equalTo(self.view);
  463. make.bottom.mas_equalTo(self.view).mas_offset(-(RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT + RQ_APPLICATION_NAV_BAR_HEIGHT));
  464. make.size.mas_equalTo(CGSizeMake(RQ_SCREEN_WIDTH, 50));
  465. }];
  466. }
  467. } else {
  468. [self.view addSubview:self.handInThePaperView];
  469. [_handInThePaperView mas_makeConstraints:^(MASConstraintMaker *make) {
  470. make.centerX.mas_equalTo(self.view);
  471. make.bottom.mas_equalTo(self.view).mas_offset(-(RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT + RQ_APPLICATION_NAV_BAR_HEIGHT));
  472. make.size.mas_equalTo(CGSizeMake(RQ_SCREEN_WIDTH, 8.f + RQ_FIT_HORIZONTAL(54.f) + 8.f + 50.f + 8.f));
  473. }];
  474. }
  475. }
  476. - (void)showCatalogue {
  477. @weakify(self)
  478. if (self.questionArr.count == 0) {
  479. return;
  480. }
  481. RQCatalogueViewModel *catalogueViewModel = [[RQCatalogueViewModel alloc] initWithServices:self.viewModel.services params:@{
  482. RQViewModelIDKey : @(self.number),
  483. RQViewModelUtilKey : self.questionArr,
  484. RQViewCommonValueKey : @(self.correctArr.count),
  485. RQViewModelRequestKey : @(self.errorArr.count),
  486. }];
  487. RQCatalogueViewController *catalogueViewController = [[RQCatalogueViewController alloc] initWithViewModel:catalogueViewModel];
  488. [catalogueViewController initCompletionWithSelectIndexBlock:^(NSInteger index) {
  489. @strongify(self)
  490. [self jumpQuestionWithIndex:index];
  491. }];
  492. [self presentPanModal:catalogueViewController];
  493. }
  494. #pragma mark - DZMCoverControllerDelegate
  495. /// 切换结果
  496. - (void)coverController:(DZMCoverController *)coverController currentController:(UIViewController *)currentController finish:(BOOL)isFinish {
  497. if (!isFinish) { // 切换失败
  498. // RQTestQuestionsViewController *vc = (RQTestQuestionsViewController *)currentController;
  499. }
  500. }
  501. /// 上一个控制器
  502. - (UIViewController *)coverController:(DZMCoverController *)coverController getAboveControllerWithCurrentController:(UIViewController *)currentController {
  503. if (self.number == 0) {
  504. return nil;
  505. }
  506. self.number -= 1;
  507. return [self creatSubVC];
  508. }
  509. /// 下一个控制器
  510. - (UIViewController *)coverController:(DZMCoverController *)coverController getBelowControllerWithCurrentController:(UIViewController *)currentController {
  511. if (self.number==self.questionArr.count-1) {
  512. return nil;
  513. }
  514. self.number += 1;
  515. return [self creatSubVC];
  516. }
  517. #pragma mark - UITableViewDataSource, UITableViewDelegate
  518. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  519. !self.scrollCallback ?: self.scrollCallback(scrollView);
  520. }
  521. #pragma mark - JXPagingViewListViewDelegate
  522. - (UIView *)listView {
  523. return self.view;
  524. }
  525. - (UIScrollView *)listScrollView {
  526. return self.tableView;
  527. }
  528. - (void)listViewDidScrollCallback:(void (^)(UIScrollView *))callback {
  529. self.scrollCallback = callback;
  530. }
  531. #pragma mark - LazyLoad
  532. - (NSMutableArray *)questionArr {
  533. if (!_questionArr) {
  534. _questionArr = @[].mutableCopy;
  535. }
  536. return _questionArr;
  537. }
  538. - (RQExerciseToolBarView *)exerciseToolBarView {
  539. if (!_exerciseToolBarView) {
  540. _exerciseToolBarView = [RQExerciseToolBarView exerciseToolBarView];
  541. @weakify(self,_exerciseToolBarView);
  542. // [RACObserve(self, number) subscribeNext:^(id _Nullable x) {
  543. // @strongify(self,_exerciseToolBarView)
  544. // _exerciseToolBarView.totalNumberOfQuestionsLabel.text = [NSString stringWithFormat:@"%ld/%lu",[x integerValue] + 1,(unsigned long)self.questionArr.count];
  545. // }];
  546. RAC(_exerciseToolBarView.totalNumberOfQuestionsLabel, text) = [RACSignal combineLatest:@[RACObserve(self, number), RACObserve(self, questionArr)] reduce:^id (NSNumber *num, NSArray *selectArr){
  547. @strongify(self)
  548. return [NSString stringWithFormat:@"%ld/%lu",(self.questionArr.count == 0)? 0 : [num integerValue] + 1,(unsigned long)self.questionArr.count];
  549. }];
  550. [_exerciseToolBarView.lastQuestionView setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
  551. @strongify(self)
  552. [self jumpLastQuestion];
  553. }];
  554. [_exerciseToolBarView.nextQuestionView setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
  555. @strongify(self)
  556. [self jumpNextQuestion];
  557. }];
  558. [_exerciseToolBarView.totalNumberOfQuestionsView setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
  559. @strongify(self)
  560. [self showCatalogue];
  561. }];
  562. [_exerciseToolBarView.officialInterpretationView setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
  563. @strongify(self)
  564. if (self.questionArr.count == 0) {
  565. return;
  566. }
  567. RQExerciseModel *exerciseModel = self.questionArr[self.number];
  568. if (RQ_Exercise_Module.isAutoRead) RQ_Exercise_Module.isAutoRead = NO;
  569. [RQ_Exercise_Module rq_showOfficialInterpretationAlertWithMessage:exerciseModel.explain_js mp3Url:exerciseModel.explainjsmp3];
  570. }];
  571. }
  572. return _exerciseToolBarView;
  573. }
  574. - (RQErrorExerciseToolBarView *)errorExerciseToolBarView {
  575. if (!_errorExerciseToolBarView) {
  576. _errorExerciseToolBarView = [RQErrorExerciseToolBarView errorExerciseToolBarView];
  577. @weakify(self);
  578. RAC(_errorExerciseToolBarView.totalNumberOfQuestionsLabel, text) = [RACSignal combineLatest:@[RACObserve(self, number), RACObserve(self, questionArr)] reduce:^id (NSNumber *num, NSArray *selectArr){
  579. @strongify(self)
  580. return [NSString stringWithFormat:@"%ld/%lu",(self.questionArr.count == 0)? 0 : [num integerValue] + 1,(unsigned long)self.questionArr.count];
  581. }];
  582. // [RACObserve(self, number) subscribeNext:^(id _Nullable x) {
  583. // @strongify(self,_errorExerciseToolBarView)
  584. // _errorExerciseToolBarView.totalNumberOfQuestionsLabel.text = [NSString stringWithFormat:@"%ld/%lu",(self.questionArr.count == 0)? 0 : [x integerValue] + 1,(unsigned long)self.questionArr.count];
  585. // }];
  586. [_errorExerciseToolBarView.deleteView setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
  587. @strongify(self)
  588. if (self.questionArr.count == 0) {
  589. return;
  590. }
  591. RQExerciseModel *exerciseModel = self.questionArr[self.number];
  592. // [[RQ_HTTP_Service queryDeleteWrongRecordWithQuestionId:[NSString qmui_stringWithNSInteger:exerciseModel._id]] subscribeNext:^(id _Nullable x) {
  593. // @strongify(self)
  594. // [RQ_SDJK_DB_MANAGER deleteWrongRecordWithQuestionId:exerciseModel._id];
  595. // [[self mutableArrayValueForKey:@"questionArr"] removeObject:exerciseModel];
  596. // [MBProgressHUD rq_showTips:@"删除成功"];
  597. // [self.coverVC.view removeFromSuperview];
  598. // [RQ_SDJK_DB_MANAGER getAllWrongModelsCount];
  599. // if ([self.errorArr containsObject:exerciseModel]) {
  600. // [self.errorArr removeObject:exerciseModel];
  601. // } else if ([self.correctArr containsObject:exerciseModel]) {
  602. // [self.correctArr removeObject:exerciseModel];
  603. // }
  604. //
  605. // if (self.questionArr.count == 0) {
  606. // self.number = 0;
  607. // _errorExerciseToolBarView.errorOptionNumLabel.text = @"0";
  608. // _errorExerciseToolBarView.correctOptionNumLabel.text = @"0";
  609. // } else {
  610. // self.number = (self.questionArr.count == 1)? 0 : ((self.number == 0)? 0 : self.number - 1);
  611. // [self creatCoverVC];
  612. // [self.view bringSubviewToFront:self.errorExerciseToolBarView];
  613. // _errorExerciseToolBarView.errorOptionNumLabel.text = [NSString stringWithFormat:@"%lu",(unsigned long)self.errorArr.count];
  614. // _errorExerciseToolBarView.correctOptionNumLabel.text = [NSString stringWithFormat:@"%lu",(unsigned long)self.correctArr.count];
  615. // }
  616. // } error:^(NSError * _Nullable error) {
  617. // [MBProgressHUD rq_showErrorTips:error];
  618. // }];
  619. BOOL isDelete = [RQ_SDJK_DB_MANAGER deleteWrongRecordWithQuestionId:exerciseModel._id];
  620. if (isDelete) {
  621. [[self mutableArrayValueForKey:@"questionArr"] removeObject:exerciseModel];
  622. [MBProgressHUD rq_showTips:@"删除成功"];
  623. [self.coverVC.view removeFromSuperview];
  624. [RQ_SDJK_DB_MANAGER getAllWrongModelsCount];
  625. if ([self.errorArr containsObject:exerciseModel]) {
  626. [self.errorArr removeObject:exerciseModel];
  627. } else if ([self.correctArr containsObject:exerciseModel]) {
  628. [self.correctArr removeObject:exerciseModel];
  629. }
  630. if (self.questionArr.count == 0) {
  631. self.number = 0;
  632. self.errorExerciseToolBarView.errorOptionNumLabel.text = @"0";
  633. self.errorExerciseToolBarView.correctOptionNumLabel.text = @"0";
  634. } else {
  635. self.number = (self.questionArr.count == 1)? 0 : ((self.number == 0)? 0 : self.number - 1);
  636. [self creatCoverVC];
  637. [self.view bringSubviewToFront:self.errorExerciseToolBarView];
  638. self.errorExerciseToolBarView.errorOptionNumLabel.text = [NSString stringWithFormat:@"%lu",(unsigned long)self.errorArr.count];
  639. self.errorExerciseToolBarView.correctOptionNumLabel.text = [NSString stringWithFormat:@"%lu",(unsigned long)self.correctArr.count];
  640. }
  641. } else {
  642. [MBProgressHUD rq_showTips:@"删除失败"];
  643. }
  644. }];
  645. [_errorExerciseToolBarView.totalNumberOfQuestionsView setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
  646. @strongify(self)
  647. [self showCatalogue];
  648. }];
  649. [_errorExerciseToolBarView.officialInterpretationView setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
  650. @strongify(self)
  651. if (self.questionArr.count == 0) {
  652. return;
  653. }
  654. RQExerciseModel *exerciseModel = self.questionArr[self.number];
  655. if (RQ_Exercise_Module.isAutoRead) RQ_Exercise_Module.isAutoRead = NO;
  656. [RQ_Exercise_Module rq_showOfficialInterpretationAlertWithMessage:exerciseModel.explain_js mp3Url:exerciseModel.explainjsmp3];
  657. }];
  658. }
  659. return _errorExerciseToolBarView;
  660. }
  661. - (RQHandInThePaperView *)handInThePaperView {
  662. if (!_handInThePaperView) {
  663. @weakify(self)
  664. _handInThePaperView = [RQHandInThePaperView handInThePaperView];
  665. [_handInThePaperView.handInThePaperBtn setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
  666. @strongify(self)
  667. 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;
  668. RQTestResultsViewModel *testResultsViewModel = [[RQTestResultsViewModel alloc] initWithServices:self.viewModel.services params:@{
  669. RQHomePageCarTypeKey : @(self.viewModel.homePageCarType),
  670. RQHomePageSubjectTypeKey : @(self.viewModel.homePageSubjectType),
  671. RQHomeSubPageTypeKey : @(self.viewModel.homeSubPageType),
  672. RQExerciseTypeKey : @(self.viewModel.exerciseType),
  673. RQViewModelIDKey : @(score),
  674. RQViewCommonValueKey : @(self.count),
  675. RQViewModelUtilKey : self.questionArr,
  676. }];
  677. [self.viewModel.services pushViewModel:testResultsViewModel animated:YES];
  678. }];
  679. [_handInThePaperView.lastQuestionBtn setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
  680. @strongify(self)
  681. [self jumpLastQuestion];
  682. }];
  683. [_handInThePaperView.nextQuestionBtn setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
  684. @strongify(self)
  685. [self jumpNextQuestion];
  686. }];
  687. [_handInThePaperView.totalNumberOfQuestionsBtn setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
  688. @strongify(self)
  689. [self showCatalogue];
  690. }];
  691. RAC(_handInThePaperView.totalNumberOfQuestionsBtn.titleLabel, text) = [RACSignal combineLatest:@[RACObserve(self, number), RACObserve(self, questionArr)] reduce:^id (NSNumber *num, NSArray *selectArr){
  692. @strongify(self)
  693. [self.handInThePaperView.totalNumberOfQuestionsBtn setTitleNormal:[NSString stringWithFormat:@"%ld/%lu",(self.questionArr.count == 0)? 0 : [num integerValue] + 1,(unsigned long)self.questionArr.count]];
  694. return [NSString stringWithFormat:@"%ld/%lu",(self.questionArr.count == 0)? 0 : [num integerValue] + 1,(unsigned long)self.questionArr.count];
  695. }];
  696. }
  697. return _handInThePaperView;
  698. }
  699. - (NSMutableArray *)correctArr {
  700. if (!_correctArr) {
  701. _correctArr = @[].mutableCopy;
  702. }
  703. return _correctArr;
  704. }
  705. - (NSMutableArray *)errorArr {
  706. if (!_errorArr) {
  707. _errorArr = @[].mutableCopy;
  708. }
  709. return _errorArr;
  710. }
  711. @end