123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643 |
- //
- // 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 <NSString *> *titles;
- @property (nonatomic, readwrite, copy) NSArray <RQYDTQuestionModel *> *ydtQuestionsArr;
- @property (nonatomic, readwrite, copy) NSArray <RQExerciseModel *> *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<self.questionArr.count-1 ?_firstNum+1:(int)self.questionArr.count-1;
- // [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithInt:popNum] forKey:@"QUESTIONNUM"];
- // [[NSUserDefaults standardUserDefaults] synchronize];
- }
- - (void)viewWillLayoutSubviews {
- [super viewWillLayoutSubviews];
- @weakify(self)
- 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);
- self.pagerView.frame = CGRectMake(0, 0, RQ_SCREEN_WIDTH, height);
- [_exerciseToolBarView mas_makeConstraints:^(MASConstraintMaker *make) {
- @strongify(self)
- make.centerX.mas_equalTo(self.view);
- make.bottom.mas_equalTo(self.view.mas_bottom).mas_offset(0);
- make.size.mas_equalTo(CGSizeMake(RQ_SCREEN_WIDTH, RQ_FIT_HORIZONTAL(50.f)));
- }];
- }
- - (void)dealloc {
- RQ_Exercise_Module.correctArr = @[];
- RQ_Exercise_Module.errorArr = @[];
- self.categoryView.delegate = nil;
- self.categoryView = nil;
- // self.pagerView.delegate = nil;
- self.pagerView = nil;
- RQ_Exercise_Module.questionArr = @[];
- }
- #pragma mark - PrivateMethods
- /// 初始化
- - (void)rq_setup {
- @weakify(self)
- [self.view addSubview:self.pagerView];
- [self.view addSubview:self.exerciseToolBarView];
-
-
- if (RQ_Exercise_Module.currentExerciseType == RQExerciseType_Exam) {
- RQ_Exercise_Module.questionArr = self.viewModel.questionArr;
- [self jumpQuestionWithIndex:0];
- [self reDoQuestionsArr];
- } else {
- NSInteger historyNum = [RQ_YDTQuestion_Module getHistoryQuestionNum];
- if (self.viewModel.questionArr.count >= 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<JXPagerSmoothViewListViewDelegate>)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<JXCategoryViewListContainer>)self.pagerView.listDict;
-
- }
- return _categoryView;
- }
- - (JXPagerSmoothView *)pagerView {
- if (!_pagerView) {
- _pagerView = [[JXPagerSmoothView alloc] initWithDataSource:self];
- self.contentScrollView = _pagerView.listCollectionView;
- }
- return _pagerView;
- }
- - (NSArray<NSString *> *)titles {
- return [self.viewModel.questionArr.rac_sequence.signal map:^id _Nullable(RQExerciseModel *exerciseModel) {
- return [NSString qmui_stringWithNSInteger:exerciseModel.ydtQuestionModel.ID];
- }].toArray;
- }
- - (NSArray<RQYDTQuestionModel *> *)ydtQuestionsArr {
- if (!_ydtQuestionsArr) {
- _ydtQuestionsArr = [self.viewModel.questionArr.rac_sequence.signal map:^id _Nullable(RQExerciseModel *exerciseModel) {
- return exerciseModel.ydtQuestionModel;
- }].toArray;
- }
- return _ydtQuestionsArr;
- }
- - (NSArray<RQExerciseModel *> *)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
|