123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 |
- //
- // RQExamProbabilyCell.m
- // jiaPei
- //
- // Created by 张嵘 on 2022/7/29.
- // Copyright © 2022 JCZ. All rights reserved.
- //
- #import "RQExamProbabilyCell.h"
- @interface RQPopupContainerView : QMUIPopupContainerView
- @end
- @implementation RQPopupContainerView
- - (instancetype)initWithFrame:(CGRect)frame {
- self = [super initWithFrame:frame];
- if (self) {
- self.contentEdgeInsets = UIEdgeInsetsZero;
- // self.maskViewBackgroundColor = nil;
- // self.backgroundColor = nil;
- // self.borderWidth = 0;
- // self.cornerRadius = 4.f;
- // self.textLabel.textAlignment = NSTextAlignmentCenter;
- // self.arrowImage = [UIImageMake(@"popover_container_arrow") qmui_imageResizedInLimitedSize:CGSizeMake(RQ_FIT_HORIZONTAL(8.f), RQ_FIT_HORIZONTAL(4.f)) resizingMode:QMUIImageResizingModeScaleAspectFit];
- }
- return self;
- }
- //- (CGSize)sizeThatFitsInContentView:(CGSize)size {
- // return CGSizeMake(RQ_SCREEN_WIDTH - 32.f, RQ_FIT_HORIZONTAL(39.f));
- //}
- - (void)layoutSubviews {
- [super layoutSubviews];
- // 所有布局都参照 contentView
- }
- @end
- @interface RQPodDownContainerView : QMUIPopupContainerView
- @end
- @implementation RQPodDownContainerView
- - (instancetype)initWithFrame:(CGRect)frame {
- self = [super initWithFrame:frame];
- if (self) {
- self.contentEdgeInsets = UIEdgeInsetsZero;
- self.maskViewBackgroundColor = nil;
- self.backgroundColor = nil;
- self.borderWidth = 0;
-
- self.preferLayoutDirection = QMUIPopupContainerViewLayoutDirectionAbove;
- self.textLabel.text = @"目标值";
- self.textLabel.textAlignment = NSTextAlignmentCenter;
- self.cornerRadius = 4.f;
- self.textLabel.font = [UIFont systemFontOfSize:13];
- self.textLabel.textColor = UIColorWhite;
- self.backgroundView = ({
- [[UIImageView alloc] initWithImage:[UIImage imageWithGradualChangingColor:^(QQGradualChangingColor *graColor) {
- graColor.fromColor = [UIColor qmui_colorWithHexString:@"#01C18D"];
- graColor.toColor = [UIColor qmui_colorWithHexString:@"#3ED2AA"];
- graColor.type = QQGradualChangeTypeLeftToRight;
- } size:CGSizeMake(RQ_FIT_HORIZONTAL(47.f), RQ_FIT_HORIZONTAL(26.f)) cornerRadius:QQRadiusMakeSame(0.f)]];
- });
- self.arrowImage = [UIImageMake(@"popover_container_arrow") qmui_imageResizedInLimitedSize:CGSizeMake(RQ_FIT_HORIZONTAL(14.f), RQ_FIT_HORIZONTAL(8.f)) resizingMode:QMUIImageResizingModeScaleAspectFit];
-
- }
- return self;
- }
- - (CGSize)sizeThatFitsInContentView:(CGSize)size {
- return CGSizeMake(RQ_FIT_HORIZONTAL(47.f), RQ_FIT_HORIZONTAL(26.f));
- }
- - (void)layoutSubviews {
- [super layoutSubviews];
- // 所有布局都参照 contentView
- }
- @end
- @interface RQExamProbabilyCell ()
- @property (nonatomic, readwrite, strong) RQExamProbabilyItemViewModel *viewModel;
- @property (weak, nonatomic) IBOutlet UIView *probabilyView;
- @property (weak, nonatomic) IBOutlet UIView *bottomView;
- @property (nonatomic, readwrite, strong) RQPodDownContainerView *popupByAddTopSubview;
- @property (nonatomic, readwrite, strong) RQPopupContainerView *popupByAddBottomSubview;
- @property (weak, nonatomic) IBOutlet UIImageView *myHeadImageView;
- @property (weak, nonatomic) IBOutlet UILabel *userNameLabel;
- @property (weak, nonatomic) IBOutlet UILabel *passRateDscLabel;
- @property (weak, nonatomic) IBOutlet UILabel *passRateTitleLabel;
- @property (weak, nonatomic) IBOutlet UIImageView *bgImageView;
- @end
- @implementation RQExamProbabilyCell
- #pragma mark - PublicMethods
- + (instancetype)cellWithTableView:(UITableView *)tableView {
- static NSString *ID = @"RQExamProbabilyCell";
- RQExamProbabilyCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
- if (!cell) {
- cell = [self rq_viewFromXib];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- }
- return cell;
- }
- - (void)bindViewModel:(RQExamProbabilyItemViewModel *)viewModel {
- _viewModel = viewModel;
- @weakify(self)
- self.passRateTitleLabel.text = viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectOne? @"科目一考试预测通过率" : @"科目四考试预测通过率";
- [[RACObserve(RQ_USER_MANAGER.currentUser, photo) takeUntil:self.rac_prepareForReuseSignal] subscribeNext:^(NSString *imageName) {
- @strongify(self);
- [self.myHeadImageView yy_setImageWithURL:[NSURL URLWithString:imageName] placeholder:RQWebAvatarImagePlaceholder() options:RQWebImageOptionAutomatic completion:^(UIImage * _Nullable image, NSURL * _Nonnull url, YYWebImageFromType from, YYWebImageStage stage, NSError * _Nullable error) {
- @strongify(self)
- if(image) {
- image = [image qmui_imageResizedInLimitedSize:CGSizeMake(RQ_FIT_HORIZONTAL(45.f), RQ_FIT_HORIZONTAL(45.f)) resizingMode:QMUIImageResizingModeScaleAspectFill];
- image = [image qmui_imageWithBorderColor:UIColor.whiteColor borderWidth:1 cornerRadius:RQ_FIT_HORIZONTAL(45.f) / 2.f];
- self.myHeadImageView.image = image;
- }
- }];
- }];
- RAC(_userNameLabel, text) = [RACObserve(RQ_USER_MANAGER.currentUser, nickName) takeUntil:self.rac_prepareForReuseSignal];
-
- NSArray *btnArr = @[_passRateBtn1,_passRateBtn2,_passRateBtn3,_passRateBtn4,_passRateBtn5,
- _passRateBtn6,_passRateBtn7,_passRateBtn8,_passRateBtn9,_passRateBtn10,
- _passRateBtn11,_passRateBtn12,_passRateBtn13,_passRateBtn14,_passRateBtn15,
- _passRateBtn16,_passRateBtn17,_passRateBtn18,_passRateBtn19,_passRateBtn20,
- _passRateBtn21,_passRateBtn22,_passRateBtn23,_passRateBtn24,_passRateBtn25,
- _passRateBtn26,_passRateBtn27,_passRateBtn28,_passRateBtn29,_passRateBtn30,];
-
- NSArray *btnHeightArr = @[_passRateBtnHeight1,_passRateBtnHeight2,_passRateBtnHeight3,_passRateBtnHeight4,_passRateBtnHeight5,_passRateBtnHeight6,_passRateBtnHeight7,_passRateBtnHeight8,_passRateBtnHeight9,_passRateBtnHeight10,_passRateBtnHeight11,_passRateBtnHeight12,_passRateBtnHeight13,_passRateBtnHeight14,_passRateBtnHeight15,_passRateBtnHeight16,_passRateBtnHeight17,_passRateBtnHeight18,_passRateBtnHeight19,_passRateBtnHeight20,_passRateBtnHeight21,_passRateBtnHeight22,_passRateBtnHeight23,_passRateBtnHeight24,_passRateBtnHeight25,_passRateBtnHeight26,_passRateBtnHeight27,_passRateBtnHeight28,_passRateBtnHeight29,_passRateBtnHeight30];
-
- _probabilyView.layer.cornerRadius = RQ_FIT_HORIZONTAL(30.f) / 2.f;
- CGFloat space = (RQ_SCREEN_WIDTH - 64.f - 20.f - (4 * 30)) / 29.f;
- [self.bottomView addSubview:self.popupByAddTopSubview];
- [self.popupByAddTopSubview mas_makeConstraints:^(MASConstraintMaker *make) {
- @strongify(self)
- make.left.mas_equalTo(self.probabilyView.mas_left).mas_offset(10.f + (4.f * 26) + (space * 26) + 2.f - (RQ_FIT_HORIZONTAL(47.f) / 2.f));
- make.bottom.mas_equalTo(self.probabilyView.mas_top).mas_offset(- 8.f);
- make.size.mas_equalTo(CGSizeMake(RQ_FIT_HORIZONTAL(47.f), RQ_FIT_HORIZONTAL(26.f)));
- self.popupByAddTopSubview.sourceRect = CGRectMake(10.f + (4.f * 26) + 2.f + (space * 26) - (RQ_FIT_HORIZONTAL(47.f)),
- self.probabilyView.frame.origin.y - 8.f - RQ_FIT_HORIZONTAL(26.f), RQ_FIT_HORIZONTAL(47.f), RQ_FIT_HORIZONTAL(26.f));
- }];
-
- [self.bottomView addSubview:self.popupByAddBottomSubview];
- [self.popupByAddBottomSubview mas_makeConstraints:^(MASConstraintMaker *make) {
- @strongify(self)
- make.left.mas_equalTo(self.probabilyView.mas_left).mas_offset(10.f + (4.f * 5) + (space * 4) + 2.f);
- make.top.mas_equalTo(self.probabilyView.mas_bottom).mas_offset(8.f);
- make.size.mas_equalTo(CGSizeMake(RQ_FIT_HORIZONTAL(120.f), RQ_FIT_HORIZONTAL(39.f)));
- [self.popupByAddBottomSubview sizeThatFitsInContentView:CGSizeMake(RQ_FIT_HORIZONTAL(120.f), RQ_FIT_HORIZONTAL(39.f))];
- self.popupByAddBottomSubview.sourceRect = CGRectMake(16.f + 16.f + 10.f + (4.f * 5) + 2.f + (space * 4) - (RQ_FIT_HORIZONTAL(120.f) / 2.f), self.probabilyView.frame.origin.y + self.probabilyView.frame.size.height + 8.f, RQ_FIT_HORIZONTAL(120.f), RQ_FIT_HORIZONTAL(39.f));
- }];
-
- [[RQ_HTTP_Service getPassRateWithSubject:viewModel.homePageSubjectType carType:RQ_YDTQuestion_Module.carType] subscribeNext:^(NSString *str) {
- @strongify(self)
- if (RQStringIsNotEmpty(str)) {
- self.passRateLabel.text = [NSString stringWithFormat:@"%@%%",str];
- NSInteger c = str.integerValue;
- UIColor *bgColor = RQColorFromHexString(@"#FF4D53");
-
- if (c >= 0 && c <= 10) {
- self.popupByAddBottomSubview.textLabel.text = @"想啥呢?快开始学习吧!";
- _passRateBtn1.selected = YES;
- _bgImageView.image = RQImageNamed(@"0%10%背景");
- } else if (c > 10 && c <= 20) {
- self.popupByAddBottomSubview.textLabel.text = @"路遥知马力,加油!";
- _bgImageView.image = RQImageNamed(@"0%10%背景");
- } else if (c > 20 && c <= 30) {
- self.popupByAddBottomSubview.textLabel.text = @"征服畏惧,建立自信。";
- _bgImageView.image = RQImageNamed(@"20%30%背景");
- } else if (c > 30 && c <= 40) {
- self.popupByAddBottomSubview.textLabel.text = @"学习就像爬山,目的性强爬得就快。";
- _bgImageView.image = RQImageNamed(@"20%30%背景");
- } else if (c > 40 && c <= 50) {
- self.popupByAddBottomSubview.textLabel.text = @"快到半山腰了哦!";
- _bgImageView.image = RQImageNamed(@"20%30%背景");
- } else if (c > 50 && c <= 60) {
- self.popupByAddBottomSubview.textLabel.text = @"不错哦,五五开了呀。";
- _bgImageView.image = RQImageNamed(@"20%30%背景");
- } else if (c > 60 && c <= 70) {
- self.popupByAddBottomSubview.textLabel.text = @"努努力,希望很大!";
- _bgImageView.image = RQImageNamed(@"80%90%背景图");
- } else if (c > 70 && c <= 80) {
- self.popupByAddBottomSubview.textLabel.text = @"离成功不远了,加油!";
- _bgImageView.image = RQImageNamed(@"80%90%背景图");
- } else if (c > 80 && c <= 90) {
- self.popupByAddBottomSubview.textLabel.text = @"上升空间挺大,继线努力!";
- _bgImageView.image = RQImageNamed(@"80%90%背景图");
- } else if (c > 90 && c <= 100) {
- self.popupByAddBottomSubview.textLabel.text = @"十拿九稳了哦,还能审一审!";
- _bgImageView.image = RQImageNamed(@"80%90%背景图");
- }
- self.passRateDscLabel.text = [NSString stringWithFormat:@"考试预测通过率%@%%,%@",str,self.popupByAddBottomSubview.textLabel.text];
- NSInteger length = 10 + self.popupByAddBottomSubview.textLabel.text.length - [@"路遥知马力,加油!" length];
- [self.popupByAddBottomSubview mas_updateConstraints:^(MASConstraintMaker *make) {
- @strongify(self)
- make.size.mas_equalTo(CGSizeMake(RQ_FIT_HORIZONTAL(120.f), RQ_FIT_HORIZONTAL(39.f)));
- [self.popupByAddBottomSubview sizeThatFitsInContentView:CGSizeMake(RQ_FIT_HORIZONTAL(120.f) + length, RQ_FIT_HORIZONTAL(39.f))];
- self.popupByAddBottomSubview.sourceRect = CGRectMake(16.f + 16.f + 10.f + (4.f * 5) + 2.f + (space * 4) - ((RQ_FIT_HORIZONTAL(120.f) + length) / 2.f), self.probabilyView.frame.origin.y + self.probabilyView.frame.size.height + 8.f, RQ_FIT_HORIZONTAL(120.f) + length, RQ_FIT_HORIZONTAL(39.f));
- }];
- [[[btnArr.rac_sequence.signal deliverOnMainThread] filter:^BOOL(QMUIButton *btn) {
- return btn.tag * 3 <= c;
- }] subscribeNext:^(QMUIButton *btn) {
- NSLayoutConstraint *layoutConstraint = btnHeightArr[btn.tag - 1];
- layoutConstraint.constant = 22.f;
- btn.backgroundColor = bgColor;
- }];
- }
- }];
- }
- - (void)awakeFromNib {
- [super awakeFromNib];
- self.myHeadImageView.layer.cornerRadius = RQ_FIT_HORIZONTAL(45.f) / 2.f;
-
- }
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
- [super setSelected:selected animated:animated];
- // Configure the view for the selected state
- }
- #pragma mark - LazyLoad
- - (RQPodDownContainerView *)popupByAddTopSubview {
- if (!_popupByAddTopSubview) {
- _popupByAddTopSubview = [[RQPodDownContainerView alloc] init];
- }
- return _popupByAddTopSubview;
- }
- - (RQPopupContainerView *)popupByAddBottomSubview {
- if (!_popupByAddBottomSubview) {
- _popupByAddBottomSubview = [[RQPopupContainerView alloc] init];
- _popupByAddBottomSubview.preferLayoutDirection = QMUIPopupContainerViewLayoutDirectionBelow;
- _popupByAddBottomSubview.textLabel.text = @"路遥知马力,加油!";
- _popupByAddBottomSubview.textLabel.textAlignment = NSTextAlignmentCenter;
- _popupByAddBottomSubview.cornerRadius = 4.f;
- _popupByAddBottomSubview.textLabel.font = [UIFont systemFontOfSize:13];
- _popupByAddBottomSubview.textLabel.textColor = RQ_MAIN_TEXT_COLOR_1;
- _popupByAddBottomSubview.backgroundView = ({
- [[UIImageView alloc] initWithImage:[UIImage imageWithGradualChangingColor:^(QQGradualChangingColor *graColor) {
- graColor.fromColor = UIColorWhite;
- graColor.toColor = UIColorWhite;
- graColor.type = QQGradualChangeTypeLeftToRight;
- } size:CGSizeMake(RQ_FIT_HORIZONTAL(120.f), RQ_FIT_HORIZONTAL(39.f)) cornerRadius:QQRadiusMakeSame(0.f)]];
- });
- _popupByAddBottomSubview.arrowImage = [UIImageMake(@"popover_container_arrow") qmui_imageResizedInLimitedSize:CGSizeMake(RQ_FIT_HORIZONTAL(14.f), RQ_FIT_HORIZONTAL(8.f)) resizingMode:QMUIImageResizingModeScaleAspectFit];
- }
- return _popupByAddBottomSubview;
- }
- - (IBAction)toUpBtnAction:(id)sender {
- [RQ_VIP_Module gotoBuyVipWithVipPageType:RQVIPPageType_Full];
- }
- @end
|