RQExerciseSubViewController.m 32 KB

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