RQHomePageOneOrFourBigItemViewModel.m 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. //
  2. // RQHomePageOneOrFourBigItemViewModel.m
  3. // jiaPei
  4. //
  5. // Created by 张嵘 on 2022/6/10.
  6. // Copyright © 2022 JCZ. All rights reserved.
  7. //
  8. #import "RQHomePageOneOrFourBigItemViewModel.h"
  9. @interface RQHomePageOneOrFourBigItemViewModel ()
  10. @property (nonatomic, readwrite, assign) RQHomePageCarType homePageCarType;
  11. @property (nonatomic, readwrite, assign) RQHomePageSubjectType homePageSubjectType;
  12. @property (nonatomic, readwrite, copy) NSAttributedString *leftStr;
  13. @property (nonatomic, readwrite, copy) NSAttributedString *rightStr;
  14. @end
  15. @implementation RQHomePageOneOrFourBigItemViewModel
  16. /// init
  17. - (instancetype)initWithRQHomePageCarType:(RQHomePageCarType)homePageCarType homePageSubjectType:(RQHomePageSubjectType)homePageSubjectType homePageOneOrFourItemModel:(RQHomePageOneOrFourItemModel *)homePageOneOrFourItemModel {
  18. if (self = [super init]) {
  19. @weakify(self)
  20. self.homePageCarType = homePageCarType;
  21. self.homePageSubjectType = homePageSubjectType;
  22. CGFloat width = (RQ_SCREEN_WIDTH - (16 * 2) - 11) / 2.f;
  23. CGFloat height = width * (68.f / 167.f);
  24. self.itemSize = CGSizeMake(width, height);
  25. self.title = homePageOneOrFourItemModel.titleStr;
  26. self.icon = homePageOneOrFourItemModel.iconImgStr;
  27. if ([self.title isEqualToString:@"顺序练习"]) {
  28. RAC(self, rightStr) = [[RACSignal combineLatest:@[RACObserve(RQ_YDTQuestion_Module, subjectOneArr), RACObserve(RQ_YDTQuestion_Module, subjectFourArr)] reduce:^id (NSArray *subjectOneArr, NSArray *subjectFourArr) {
  29. @strongify(self)
  30. NSInteger allCount = [RQ_YDTQuestion_Module getQuestionNumWithWithSubject:self.homePageSubjectType exerciseType:RQExerciseType_Sequential];
  31. return [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"/%ld",allCount]];
  32. }] takeUntil:self.rac_willDeallocSignal];
  33. RAC(self, leftStr) = [[RACSignal combineLatest:@[RACObserve(RQ_YDTQuestion_Module, carType), [RACObserve(RQ_YDTQuestion_Module, subject) filter:^BOOL(id _Nullable value) {
  34. return (RQ_YDTQuestion_Module.subject == RQHomePageSubjectType_SubjectFour || RQ_YDTQuestion_Module.subject == RQHomePageSubjectType_SubjectOne);
  35. }], RACObserve(RQ_YDT_USER_Question_Module, doNum)] reduce:^id (NSNumber *carType, NSNumber *subject, NSNumber *doNum) {
  36. NSArray *readList = [NYTools readExerciseListUserKey:RQ_USER_MANAGER.currentUser.outId carType:RQ_YDTQuestion_Module.carType subject:RQ_YDTQuestion_Module.subject exerciseType:RQ_Exercise_Module.currentExerciseType];
  37. return [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%ld",readList.count]];
  38. }] takeUntil:self.rac_willDeallocSignal];
  39. self.operation = ^{
  40. @strongify(self)
  41. // NSMutableArray *oneArr = [[NSMutableArray alloc] init];
  42. // NSMutableArray *fourArr = [NSMutableArray array];
  43. // [oneArr addObjectsFromArray:RQ_YDTQuestion_Module.subjectOneArr];
  44. // [fourArr addObjectsFromArray:RQ_YDTQuestion_Module.subjectFourArr];
  45. NSArray *arr = [[RQ_YDTQuestion_Module getQuestionWithSubject:RQ_YDTQuestion_Module.subject exerciseType:RQExerciseType_Sequential ].rac_sequence.signal map:^id _Nullable(RQYDTQuestionModel *ydtQuestionModel) {
  46. return [RQExerciseModel exerciseModelWithRQYDTQuestionModel:ydtQuestionModel];
  47. }].toArray;
  48. // NSArray *arr = (self.homePageSubjectType == RQHomePageSubjectType_SubjectFour)? fourArr.copy : oneArr.copy;
  49. // arr = [arr.rac_sequence.signal map:^id _Nullable(RQYDTQuestionModel *ydtQuestionModel) {
  50. // return [RQExerciseModel exerciseModelWithRQYDTQuestionModel:ydtQuestionModel];
  51. // }].toArray;
  52. RQExerciseViewModel *exerciseViewModel = [[RQExerciseViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{
  53. RQHomePageCarTypeKey : @(self.homePageCarType),
  54. RQHomePageSubjectTypeKey : @(self.homePageSubjectType),
  55. RQHomeSubPageTypeKey : @(RQHomeSubPageType_SequentialPractice),
  56. RQViewModelIDKey : self.title,
  57. RQExerciseTypeKey : @(RQExerciseType_Sequential),
  58. RQViewModelUtilKey : arr,
  59. }];
  60. [RQ_APPDELEGATE.services pushViewModel:exerciseViewModel animated:YES];
  61. };
  62. } else if (([self.title isEqualToString:@"模拟考试"])) {
  63. NSString *score = [NSString stringWithFormat:@"%@",@"0"];
  64. NSString *fen = [NSString stringWithFormat:@"分"];
  65. NSString *myScore = [NSString stringWithFormat:@"%@%@",score,fen];
  66. NSMutableAttributedString *myScoreAttrStr = [[NSMutableAttributedString alloc] initWithString:myScore];
  67. [myScoreAttrStr addAttribute:NSFontAttributeName value:RQSemiboldFont(34) range:[myScore rangeOfString:score]];
  68. [myScoreAttrStr addAttribute:NSFontAttributeName value:RQRegularFont_15 range:[myScore rangeOfString:fen]];
  69. self.leftStr = myScoreAttrStr;
  70. self.rightStr = [[NSMutableAttributedString alloc] initWithString:[self.leftStr.string isEqualToString:@"0分"]? @"最高分" : @"最高分"];
  71. RAC(self, leftStr) = [[RACSignal combineLatest:@[RACObserve(RQ_COMMON_MANAGER, examResultOneListArr), RACObserve(RQ_COMMON_MANAGER, examResultFourListArr)] reduce:^id (NSArray *examResultOneListArr, NSArray *examResultFourListArr) {
  72. @strongify(self)
  73. NSArray *arr;
  74. if (self.homePageSubjectType == RQHomePageSubjectType_SubjectOne) {
  75. arr = examResultOneListArr;
  76. }
  77. if (self.homePageSubjectType == RQHomePageSubjectType_SubjectFour) {
  78. arr = examResultFourListArr;
  79. }
  80. float max = [[[arr.rac_sequence.signal map:^id _Nullable(RQExamResultModel *examResultModel) {
  81. return examResultModel.score;
  82. }].toArray valueForKeyPath:@"@max.floatValue"] floatValue];
  83. NSString *score = [NSString qmui_stringWithCGFloat:max decimal:0];
  84. NSString *fen = [NSString stringWithFormat:@"分"];
  85. NSString *myScore = [NSString stringWithFormat:@"%@%@",score,fen];
  86. NSMutableAttributedString *myScoreAttrStr = [[NSMutableAttributedString alloc] initWithString:myScore];
  87. [myScoreAttrStr addAttribute:NSFontAttributeName value:RQSemiboldFont(34) range:[myScore rangeOfString:score]];
  88. [myScoreAttrStr addAttribute:NSFontAttributeName value:RQRegularFont_15 range:[myScore rangeOfString:fen]];
  89. self.rightStr = [[NSMutableAttributedString alloc] initWithString:[myScoreAttrStr.string isEqualToString:@"0分"]? @"最高分" : @"最高分"];
  90. return myScoreAttrStr;
  91. }] takeUntil:self.rac_willDeallocSignal];
  92. self.operation = ^{
  93. if (RQ_USER_MANAGER.isShouldLogin) {
  94. RQSimulateExamViewModel *viewModel = [[RQSimulateExamViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{}];
  95. [RQ_APPDELEGATE.services pushViewModel:viewModel animated:YES];
  96. }
  97. };
  98. }
  99. }
  100. return self;
  101. }
  102. @end