// // RQExerciseToolBarCell.m // SDJK // // Created by 张嵘 on 2021/8/16. // #import "RQExerciseToolBarCell.h" @interface RQExerciseToolBarCell () @property (nonatomic, readwrite, strong) RQExerciseToolBarItemViewModel *viewModel; @end @implementation RQExerciseToolBarCell #pragma mark - PublicMethods + (instancetype)cellWithTableView:(UITableView *)tableView { static NSString *ID = @"RQExerciseToolBarCell"; RQExerciseToolBarCell *cell = [tableView dequeueReusableCellWithIdentifier:ID]; if (!cell) { cell = [self rq_viewFromXib]; cell.selectionStyle = UITableViewCellSelectionStyleNone; } return cell; } - (void)bindViewModel:(RQExerciseToolBarItemViewModel *)viewModel { @weakify(self) _viewModel = viewModel; RQCollectionModel *collectionModel = [[RQCollectionModel alloc] init]; collectionModel.questionId = viewModel.exerciseModel._id==0?viewModel.exerciseModel.idYdt:viewModel.exerciseModel._id; collectionModel.km = RQ_COMMON_MANAGER.subjectStr; collectionModel.createTime = [NSDate rq_currentTimeSSSInterval]; collectionModel.userId = RQ_USER_MANAGER.currentUserId; _collectBtn.selected = [RQ_SDJK_DB_MANAGER isExistWithRQCollectionModel:collectionModel]; [_collectBtn setTapActionWithBlock:^(UITapGestureRecognizer *tap) { if (!_collectBtn.selected) { // [[RQ_HTTP_Service queryAddCollectionRecordWithQuestionId:viewModel.exerciseModel._id carType:viewModel.homePageCarType subject:viewModel.homePageSubjectType] subscribeNext:^(id _Nullable x) { // [MBProgressHUD rq_showTips:@"收藏成功"]; // [RQ_SDJK_DB_MANAGER addCollectionRecordWithRQCollectionModel:collectionModel]; // _collectBtn.selected = [RQ_SDJK_DB_MANAGER isExistWithRQCollectionModel:collectionModel]; // [RQ_SDJK_DB_MANAGER getAllCollectionModelsCount]; // NSLog(@"%@",x); // } error:^(NSError * _Nullable error) { // [MBProgressHUD rq_showErrorTips:error]; // }]; [RQ_SDJK_DB_MANAGER addCollectionRecordWithRQCollectionModel:collectionModel]; if ([RQ_SDJK_DB_MANAGER isExistWithRQCollectionModel:collectionModel]) { self.collectBtn.selected = YES; [QMUITips showSucceed:@"收藏成功"]; [RQ_SDJK_DB_MANAGER getAllCollectionModelsCount]; // [RQNotificationCenter postNotificationName:RQAddCollectNotification object:nil userInfo:@{RQAddCollectExerciseModelKey:self.viewModel.exerciseModel}]; } else { [QMUITips showError:@"收藏失败"]; } } else { // [[RQ_HTTP_Service queryCancleCollectionRecordWithQuestionIdArr:@[@(viewModel.exerciseModel._id)]] subscribeNext:^(id _Nullable x) { // NSLog(@"%@" ,x); // [MBProgressHUD rq_showTips:@"取消收藏成功"]; // [RQ_SDJK_DB_MANAGER deleteCollectionRecordWithQuestionId:collectionModel.questionId]; // _collectBtn.selected = [RQ_SDJK_DB_MANAGER isExistWithRQCollectionModel:collectionModel]; // [RQ_SDJK_DB_MANAGER getAllCollectionModelsCount]; // [RQNotificationCenter postNotificationName:RQCancelCollectNotification object:nil userInfo:@{RQCancelCollectExerciseModelKey:viewModel.exerciseModel}]; // } error:^(NSError * _Nullable error) { // [MBProgressHUD rq_showErrorTips:error]; // }]; [RQ_SDJK_DB_MANAGER deleteCollectionRecordWithQuestionId:collectionModel.questionId]; if (![RQ_SDJK_DB_MANAGER isExistWithRQCollectionModel:collectionModel]) { self.collectBtn.selected = NO; [QMUITips showSucceed:@"取消收藏成功"]; [RQ_SDJK_DB_MANAGER getAllCollectionModelsCount]; [RQNotificationCenter postNotificationName:RQCancelCollectNotification object:nil userInfo:@{RQCancelCollectExerciseModelKey:self.viewModel.exerciseModel}]; } else { [QMUITips showError:@"取消收藏失败"]; } } }]; [_readingQuestionsAndAnswersBtn setTapActionWithBlock:^(UITapGestureRecognizer *tap) { [viewModel.readingQuestionsAndAnswerCommand execute:nil]; }]; [_readingQuestionsBtn setTapActionWithBlock:^(UITapGestureRecognizer *tap) { // [RQ_VOICE_MANAGER playString:viewModel.exerciseModel.issue]; [RQ_MUSIC_MANAGER rq_resetStreamerWithURLString:viewModel.exerciseModel.issuemp3]; }]; [_skillExplanationBtn setTapActionWithBlock:^(UITapGestureRecognizer *tap) { [viewModel.skillExplanationCommand execute:nil]; }]; } #pragma mark - SystemMethods - (void)awakeFromNib { [super awakeFromNib]; // Initialization code } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } @end