RQExerciseSubViewController.m 33 KB

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