RQExerciseExamToolBarCell.m 5.6 KB

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