123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- //
- // RQProfilePracticeCell.m
- // jiaPei
- //
- // Created by 张嵘 on 2022/4/27.
- // Copyright © 2022 JCZ. All rights reserved.
- //
- #import "RQProfilePracticeCell.h"
- @interface RQProfilePracticeCell () <RQSwitchDelegate>
- @property (nonatomic, readwrite, strong) RQProfilePracticeItemViewModel *viewModel;
- @property (nonatomic, readwrite, strong) RQSwitch *rqSwitch;
- @property (weak, nonatomic) IBOutlet UILabel *leftTitleLabel;
- @property (nonatomic, readwrite, assign) RQSwitchState switchState;
- @property (weak, nonatomic) IBOutlet UILabel *carTypeLabel;
- @property (weak, nonatomic) IBOutlet UIStackView *chooseCarTypeView;
- @property (weak, nonatomic) IBOutlet UILabel *questionAllNumLabel;
- @property (weak, nonatomic) IBOutlet UILabel *hasDoneQuestionNumLabel;
- @property (weak, nonatomic) IBOutlet UILabel *scoreLabel;
- @property (weak, nonatomic) IBOutlet UILabel *countLabel;
- @property (weak, nonatomic) IBOutlet UIStackView *upScoreView;
- @end
- @implementation RQProfilePracticeCell
- #pragma mark - PublicMethods
- + (instancetype)cellWithCollectionView:(UICollectionView *)collectionView forIndexPath:(NSIndexPath *)indexPath {
- static NSString *ID = @"RQProfilePracticeCell";
- [collectionView registerNib:[UINib nibWithNibName:ID bundle:nil] forCellWithReuseIdentifier:ID];
- RQProfilePracticeCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath];
- if (!cell) cell = [self rq_viewFromXib];
- [cell.contentView addSubview:cell.rqSwitch];
- return cell;
- }
- - (void)bindViewModel:(RQProfilePracticeItemViewModel *)viewModel {
- self.viewModel = viewModel;
- }
- #pragma mark - SystemMethods
- - (void)awakeFromNib {
- [super awakeFromNib];
- @weakify(self)
- [_chooseCarTypeView setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
- [RQ_APPDELEGATE.services pushViewModel:[[RQChooseCarTypeViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:nil] animated:YES];
- }];
-
- RAC(_upScoreView, hidden) = [[[RACObserve(RQ_COMMON_MANAGER, APP_SWITCH) takeUntil:self.rac_prepareForReuseSignal] deliverOnMainThread] distinctUntilChanged];
-
- [_upScoreView setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
- [RQ_VIP_Module isVipWithSubject:0 complete:^(BOOL isVip) {
- if (RQ_VIP_Module.isVip) {
- [RQ_VIP_Module gotoVipCenter];
- } else {
- [RQ_VIP_Module gotoBuyVipWithVipPageType:RQVIPPageType_Full];
- }
- }];
- }];
-
- RAC(self.carTypeLabel, text) = [[RACObserve(RQ_YDTQuestion_Module, carType) map:^id _Nullable(id _Nullable value) {
- RQHomePageCarType carType = [value integerValue];
- return [RQ_YDTQuestion_Module getCarTypeCNNameWithCarType:carType];
- }] takeUntil:self.rac_prepareForReuseSignal];
-
- RAC(self.leftTitleLabel, hidden) = [[[RACObserve(RQ_YDTQuestion_Module, carType) deliverOnMainThread] takeUntil:self.rac_prepareForReuseSignal] map:^id _Nullable(id _Nullable value) {
- RQHomePageCarType carType = [value integerValue];
- BOOL needHide = (carType == RQHomePageCarType_Car || carType == RQHomePageCarType_Bus || carType == RQHomePageCarType_Truck || carType == RQHomePageCarType_Motorcycle);
- return @(needHide);
- }];
-
- RAC(self.rqSwitch, hidden) = [[[RACObserve(RQ_YDTQuestion_Module, carType) deliverOnMainThread] takeUntil:self.rac_prepareForReuseSignal] map:^id _Nullable(id _Nullable value) {
- RQHomePageCarType carType = [value integerValue];
- BOOL needHide = (carType == RQHomePageCarType_Car || carType == RQHomePageCarType_Bus || carType == RQHomePageCarType_Truck || carType == RQHomePageCarType_Motorcycle);
- return @(!needHide);
- }];
-
- RAC(self.questionAllNumLabel, text) = [[RACSignal combineLatest:@[RACObserve(RQ_YDTQuestion_Module, carType), [RACObserve(self, switchState) distinctUntilChanged]] reduce:^id (NSNumber *carType, NSNumber *switchState) {
- BOOL isSubjectOne = switchState.boolValue;
- NSInteger allCount = [RQ_YDTQuestion_Module getQuestionNumWithWithSubject:isSubjectOne? RQHomePageSubjectType_SubjectOne : RQHomePageSubjectType_SubjectFour exerciseType:RQExerciseType_Sequential];
- return [NSString stringWithFormat:@"%ld",allCount];
- }] takeUntil:self.rac_prepareForReuseSignal];
-
- RAC(self.hasDoneQuestionNumLabel, text) = [[RACSignal combineLatest:@[RACObserve(RQ_YDTQuestion_Module, carType), [RACObserve(self, switchState) distinctUntilChanged], RACObserve(RQ_YDT_USER_Question_Module, doNum)] reduce:^id (NSNumber *carType, NSNumber *switchState, NSNumber *doNum) {
- BOOL isSubjectOne = switchState.boolValue;
- NSInteger hasDoneCount = [RQ_YDT_USER_Question_Module getDoQuestionNumWithCarType:RQ_YDTQuestion_Module.carType subject:isSubjectOne? RQHomePageSubjectType_SubjectOne : RQHomePageSubjectType_SubjectFour];
- return [NSString qmui_stringWithNSInteger:hasDoneCount];
- }] takeUntil:self.rac_prepareForReuseSignal];
-
- RAC(self.scoreLabel, text) = [[RACSignal combineLatest:@[RACObserve(RQ_COMMON_MANAGER, examResultOneListArr), RACObserve(RQ_COMMON_MANAGER, examResultFourListArr), [RACObserve(self, switchState) distinctUntilChanged]] reduce:^id (NSArray *examResultOneListArr, NSArray *examResultFourListArr, NSNumber *switchState) {
- BOOL isSubjectOne = switchState.boolValue;
- NSArray *arr;
- if (isSubjectOne) {
- arr = examResultOneListArr;
- } else {
- arr = examResultFourListArr;
- }
-
- float avg = [[[arr.rac_sequence.signal map:^id _Nullable(RQExamResultModel *examResultModel) {
- return examResultModel.score;
- }].toArray valueForKeyPath:@"@avg.floatValue"] floatValue];
- NSString *score = [NSString qmui_stringWithCGFloat:avg decimal:0];
- return score;
- }] takeUntil:self.rac_willDeallocSignal];
-
- RAC(self.countLabel, text) = [[RACSignal combineLatest:@[RACObserve(RQ_COMMON_MANAGER, examResultOneListArr), RACObserve(RQ_COMMON_MANAGER, examResultFourListArr), [RACObserve(self, switchState) distinctUntilChanged]] reduce:^id (NSArray *examResultOneListArr, NSArray *examResultFourListArr, NSNumber *switchState) {
- BOOL isSubjectOne = switchState.boolValue;
- NSArray *arr;
- if (isSubjectOne) {
- arr = examResultOneListArr;
- } else {
- arr = examResultFourListArr;
- }
- NSString *count = [NSString qmui_stringWithNSInteger:arr.count];
- return [NSString stringWithFormat:@"近%@次",count];
- }] takeUntil:self.rac_willDeallocSignal];
-
- self.switchState = ![self.rqSwitch getSwitchState];
-
- [[RACObserve(RQ_Profile_Module, profileSubject) takeUntil:self.rac_prepareForReuseSignal] subscribeNext:^(id _Nullable x) {
- switch (RQ_Profile_Module.profileSubject) {
- case 0:
- self.rqSwitch.thumbOnTintColor = RQ_VIP_Module.isSubject1Vip? RQColorFromHexString(@"#8950C5") : RQColorFromHexString(@"#498EF5");
- self.rqSwitch.thumbOffTintColor = RQ_VIP_Module.isSubject1Vip? RQColorFromHexString(@"#8950C5") : RQColorFromHexString(@"#498EF5");
- self.rqSwitch.thumbDisabledTintColor = RQ_VIP_Module.isSubject1Vip? RQColorFromHexString(@"#8950C5") : RQColorFromHexString(@"#498EF5");
- break;
- case 1:
- self.rqSwitch.thumbOnTintColor = RQ_VIP_Module.isSubject2Vip? RQColorFromHexString(@"#8950C5") : RQColorFromHexString(@"#498EF5");
- self.rqSwitch.thumbOffTintColor = RQ_VIP_Module.isSubject2Vip? RQColorFromHexString(@"#8950C5") : RQColorFromHexString(@"#498EF5");
- self.rqSwitch.thumbDisabledTintColor = RQ_VIP_Module.isSubject2Vip? RQColorFromHexString(@"#8950C5") : RQColorFromHexString(@"#498EF5");
- break;
- case 2:
- self.rqSwitch.thumbOnTintColor = RQ_VIP_Module.isSubject3Vip? RQColorFromHexString(@"#8950C5") : RQColorFromHexString(@"#498EF5");
- self.rqSwitch.thumbOffTintColor = RQ_VIP_Module.isSubject3Vip? RQColorFromHexString(@"#8950C5") : RQColorFromHexString(@"#498EF5");
- self.rqSwitch.thumbDisabledTintColor = RQ_VIP_Module.isSubject3Vip? RQColorFromHexString(@"#8950C5") : RQColorFromHexString(@"#498EF5");
- break;
- case 3:
- self.rqSwitch.thumbOnTintColor = RQ_VIP_Module.isSubject4Vip? RQColorFromHexString(@"#8950C5") : RQColorFromHexString(@"#498EF5");
- self.rqSwitch.thumbOffTintColor = RQ_VIP_Module.isSubject4Vip? RQColorFromHexString(@"#8950C5") : RQColorFromHexString(@"#498EF5");
- self.rqSwitch.thumbDisabledTintColor = RQ_VIP_Module.isSubject4Vip? RQColorFromHexString(@"#8950C5") : RQColorFromHexString(@"#498EF5");
- break;
- case 4:
- self.rqSwitch.thumbOnTintColor = RQ_VIP_Module.isSubjectAllVip? RQColorFromHexString(@"#8950C5") : RQColorFromHexString(@"#498EF5");
- self.rqSwitch.thumbOffTintColor = RQ_VIP_Module.isSubjectAllVip? RQColorFromHexString(@"#8950C5") : RQColorFromHexString(@"#498EF5");
- self.rqSwitch.thumbDisabledTintColor = RQ_VIP_Module.isSubjectAllVip? RQColorFromHexString(@"#8950C5") : RQColorFromHexString(@"#498EF5");
- break;
-
- default:
- break;
- }
- self.rqSwitch.switchThumb.backgroundColor = self.rqSwitch.thumbOnTintColor;
- self.rqSwitch.track.backgroundColor = self.rqSwitch.trackOnTintColor;
- }];
- }
- #pragma mark - RQSwitchDelegate
- - (void)switchStateChanged:(RQSwitchState)currentState {
- self.switchState = currentState;
- }
- #pragma mark - LazyLoad
- - (RQSwitch *)rqSwitch {
- if (!_rqSwitch) {
- _rqSwitch = [[RQSwitch alloc] initWithSize:RQSwitchSizeSubject style:RQSwitchStyleSubject state:RQSwitchStateOn];
- _rqSwitch.delegate = self;
- _rqSwitch.center = CGPointMake(RQ_FIT_HORIZONTAL(105.f) / 2.f + 16, RQ_FIT_HORIZONTAL(25.f) / 2.f + 16);
- }
- return _rqSwitch;
- }
- @end
|