RQExerciseToolBarCell.m 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. //
  2. // RQExerciseToolBarCell.m
  3. // SDJK
  4. //
  5. // Created by 张嵘 on 2021/8/16.
  6. //
  7. #import "RQExerciseToolBarCell.h"
  8. @interface RQExerciseToolBarCell ()
  9. @property (nonatomic, readwrite, strong) RQExerciseToolBarItemViewModel *viewModel;
  10. @end
  11. @implementation RQExerciseToolBarCell
  12. #pragma mark - PublicMethods
  13. + (instancetype)cellWithTableView:(UITableView *)tableView {
  14. static NSString *ID = @"RQExerciseToolBarCell";
  15. RQExerciseToolBarCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
  16. if (!cell) {
  17. cell = [self rq_viewFromXib];
  18. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  19. }
  20. return cell;
  21. }
  22. - (void)bindViewModel:(RQExerciseToolBarItemViewModel *)viewModel {
  23. @weakify(self)
  24. _viewModel = viewModel;
  25. RQCollectionModel *collectionModel = [[RQCollectionModel alloc] init];
  26. collectionModel.questionId = viewModel.exerciseModel._id==0?viewModel.exerciseModel.idYdt:viewModel.exerciseModel._id;
  27. collectionModel.km = RQ_COMMON_MANAGER.subjectStr;
  28. collectionModel.createTime = [NSDate rq_currentTimeSSSInterval];
  29. collectionModel.userId = RQ_USER_MANAGER.currentUserId;
  30. _collectBtn.selected = [RQ_SDJK_DB_MANAGER isExistWithRQCollectionModel:collectionModel];
  31. [_collectBtn setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
  32. if (!_collectBtn.selected) {
  33. // [[RQ_HTTP_Service queryAddCollectionRecordWithQuestionId:viewModel.exerciseModel._id carType:viewModel.homePageCarType subject:viewModel.homePageSubjectType] subscribeNext:^(id _Nullable x) {
  34. // [MBProgressHUD rq_showTips:@"收藏成功"];
  35. // [RQ_SDJK_DB_MANAGER addCollectionRecordWithRQCollectionModel:collectionModel];
  36. // _collectBtn.selected = [RQ_SDJK_DB_MANAGER isExistWithRQCollectionModel:collectionModel];
  37. // [RQ_SDJK_DB_MANAGER getAllCollectionModelsCount];
  38. // NSLog(@"%@",x);
  39. // } error:^(NSError * _Nullable error) {
  40. // [MBProgressHUD rq_showErrorTips:error];
  41. // }];
  42. [RQ_SDJK_DB_MANAGER addCollectionRecordWithRQCollectionModel:collectionModel];
  43. if ([RQ_SDJK_DB_MANAGER isExistWithRQCollectionModel:collectionModel]) {
  44. self.collectBtn.selected = YES;
  45. [QMUITips showSucceed:@"收藏成功"];
  46. [RQ_SDJK_DB_MANAGER getAllCollectionModelsCount];
  47. // [RQNotificationCenter postNotificationName:RQAddCollectNotification object:nil userInfo:@{RQAddCollectExerciseModelKey:self.viewModel.exerciseModel}];
  48. } else {
  49. [QMUITips showError:@"收藏失败"];
  50. }
  51. } else {
  52. // [[RQ_HTTP_Service queryCancleCollectionRecordWithQuestionIdArr:@[@(viewModel.exerciseModel._id)]] subscribeNext:^(id _Nullable x) {
  53. // NSLog(@"%@" ,x);
  54. // [MBProgressHUD rq_showTips:@"取消收藏成功"];
  55. // [RQ_SDJK_DB_MANAGER deleteCollectionRecordWithQuestionId:collectionModel.questionId];
  56. // _collectBtn.selected = [RQ_SDJK_DB_MANAGER isExistWithRQCollectionModel:collectionModel];
  57. // [RQ_SDJK_DB_MANAGER getAllCollectionModelsCount];
  58. // [RQNotificationCenter postNotificationName:RQCancelCollectNotification object:nil userInfo:@{RQCancelCollectExerciseModelKey:viewModel.exerciseModel}];
  59. // } error:^(NSError * _Nullable error) {
  60. // [MBProgressHUD rq_showErrorTips:error];
  61. // }];
  62. [RQ_SDJK_DB_MANAGER deleteCollectionRecordWithQuestionId:collectionModel.questionId];
  63. if (![RQ_SDJK_DB_MANAGER isExistWithRQCollectionModel:collectionModel]) {
  64. self.collectBtn.selected = NO;
  65. [QMUITips showSucceed:@"取消收藏成功"];
  66. [RQ_SDJK_DB_MANAGER getAllCollectionModelsCount];
  67. [RQNotificationCenter postNotificationName:RQCancelCollectNotification object:nil userInfo:@{RQCancelCollectExerciseModelKey:self.viewModel.exerciseModel}];
  68. } else {
  69. [QMUITips showError:@"取消收藏失败"];
  70. }
  71. }
  72. }];
  73. [_readingQuestionsAndAnswersBtn setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
  74. [viewModel.readingQuestionsAndAnswerCommand execute:nil];
  75. }];
  76. [_readingQuestionsBtn setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
  77. // [RQ_VOICE_MANAGER playString:viewModel.exerciseModel.issue];
  78. [RQ_MUSIC_MANAGER rq_resetStreamerWithURLString:viewModel.exerciseModel.issuemp3];
  79. }];
  80. [_skillExplanationBtn setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
  81. [viewModel.skillExplanationCommand execute:nil];
  82. }];
  83. }
  84. #pragma mark - SystemMethods
  85. - (void)awakeFromNib {
  86. [super awakeFromNib];
  87. // Initialization code
  88. }
  89. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  90. [super setSelected:selected animated:animated];
  91. // Configure the view for the selected state
  92. }
  93. @end