123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
- //
- // RQExerciseViewController.m
- // SDJK
- //
- // Created by 张嵘 on 2021/8/12.
- //
- #import "RQExerciseViewController.h"
- #import "YYTimer.h"
- @interface RQExerciseViewController () <JXCategoryViewDelegate, JXPagerViewDelegate, JXPagerMainTableViewGestureDelegate>
- /// viewModel
- @property (nonatomic, readonly, strong) RQExerciseViewModel *viewModel;
- @property (nonatomic, readwrite, strong) JXPagerView *pagerView;
- @property (nonatomic, readwrite, strong) JXCategoryTitleBackgroundView *categoryView;
- @property (nonatomic, readwrite, copy) NSArray <NSString *> *titles;
- @property (nonatomic, readwrite, strong) UIView *customPinView;
- @property (nonatomic, readwrite, strong) UIButton *autoReadBtn;
- @property (nonatomic, readwrite, strong) RQCountdownView *countdownView;
- /// Timer
- @property (nonatomic, readwrite, strong) YYTimer *timer;
- /// Count
- @property (nonatomic, readwrite, assign) NSUInteger count;
- @end
- @implementation RQExerciseViewController
- @dynamic viewModel;
- #pragma mark - SystemMethod
- - (void)viewDidLoad {
- [super viewDidLoad];
- /// 初始化
- [self rq_setup];
- }
- - (void)viewDidLayoutSubviews {
- [super viewDidLayoutSubviews];
- self.pagerView.frame = CGRectMake(0, RQ_APPLICATION_TOP_BAR_HEIGHT, RQ_SCREEN_WIDTH, RQ_SCREEN_HEIGHT - RQ_APPLICATION_TOP_BAR_HEIGHT - RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT);
- }
- - (void)dealloc {
- [RQ_Exercise_Module cancleAutoReadQuestion];
- }
- #pragma mark - PrivateMethods
- /// 初始化
- - (void)rq_setup {
- /// set up ...
- [self.view addSubview:self.pagerView];
- self.navigationItem.rightBarButtonItem = [UIBarButtonItem rq_customItemWithTitle:@"" font:RQMediumFont(15) titleColor:RQ_MAIN_TEXT_COLOR_1 imageName:@"SetUp" target:self selector:@selector(setAction) contentHorizontalAlignment:UIControlContentHorizontalAlignmentRight EdgeInsetsStyle:RQButtonEdgeInsetsStyleLeft space:4.f];
-
-
-
- self.count = (self.viewModel.homePageCarType == RQHomePageCarType_Motorcycle)? 30 * 60 : 45 * 60;
-
- self.timer = [YYTimer timerWithTimeInterval:1 target:self selector:@selector(_timerValueChanged:) repeats:YES];
-
- [self.navigationItem setLeftBarButtonItems:@[[UIBarButtonItem rq_backItemWithTitle:@"" imageName:@"back_black" target:self action:@selector(rq_back)]]];
- }
- - (void)rq_back {
- if (self.viewModel.exerciseType == RQExerciseType_Exam) {
- [self.navigationController popToRootViewControllerAnimated:YES];
- } else {
- [self.navigationController popViewControllerAnimated:YES];
- }
- }
- - (void)setAction {
- // @weakify(self)
- [RQ_Exercise_Module cancleAutoReadQuestion];
- RQExerciseSettingViewModel *exerciseSettingViewModel = [[RQExerciseSettingViewModel alloc] initWithServices:self.viewModel.services params:nil];
- RQExerciseSettingViewController *exerciseSettingViewController = [[RQExerciseSettingViewController alloc] initWithViewModel:exerciseSettingViewModel];
- // [catalogueViewController initCompletionWithSelectIndexBlock:^(NSInteger index) {
- // @strongify(self)
- // [self jumpQuestionWithIndex:index];
- // }];
- [self presentPanModal:exerciseSettingViewController];
- }
- - (void)_timerValueChanged:(YYTimer *)timer {
- self.count--;
- if (self.count == 0) {
- [timer invalidate];
- self.timer = nil;
- // [self _resetCaptcha];
- return;
- }
- NSUInteger sec = _count%60;
- NSUInteger min = _count/60;
- NSString* sec0,*min0;
- sec0 = sec<10 ? @"0" : @"";
- min0 = min<10 ? @"0" : @"";
- self.countdownView.timeLabel.text = [NSString stringWithFormat:@"%@%lu分%@%lu秒",min0,(unsigned long)min,sec0,(unsigned long)sec];
- }
- #pragma mark - JXPagerViewDelegate
- - (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView {
- return [UIView new];
- }
- - (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView {
- return 0;
- }
- - (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
- return (self.viewModel.exerciseType == RQExerciseType_Test || self.viewModel.exerciseType == RQExerciseType_Exam)? 58.f : 65.f;
- }
- - (UIView *)viewForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
- return (self.viewModel.exerciseType == RQExerciseType_Test || self.viewModel.exerciseType == RQExerciseType_Exam)? self.countdownView : self.customPinView;
- }
- - (NSInteger)numberOfListsInPagerView:(JXPagerView *)pagerView {
- //和categoryView的item数量一致
- return self.categoryView.titles.count;
- }
- - (id<JXPagerViewListViewDelegate>)pagerView:(JXPagerView *)pagerView initListAtIndex:(NSInteger)index {
- RQExerciseSubViewModel *exerciseSubViewModel = [[RQExerciseSubViewModel alloc] initWithServices:self.viewModel.services params:@{
- RQExerciseTypeKey : (self.viewModel.exerciseType == RQExerciseType_Test)? @(RQExerciseType_Test) : ((self.viewModel.exerciseType == RQExerciseType_Exam)? @(RQExerciseType_Exam) : @(index)),
- RQHomePageCarTypeKey : @(self.viewModel.homePageCarType),
- RQHomePageSubjectTypeKey : @(self.viewModel.homePageSubjectType),
- RQHomeSubPageTypeKey : @(self.viewModel.homeSubPageType),
- RQHomeSubEditListTypeKey : @(self.viewModel.homeSubEditListType),
- RQViewModelIDKey : self.viewModel.titleStr? : @"",
- RQViewCommonValueKey : @(self.viewModel.number),
- RQViewModelUtilKey : self.viewModel.questionArr? : @[],
- }];
- exerciseSubViewModel.title = self.viewModel.title;
- RQExerciseSubViewController *exerciseSubViewController = [[RQExerciseSubViewController alloc] initWithViewModel:exerciseSubViewModel];
- RAC(exerciseSubViewController, count) = RACObserve(self, count);
- __weak typeof(exerciseSubViewController) weakController = exerciseSubViewController;
- return weakController;
- }
- #pragma mark - JXCategoryViewDelegate
- - (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
- [RQ_Exercise_Module cancleAutoReadQuestion];
- self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0);
- //根据选中的下标,实时更新currentListView
- RQExerciseSubViewController *list = (RQExerciseSubViewController *)self.pagerView.listContainerView.validListDict[@(index)];
- [list rq_setup];
- if (list.questionArr.count > 0) {
- if (list.number < list.questionArr.count) {
- RQ_Exercise_Module.currrentExerciseModel = list.questionArr[list.number];
- }
- }
- }
- #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
- - (JXPagerView *)pagerView {
- if (!_pagerView) {
- _pagerView = [[JXPagerView alloc] initWithDelegate:self];
- _pagerView.mainTableView.gestureDelegate = self;
- _pagerView.isListHorizontalScrollEnabled = NO;
- _pagerView.mainTableView.bounces = NO;
- }
- return _pagerView;
- }
- - (JXCategoryTitleBackgroundView *)categoryView {
- if (!_categoryView) {
- CGFloat autoReadBtnWidth = (RQ_SCREEN_WIDTH) / 4.f + 8;
- _categoryView = [[JXCategoryTitleBackgroundView alloc] initWithFrame:CGRectMake(0, 0, RQ_SCREEN_WIDTH - autoReadBtnWidth, 55)];
- _categoryView.delegate = self;
-
- _categoryView.titles = self.titles;
- _categoryView.titleSelectedColor = UIColor.whiteColor;
- _categoryView.titleColor = UIColor.whiteColor;
- _categoryView.titleFont = RQRegularFont(15);
- _categoryView.titleSelectedFont = RQRegularFont(15);
- _categoryView.titleNumberOfLines = 0;
- _categoryView.contentScrollViewClickTransitionAnimationEnabled = NO;
- _categoryView.borderLineWidth = 0;
- _categoryView.selectedBackgroundColor = RQ_MAIN_COLOR;
- _categoryView.normalBackgroundColor = RQ_BACKGROUNDCOLOR_3;
- _categoryView.contentEdgeInsetLeft = 16;
- _categoryView.contentEdgeInsetRight = 16;
- _categoryView.backgroundColor = RQ_MAIN_BACKGROUNDCOLOR;
-
- _categoryView.cellSpacing = 8;
- _categoryView.cellWidth = autoReadBtnWidth - (3 * 8);
-
- _categoryView.backgroundHeight = 30;
- _categoryView.backgroundWidth = _categoryView.cellWidth;
- _categoryView.backgroundCornerRadius = 15;
-
- _categoryView.defaultSelectedIndex = 0;
- /// !!!: 将列表容器视图关联到 categoryView
- _categoryView.listContainer = (id<JXCategoryViewListContainer>)self.pagerView.listContainerView;
- self.autoReadBtn.frame = CGRectMake(_categoryView.width, 12.5, autoReadBtnWidth - 16, 30);
- [self.customPinView addSubview:_autoReadBtn];
- }
- return _categoryView;
- }
- - (NSArray<NSString *> *)titles {
- return (self.viewModel.exerciseType == RQExerciseType_Test || self.viewModel.exerciseType == RQExerciseType_Exam)? @[@""] : @[@"顺序练习", @"随机练习", @"背题模式"];
- }
- - (UIButton *)autoReadBtn {
- if (!_autoReadBtn) {
- _autoReadBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [_autoReadBtn setImage:RQImageNamed(@"autoRead") withTitle:@"自动读题" textColor:UIColor.whiteColor Font:15 fotState:UIControlStateNormal];
- [_autoReadBtn setImage:RQImageNamed(@"stopRead") withTitle:@"停止读题" textColor:UIColor.whiteColor Font:15 fotState:UIControlStateSelected];
-
- _autoReadBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
- [_autoReadBtn setBackgroundImage:[UIImage imageWithColor:RQ_MAIN_COLOR] forState:UIControlStateSelected];
- [_autoReadBtn setBackgroundImage:[UIImage imageWithColor:RQ_BACKGROUNDCOLOR_3] forState:UIControlStateNormal];
- [_autoReadBtn layoutButtonWithEdgeInsetsStyle:RQButtonEdgeInsetsStyleLeft imageTitleSpace:2];
- _autoReadBtn.layer.cornerRadius = 15;
- _autoReadBtn.clipsToBounds = YES;
- _autoReadBtn.userInteractionEnabled = YES;
- // @weakify(_autoReadBtn);
- [_autoReadBtn setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
- // @strongify(_autoReadBtn);
- if (RQ_Exercise_Module.isAutoRead) {
- [RQ_Exercise_Module cancleAutoReadQuestion];
- } else {
- RQ_Exercise_Module.isAutoRead = YES;
- }
- }];
-
- RAC(_autoReadBtn, selected) = RACObserve(RQ_Exercise_Module, isAutoRead);
- }
- return _autoReadBtn;
- }
- - (UIView *)customPinView {
- if (!_customPinView) {
- _customPinView = [[UIView alloc] init];
- [_customPinView addSubview:self.categoryView];
- UIImageView *lineImageView = [[UIImageView alloc] initWithImage:[UIImage imageWithColor:RQ_LIST_BACKGROUNDCOLOR size:CGSizeMake(RQ_SCREEN_WIDTH, 10)]];
- lineImageView.rq_y = 55;
- [_customPinView addSubview:lineImageView];
- }
- return _customPinView;
- }
- - (RQCountdownView *)countdownView {
- if (!_countdownView) {
- _countdownView = [RQCountdownView countdownView];
- }
- return _countdownView;
- }
- @end
|