// // RQExerciseSubViewController.m // JSJP // // Created by 张嵘 on 2021/8/12. // #import "RQExerciseSubViewController.h" #import "HWPanModal.h" @interface RQExerciseSubViewController () /// viewModel @property (nonatomic, readonly, strong) RQExerciseSubViewModel *viewModel; @property (nonatomic, readwrite, strong) RQExerciseToolBarView *exerciseToolBarView; @property (nonatomic, readwrite, strong) JXPagerSmoothView *pagerView; @property (nonatomic, readwrite, strong) JXCategoryTitleView *categoryView; @property (nonatomic, copy) void(^scrollCallback)(UIScrollView *scrollView); @property (nonatomic, readwrite, strong) UIScrollView *currentListView; @property (nonatomic, readwrite, copy) NSArray *titles; @property (nonatomic, readwrite, copy) NSArray *ydtQuestionsArr; @property (nonatomic, readwrite, copy) NSArray *reDoQuestionsArr; @property (nonatomic, readwrite, strong) NSMutableDictionary *listVcDic; @property (nonatomic, readwrite, strong) NSMapTable *mapTable; @end @implementation RQExerciseSubViewController @dynamic viewModel; #pragma mark - SystemMethod - (void)viewDidLoad { [super viewDidLoad]; /// 初始化 [self rq_setup]; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; // int popNum = _firstNum= historyNum + 1) { if (historyNum == 0) { [self jumpQuestionWithIndex:0]; } else { [RQ_ALERTVIEW_MANAGER showAlertWithAlertType:RQAlertType_Default title:@"温馨提示" message:[NSString stringWithFormat:@"上次做题至%ld题,是否继续?",historyNum + 1] confirmTitle:@"是" cancelTitle:@"否" confirmAction:^(__kindof QMUIDialogViewController * _Nonnull dialogViewController) { @strongify(self) [self jumpQuestionWithIndex:historyNum]; } cancelAction:^(__kindof QMUIDialogViewController * _Nonnull dialogViewController) { @strongify(self) [self jumpQuestionWithIndex:0]; }]; } } } [[RACObserve(self, number) deliverOnMainThread] subscribeNext:^(id _Nullable x) { @strongify(self) if (self.viewModel.questionArr) { if (self.viewModel.questionArr.count >= self.number + 1) { self.exerciseToolBarView.totalNumberOfQuestionsLabel.text = [NSString stringWithFormat:@"%ld/%lu",[x integerValue] + 1,(unsigned long)self.viewModel.questionArr.count]; RQExerciseModel *exerciseModel = self.viewModel.questionArr[self.number]; self.exerciseToolBarView.collectBtn.selected = [RQ_YDT_USER_Question_Module getCollectRecordWithQuestionId:exerciseModel.ydtQuestionModel.ID carType:RQ_YDTQuestion_Module.carType subject:RQ_YDTQuestion_Module.subject]; } } }]; RAC(self.exerciseToolBarView.errorOptionNumLabel, text) = [RACObserve(RQ_Exercise_Module, errorArr) map:^id _Nullable(id _Nullable value) { return (RQ_Exercise_Module.currentExerciseType == RQExerciseType_Recitation)? @"0" : [NSString qmui_stringWithNSInteger:RQ_Exercise_Module.errorArr.count]; }]; RAC(self.exerciseToolBarView.correctOptionNumLabel, text) = [RACObserve(RQ_Exercise_Module, correctArr) map:^id _Nullable(id _Nullable value) { return (RQ_Exercise_Module.currentExerciseType == RQExerciseType_Recitation)? @"0" : [NSString qmui_stringWithNSInteger:RQ_Exercise_Module.correctArr.count]; }]; // [[[[RQNotificationCenter rac_addObserverForName:RQExerciseAlertNotification object:nil] deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSNotification * note) { // @strongify(self) // RQExerciseAlertType type = [note.object[RQExerciseAlertTypeKey] integerValue]; // if (RQ_Exercise_Module.currentExerciseType == RQExerciseType_Exam) { // NSDictionary *dic = @{ // @"questionArr" : self.viewModel.questionArr, // }; // // [RQ_Exercise_Module showAlertWithRQExerciseAlertType:type valueDic:dic confirmAction:^(__kindof QMUIDialogViewController *dialogViewController) { // @strongify(self); // if (type == RQExerciseAlertType_Exam_HandUp) { // /// 交卷 // RQExamResultViewModel *examResultViewModel = [[RQExamResultViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{ // RQViewModelUtilKey : self.viewModel.questionArr, // RQViewModelIDKey : RQ_Exercise_Module.correctArr, // RQViewCommonValueKey : RQ_Exercise_Module.errorArr, // }]; // [RQ_APPDELEGATE.services pushViewModel:examResultViewModel animated:YES]; // } else if (type == RQExerciseAlertType_Exam_Resume || type == RQExerciseAlertType_Exam_Suspend) { // if (RQ_Exercise_Module.timer) { // [RQ_Exercise_Module.timer setFireDate:[NSDate distantPast]]; // } // } // } cancelAction:^(__kindof QMUIDialogViewController *dialogViewController) { // @strongify(self) // if (type == RQExerciseAlertType_Exam_HandUp) { // if (RQ_Exercise_Module.timer) { // [RQ_Exercise_Module.timer setFireDate:[NSDate distantPast]]; // } // } else if (type == RQExerciseAlertType_Exam_Resume || type == RQExerciseAlertType_Exam_Suspend) { // /// 重新考试 // self.viewModel.questionArr = self.reDoQuestionsArr; // if (RQ_Exercise_Module.timer) { // [RQ_Exercise_Module.timer invalidate]; // RQ_Exercise_Module.timer = nil; // [RQ_Exercise_Module startTimer]; // RQ_Exercise_Module.errorArr = @[]; // RQ_Exercise_Module.correctArr = @[]; // [self jumpQuestionWithIndex:0]; // } // } // }]; // } // }]; [[[[RQNotificationCenter rac_addObserverForName:RQAutoJumpNextNotification object:nil] deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSNotification * _Nullable x) { @strongify(self); if (RQ_Exercise_Module.isRightAutoJumpToNext) { if (self.viewModel.questionArr.count == self.number + 1) { [QMUITips showWithText:@"已经是最后一题啦!"]; } else { [self jumpQuestionWithIndex:self.number + 1]; } } }]; } - (void)jumpQuestionWithIndex:(NSUInteger)index { self.number = (int)index; self.pagerView.defaultSelectedIndex = index; self.categoryView.defaultSelectedIndex = index; [self.pagerView reloadData]; [self.categoryView reloadData]; [self saveNumWithIndex:index]; } - (void)showCatalogue { @weakify(self) RQCatalogueViewModel *catalogueViewModel = [[RQCatalogueViewModel alloc] initWithServices:self.viewModel.services params:@{ RQViewModelIDKey : @(self.number), RQViewModelUtilKey : self.viewModel.questionArr, // RQExerciseTypeKey : @(self.viewModel.exerciseType), }]; RQCatalogueViewController *catalogueViewController = [[RQCatalogueViewController alloc] initWithViewModel:catalogueViewModel]; [catalogueViewController initCompletionWithSelectIndexBlock:^(NSInteger index) { @strongify(self) [self jumpQuestionWithIndex:index]; }]; [self presentPanModal:catalogueViewController]; } #pragma mark - UITableViewDataSource, UITableViewDelegate - (void)scrollViewDidScroll:(UIScrollView *)scrollView { !self.scrollCallback ?: self.scrollCallback(scrollView); } #pragma mark - JXPagerViewListViewDelegate - (UIView *)listView { return self.view; } - (UIScrollView *)listScrollView { return self.tableView; } - (void)listViewDidScrollCallback:(void (^)(UIScrollView *))callback { self.scrollCallback = callback; } - (void)listScrollViewWillResetContentOffset { //当前的listScrollView需要重置的时候,就把所有列表的contentOffset都重置了 for (RQTestQuestionsViewController *list in self.pagerView.listDict.allValues) { list.tableView.contentOffset = CGPointZero; } } #pragma mark - JXPagerSmoothViewDataSource - (UIView *)viewForPagerHeaderInPagerView:(JXPagerSmoothView *)pagerView { return [UIView new]; } - (CGFloat)heightForPagerHeaderInPagerView:(JXPagerSmoothView *)pagerView { return 0.f; } - (CGFloat)heightForPinHeaderInPagerView:(JXPagerSmoothView *)pagerView { return 0.f; } - (UIView *)viewForPinHeaderInPagerView:(JXPagerSmoothView *)pagerView { return self.categoryView; } - (NSInteger)numberOfListsInPagerView:(JXPagerSmoothView *)pagerView { return self.categoryView.titles.count; } - (id)pagerView:(JXPagerSmoothView *)pagerView initListAtIndex:(NSInteger)index { NSLog(@"JXCategoryViewDelegate=====initListAtIndex=%zd",index); @weakify(self) RQTestQuestionsViewController *currentQuestionsViewController = [self.listVcDic objectForKey:[NSString qmui_stringWithNSInteger:index]]; if (RQObjectIsNil(currentQuestionsViewController)) { RQExerciseModel *exerciseModel = self.viewModel.questionArr[index]; // exerciseModel.exerciseType = self.viewModel.exerciseType; exerciseModel.allNum = self.viewModel.questionArr.count; RQTestQuestionsViewModel *testQuestionsViewModel = [[RQTestQuestionsViewModel alloc] initWithServices:self.viewModel.services params:@{ RQViewModelUtilKey : exerciseModel, // RQExerciseTypeKey : @(self.viewModel.exerciseType), RQHomePageCarTypeKey : @(self.viewModel.homePageCarType), RQHomePageSubjectTypeKey: @(self.viewModel.homePageSubjectType), }]; RQTestQuestionsViewController *testQuestionsViewController = [[RQTestQuestionsViewController alloc] initWithViewModel:testQuestionsViewModel]; currentQuestionsViewController = testQuestionsViewController; [self.listVcDic setObject:testQuestionsViewController forKey:[NSString qmui_stringWithNSInteger:index]]; } [[RACScheduler scheduler] schedule:^{ @strongify(self) if (index > 0) { if (index > 1) { RQTestQuestionsViewController *lastQuestionsViewController1 = [self.listVcDic objectForKey:[NSString qmui_stringWithNSInteger:index - 2]]; if (RQObjectIsNil(lastQuestionsViewController1)) { RQExerciseModel *exerciseModel = self.viewModel.questionArr[index - 2]; // exerciseModel.exerciseType = self.viewModel.exerciseType; exerciseModel.allNum = self.viewModel.questionArr.count; RQTestQuestionsViewModel *testQuestionsViewModel = [[RQTestQuestionsViewModel alloc] initWithServices:self.viewModel.services params:@{ RQViewModelUtilKey : exerciseModel, // RQExerciseTypeKey : @(self.viewModel.exerciseType), RQHomePageCarTypeKey : @(self.viewModel.homePageCarType), RQHomePageSubjectTypeKey: @(self.viewModel.homePageSubjectType), }]; RQTestQuestionsViewController *testQuestionsViewController = [[RQTestQuestionsViewController alloc] initWithViewModel:testQuestionsViewModel]; [self.listVcDic setObject:testQuestionsViewController forKey:[NSString qmui_stringWithNSInteger:index - 2]]; } } RQTestQuestionsViewController *lastQuestionsViewController = [self.listVcDic objectForKey:[NSString qmui_stringWithNSInteger:index - 1]]; if (RQObjectIsNil(lastQuestionsViewController)) { RQExerciseModel *exerciseModel = self.viewModel.questionArr[index - 1]; // exerciseModel.exerciseType = self.viewModel.exerciseType; exerciseModel.allNum = self.viewModel.questionArr.count; RQTestQuestionsViewModel *testQuestionsViewModel = [[RQTestQuestionsViewModel alloc] initWithServices:self.viewModel.services params:@{ RQViewModelUtilKey : exerciseModel, // RQExerciseTypeKey : @(self.viewModel.exerciseType), RQHomePageCarTypeKey : @(self.viewModel.homePageCarType), RQHomePageSubjectTypeKey: @(self.viewModel.homePageSubjectType), }]; RQTestQuestionsViewController *testQuestionsViewController = [[RQTestQuestionsViewController alloc] initWithViewModel:testQuestionsViewModel]; [self.listVcDic setObject:testQuestionsViewController forKey:[NSString qmui_stringWithNSInteger:index - 1]]; } } if (index + 1 < self.viewModel.questionArr.count) { if (index + 2 < self.viewModel.questionArr.count) { RQTestQuestionsViewController *nextQuestionsViewController1 = [self.listVcDic objectForKey:[NSString qmui_stringWithNSInteger:index + 2]]; if (RQObjectIsNil(nextQuestionsViewController1)) { RQExerciseModel *exerciseModel = self.viewModel.questionArr[index + 2]; // exerciseModel.exerciseType = self.viewModel.exerciseType; exerciseModel.allNum = self.viewModel.questionArr.count; RQTestQuestionsViewModel *testQuestionsViewModel = [[RQTestQuestionsViewModel alloc] initWithServices:self.viewModel.services params:@{ RQViewModelUtilKey : exerciseModel, // RQExerciseTypeKey : @(self.viewModel.exerciseType), RQHomePageCarTypeKey : @(self.viewModel.homePageCarType), RQHomePageSubjectTypeKey: @(self.viewModel.homePageSubjectType), }]; RQTestQuestionsViewController *testQuestionsViewController = [[RQTestQuestionsViewController alloc] initWithViewModel:testQuestionsViewModel]; [self.listVcDic setObject:testQuestionsViewController forKey:[NSString qmui_stringWithNSInteger:index + 2]]; } } RQTestQuestionsViewController *nextQuestionsViewController = [self.listVcDic objectForKey:[NSString qmui_stringWithNSInteger:index + 1]]; if (RQObjectIsNil(nextQuestionsViewController)) { RQExerciseModel *exerciseModel = self.viewModel.questionArr[index + 1]; // exerciseModel.exerciseType = self.viewModel.exerciseType; exerciseModel.allNum = self.viewModel.questionArr.count; RQTestQuestionsViewModel *testQuestionsViewModel = [[RQTestQuestionsViewModel alloc] initWithServices:self.viewModel.services params:@{ RQViewModelUtilKey : exerciseModel, // RQExerciseTypeKey : @(self.viewModel.exerciseType), RQHomePageCarTypeKey : @(self.viewModel.homePageCarType), RQHomePageSubjectTypeKey: @(self.viewModel.homePageSubjectType), }]; RQTestQuestionsViewController *testQuestionsViewController = [[RQTestQuestionsViewController alloc] initWithViewModel:testQuestionsViewModel]; [self.listVcDic setObject:testQuestionsViewController forKey:[NSString qmui_stringWithNSInteger:index + 1]]; } } }]; // RQExerciseModel *exerciseModel = self.viewModel.questionArr[index]; // exerciseModel.exerciseType = self.viewModel.exerciseType; // exerciseModel.allNum = self.viewModel.questionArr.count; // // RQTestQuestionsViewModel *testQuestionsViewModel = [[RQTestQuestionsViewModel alloc] initWithServices:self.viewModel.services params:@{ // RQViewModelUtilKey : exerciseModel, // RQExerciseTypeKey : @(self.viewModel.exerciseType), // RQHomePageCarTypeKey : @(self.viewModel.homePageCarType), // RQHomePageSubjectTypeKey: @(self.viewModel.homePageSubjectType), // }]; // RQTestQuestionsViewController *testQuestionsViewController = [[RQTestQuestionsViewController alloc] initWithViewModel:testQuestionsViewModel]; self.currentListView = currentQuestionsViewController.tableView; __weak typeof(currentQuestionsViewController) weakController = currentQuestionsViewController; [[RACScheduler scheduler] schedule:^{ if (pagerView.listDict.allValues.count > 5) { NSMutableDictionary *dic = pagerView.listDict.mutableCopy; [[dic.allKeys.rac_sequence.signal filter:^BOOL(id _Nullable value) { NSInteger integerValue = [value integerValue]; NSInteger frontIndex = ((index - 1) < 0)? 0 : index - 1; NSInteger frontIndex1 = ((index - 2) < 0)? 0 : index - 2; NSInteger beforeIndex = index + 1; NSInteger beforeIndex1 = index + 2; return index != integerValue && beforeIndex != integerValue && frontIndex != integerValue && beforeIndex1 != integerValue && frontIndex1 != integerValue; }].toArray.rac_sequence.signal subscribeNext:^(id _Nullable x) { @strongify(self) NSString *key = [NSString stringWithFormat:@"%@",x]; RQTestQuestionsViewController *list = [dic objectForKey:key.numberValue]; [[list listView] removeFromSuperview]; [list removeFromParentViewController]; [dic removeObjectForKey:key.numberValue]; pagerView.listDict = dic; RQTestQuestionsViewController *list1 = [self.listVcDic objectForKey:key]; [[list1 listView] removeFromSuperview]; [list1 removeFromParentViewController]; [self.listVcDic removeObjectForKey:key]; }]; } }]; return weakController; } #pragma mark - JXCategoryViewDelegate - (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index { self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0); //根据选中的下标,实时更新currentListView RQTestQuestionsViewController *list = (RQTestQuestionsViewController *)self.pagerView.listDict[@(index)]; self.currentListView = list.tableView; self.number = index; [self saveNumWithIndex:index]; NSLog(@"JXCategoryViewDelegate=====didSelectedItemAtIndex=%zd",index); //控制-语音停止-切换 // RQExerciseModel *exerciseModel = self.viewModel.questionArr[index]; // if(![exerciseModel.ydtQuestionModel.Question isEqual:NY_VOICE_MANAGER.paytext]&& // //NY_VOICE_MANAGER.state==NYVoiceType_Start&& // NY_VOICE_MANAGER.paytext!=nil){ // // } [NY_VOICE_MANAGER stopPayVoiceAction]; [NY_VOICE_MANAGER stopPayVoiceActionUrl]; } - (void)saveNumWithIndex:(NSInteger)index { RQExerciseModel *exerciseModel = self.viewModel.questionArr[index]; [RQ_YDTQuestion_Module saveHistoryQuestionNumWithQuestionId:exerciseModel.ydtQuestionModel.num]; } - (void)categoryView:(JXCategoryBaseView *)categoryView scrollingFromLeftIndex:(NSInteger)leftIndex toRightIndex:(NSInteger)rightIndex ratio:(CGFloat)ratio { RQ_Exercise_Module.isScrolling = (ratio > 0.1) && (ratio < 0.9); } #pragma mark - JXPagerMainTableViewGestureDelegate - (BOOL)mainTableViewGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { //禁止categoryView左右滑动的时候,上下和左右都可以滚动 if (otherGestureRecognizer == self.categoryView.collectionView.panGestureRecognizer) { return NO; } return [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]; } #pragma mark - LazyLoad - (RQExerciseToolBarView *)exerciseToolBarView { if (!_exerciseToolBarView) { _exerciseToolBarView = [RQExerciseToolBarView exerciseToolBarView]; @weakify(self, _exerciseToolBarView) [_exerciseToolBarView.catalogueView setTapActionWithBlock:^(UITapGestureRecognizer *tap) { [[RACScheduler mainThreadScheduler] schedule:^{ @strongify(self) [self showCatalogue]; }]; }]; RAC(_exerciseToolBarView.handInBtn, hidden) = [RACObserve(RQ_Exercise_Module, currentExerciseType) map:^id _Nullable(id _Nullable value) { return @(RQ_Exercise_Module.currentExerciseType != RQExerciseType_Exam); }]; RAC(_exerciseToolBarView.collectBtn, hidden) = [RACObserve(self.viewModel, homeSubPageType) map:^id _Nullable(id _Nullable value) { @strongify(self) return @(self.viewModel.homeSubPageType == RQHomeSubPageType_WrongTopicAndCollection); }]; RAC(_exerciseToolBarView.deleteBtn, hidden) = [RACObserve(self.viewModel, homeSubPageType) map:^id _Nullable(id _Nullable value) { @strongify(self) return @(self.viewModel.homeSubPageType != RQHomeSubPageType_WrongTopicAndCollection); }]; [_exerciseToolBarView.handInBtn setTapActionWithBlock:^(UITapGestureRecognizer *tap) { @strongify(self) if (RQ_Exercise_Module.timer) { [RQ_Exercise_Module.timer setFireDate:[NSDate distantFuture]]; } NSDictionary *dic = @{ @"questionArr" : self.viewModel.questionArr, }; [RQ_Exercise_Module showAlertWithRQExerciseAlertType:RQExerciseAlertType_Exam_HandUp valueDic:dic confirmAction:^(__kindof QMUIDialogViewController *dialogViewController) { @strongify(self); /// 交卷 RQExamResultViewModel *examResultViewModel = [[RQExamResultViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{ RQViewModelUtilKey : self.viewModel.questionArr, RQViewModelIDKey : RQ_Exercise_Module.correctArr, RQViewCommonValueKey : RQ_Exercise_Module.errorArr, }]; [RQ_APPDELEGATE.services pushViewModel:examResultViewModel animated:YES]; } cancelAction:^(__kindof QMUIDialogViewController *dialogViewController) { if (RQ_Exercise_Module.timer) { [RQ_Exercise_Module.timer setFireDate:[NSDate distantPast]]; } }]; }]; [_exerciseToolBarView.collectBtn setTapActionWithBlock:^(UITapGestureRecognizer *tap) { @strongify(self, _exerciseToolBarView) RQExerciseModel *exerciseModel = self.viewModel.questionArr[self.number]; if (_exerciseToolBarView.collectBtn.selected) { [MBProgressHUD rq_showProgressHUD:@"取消中..."]; [[[RQ_HTTP_Service deleteFavQuestionWithQuestionId:exerciseModel.ydtQuestionModel.ID type:RQSaveFavQuestionType_Collect] deliverOnMainThread] subscribeNext:^(id _Nullable x) { @strongify(_exerciseToolBarView) [RQ_YDT_USER_Question_Module deleteCollectRecordWithQuestionId:exerciseModel.ydtQuestionModel.ID]; _exerciseToolBarView.collectBtn.selected = [RQ_YDT_USER_Question_Module getCollectRecordWithQuestionId:exerciseModel.ydtQuestionModel.ID carType:RQ_YDTQuestion_Module.carType subject:RQ_YDTQuestion_Module.subject]; [MBProgressHUD rq_hideHUD]; } error:^(NSError * _Nullable error) { [MBProgressHUD rq_hideHUD]; }]; } else { [MBProgressHUD rq_showProgressHUD:@"收藏中..."]; [[[RQ_HTTP_Service saveFavQuestionWithQuestionId:exerciseModel.ydtQuestionModel.ID type:RQSaveFavQuestionType_Collect] deliverOnMainThread] subscribeNext:^(id _Nullable x) { @strongify(_exerciseToolBarView) [RQ_YDT_USER_Question_Module collectQuestionWithID:exerciseModel.ydtQuestionModel.ID carType:RQ_YDTQuestion_Module.carType subject:RQ_YDTQuestion_Module.subject]; _exerciseToolBarView.collectBtn.selected = [RQ_YDT_USER_Question_Module getCollectRecordWithQuestionId:exerciseModel.ydtQuestionModel.ID carType:RQ_YDTQuestion_Module.carType subject:RQ_YDTQuestion_Module.subject]; [MBProgressHUD rq_hideHUD]; } error:^(NSError * _Nullable error) { [MBProgressHUD rq_hideHUD]; }]; } }]; [_exerciseToolBarView.deleteBtn setTapActionWithBlock:^(UITapGestureRecognizer *tap) { @strongify(self) RQExerciseModel *exerciseModel = self.viewModel.questionArr[self.number]; NSMutableArray *questionArr = self.viewModel.questionArr.mutableCopy; NSInteger index = [questionArr indexOfObject:exerciseModel]; NSMutableArray *titleArr = self.titles.mutableCopy; NSMutableArray *errorArr = RQ_Exercise_Module.errorArr.mutableCopy; NSMutableArray *correctArr = RQ_Exercise_Module.correctArr.mutableCopy; [MBProgressHUD rq_showProgressHUD:@"删除中..."]; [[[RQ_HTTP_Service deleteFavQuestionWithQuestionId:exerciseModel.ydtQuestionModel.ID type:RQSaveFavQuestionType_Collect] deliverOnMainThread] subscribeNext:^(id _Nullable x) { @strongify(self) [RQ_YDT_USER_Question_Module deleteCollectRecordWithQuestionId:exerciseModel.ydtQuestionModel.ID]; [questionArr removeObject:exerciseModel]; [titleArr removeObjectAtIndex:self.number]; self.viewModel.questionArr = questionArr.copy; [RQNotificationCenter postNotificationName:RQCancelCollectNotification object:nil userInfo:@{RQCancelCollectExerciseModelKey:self.viewModel.questionArr}]; if ([errorArr containsObject:exerciseModel]) { [errorArr removeObject:exerciseModel]; RQ_Exercise_Module.errorArr = errorArr.copy; } if ([correctArr containsObject:exerciseModel]) { [correctArr removeObject:exerciseModel]; RQ_Exercise_Module.correctArr = correctArr.copy; } if (questionArr.count > 0) { if (questionArr.count - 1 >= index) { // [self jumpQuestionWithIndex:index]; // self.number = index; [self jumpQuestionWithIndex:index]; self.categoryView.titles = titleArr; [self.categoryView reloadData]; } else { if (questionArr.count - 1 >= index - 1 && index - 1 > 0) { // [self jumpQuestionWithIndex:index - 1]; // self.number = index - 1; // self.categoryView.defaultSelectedIndex = index - 1; [self jumpQuestionWithIndex:index - 1]; self.categoryView.titles = titleArr; [self.categoryView reloadData]; } } } else { [self.viewModel.services popViewModelAnimated:YES]; } [MBProgressHUD rq_hideHUD]; } error:^(NSError * _Nullable error) { [MBProgressHUD rq_hideHUD]; }]; }]; } return _exerciseToolBarView; } - (JXCategoryTitleView *)categoryView { if (!_categoryView) { __typeof(self) __weak weakSelf = self; _categoryView = [[JXCategoryTitleView alloc] init]; _categoryView.titles = self.titles; _categoryView.delegate = weakSelf; /// !!!: 将列表容器视图关联到 categoryView _categoryView.contentScrollView = self.pagerView.listCollectionView; // self.categoryView.listContainer = (id)self.pagerView.listDict; } return _categoryView; } - (JXPagerSmoothView *)pagerView { if (!_pagerView) { _pagerView = [[JXPagerSmoothView alloc] initWithDataSource:self]; self.contentScrollView = _pagerView.listCollectionView; } return _pagerView; } - (NSArray *)titles { return [self.viewModel.questionArr.rac_sequence.signal map:^id _Nullable(RQExerciseModel *exerciseModel) { return [NSString qmui_stringWithNSInteger:exerciseModel.ydtQuestionModel.ID]; }].toArray; } - (NSArray *)ydtQuestionsArr { if (!_ydtQuestionsArr) { _ydtQuestionsArr = [self.viewModel.questionArr.rac_sequence.signal map:^id _Nullable(RQExerciseModel *exerciseModel) { return exerciseModel.ydtQuestionModel; }].toArray; } return _ydtQuestionsArr; } - (NSArray *)reDoQuestionsArr { if (!_reDoQuestionsArr) { _reDoQuestionsArr = [self.ydtQuestionsArr.rac_sequence.signal map:^id _Nullable(RQYDTQuestionModel *ydtQuestionModel) { return [RQExerciseModel exerciseModelWithRQYDTQuestionModel:ydtQuestionModel]; }].toArray; } return _reDoQuestionsArr; } - (NSMapTable *)mapTable { if (!_mapTable) { _mapTable = [[NSMapTable alloc] initWithKeyOptions:NSMapTableWeakMemory valueOptions:NSMapTableWeakMemory capacity:0]; } return _mapTable; } - (NSMutableDictionary *)listVcDic { if (!_listVcDic) { _listVcDic = @{}.mutableCopy; } return _listVcDic; } @end