123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- //
- // RQCollectViewController.m
- // jiaPei
- //
- // Created by 张嵘 on 2022/8/3.
- // Copyright © 2022 JCZ. All rights reserved.
- //
- #import "RQCollectViewController.h"
- @interface RQCollectViewController ()
- /// viewModel
- @property (nonatomic, readonly, strong) RQCollectViewModel *viewModel;
- @property (nonatomic, readwrite, strong) RQErrorAndCollectHeaderView *collectHeaderView;
- @property (nonatomic, readwrite, strong) QMUIButton *clearBtn;
- @end
- @implementation RQCollectViewController
- @dynamic viewModel;
- #pragma mark - SystemMethod
- - (void)viewDidLoad {
- @weakify(self)
- [super viewDidLoad];
- self.tableView.tableHeaderView = self.collectHeaderView;
- self.tableView.backgroundColor = UIColor.clearColor;
- [self.view addSubview:self.clearBtn];
- [[RACObserve(self.viewModel, dataSource) deliverOnMainThread] subscribeNext:^(NSArray *dataSource) {
- @strongify(self)
- NSUInteger count = dataSource.count;
- if (count == 0) {
- // [self showEmptyViewWithImage:RQImageNamed(@"自动收藏") text:@"您收藏的题目会自动记录到这里哟~" detailText:nil buttonTitle:nil buttonAction:nil];
- [self.emptyView setImage:RQImageNamed(@"自动收藏")];
- [self.emptyView setLoadingViewHidden:YES];
- [self.emptyView setTextLabelText:@"您收藏的题目会自动记录到这里哟~"];
- [self.tableView addSubview:self.emptyView];
- [self.tableView sendSubviewToBack:self.emptyView];
- CGFloat a = 8.f + RQ_FIT_HORIZONTAL(214.f) + 4.f + RQ_FIT_HORIZONTAL(40.f) + 20.f + 10.f;
- self.emptyView.frame = CGRectMake(0, a / 2.f, RQ_SCREEN_WIDTH, RQ_SCREEN_HEIGHT);
- [self.clearBtn setTitleNormal:@"去练习"];
- } else {
- [self hideEmptyView];
- [self.clearBtn setTitleNormal:@"清空我的收藏"];
- }
- }];
-
- [[[RQNotificationCenter rac_addObserverForName:RQCancelCollectNotification object:nil] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSNotification * _Nullable x) {
- @strongify(self);
- self.collectHeaderView.allNumLabel.text = [NSString qmui_stringWithNSInteger:[RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Collect].count];
- }];
- }
- - (void)viewDidLayoutSubviews {
- [super viewDidLayoutSubviews];
- self.tableView.frame = CGRectMake(0, 0, RQ_SCREEN_WIDTH, RQ_SCREEN_HEIGHT - RQ_APPLICATION_STATUS_BAR_HEIGHT - RQ_APPLICATION_NAV_BAR_HEIGHT - RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT - RQ_FIT_HORIZONTAL(40.f) - 30.f - 16.f);
- self.collectHeaderView.size = CGSizeMake(RQ_SCREEN_WIDTH, 8.f + RQ_FIT_HORIZONTAL(214.f) + 4.f + RQ_FIT_HORIZONTAL(40.f) + 20.f + 10.f);
- self.clearBtn.frame = CGRectMake(16, RQ_SCREEN_HEIGHT - RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT - RQ_APPLICATION_STATUS_BAR_HEIGHT - RQ_APPLICATION_NAV_BAR_HEIGHT - 30.f - RQ_FIT_HORIZONTAL(40.f), RQ_SCREEN_WIDTH - 32.f, RQ_FIT_HORIZONTAL(40.f));
- self.clearBtn.layer.cornerRadius = RQ_FIT_HORIZONTAL(40.f) / 2.f;
- }
- - (void)clearBtnAction {
- // @weakify(self)
- if (self.viewModel.dataSource.count == 0) {
- [self.viewModel.services popToRootViewModelAnimated:YES];
- } else {
- [MBProgressHUD rq_showProgressHUD:@"删除中..."];
- [[RQ_HTTP_Service deleteQuestionFavAllWithType:RQSaveFavQuestionType_Collect] subscribeNext:^(id _Nullable x) {
- // @strongify(self)
- [MBProgressHUD rq_hideHUD];
- [MBProgressHUD rq_showTips:@"删除成功!"];
- [RQ_YDT_USER_Question_Module deleteAllCollectRecordWithCarType:RQ_YDTQuestion_Module.carType subject:RQ_YDTQuestion_Module.subject];
- [RQNotificationCenter postNotificationName:RQCancelCollectNotification object:nil userInfo:@{}];
- } error:^(NSError * _Nullable error) {
- [MBProgressHUD rq_hideHUD];
- [MBProgressHUD rq_showErrorTips:error];
- }];
- }
- }
- #pragma mark - OverrideMethods
- - (UITableViewCell *)tableView:(UITableView *)tableView dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath {
- RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section];
- RQCommonCollectionItemViewModel *itemViewModel = groupViewModel.itemViewModels[indexPath.row];
- return [NSClassFromString(itemViewModel.itemClassName) cellWithTableView:tableView];
- }
- - (void)configureCell:(RQCommonCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object {
- [cell bindViewModel:object];
- }
- #pragma mark - JXPagerSmoothViewListViewDelegate
- - (UIView *)listView {
- return self.view;
- }
- - (UIScrollView *)listScrollView {
- return self.tableView;
- }
- #pragma mark - LazyLoad
- - (RQErrorAndCollectHeaderView *)collectHeaderView {
- if (!_collectHeaderView) {
- _collectHeaderView = [RQErrorAndCollectHeaderView errorAndCollectHeaderView];
- _collectHeaderView.bottomView.hidden = YES;
- [_collectHeaderView.todayErrorBtn setTitleNormal:@"今日收藏"];
- [_collectHeaderView.allErrorBtn setTitleNormal:@"全部收藏"];
- _collectHeaderView.titleLabel.text = @"累计收藏";
-
- _collectHeaderView.allNumLabel.text = [NSString qmui_stringWithNSInteger:[RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Collect].count];
-
- [_collectHeaderView.todayErrorBtn setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
- NSArray *todayArr = [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Collect];
- NSArray *arr = [todayArr.rac_sequence.signal map:^id _Nullable(RQYDTQuestionModel *ydtQuestionModel) {
- return [RQExerciseModel exerciseModelWithRQYDTQuestionModel:ydtQuestionModel];
- }].toArray;
- RQExerciseViewModel *exerciseViewModel = [[RQExerciseViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{
- RQHomePageCarTypeKey : @(RQ_YDTQuestion_Module.carType),
- RQHomePageSubjectTypeKey : @(RQ_YDTQuestion_Module.subject),
- RQHomeSubPageTypeKey : @(RQHomeSubPageType_WrongTopicAndCollection),
- RQViewModelIDKey : @"今日收藏",
- RQExerciseTypeKey : @(RQExerciseType_Collect),
- RQViewModelUtilKey : arr,
- }];
- [RQ_APPDELEGATE.services pushViewModel:exerciseViewModel animated:YES];
- }];
-
- [_collectHeaderView.allErrorBtn setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
- NSArray *allArr = [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Collect];
- NSArray *arr = [allArr.rac_sequence.signal map:^id _Nullable(RQYDTQuestionModel *ydtQuestionModel) {
- return [RQExerciseModel exerciseModelWithRQYDTQuestionModel:ydtQuestionModel];
- }].toArray;
- RQExerciseViewModel *exerciseViewModel = [[RQExerciseViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{
- RQHomePageCarTypeKey : @(RQ_YDTQuestion_Module.carType),
- RQHomePageSubjectTypeKey : @(RQ_YDTQuestion_Module.subject),
- RQHomeSubPageTypeKey : @(RQHomeSubPageType_WrongTopicAndCollection),
- RQViewModelIDKey : @"全部收藏",
- RQExerciseTypeKey : @(RQExerciseType_Collect),
- RQViewModelUtilKey : arr,
- }];
- [RQ_APPDELEGATE.services pushViewModel:exerciseViewModel animated:YES];
- }];
- }
- return _collectHeaderView;
- }
- - (QMUIButton *)clearBtn {
- if (!_clearBtn) {
- _clearBtn = [QMUIButton buttonWithType:UIButtonTypeCustom];
- [_clearBtn addTarget:self action:@selector(clearBtnAction) forControlEvents:UIControlEventTouchUpInside];
- [_clearBtn setTitleNormal:@"清空我的收藏"];
- [_clearBtn setTitleColor:RQ_MAIN_BACKGROUNDCOLOR forState:UIControlStateNormal];
- [_clearBtn setBackgroundColor:RQ_MAIN_COLOR];
- _clearBtn.layer.masksToBounds = YES;
- }
- return _clearBtn;
- }
- @end
|