RQWrongAndCollectionViewModel.m 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //
  2. // RQWrongAndCollectionViewModel.m
  3. // SDJK
  4. //
  5. // Created by 张嵘 on 2022/5/23.
  6. //
  7. #import "RQWrongAndCollectionViewModel.h"
  8. @interface RQWrongAndCollectionViewModel ()
  9. /// homePageCarType
  10. @property (nonatomic, readwrite, assign) RQHomePageCarType homePageCarType;
  11. /// homePageSubjectType
  12. @property (nonatomic, readwrite, assign) RQHomePageSubjectType homePageSubjectType;
  13. /// homeSubPageType
  14. @property (nonatomic, readwrite, assign) RQHomeSubPageType homeSubPageType;
  15. @end
  16. @implementation RQWrongAndCollectionViewModel
  17. #pragma mark - Public Method
  18. - (instancetype)initWithServices:(id<RQViewModelServices>)services params:(NSDictionary *)params{
  19. if (self = [super initWithServices:services params:params]) {
  20. self.homePageCarType = [params[RQHomePageCarTypeKey] integerValue];
  21. self.homePageSubjectType = [params[RQHomePageSubjectTypeKey] integerValue];
  22. self.homeSubPageType = [params[RQHomeSubPageTypeKey] integerValue];
  23. }
  24. return self;
  25. }
  26. - (void)initialize{
  27. [super initialize];
  28. self.title = @"做错题和收藏题";
  29. /// 配置数据
  30. [self rq_configureData];
  31. }
  32. #pragma mark - PrivateMethod
  33. - (void)rq_configureData {
  34. @weakify(self);
  35. /// 第零组
  36. RQCommonGroupViewModel *group0 = [RQCommonGroupViewModel groupViewModel];
  37. RQWrongAndCollectionItemViewModel *wrongItemViewModel = [[RQWrongAndCollectionItemViewModel alloc] initWithHomePageCarType:self.homePageCarType homePageSubjectType:self.homePageSubjectType homeSubPageType:self.homeSubPageType];
  38. wrongItemViewModel.title = @"做错题";
  39. RAC(wrongItemViewModel, subtitle) = [[RACObserve(RQ_SDJK_DB_MANAGER, wrongModelsCount) takeUntil:self.rac_willDeallocSignal] map:^id _Nullable(id _Nullable value) {
  40. return [NSString stringWithFormat:@"共 %ld 题", RQ_SDJK_DB_MANAGER.wrongModelsCount];
  41. }];
  42. wrongItemViewModel.icon = @"做错题背景";
  43. wrongItemViewModel.operation = ^{
  44. @strongify(self)
  45. RQExerciseViewModel *exerciseViewModel = [[RQExerciseViewModel alloc] initWithServices:self.services params:@{
  46. RQHomePageCarTypeKey : @(self.homePageCarType),
  47. RQHomePageSubjectTypeKey : @(self.homePageSubjectType),
  48. RQHomeSubPageTypeKey : @(self.homeSubPageType),
  49. RQViewModelIDKey : self.title,
  50. RQViewCommonValueKey : @(0),
  51. RQHomeSubEditListTypeKey : @(RQHomeSubEditListType_WrongTopic),
  52. }];
  53. dispatch_async_on_main_queue(^{
  54. [self.services pushViewModel:exerciseViewModel animated:YES];
  55. });
  56. };
  57. RQWrongAndCollectionItemViewModel *collectionItemViewModel = [[RQWrongAndCollectionItemViewModel alloc] initWithHomePageCarType:self.homePageCarType homePageSubjectType:self.homePageSubjectType homeSubPageType:self.homeSubPageType];
  58. collectionItemViewModel.title = @"收藏题";
  59. RAC(collectionItemViewModel, subtitle) = [[RACObserve(RQ_SDJK_DB_MANAGER, collectionModelsCount) takeUntil:self.rac_willDeallocSignal] map:^id _Nullable(id _Nullable value) {
  60. return [NSString stringWithFormat:@"共 %ld 题", RQ_SDJK_DB_MANAGER.collectionModelsCount];
  61. }];
  62. collectionItemViewModel.icon = @"收藏题背景";
  63. collectionItemViewModel.operation = ^{
  64. @strongify(self)
  65. RQExerciseViewModel *exerciseViewModel = [[RQExerciseViewModel alloc] initWithServices:self.services params:@{
  66. RQHomePageCarTypeKey : @(self.homePageCarType),
  67. RQHomePageSubjectTypeKey : @(self.homePageSubjectType),
  68. RQHomeSubPageTypeKey : @(self.homeSubPageType),
  69. RQViewModelIDKey : self.title,
  70. RQViewCommonValueKey : @(0),
  71. RQHomeSubEditListTypeKey : @(RQHomeSubEditListType_Collection),
  72. }];
  73. dispatch_async_on_main_queue(^{
  74. [self.services pushViewModel:exerciseViewModel animated:YES];
  75. });
  76. };
  77. // RQSynExerciseItemViewModel *synExerciseItemViewModel = [[RQSynExerciseItemViewModel alloc] init];
  78. group0.itemViewModels = @[wrongItemViewModel, collectionItemViewModel];
  79. self.dataSource = @[group0];
  80. [RQ_SDJK_DB_MANAGER refreshWrongAndCollectCount];
  81. }
  82. @end