RQExerciseToolBarCell.m 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. _viewModel = viewModel;
  24. RQCollectionModel *collectionModel = [[RQCollectionModel alloc] init];
  25. collectionModel.questionId = viewModel.exerciseModel._id;
  26. _collectBtn.selected = [RQ_SDJK_DB_MANAGER isExistWithRQCollectionModel:collectionModel];
  27. [_collectBtn setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
  28. if (!_collectBtn.selected) {
  29. [[RQ_HTTP_Service queryAddCollectionRecordWithQuestionId:viewModel.exerciseModel._id carType:viewModel.homePageCarType subject:viewModel.homePageSubjectType] subscribeNext:^(id _Nullable x) {
  30. [MBProgressHUD rq_showTips:@"收藏成功"];
  31. [RQ_SDJK_DB_MANAGER addCollectionRecordWithRQCollectionModel:collectionModel];
  32. _collectBtn.selected = [RQ_SDJK_DB_MANAGER isExistWithRQCollectionModel:collectionModel];
  33. NSLog(@"%@",x);
  34. } error:^(NSError * _Nullable error) {
  35. [MBProgressHUD rq_showErrorTips:error];
  36. }];
  37. } else {
  38. [[RQ_HTTP_Service queryCancleCollectionRecordWithQuestionIdArr:@[@(viewModel.exerciseModel._id)]] subscribeNext:^(id _Nullable x) {
  39. NSLog(@"%@" ,x);
  40. [MBProgressHUD rq_showTips:@"取消收藏成功"];
  41. [RQ_SDJK_DB_MANAGER deleteCollectionRecordWithQuestionId:collectionModel.questionId];
  42. _collectBtn.selected = [RQ_SDJK_DB_MANAGER isExistWithRQCollectionModel:collectionModel];
  43. } error:^(NSError * _Nullable error) {
  44. [MBProgressHUD rq_showErrorTips:error];
  45. }];
  46. }
  47. }];
  48. [_readingQuestionsAndAnswersBtn setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
  49. [viewModel.readingQuestionsAndAnswerCommand execute:nil];
  50. }];
  51. [_readingQuestionsBtn setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
  52. [RQ_MUSIC_MANAGER rq_resetStreamerWithURLString:viewModel.exerciseModel.issuemp3];
  53. }];
  54. [_skillExplanationBtn setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
  55. [viewModel.skillExplanationCommand execute:nil];
  56. }];
  57. }
  58. #pragma mark - SystemMethods
  59. - (void)awakeFromNib {
  60. [super awakeFromNib];
  61. // Initialization code
  62. }
  63. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  64. [super setSelected:selected animated:animated];
  65. // Configure the view for the selected state
  66. }
  67. @end