12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- //
- // RQWrongAndCollectionViewModel.m
- // SDJK
- //
- // Created by 张嵘 on 2022/5/23.
- //
- #import "RQWrongAndCollectionViewModel.h"
- @interface RQWrongAndCollectionViewModel ()
- /// homePageCarType
- @property (nonatomic, readwrite, assign) RQHomePageCarType homePageCarType;
- /// homePageSubjectType
- @property (nonatomic, readwrite, assign) RQHomePageSubjectType homePageSubjectType;
- /// homeSubPageType
- @property (nonatomic, readwrite, assign) RQHomeSubPageType homeSubPageType;
- @end
- @implementation RQWrongAndCollectionViewModel
- #pragma mark - Public Method
- - (instancetype)initWithServices:(id<RQViewModelServices>)services params:(NSDictionary *)params{
- if (self = [super initWithServices:services params:params]) {
- self.homePageCarType = [params[RQHomePageCarTypeKey] integerValue];
- self.homePageSubjectType = [params[RQHomePageSubjectTypeKey] integerValue];
- self.homeSubPageType = [params[RQHomeSubPageTypeKey] integerValue];
- }
- return self;
- }
- - (void)initialize{
- [super initialize];
- self.title = @"做错题和收藏题";
- /// 配置数据
- [self rq_configureData];
- }
- #pragma mark - PrivateMethod
- - (void)rq_configureData {
- @weakify(self);
- /// 第零组
- RQCommonGroupViewModel *group0 = [RQCommonGroupViewModel groupViewModel];
-
- RQWrongAndCollectionItemViewModel *wrongItemViewModel = [[RQWrongAndCollectionItemViewModel alloc] initWithHomePageCarType:self.homePageCarType homePageSubjectType:self.homePageSubjectType homeSubPageType:self.homeSubPageType];
- wrongItemViewModel.title = @"做错题";
- RAC(wrongItemViewModel, subtitle) = [[RACObserve(RQ_SDJK_DB_MANAGER, wrongModelsCount) takeUntil:self.rac_willDeallocSignal] map:^id _Nullable(id _Nullable value) {
- return [NSString stringWithFormat:@"共 %ld 题", RQ_SDJK_DB_MANAGER.wrongModelsCount];
- }];
- wrongItemViewModel.icon = @"做错题背景";
- wrongItemViewModel.operation = ^{
- @strongify(self)
- RQExerciseViewModel *exerciseViewModel = [[RQExerciseViewModel alloc] initWithServices:self.services params:@{
- RQHomePageCarTypeKey : @(self.homePageCarType),
- RQHomePageSubjectTypeKey : @(self.homePageSubjectType),
- RQHomeSubPageTypeKey : @(self.homeSubPageType),
- RQViewModelIDKey : self.title,
- RQViewCommonValueKey : @(0),
- RQHomeSubEditListTypeKey : @(RQHomeSubEditListType_WrongTopic),
- }];
- dispatch_async_on_main_queue(^{
- [self.services pushViewModel:exerciseViewModel animated:YES];
- });
- };
-
- RQWrongAndCollectionItemViewModel *collectionItemViewModel = [[RQWrongAndCollectionItemViewModel alloc] initWithHomePageCarType:self.homePageCarType homePageSubjectType:self.homePageSubjectType homeSubPageType:self.homeSubPageType];
- collectionItemViewModel.title = @"收藏题";
- RAC(collectionItemViewModel, subtitle) = [[RACObserve(RQ_SDJK_DB_MANAGER, collectionModelsCount) takeUntil:self.rac_willDeallocSignal] map:^id _Nullable(id _Nullable value) {
- return [NSString stringWithFormat:@"共 %ld 题", RQ_SDJK_DB_MANAGER.collectionModelsCount];
- }];
- collectionItemViewModel.icon = @"收藏题背景";
- collectionItemViewModel.operation = ^{
- @strongify(self)
- RQExerciseViewModel *exerciseViewModel = [[RQExerciseViewModel alloc] initWithServices:self.services params:@{
- RQHomePageCarTypeKey : @(self.homePageCarType),
- RQHomePageSubjectTypeKey : @(self.homePageSubjectType),
- RQHomeSubPageTypeKey : @(self.homeSubPageType),
- RQViewModelIDKey : self.title,
- RQViewCommonValueKey : @(0),
- RQHomeSubEditListTypeKey : @(RQHomeSubEditListType_Collection),
- }];
- dispatch_async_on_main_queue(^{
- [self.services pushViewModel:exerciseViewModel animated:YES];
- });
- };
-
- // RQSynExerciseItemViewModel *synExerciseItemViewModel = [[RQSynExerciseItemViewModel alloc] init];
-
- group0.itemViewModels = @[wrongItemViewModel, collectionItemViewModel];
-
- self.dataSource = @[group0];
-
- [RQ_SDJK_DB_MANAGER refreshWrongAndCollectCount];
- }
- @end
|