123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345 |
- //
- // RQExerciseViewController.m
- // JSJP
- //
- // Created by 张嵘 on 2021/8/12.
- //
- #import "RQExerciseViewController.h"
- @interface RQExerciseViewController () <JXCategoryViewDelegate, JXPagerViewDelegate, JXPagerMainTableViewGestureDelegate>
- /// viewModel
- @property (nonatomic, readonly, strong) RQExerciseViewModel *viewModel;
- @property (nonatomic, readwrite, strong) JXPagerView *pagerView;
- @property (nonatomic, readwrite, strong) JXCategoryTitleView *categoryView;
- @property (nonatomic, readwrite, copy) NSArray <NSString *> *titles;
- @property (nonatomic, readwrite, copy) NSArray *beitiQuestionsArr;
- @property (nonatomic, readwrite, strong) RQCountdownView *countdownView;
- @property (nonatomic, readwrite, strong) UIView *myAdView;
- @property (nonatomic, readwrite, strong) UIView *myTitleView;
- @property (nonatomic, readwrite, assign) RQExerciseType historyExerciseType;
- @end
- @implementation RQExerciseViewController
- @dynamic viewModel;
- #pragma mark - SystemMethod
- - (void)viewDidLoad {
- [super viewDidLoad];
- /// 初始化
- [self rq_setup];
-
- [self rq_noti];
- }
- - (void)viewDidLayoutSubviews {
- [super viewDidLayoutSubviews];
- [self updateFrame];
- }
- - (void)updateFrame {
- self.myAdView.frame = CGRectMake(0, RQ_APPLICATION_NAV_BAR_HEIGHT + RQ_APPLICATION_STATUS_BAR_HEIGHT, RQ_SCREEN_WIDTH, (RQ_Exercise_Module.currentExerciseType == RQExerciseType_Exam)? 0.f : (self.myAdView.hidden? 0.f : RQ_SCREEN_WIDTH / (640/100.0)));
- self.pagerView.frame = CGRectMake(0, CGRectGetMaxY(self.myAdView.frame), RQ_SCREEN_WIDTH, RQ_SCREEN_HEIGHT - (RQ_APPLICATION_NAV_BAR_HEIGHT + RQ_APPLICATION_STATUS_BAR_HEIGHT) - RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT - ((RQ_Exercise_Module.currentExerciseType == RQExerciseType_Exam)? 0.f : (self.myAdView.hidden? 0.f : RQ_SCREEN_WIDTH / (640/100.0))));
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- if (RQ_Exercise_Module.timer) {
- [RQ_Exercise_Module.timer setFireDate:[NSDate distantPast]];
- }
- }
- - (void)viewWillDisappear:(BOOL)animated {
- [super viewWillDisappear:animated];
- if (RQ_Exercise_Module.timer) {
- [RQ_Exercise_Module.timer setFireDate:[NSDate distantFuture]];
- }
- }
- - (void)viewDidDisappear:(BOOL)animated {
- [super viewDidDisappear:animated];
- self.categoryView.delegate = nil;
- // [self.myTitleView removeAllSubviews];
- // self.myTitleView = nil;
- self.pagerView = nil;
- [RQ_Exercise_Module.timer invalidate];
- RQ_Exercise_Module.timer = nil;
- RQ_Exercise_Module.count = 0;
- RQ_Exercise_Module.beginDate = nil;
- }
- - (void)dealloc {
-
- }
- #pragma mark - PrivateMethods
- /// 初始化
- - (void)rq_setup {
- @weakify(self)
- /// set up ...
- if (RQ_Exercise_Module.currentExerciseType != RQExerciseType_Exam) {
- [self.view addSubview:self.myAdView];
- self.myAdView.hidden = YES;
- [RQ_AD_MANAGER loadAdWithAdType:RQADType_Banner customView:self.myAdView controller:self cycleSecound:RQ_COMMON_MANAGER.JSJP_APP_AD_CYCLE];
- [RQ_AD_MANAGER initCloseBlock:^(RQADDoType adDoType) {
- @strongify(self)
- if (adDoType == RQADDoType_Close || adDoType == RQADDoType_Faild) {
- self.myAdView.hidden = YES;
- } else if (adDoType == RQADDoType_Success) {
- self.myAdView.hidden = NO;
- }
- [self updateFrame];
- }];
-
- RAC(RQ_AD_MANAGER, bannerIsShow) = [[RACObserve(self.myAdView, hidden) map:^id _Nullable(id _Nullable value) {
- @strongify(self)
- return @(!self.myAdView.hidden);
- }] takeUntil:self.rac_willDeallocSignal];
- }
-
- [self.view addSubview:self.pagerView];
- self.navigationItem.rightBarButtonItem = [UIBarButtonItem rq_customItemWithTitle:@"" font:RQMediumFont(13) titleColor:RQ_MAIN_TEXT_COLOR_1 imageName:@"设置-黑" target:self selector:@selector(setAction) contentHorizontalAlignment:UIControlContentHorizontalAlignmentRight EdgeInsetsStyle:RQButtonEdgeInsetsStyleLeft space:4.f];
-
-
-
- RQ_Exercise_Module.count = (self.viewModel.homePageCarType == RQHomePageCarType_Motorcycle)? 30 * 60 : 45 * 60;
-
- [self.navigationItem setLeftBarButtonItems:@[[UIBarButtonItem rq_backItemWithTitle:@"" imageName:@"backIcon" target:self action:@selector(rq_back)]]];
-
- [[RACScheduler mainThreadScheduler] schedule:^{
- @strongify(self)
- if (RQ_Exercise_Module.currentExerciseType == RQExerciseType_Exam) {
- self.navigationItem.titleView = self.countdownView;
- self.countdownView.countDownBtn.selected = YES;
- RAC(self.countdownView.countDownBtn, selected) = [RACObserve(RQ_Exercise_Module, timer) map:^id _Nullable(id _Nullable value) {
- if (RQ_Exercise_Module.timer) {
- return @(RQ_Exercise_Module.timer.isValid);
- } else {
- return @(NO);
- }
- }];
- [RQ_Exercise_Module startTimer];
- } else {
- self.navigationItem.titleView = self.myTitleView;
- [self.myTitleView addSubview:self.categoryView];
- }
- }];
-
-
- self.historyExerciseType = RQ_Exercise_Module.currentExerciseType;
-
- }
- - (void)rq_noti {
- // @weakify(self)
- }
- - (void)rq_back {
- if (RQ_Exercise_Module.currentExerciseType == RQExerciseType_Exam) {
- [self.viewModel.services popToRootViewModelAnimated:YES];
- } else {
- [self.viewModel.services popViewModelAnimated:YES];
- }
- [NY_VOICE_MANAGER stopPayVoiceAction];//停止读题
- [NY_VOICE_MANAGER stopPayVoiceActionUrl];
- }
- - (void)setAction {
- RQExerciseSettingViewModel *exerciseSettingViewModel = [[RQExerciseSettingViewModel alloc] initWithServices:self.viewModel.services params:nil];
- RQExerciseSettingViewController *exerciseSettingViewController = [[RQExerciseSettingViewController alloc] initWithViewModel:exerciseSettingViewModel];
- [self presentPanModal:exerciseSettingViewController];
- }
- #pragma mark - JXPagerViewDelegate
- - (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView {
- return [UIView new];
- }
- - (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView {
- return 0.f;
- }
- - (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
- return 0.f;
- }
- - (UIView *)viewForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
- return [UIView new];
- }
- - (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_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? : @[],
- }];
- RQExerciseSubViewController *exerciseSubViewController = [[RQExerciseSubViewController alloc] initWithViewModel:exerciseSubViewModel];
- // RAC(exerciseSubViewController, count) = RACObserve(self, count);
- return exerciseSubViewController;
- }
- #pragma mark - JXCategoryViewDelegate
- - (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
- self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0);
- if (index == 0) {
- if (RQ_Exercise_Module.currentExerciseType == RQExerciseType_Recitation) {
- RQ_Exercise_Module.currentExerciseType = self.historyExerciseType;
- } else {
- self.historyExerciseType = RQ_Exercise_Module.currentExerciseType;
- RQ_Exercise_Module.currentExerciseType = RQExerciseType_Recitation;
- }
- } else {
- RQ_Exercise_Module.currentExerciseType = RQExerciseType_Recitation;
- }
-
- //根据选中的下标,实时更新currentListView
- // RQExerciseSubViewController *list = (RQExerciseSubViewController *)self.pagerView.listContainerView.validListDict[@(index)];
- // RQ_Exercise_Module.currrentExerciseModel = list.questionArr[list.number];
- }
- #pragma mark - JXPagerMainTableViewGestureDelegate
- - (BOOL)mainTableViewGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
- if ([self checkIsNestContentScrollView:(UIScrollView *)gestureRecognizer.view] || [self checkIsNestContentScrollView:(UIScrollView *)otherGestureRecognizer.view]) {
- //如果交互的是嵌套的contentScrollView,证明在左右滑动,就不允许同时响应
- return NO;
- }
- return [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]];
- }
- - (BOOL)checkIsNestContentScrollView:(UIScrollView *)scrollView {
- for (RQExerciseSubViewController *list in self.pagerView.validListDict.allValues) {
- if (list.contentScrollView == scrollView) {
- return YES;
- }
- }
- return NO;
- }
- #pragma mark - LazyLoad
- - (JXPagerView *)pagerView {
- if (!_pagerView) {
- _pagerView = [[JXPagerView alloc] initWithDelegate:self listContainerType:JXPagerListContainerType_CollectionView];
- _pagerView.mainTableView.gestureDelegate = self;
- _pagerView.isListHorizontalScrollEnabled = NO;
- _pagerView.mainTableView.bounces = NO;
- }
- return _pagerView;
- }
- - (UIView *)myTitleView {
- if (!_myTitleView) {
- CGFloat autoReadBtnWidth = RQ_FIT_HORIZONTAL(80.f);
- CGFloat autoReadBtnHeight = RQ_FIT_HORIZONTAL(28.f);
- _myTitleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, autoReadBtnWidth * 2, autoReadBtnHeight)];
- }
- return _myTitleView;
- }
- - (JXCategoryTitleView *)categoryView {
- if (!_categoryView) {
- CGFloat autoReadBtnWidth = RQ_FIT_HORIZONTAL(80.f);
- CGFloat autoReadBtnHeight = RQ_FIT_HORIZONTAL(28.f);
- _categoryView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(0, 0, autoReadBtnWidth * 2, autoReadBtnHeight)];
- _categoryView.delegate = self;
-
- _categoryView.titles = self.titles;
- _categoryView.titleSelectedColor = UIColor.whiteColor;
- _categoryView.titleColor = RQ_MAIN_TEXT_COLOR_3;
- _categoryView.titleFont = RQRegularFont(13);
- _categoryView.titleSelectedFont = RQRegularFont(13);
- _categoryView.titleNumberOfLines = 0;
- _categoryView.layer.cornerRadius = autoReadBtnHeight / 2.f;
- _categoryView.layer.borderWidth = 1;
- _categoryView.layer.borderColor = RQColorFromHexString(@"#B8C0CC").CGColor;
- _categoryView.contentScrollViewClickTransitionAnimationEnabled = YES;
- _categoryView.backgroundColor = UIColor.whiteColor;
- _categoryView.contentEdgeInsetLeft = 0;
- _categoryView.contentEdgeInsetRight = 0;
- _categoryView.backgroundColor = RQ_MAIN_BACKGROUNDCOLOR;
-
- _categoryView.cellSpacing = 0;
- _categoryView.cellWidth = autoReadBtnWidth;
-
-
- JXCategoryIndicatorBackgroundView *backgroundView = [[JXCategoryIndicatorBackgroundView alloc] init];
- backgroundView.indicatorHeight = autoReadBtnHeight;
- backgroundView.indicatorWidth = autoReadBtnWidth;
- backgroundView.indicatorWidthIncrement = 0;
- backgroundView.indicatorColor = RQ_MAIN_COLOR;
- _categoryView.indicators = @[backgroundView];
-
- _categoryView.defaultSelectedIndex = 0;
- /// !!!: 将列表容器视图关联到 categoryView
- _categoryView.listContainer = (id<JXCategoryViewListContainer>)self.pagerView.listContainerView;
- }
- return _categoryView;
- }
- - (NSArray<NSString *> *)titles {
- return (RQ_Exercise_Module.currentExerciseType == RQExerciseType_Exam)? @[@""] : @[@"答题模式", @"背题模式"];
- }
- - (RQCountdownView *)countdownView {
- if (!_countdownView) {
- @weakify(self)
- _countdownView = [RQCountdownView countdownView];
- _countdownView.frame = CGRectMake(0, 0, RQ_SCREEN_WIDTH / 2.f, RQ_APPLICATION_NAV_BAR_HEIGHT);
- [_countdownView 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_Suspend valueDic:dic confirmAction:^(__kindof QMUIDialogViewController *dialogViewController) {
- // @strongify(self);
- if (RQ_Exercise_Module.timer) {
- [RQ_Exercise_Module.timer setFireDate:[NSDate distantPast]];
- }
- } cancelAction:nil];
- }
- }];
-
- RAC(_countdownView.timeLabel, text) = [RACObserve(RQ_Exercise_Module, count) map:^id _Nullable(id _Nullable value) {
- NSUInteger sec = RQ_Exercise_Module.count%60;
- NSUInteger min = RQ_Exercise_Module.count/60;
- NSString* sec0,*min0;
- sec0 = sec<10 ? @"0" : @"";
- min0 = min<10 ? @"0" : @"";
- return [NSString stringWithFormat:@"%@%lu:%@%lu",min0,(unsigned long)min,sec0,(unsigned long)sec];
- }];
- }
- return _countdownView;
- }
- - (UIView *)myAdView {
- if (!_myAdView) {
- _myAdView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, RQ_SCREEN_WIDTH, RQ_SCREEN_WIDTH / (640/100.0))];
- }
- return _myAdView;
- }
- @end
|