RQExerciseSubViewController.m 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. //
  2. // RQExerciseSubViewController.m
  3. // JSJP
  4. //
  5. // Created by 张嵘 on 2021/8/12.
  6. //
  7. #import "RQExerciseSubViewController.h"
  8. #import "HWPanModal.h"
  9. @interface RQExerciseSubViewController ()
  10. /// viewModel
  11. @property (nonatomic, readonly, strong) RQExerciseSubViewModel *viewModel;
  12. @property (nonatomic, readwrite, strong) RQExerciseToolBarView *exerciseToolBarView;
  13. @property (nonatomic, readwrite, strong) JXPagerSmoothView *pagerView;
  14. @property (nonatomic, readwrite, strong) JXCategoryTitleView *categoryView;
  15. @property (nonatomic, copy) void(^scrollCallback)(UIScrollView *scrollView);
  16. @property (nonatomic, readwrite, strong) UIScrollView *currentListView;
  17. @property (nonatomic, readwrite, copy) NSArray <NSString *> *titles;
  18. @property (nonatomic, readwrite, copy) NSArray <RQYDTQuestionModel *> *ydtQuestionsArr;
  19. @property (nonatomic, readwrite, copy) NSArray <RQExerciseModel *> *reDoQuestionsArr;
  20. @property (nonatomic, readwrite, strong) NSMutableDictionary *listVcDic;
  21. @property (nonatomic, readwrite, strong) NSMapTable *mapTable;
  22. @end
  23. @implementation RQExerciseSubViewController
  24. @dynamic viewModel;
  25. #pragma mark - SystemMethod
  26. - (void)viewDidLoad {
  27. [super viewDidLoad];
  28. /// 初始化
  29. [self rq_setup];
  30. @weakify(self)
  31. dispatch_async(dispatch_get_main_queue(), ^{
  32. CGFloat height = RQ_SCREEN_HEIGHT - (RQ_APPLICATION_NAV_BAR_HEIGHT + RQ_APPLICATION_STATUS_BAR_HEIGHT) - RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT - RQ_FIT_HORIZONTAL(50.f);
  33. self.pagerView.frame = CGRectMake(0, 0, RQ_SCREEN_WIDTH, height);
  34. [self.exerciseToolBarView mas_makeConstraints:^(MASConstraintMaker *make) {
  35. @strongify(self)
  36. make.centerX.mas_equalTo(self.view);
  37. make.bottom.mas_equalTo(self.view.mas_bottom).mas_offset(0);
  38. make.size.mas_equalTo(CGSizeMake(RQ_SCREEN_WIDTH, RQ_FIT_HORIZONTAL(50.f)));
  39. }];
  40. });
  41. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateScoreView) name:@"updateScoreView" object:nil];
  42. }
  43. - (void)viewWillDisappear:(BOOL)animated {
  44. [super viewWillDisappear:animated];
  45. // int popNum = _firstNum<self.questionArr.count-1 ?_firstNum+1:(int)self.questionArr.count-1;
  46. // [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithInt:popNum] forKey:@"QUESTIONNUM"];
  47. // [[NSUserDefaults standardUserDefaults] synchronize];
  48. }
  49. - (void)viewWillLayoutSubviews {
  50. [super viewWillLayoutSubviews];
  51. }
  52. - (void)updateScoreView {
  53. RQExamResultViewModel *examResultViewModel = [[RQExamResultViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{
  54. RQViewModelUtilKey : self.viewModel.questionArr,
  55. RQViewModelIDKey : RQ_Exercise_Module.correctArr,
  56. RQViewCommonValueKey : RQ_Exercise_Module.errorArr,
  57. RQHomeSubPageTypeKHModeKey : @(self.viewModel.subPageTypeKHMode)
  58. }];
  59. [RQ_APPDELEGATE.services pushViewModel:examResultViewModel animated:YES];
  60. }
  61. - (void)dealloc {
  62. [[NSNotificationCenter defaultCenter] removeObserver:self];
  63. RQ_Exercise_Module.correctArr = @[];
  64. RQ_Exercise_Module.errorArr = @[];
  65. self.categoryView.delegate = nil;
  66. self.categoryView = nil;
  67. // self.pagerView.delegate = nil;
  68. self.pagerView = nil;
  69. RQ_Exercise_Module.questionArr = @[];
  70. }
  71. #pragma mark - PrivateMethods
  72. /// 初始化
  73. - (void)rq_setup {
  74. @weakify(self)
  75. [self.view addSubview:self.pagerView];
  76. [self.view addSubview:self.exerciseToolBarView];
  77. if (RQ_Exercise_Module.currentExerciseType == RQExerciseType_Exam) {
  78. RQ_Exercise_Module.questionArr = self.viewModel.questionArr;
  79. [self jumpQuestionWithIndex:0];
  80. [self reDoQuestionsArr];
  81. } else {
  82. NSInteger historyNum = [RQ_YDTQuestion_Module getHistoryQuestionNum];
  83. if (self.viewModel.questionArr.count >= historyNum + 1) {
  84. if (historyNum == 0) {
  85. [self jumpQuestionWithIndex:0];
  86. } else {
  87. [RQ_ALERTVIEW_MANAGER showAlertWithAlertType:RQAlertType_Default title:@"温馨提示" message:[NSString stringWithFormat:@"上次做题至%ld题,是否继续?",historyNum + 1] confirmTitle:@"是" cancelTitle:@"否" confirmAction:^(__kindof QMUIDialogViewController * _Nonnull dialogViewController) {
  88. @strongify(self)
  89. [self jumpQuestionWithIndex:historyNum];
  90. } cancelAction:^(__kindof QMUIDialogViewController * _Nonnull dialogViewController) {
  91. @strongify(self)
  92. [self jumpQuestionWithIndex:0];
  93. }];
  94. }
  95. }
  96. }
  97. [[RACObserve(self, number) deliverOnMainThread] subscribeNext:^(id _Nullable x) {
  98. @strongify(self)
  99. if (self.viewModel.questionArr) {
  100. if (self.viewModel.questionArr.count >= self.number + 1) {
  101. self.exerciseToolBarView.totalNumberOfQuestionsLabel.text = [NSString stringWithFormat:@"%ld/%lu",[x integerValue] + 1,(unsigned long)self.viewModel.questionArr.count];
  102. RQExerciseModel *exerciseModel = self.viewModel.questionArr[self.number];
  103. self.exerciseToolBarView.collectBtn.selected = [RQ_YDT_USER_Question_Module getCollectRecordWithQuestionId:exerciseModel.ydtQuestionModel.ID carType:RQ_YDTQuestion_Module.carType subject:RQ_YDTQuestion_Module.subject];
  104. }
  105. }
  106. if(RQ_Exercise_Module.errorArr.count)
  107. self.exerciseToolBarView.errorOptionNumLabel.text = (RQ_Exercise_Module.currentExerciseType == RQExerciseType_Recitation)? @"0" : [NSString qmui_stringWithNSInteger:RQ_Exercise_Module.errorArr.count];//错题
  108. if(RQ_Exercise_Module.correctArr.count)
  109. self.exerciseToolBarView.correctOptionNumLabel.text = (RQ_Exercise_Module.currentExerciseType == RQExerciseType_Recitation)? @"0" : [NSString qmui_stringWithNSInteger:RQ_Exercise_Module.correctArr.count];//对题
  110. }];
  111. // RAC(self.exerciseToolBarView.errorOptionNumLabel, text) = [RACObserve(RQ_Exercise_Module, errorArr) map:^id _Nullable(id _Nullable value) {
  112. // return (RQ_Exercise_Module.currentExerciseType == RQExerciseType_Recitation)? @"0" : [NSString qmui_stringWithNSInteger:RQ_Exercise_Module.errorArr.count];
  113. // }];
  114. //
  115. // RAC(self.exerciseToolBarView.correctOptionNumLabel, text) = [RACObserve(RQ_Exercise_Module, correctArr) map:^id _Nullable(id _Nullable value) {
  116. // return (RQ_Exercise_Module.currentExerciseType == RQExerciseType_Recitation)? @"0" : [NSString qmui_stringWithNSInteger:RQ_Exercise_Module.correctArr.count];
  117. // }];
  118. // [[[[RQNotificationCenter rac_addObserverForName:RQExerciseAlertNotification object:nil] deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSNotification * note) {
  119. // @strongify(self)
  120. // RQExerciseAlertType type = [note.object[RQExerciseAlertTypeKey] integerValue];
  121. // if (RQ_Exercise_Module.currentExerciseType == RQExerciseType_Exam) {
  122. // NSDictionary *dic = @{
  123. // @"questionArr" : self.viewModel.questionArr,
  124. // };
  125. //
  126. // [RQ_Exercise_Module showAlertWithRQExerciseAlertType:type valueDic:dic confirmAction:^(__kindof QMUIDialogViewController *dialogViewController) {
  127. // @strongify(self);
  128. // if (type == RQExerciseAlertType_Exam_HandUp) {
  129. // /// 交卷
  130. // RQExamResultViewModel *examResultViewModel = [[RQExamResultViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{
  131. // RQViewModelUtilKey : self.viewModel.questionArr,
  132. // RQViewModelIDKey : RQ_Exercise_Module.correctArr,
  133. // RQViewCommonValueKey : RQ_Exercise_Module.errorArr,
  134. // }];
  135. // [RQ_APPDELEGATE.services pushViewModel:examResultViewModel animated:YES];
  136. // } else if (type == RQExerciseAlertType_Exam_Resume || type == RQExerciseAlertType_Exam_Suspend) {
  137. // if (RQ_Exercise_Module.timer) {
  138. // [RQ_Exercise_Module.timer setFireDate:[NSDate distantPast]];
  139. // }
  140. // }
  141. // } cancelAction:^(__kindof QMUIDialogViewController *dialogViewController) {
  142. // @strongify(self)
  143. // if (type == RQExerciseAlertType_Exam_HandUp) {
  144. // if (RQ_Exercise_Module.timer) {
  145. // [RQ_Exercise_Module.timer setFireDate:[NSDate distantPast]];
  146. // }
  147. // } else if (type == RQExerciseAlertType_Exam_Resume || type == RQExerciseAlertType_Exam_Suspend) {
  148. // /// 重新考试
  149. // self.viewModel.questionArr = self.reDoQuestionsArr;
  150. // if (RQ_Exercise_Module.timer) {
  151. // [RQ_Exercise_Module.timer invalidate];
  152. // RQ_Exercise_Module.timer = nil;
  153. // [RQ_Exercise_Module startTimer];
  154. // RQ_Exercise_Module.errorArr = @[];
  155. // RQ_Exercise_Module.correctArr = @[];
  156. // [self jumpQuestionWithIndex:0];
  157. // }
  158. // }
  159. // }];
  160. // }
  161. // }];
  162. [[[[RQNotificationCenter rac_addObserverForName:RQAutoJumpNextNotification object:nil] deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSNotification * _Nullable x) {
  163. @strongify(self);
  164. if (RQ_Exercise_Module.isRightAutoJumpToNext) {
  165. if (self.viewModel.questionArr.count == self.number + 1) {
  166. [QMUITips showWithText:@"已经是最后一题啦!"];
  167. } else {
  168. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  169. [self jumpQuestionWithIndex:self.number + 1];
  170. });
  171. }
  172. }
  173. }];
  174. }
  175. - (void)jumpQuestionWithIndex:(NSUInteger)index {
  176. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  177. self.number = (int)index;
  178. self.pagerView.defaultSelectedIndex = index;
  179. self.categoryView.defaultSelectedIndex = index;
  180. [self.pagerView reloadData];
  181. [self.categoryView reloadData];
  182. [self saveNumWithIndex:index];
  183. });
  184. }
  185. - (void)showCatalogue {
  186. @weakify(self)
  187. RQ_Exercise_Module.isShow_CatalogueView = YES;
  188. RQCatalogueViewModel *catalogueViewModel = [[RQCatalogueViewModel alloc] initWithServices:self.viewModel.services params:@{
  189. RQViewModelIDKey : @(self.number),
  190. RQViewModelUtilKey : self.viewModel.questionArr,
  191. // RQExerciseTypeKey : @(self.viewModel.exerciseType),
  192. }];
  193. RQCatalogueViewController *catalogueViewController = [[RQCatalogueViewController alloc] initWithViewModel:catalogueViewModel];
  194. [catalogueViewController initCompletionWithSelectIndexBlock:^(NSInteger index) {
  195. @strongify(self)
  196. [self jumpQuestionWithIndex:index];
  197. }];
  198. [self presentPanModal:catalogueViewController];
  199. }
  200. #pragma mark - UITableViewDataSource, UITableViewDelegate
  201. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  202. !self.scrollCallback ?: self.scrollCallback(scrollView);
  203. }
  204. #pragma mark - JXPagerViewListViewDelegate
  205. - (UIView *)listView {
  206. return self.view;
  207. }
  208. - (UIScrollView *)listScrollView {
  209. return self.tableView;
  210. }
  211. - (void)listViewDidScrollCallback:(void (^)(UIScrollView *))callback {
  212. self.scrollCallback = callback;
  213. }
  214. - (void)listScrollViewWillResetContentOffset {
  215. //当前的listScrollView需要重置的时候,就把所有列表的contentOffset都重置了
  216. for (RQTestQuestionsViewController *list in self.pagerView.listDict.allValues) {
  217. list.tableView.contentOffset = CGPointZero;
  218. }
  219. }
  220. #pragma mark - JXPagerSmoothViewDataSource
  221. - (UIView *)viewForPagerHeaderInPagerView:(JXPagerSmoothView *)pagerView {
  222. return [UIView new];
  223. }
  224. - (CGFloat)heightForPagerHeaderInPagerView:(JXPagerSmoothView *)pagerView {
  225. return 0.f;
  226. }
  227. - (CGFloat)heightForPinHeaderInPagerView:(JXPagerSmoothView *)pagerView {
  228. return 0.f;
  229. }
  230. - (UIView *)viewForPinHeaderInPagerView:(JXPagerSmoothView *)pagerView {
  231. return self.categoryView;
  232. }
  233. - (NSInteger)numberOfListsInPagerView:(JXPagerSmoothView *)pagerView {
  234. return self.categoryView.titles.count;
  235. }
  236. - (id<JXPagerSmoothViewListViewDelegate>)pagerView:(JXPagerSmoothView *)pagerView initListAtIndex:(NSInteger)index {
  237. NSLog(@"JXCategoryViewDelegate=====initListAtIndex=%zd",index);
  238. @weakify(self)
  239. RQTestQuestionsViewController *currentQuestionsViewController = [self.listVcDic objectForKey:[NSString qmui_stringWithNSInteger:index]];
  240. if (RQObjectIsNil(currentQuestionsViewController)) {
  241. RQExerciseModel *exerciseModel = self.viewModel.questionArr[index];
  242. // exerciseModel.exerciseType = self.viewModel.exerciseType;
  243. exerciseModel.allNum = self.viewModel.questionArr.count;
  244. RQTestQuestionsViewModel *testQuestionsViewModel = [[RQTestQuestionsViewModel alloc] initWithServices:self.viewModel.services params:@{
  245. RQViewModelUtilKey : exerciseModel,
  246. // RQExerciseTypeKey : @(self.viewModel.exerciseType),
  247. RQHomePageCarTypeKey : @(self.viewModel.homePageCarType),
  248. RQHomePageSubjectTypeKey: @(self.viewModel.homePageSubjectType),
  249. }];
  250. RQTestQuestionsViewController *testQuestionsViewController = [[RQTestQuestionsViewController alloc] initWithViewModel:testQuestionsViewModel];
  251. currentQuestionsViewController = testQuestionsViewController;
  252. [self.listVcDic setObject:testQuestionsViewController forKey:[NSString qmui_stringWithNSInteger:index]];
  253. }
  254. [[RACScheduler scheduler] schedule:^{
  255. @strongify(self)
  256. if (index > 0) {
  257. if (index > 1) {
  258. RQTestQuestionsViewController *lastQuestionsViewController1 = [self.listVcDic objectForKey:[NSString qmui_stringWithNSInteger:index - 2]];
  259. if (RQObjectIsNil(lastQuestionsViewController1)) {
  260. RQExerciseModel *exerciseModel = self.viewModel.questionArr[index - 2];
  261. // exerciseModel.exerciseType = self.viewModel.exerciseType;
  262. exerciseModel.allNum = self.viewModel.questionArr.count;
  263. RQTestQuestionsViewModel *testQuestionsViewModel = [[RQTestQuestionsViewModel alloc] initWithServices:self.viewModel.services params:@{
  264. RQViewModelUtilKey : exerciseModel,
  265. // RQExerciseTypeKey : @(self.viewModel.exerciseType),
  266. RQHomePageCarTypeKey : @(self.viewModel.homePageCarType),
  267. RQHomePageSubjectTypeKey: @(self.viewModel.homePageSubjectType),
  268. }];
  269. RQTestQuestionsViewController *testQuestionsViewController = [[RQTestQuestionsViewController alloc] initWithViewModel:testQuestionsViewModel];
  270. [self.listVcDic setObject:testQuestionsViewController forKey:[NSString qmui_stringWithNSInteger:index - 2]];
  271. }
  272. }
  273. RQTestQuestionsViewController *lastQuestionsViewController = [self.listVcDic objectForKey:[NSString qmui_stringWithNSInteger:index - 1]];
  274. if (RQObjectIsNil(lastQuestionsViewController)) {
  275. RQExerciseModel *exerciseModel = self.viewModel.questionArr[index - 1];
  276. // exerciseModel.exerciseType = self.viewModel.exerciseType;
  277. exerciseModel.allNum = self.viewModel.questionArr.count;
  278. RQTestQuestionsViewModel *testQuestionsViewModel = [[RQTestQuestionsViewModel alloc] initWithServices:self.viewModel.services params:@{
  279. RQViewModelUtilKey : exerciseModel,
  280. // RQExerciseTypeKey : @(self.viewModel.exerciseType),
  281. RQHomePageCarTypeKey : @(self.viewModel.homePageCarType),
  282. RQHomePageSubjectTypeKey: @(self.viewModel.homePageSubjectType),
  283. }];
  284. RQTestQuestionsViewController *testQuestionsViewController = [[RQTestQuestionsViewController alloc] initWithViewModel:testQuestionsViewModel];
  285. [self.listVcDic setObject:testQuestionsViewController forKey:[NSString qmui_stringWithNSInteger:index - 1]];
  286. }
  287. }
  288. if (index + 1 < self.viewModel.questionArr.count) {
  289. if (index + 2 < self.viewModel.questionArr.count) {
  290. RQTestQuestionsViewController *nextQuestionsViewController1 = [self.listVcDic objectForKey:[NSString qmui_stringWithNSInteger:index + 2]];
  291. if (RQObjectIsNil(nextQuestionsViewController1)) {
  292. RQExerciseModel *exerciseModel = self.viewModel.questionArr[index + 2];
  293. // exerciseModel.exerciseType = self.viewModel.exerciseType;
  294. exerciseModel.allNum = self.viewModel.questionArr.count;
  295. RQTestQuestionsViewModel *testQuestionsViewModel = [[RQTestQuestionsViewModel alloc] initWithServices:self.viewModel.services params:@{
  296. RQViewModelUtilKey : exerciseModel,
  297. // RQExerciseTypeKey : @(self.viewModel.exerciseType),
  298. RQHomePageCarTypeKey : @(self.viewModel.homePageCarType),
  299. RQHomePageSubjectTypeKey: @(self.viewModel.homePageSubjectType),
  300. }];
  301. RQTestQuestionsViewController *testQuestionsViewController = [[RQTestQuestionsViewController alloc] initWithViewModel:testQuestionsViewModel];
  302. [self.listVcDic setObject:testQuestionsViewController forKey:[NSString qmui_stringWithNSInteger:index + 2]];
  303. }
  304. }
  305. RQTestQuestionsViewController *nextQuestionsViewController = [self.listVcDic objectForKey:[NSString qmui_stringWithNSInteger:index + 1]];
  306. if (RQObjectIsNil(nextQuestionsViewController)) {
  307. RQExerciseModel *exerciseModel = self.viewModel.questionArr[index + 1];
  308. // exerciseModel.exerciseType = self.viewModel.exerciseType;
  309. exerciseModel.allNum = self.viewModel.questionArr.count;
  310. RQTestQuestionsViewModel *testQuestionsViewModel = [[RQTestQuestionsViewModel alloc] initWithServices:self.viewModel.services params:@{
  311. RQViewModelUtilKey : exerciseModel,
  312. // RQExerciseTypeKey : @(self.viewModel.exerciseType),
  313. RQHomePageCarTypeKey : @(self.viewModel.homePageCarType),
  314. RQHomePageSubjectTypeKey: @(self.viewModel.homePageSubjectType),
  315. }];
  316. RQTestQuestionsViewController *testQuestionsViewController = [[RQTestQuestionsViewController alloc] initWithViewModel:testQuestionsViewModel];
  317. [self.listVcDic setObject:testQuestionsViewController forKey:[NSString qmui_stringWithNSInteger:index + 1]];
  318. }
  319. }
  320. }];
  321. // RQExerciseModel *exerciseModel = self.viewModel.questionArr[index];
  322. // exerciseModel.exerciseType = self.viewModel.exerciseType;
  323. // exerciseModel.allNum = self.viewModel.questionArr.count;
  324. //
  325. // RQTestQuestionsViewModel *testQuestionsViewModel = [[RQTestQuestionsViewModel alloc] initWithServices:self.viewModel.services params:@{
  326. // RQViewModelUtilKey : exerciseModel,
  327. // RQExerciseTypeKey : @(self.viewModel.exerciseType),
  328. // RQHomePageCarTypeKey : @(self.viewModel.homePageCarType),
  329. // RQHomePageSubjectTypeKey: @(self.viewModel.homePageSubjectType),
  330. // }];
  331. // RQTestQuestionsViewController *testQuestionsViewController = [[RQTestQuestionsViewController alloc] initWithViewModel:testQuestionsViewModel];
  332. self.currentListView = currentQuestionsViewController.tableView;
  333. __weak typeof(currentQuestionsViewController) weakController = currentQuestionsViewController;
  334. [[RACScheduler scheduler] schedule:^{
  335. if (pagerView.listDict.allValues.count > 5) {
  336. NSMutableDictionary *dic = pagerView.listDict.mutableCopy;
  337. [[dic.allKeys.rac_sequence.signal filter:^BOOL(id _Nullable value) {
  338. NSInteger integerValue = [value integerValue];
  339. NSInteger frontIndex = ((index - 1) < 0)? 0 : index - 1;
  340. NSInteger frontIndex1 = ((index - 2) < 0)? 0 : index - 2;
  341. NSInteger beforeIndex = index + 1;
  342. NSInteger beforeIndex1 = index + 2;
  343. return index != integerValue && beforeIndex != integerValue && frontIndex != integerValue && beforeIndex1 != integerValue && frontIndex1 != integerValue;
  344. }].toArray.rac_sequence.signal subscribeNext:^(id _Nullable x) {
  345. @strongify(self)
  346. NSString *key = [NSString stringWithFormat:@"%@",x];
  347. RQTestQuestionsViewController *list = [dic objectForKey:key.numberValue];
  348. [[list listView] removeFromSuperview];
  349. [list removeFromParentViewController];
  350. [dic removeObjectForKey:key.numberValue];
  351. pagerView.listDict = dic;
  352. RQTestQuestionsViewController *list1 = [self.listVcDic objectForKey:key];
  353. [[list1 listView] removeFromSuperview];
  354. [list1 removeFromParentViewController];
  355. [self.listVcDic removeObjectForKey:key];
  356. }];
  357. }
  358. }];
  359. return weakController;
  360. }
  361. #pragma mark - JXCategoryViewDelegate
  362. - (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
  363. self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0);
  364. //根据选中的下标,实时更新currentListView
  365. RQTestQuestionsViewController *list = (RQTestQuestionsViewController *)self.pagerView.listDict[@(index)];
  366. self.currentListView = list.tableView;
  367. self.number = index;
  368. [self saveNumWithIndex:index];
  369. NSLog(@"JXCategoryViewDelegate=====didSelectedItemAtIndex=%zd",index);
  370. //控制-语音停止-切换
  371. // RQExerciseModel *exerciseModel = self.viewModel.questionArr[index];
  372. // if(![exerciseModel.ydtQuestionModel.Question isEqual:NY_VOICE_MANAGER.paytext]&&
  373. // //NY_VOICE_MANAGER.state==NYVoiceType_Start&&
  374. // NY_VOICE_MANAGER.paytext!=nil){
  375. //
  376. // }
  377. [NY_VOICE_MANAGER stopPayVoiceAction];
  378. [NY_VOICE_MANAGER stopPayVoiceActionUrl];
  379. }
  380. - (void)saveNumWithIndex:(NSInteger)index {
  381. RQExerciseModel *exerciseModel = self.viewModel.questionArr[index];
  382. [RQ_YDTQuestion_Module saveHistoryQuestionNumWithQuestionId:exerciseModel.ydtQuestionModel.num];
  383. }
  384. - (void)categoryView:(JXCategoryBaseView *)categoryView scrollingFromLeftIndex:(NSInteger)leftIndex toRightIndex:(NSInteger)rightIndex ratio:(CGFloat)ratio {
  385. RQ_Exercise_Module.isScrolling = (ratio > 0.1) && (ratio < 0.9);
  386. }
  387. #pragma mark - JXPagerMainTableViewGestureDelegate
  388. - (BOOL)mainTableViewGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
  389. //禁止categoryView左右滑动的时候,上下和左右都可以滚动
  390. if (otherGestureRecognizer == self.categoryView.collectionView.panGestureRecognizer) {
  391. return NO;
  392. }
  393. return [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]];
  394. }
  395. #pragma mark - LazyLoad
  396. - (RQExerciseToolBarView *)exerciseToolBarView {
  397. if (!_exerciseToolBarView) {
  398. _exerciseToolBarView = [RQExerciseToolBarView exerciseToolBarView];
  399. @weakify(self, _exerciseToolBarView)
  400. [_exerciseToolBarView.catalogueView setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
  401. [[RACScheduler mainThreadScheduler] schedule:^{
  402. @strongify(self)
  403. [self showCatalogue];
  404. }];
  405. }];
  406. RAC(_exerciseToolBarView.handInBtn, hidden) = [RACObserve(RQ_Exercise_Module, currentExerciseType) map:^id _Nullable(id _Nullable value) {
  407. return @(RQ_Exercise_Module.currentExerciseType != RQExerciseType_Exam);
  408. }];
  409. RAC(_exerciseToolBarView.collectBtn, hidden) = [RACObserve(self.viewModel, homeSubPageType) map:^id _Nullable(id _Nullable value) {
  410. @strongify(self)
  411. return @(self.viewModel.homeSubPageType == RQHomeSubPageType_WrongTopicAndCollection);
  412. }];
  413. RAC(_exerciseToolBarView.deleteBtn, hidden) = [RACObserve(self.viewModel, homeSubPageType) map:^id _Nullable(id _Nullable value) {
  414. @strongify(self)
  415. return @(self.viewModel.homeSubPageType != RQHomeSubPageType_WrongTopicAndCollection);
  416. }];
  417. [_exerciseToolBarView.handInBtn setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
  418. @strongify(self)
  419. if (RQ_Exercise_Module.timer) {
  420. [RQ_Exercise_Module.timer setFireDate:[NSDate distantFuture]];
  421. }
  422. NSDictionary *dic = @{
  423. @"questionArr" : self.viewModel.questionArr,
  424. };
  425. [RQ_Exercise_Module showAlertWithRQExerciseAlertType:RQExerciseAlertType_Exam_HandUp valueDic:dic confirmAction:^(__kindof QMUIDialogViewController *dialogViewController) {
  426. @strongify(self);
  427. NSInteger totalNum = self.viewModel.questionArr.count;
  428. NSInteger rightNum = RQ_Exercise_Module.correctArr.count;
  429. NSInteger perScore = 100 / totalNum;
  430. NSInteger score = rightNum * perScore;
  431. if(self.viewModel.subPageTypeKHMode == 1){//广西特殊处理score
  432. dispatch_time_t dipatchTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC));
  433. dispatch_after(dipatchTime, dispatch_get_main_queue(), ^{
  434. [[NSNotificationCenter defaultCenter] postNotificationName:RQHomeSubPageTypeKHModeKey object:@(score)];//通知-签退
  435. });
  436. }else{
  437. /// 现在交卷
  438. RQExamResultViewModel *examResultViewModel = [[RQExamResultViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{
  439. RQViewModelUtilKey : self.viewModel.questionArr,
  440. RQViewModelIDKey : RQ_Exercise_Module.correctArr,
  441. RQViewCommonValueKey : RQ_Exercise_Module.errorArr,
  442. RQHomeSubPageTypeKHModeKey : @(self.viewModel.subPageTypeKHMode)
  443. }];
  444. [RQ_APPDELEGATE.services pushViewModel:examResultViewModel animated:YES];
  445. }
  446. } cancelAction:^(__kindof QMUIDialogViewController *dialogViewController) {
  447. if (RQ_Exercise_Module.timer) {
  448. [RQ_Exercise_Module.timer setFireDate:[NSDate distantPast]];
  449. }
  450. }];
  451. }];
  452. [_exerciseToolBarView.collectBtn setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
  453. @strongify(self, _exerciseToolBarView)
  454. RQExerciseModel *exerciseModel = self.viewModel.questionArr[self.number];
  455. if (_exerciseToolBarView.collectBtn.selected) {
  456. [MBProgressHUD rq_showProgressHUD:@"取消中..."];
  457. [[[RQ_HTTP_Service deleteFavQuestionWithQuestionId:exerciseModel.ydtQuestionModel.ID type:RQSaveFavQuestionType_Collect] deliverOnMainThread] subscribeNext:^(id _Nullable x) {
  458. @strongify(_exerciseToolBarView)
  459. [RQ_YDT_USER_Question_Module deleteCollectRecordWithQuestionId:exerciseModel.ydtQuestionModel.ID];
  460. _exerciseToolBarView.collectBtn.selected = [RQ_YDT_USER_Question_Module getCollectRecordWithQuestionId:exerciseModel.ydtQuestionModel.ID carType:RQ_YDTQuestion_Module.carType subject:RQ_YDTQuestion_Module.subject];
  461. [MBProgressHUD rq_hideHUD];
  462. } error:^(NSError * _Nullable error) {
  463. [MBProgressHUD rq_hideHUD];
  464. }];
  465. } else {
  466. [MBProgressHUD rq_showProgressHUD:@"收藏中..."];
  467. [[[RQ_HTTP_Service saveFavQuestionWithQuestionId:exerciseModel.ydtQuestionModel.ID type:RQSaveFavQuestionType_Collect] deliverOnMainThread] subscribeNext:^(id _Nullable x) {
  468. @strongify(_exerciseToolBarView)
  469. [RQ_YDT_USER_Question_Module collectQuestionWithID:exerciseModel.ydtQuestionModel.ID carType:RQ_YDTQuestion_Module.carType subject:RQ_YDTQuestion_Module.subject];
  470. _exerciseToolBarView.collectBtn.selected = [RQ_YDT_USER_Question_Module getCollectRecordWithQuestionId:exerciseModel.ydtQuestionModel.ID carType:RQ_YDTQuestion_Module.carType subject:RQ_YDTQuestion_Module.subject];
  471. [MBProgressHUD rq_hideHUD];
  472. } error:^(NSError * _Nullable error) {
  473. [MBProgressHUD rq_hideHUD];
  474. }];
  475. }
  476. }];
  477. [_exerciseToolBarView.deleteBtn setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
  478. @strongify(self)
  479. RQExerciseModel *exerciseModel = self.viewModel.questionArr[self.number];
  480. NSMutableArray *questionArr = self.viewModel.questionArr.mutableCopy;
  481. NSInteger index = [questionArr indexOfObject:exerciseModel];
  482. NSMutableArray *titleArr = self.titles.mutableCopy;
  483. NSMutableArray *errorArr = RQ_Exercise_Module.errorArr.mutableCopy;
  484. NSMutableArray *correctArr = RQ_Exercise_Module.correctArr.mutableCopy;
  485. [MBProgressHUD rq_showProgressHUD:@"删除中..."];
  486. [[[RQ_HTTP_Service deleteFavQuestionWithQuestionId:exerciseModel.ydtQuestionModel.ID type:RQSaveFavQuestionType_Collect] deliverOnMainThread] subscribeNext:^(id _Nullable x) {
  487. @strongify(self)
  488. [RQ_YDT_USER_Question_Module deleteCollectRecordWithQuestionId:exerciseModel.ydtQuestionModel.ID];
  489. [questionArr removeObject:exerciseModel];
  490. [titleArr removeObjectAtIndex:self.number];
  491. self.viewModel.questionArr = questionArr.copy;
  492. [RQNotificationCenter postNotificationName:RQCancelCollectNotification object:nil userInfo:@{RQCancelCollectExerciseModelKey:self.viewModel.questionArr}];
  493. if ([errorArr containsObject:exerciseModel]) {
  494. [errorArr removeObject:exerciseModel];
  495. RQ_Exercise_Module.errorArr = errorArr.copy;
  496. }
  497. if ([correctArr containsObject:exerciseModel]) {
  498. [correctArr removeObject:exerciseModel];
  499. RQ_Exercise_Module.correctArr = correctArr.copy;
  500. }
  501. if (questionArr.count > 0) {
  502. if (questionArr.count - 1 >= index) {
  503. // [self jumpQuestionWithIndex:index];
  504. // self.number = index;
  505. [self jumpQuestionWithIndex:index];
  506. self.categoryView.titles = titleArr;
  507. [self.categoryView reloadData];
  508. } else {
  509. if (questionArr.count - 1 >= index - 1 && index - 1 > 0) {
  510. // [self jumpQuestionWithIndex:index - 1];
  511. // self.number = index - 1;
  512. // self.categoryView.defaultSelectedIndex = index - 1;
  513. [self jumpQuestionWithIndex:index - 1];
  514. self.categoryView.titles = titleArr;
  515. [self.categoryView reloadData];
  516. }
  517. }
  518. } else {
  519. [self.viewModel.services popViewModelAnimated:YES];
  520. }
  521. [MBProgressHUD rq_hideHUD];
  522. } error:^(NSError * _Nullable error) {
  523. [MBProgressHUD rq_hideHUD];
  524. }];
  525. }];
  526. }
  527. return _exerciseToolBarView;
  528. }
  529. - (JXCategoryTitleView *)categoryView {
  530. if (!_categoryView) {
  531. __typeof(self) __weak weakSelf = self;
  532. _categoryView = [[JXCategoryTitleView alloc] init];
  533. _categoryView.titles = self.titles;
  534. _categoryView.delegate = weakSelf;
  535. /// !!!: 将列表容器视图关联到 categoryView
  536. _categoryView.contentScrollView = self.pagerView.listCollectionView;
  537. // self.categoryView.listContainer = (id<JXCategoryViewListContainer>)self.pagerView.listDict;
  538. }
  539. return _categoryView;
  540. }
  541. - (JXPagerSmoothView *)pagerView {
  542. if (!_pagerView) {
  543. _pagerView = [[JXPagerSmoothView alloc] initWithDataSource:self];
  544. self.contentScrollView = _pagerView.listCollectionView;
  545. }
  546. return _pagerView;
  547. }
  548. - (NSArray<NSString *> *)titles {
  549. return [self.viewModel.questionArr.rac_sequence.signal map:^id _Nullable(RQExerciseModel *exerciseModel) {
  550. return [NSString qmui_stringWithNSInteger:exerciseModel.ydtQuestionModel.ID];
  551. }].toArray;
  552. }
  553. - (NSArray<RQYDTQuestionModel *> *)ydtQuestionsArr {
  554. if (!_ydtQuestionsArr) {
  555. _ydtQuestionsArr = [self.viewModel.questionArr.rac_sequence.signal map:^id _Nullable(RQExerciseModel *exerciseModel) {
  556. return exerciseModel.ydtQuestionModel;
  557. }].toArray;
  558. }
  559. return _ydtQuestionsArr;
  560. }
  561. - (NSArray<RQExerciseModel *> *)reDoQuestionsArr {
  562. if (!_reDoQuestionsArr) {
  563. _reDoQuestionsArr = [self.ydtQuestionsArr.rac_sequence.signal map:^id _Nullable(RQYDTQuestionModel *ydtQuestionModel) {
  564. return [RQExerciseModel exerciseModelWithRQYDTQuestionModel:ydtQuestionModel];
  565. }].toArray;
  566. }
  567. return _reDoQuestionsArr;
  568. }
  569. - (NSMapTable *)mapTable {
  570. if (!_mapTable) {
  571. _mapTable = [[NSMapTable alloc] initWithKeyOptions:NSMapTableWeakMemory valueOptions:NSMapTableWeakMemory capacity:0];
  572. }
  573. return _mapTable;
  574. }
  575. - (NSMutableDictionary *)listVcDic {
  576. if (!_listVcDic) {
  577. _listVcDic = @{}.mutableCopy;
  578. }
  579. return _listVcDic;
  580. }
  581. @end