RQExerciseModule.m 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. //
  2. // RQExerciseModule.m
  3. // SDJK
  4. //
  5. // Created by 张嵘 on 2021/8/12.
  6. //
  7. #import "RQExerciseModule.h"
  8. /// 刷新TableView
  9. NSString * const RQRefreshExerciseTableViewNotification = @"RQRefreshExerciseTableViewNotification";
  10. /// 答题结果
  11. NSString * const RQAnswerResultsNotification = @"RQAnswerResultsNotification";
  12. /// 答题页面更新
  13. NSString * const RQQuestionReloadNotification = @"RQQuestionReloadNotification";
  14. /// 答题结果 key
  15. NSString * const RQAnswerResultsKey = @"RQAnswerResultsKey";
  16. /// 练习模式Key
  17. NSString * const RQExerciseTypeKey = @"RQExerciseTypeKey";
  18. /// 页面操作类型Key
  19. NSString * const RQExerciseDoTypeKey = @"RQExerciseDoTypeKey";
  20. /// 答题页面更新ExerciseModelKey
  21. NSString * const RQQuestionReloadExerciseModelKey = @"RQQuestionReloadExerciseModelKey";
  22. /// 收藏成功通知
  23. NSString * const RQAddCollectNotification = @"RQAddCollectNotification";
  24. /// 取消收藏成功通知
  25. NSString * const RQCancelCollectNotification = @"RQCancelCollectNotification";
  26. /// 取消收藏题目Key
  27. NSString * const RQCancelCollectExerciseModelKey = @"RQCancelCollectExerciseModelKey";
  28. @interface RQExerciseModule ()
  29. @property (nonatomic, readwrite, strong) SCLAlertView *alert;
  30. @property (nonatomic, readwrite, strong) UITextView *messageTextView;
  31. @property (nonatomic, readwrite, strong) SCLButton *rePlayButton;
  32. @property (nonatomic, readwrite, strong) SCLButton *closeButton;
  33. @property (nonatomic, readwrite, assign) BOOL isShow;
  34. @end
  35. @implementation RQExerciseModule
  36. static id rq_RQExerciseModule = nil;
  37. #pragma mark - init
  38. + (instancetype)sharedInstance {
  39. static dispatch_once_t onceToken;
  40. dispatch_once(&onceToken, ^{
  41. rq_RQExerciseModule = [[self alloc] init];
  42. });
  43. return rq_RQExerciseModule;
  44. }
  45. - (instancetype)init {
  46. if (self = [super init]) {
  47. self.exerciseDoType = RQExerciseDoType_Default;
  48. self.isRightAutoJumpToNext = [RQ_SDJK_DB_MANAGER getRightAutoJumpToNext];
  49. self.isExerciseSound = [RQ_SDJK_DB_MANAGER getExerciseSound];
  50. self.exerciseFontSize = [RQ_SDJK_DB_MANAGER getExerciseFontSize];
  51. }
  52. return self;
  53. }
  54. #pragma mark - PublicMethods
  55. - (void)rq_RACIsAutoRead {
  56. [[[RACSignal combineLatest:@[RACObserve(RQ_Exercise_Module, isAutoRead),RACObserve(RQ_Exercise_Module, currrentExerciseModel)] reduce:^(id isAutoRead, RQExerciseModel *exerciseModel){
  57. if (RQ_Exercise_Module.isAutoRead && !exerciseModel.isAuto) {
  58. return exerciseModel;
  59. } else if (RQ_Exercise_Module.isAutoRead && exerciseModel.isAuto) {
  60. [RQ_MUSIC_MANAGER rq_cancelStreamer];
  61. [RQNotificationCenter postNotificationName:RQQuestionReloadNotification object:@{RQQuestionReloadExerciseModelKey : exerciseModel}];
  62. RQExerciseModel *exerciseModel = nil;
  63. return exerciseModel;
  64. } else {
  65. exerciseModel.isAuto = NO;
  66. RQExerciseModel *exerciseModel = nil;
  67. return exerciseModel;
  68. }
  69. }] deliverOnMainThread] subscribeNext:^(RQExerciseModel *exerciseModel) {
  70. if (exerciseModel) {
  71. exerciseModel.isAuto = YES;
  72. NSLog(@"1.读题目---%@---%@",exerciseModel.issue,exerciseModel.issuemp3);
  73. [RQ_MUSIC_MANAGER rq_resetStreamerWithURLString:exerciseModel.issuemp3 DOUAudioStreamerStatusBlock:^(DOUAudioStreamerStatus status) {
  74. if (status == DOUAudioStreamerFinished) {
  75. NSLog(@"2.读技巧---%@---%@",exerciseModel.issue,exerciseModel.explain_mp3);
  76. [RQ_Exercise_Module rq_showSkillExplanationAlertWithMessage:exerciseModel.explain_jq skillkeyword:exerciseModel.skillkeyword explainGifUrl:exerciseModel.explain_gif mp3Url:exerciseModel.explain_mp3 completeBlock:^{
  77. NSLog(@"3.结束---自动读题模式下: 当前题目正在自动读题 即将自动跳到下一题");
  78. exerciseModel.isShowSkillExplanation = YES;
  79. exerciseModel.isAuto = NO;
  80. // self.currrentExerciseModel = exerciseModel;
  81. [RQNotificationCenter postNotificationName:RQQuestionReloadNotification object:@{RQQuestionReloadExerciseModelKey : exerciseModel}];
  82. }];
  83. exerciseModel.userAnswer = exerciseModel.answer;
  84. // self.currrentExerciseModel = exerciseModel;
  85. [RQNotificationCenter postNotificationName:RQQuestionReloadNotification object:@{RQQuestionReloadExerciseModelKey : exerciseModel}];
  86. }
  87. }];
  88. }
  89. }];
  90. // [[RACObserve(RQ_Exercise_Module, isAutoRead) takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id _Nullable x) {
  91. // if (RQ_Exercise_Module.isAutoRead) {
  92. // self.currrentExerciseModel.isAuto = YES;
  93. // NSLog(@"1.读题目---%@---%@",self.currrentExerciseModel.issue,self.currrentExerciseModel.issuemp3);
  94. // [RQ_MUSIC_MANAGER rq_resetStreamerWithURLString:self.currrentExerciseModel.issuemp3 DOUAudioStreamerStatusBlock:^(DOUAudioStreamerStatus status) {
  95. // if (status == DOUAudioStreamerFinished) {
  96. // NSLog(@"2.读技巧---%@---%@",self.currrentExerciseModel.issue,self.currrentExerciseModel.explain_mp3);
  97. // [RQ_Exercise_Module rq_showSkillExplanationAlertWithMessage:self.currrentExerciseModel.explain_jq skillkeyword:self.currrentExerciseModel.skillkeyword explainGifUrl:self.currrentExerciseModel.explain_gif mp3Url:self.currrentExerciseModel.explain_mp3 completeBlock:^{
  98. // NSLog(@"3.结束---%@\r\n -%@\r\n -%@\r\n -%@\r\n -%@",self.currrentExerciseModel.issue,self.currrentExerciseModel.issuemp3,self.currrentExerciseModel.answermp3,self.currrentExerciseModel.explain_mp3,self.currrentExerciseModel.explainjsmp3);
  99. // self.currrentExerciseModel.isShowSkillExplanation = YES;
  100. // self.currrentExerciseModel.isAuto = NO;
  101. // self.currrentExerciseModel = self.currrentExerciseModel;
  102. // [RQNotificationCenter postNotificationName:RQQuestionReloadNotification object:nil];
  103. // }];
  104. // self.currrentExerciseModel.userAnswer = self.currrentExerciseModel.answer;
  105. // self.currrentExerciseModel = self.currrentExerciseModel;
  106. // [RQNotificationCenter postNotificationName:RQQuestionReloadNotification object:nil];
  107. // }
  108. // }];
  109. // } else {
  110. // [RQ_MUSIC_MANAGER rq_cancelStreamer];
  111. // [RQNotificationCenter postNotificationName:RQQuestionReloadNotification object:nil];
  112. // }
  113. // }];
  114. }
  115. - (void)cancleAutoReadQuestion {
  116. [RQ_MUSIC_MANAGER rq_cancelStreamer];
  117. RQ_Exercise_Module.isAutoRead = NO;
  118. }
  119. - (void)rq_showOfficialInterpretationAlertWithMessage:(NSString *)messageStr mp3Url:(NSString *)mp3Url {
  120. SCLAlertView *alert = [[SCLAlertView alloc] initWithNewWindowWidth:RQ_SCREEN_WIDTH - 80.f];
  121. @weakify(alert)
  122. CGFloat viewTextWideth = RQ_SCREEN_WIDTH - (20 * 2) - (40 * 2);
  123. CGFloat textHeight = [messageStr heightForFont:[UIFont systemFontOfSize:16] width:viewTextWideth] > RQ_SCREEN_HEIGHT / 2.f? RQ_SCREEN_HEIGHT / 2.f : [messageStr heightForFont:[UIFont systemFontOfSize:16] width:viewTextWideth];
  124. [alert removeTopCircle];
  125. alert.tintTopCircle = NO;
  126. alert.useLargerIcon = NO;
  127. alert.iconTintColor = RQ_MAIN_COLOR;
  128. alert.cornerRadius = 10;
  129. alert.labelTitle.textColor = RQ_MAIN_TEXT_COLOR_1;
  130. alert.labelTitle.font = [UIFont boldSystemFontOfSize:20];
  131. [alert.labelTitle mas_makeConstraints:^(MASConstraintMaker *make) {
  132. make.top.mas_offset(20);
  133. make.centerX.mas_offset(0);
  134. make.size.mas_equalTo(CGSizeMake(viewTextWideth, 21.f));
  135. }];
  136. UITextView *messageTextView = [[UITextView alloc] initWithFrame:CGRectMake(20, alert.labelTitle.rq_y + alert.labelTitle.rq_height, viewTextWideth, textHeight)];
  137. messageTextView.font = [UIFont systemFontOfSize:self.exerciseFontSize];
  138. messageTextView.editable = NO;
  139. messageTextView.textColor = RQ_MAIN_TEXT_COLOR_3;
  140. messageTextView.textAlignment = NSTextAlignmentLeft;
  141. messageTextView.text = messageStr;
  142. [alert addCustomView:messageTextView];
  143. [messageTextView mas_makeConstraints:^(MASConstraintMaker *make) {
  144. make.top.mas_equalTo(alert.labelTitle.mas_bottom).mas_offset(20);
  145. make.centerX.mas_offset(0);
  146. make.size.mas_equalTo(CGSizeMake(viewTextWideth, textHeight)).priority(500);
  147. }];
  148. SCLButton *closeButton = [alert addButton:@"关闭" actionBlock:^{
  149. @strongify(alert);
  150. [alert hideView];
  151. [RQ_MUSIC_MANAGER rq_cancelStreamer];
  152. }];
  153. closeButton.buttonFormatBlock = ^NSDictionary* (void) {
  154. NSMutableDictionary *buttonConfig = [[NSMutableDictionary alloc] init];
  155. buttonConfig[@"cornerRadius"] = @"20.f";
  156. buttonConfig[@"backgroundColor"] = RQ_MAIN_BACKGROUNDCOLOR;
  157. buttonConfig[@"textColor"] = RQ_MAIN_TEXT_COLOR_3;
  158. buttonConfig[@"borderWidth"] = @1.0f;
  159. buttonConfig[@"borderColor"] = RQ_MAIN_TEXT_COLOR_3;
  160. buttonConfig[@"font"] = [UIFont systemFontOfSize:16];
  161. return buttonConfig;
  162. };
  163. [closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
  164. make.top.mas_equalTo(messageTextView.mas_bottom).mas_offset(20);
  165. make.left.mas_equalTo(messageTextView.mas_left);
  166. make.bottom.mas_offset(-20);
  167. make.size.mas_equalTo(CGSizeMake((viewTextWideth - 16) / 2.f, 40.f));
  168. }];
  169. SCLButton *rePlayButton = [alert addButton:@"语音重播" validationBlock:^BOOL{
  170. [RQ_MUSIC_MANAGER rq_resetStreamerWithURLString:mp3Url];
  171. return NO;
  172. } actionBlock:nil];
  173. rePlayButton.buttonFormatBlock = ^NSDictionary* (void) {
  174. NSMutableDictionary *buttonConfig = [[NSMutableDictionary alloc] init];
  175. buttonConfig[@"cornerRadius"] = @"20.f";
  176. buttonConfig[@"backgroundColor"] = RQ_MAIN_COLOR;
  177. buttonConfig[@"textColor"] = RQ_MAIN_TEXT_COLOR_WHITE;
  178. buttonConfig[@"font"] = [UIFont systemFontOfSize:16];
  179. return buttonConfig;
  180. };
  181. [rePlayButton mas_makeConstraints:^(MASConstraintMaker *make) {
  182. make.right.mas_equalTo(messageTextView.mas_right);
  183. make.bottom.mas_offset(-20);
  184. make.size.mas_equalTo(CGSizeMake((viewTextWideth - 16) / 2.f, 40.f));
  185. }];
  186. alert.horizontalButtons = YES;
  187. alert.showAnimationType = SCLAlertViewShowAnimationFadeIn;
  188. [alert showTitle:@"官方解释" subTitle:nil style:SCLAlertViewStyleCustom closeButtonTitle:nil duration:0.f];
  189. [RQ_MUSIC_MANAGER rq_resetStreamerWithURLString:mp3Url];
  190. }
  191. - (void)rq_showSkillExplanationAlertWithMessage:(NSString *)messageStr skillkeyword:(NSString *)skillkeyword explainGifUrl:(NSString *)explainGifUrl mp3Url:(NSString *)mp3Url completeBlock:(void(^__nullable)(void))completeBlock {
  192. if (_isShow) {
  193. return;
  194. }
  195. self.messageTextView = nil;
  196. self.alert = [[SCLAlertView alloc] initWithNewWindowWidth:RQ_SCREEN_WIDTH - 80.f];
  197. [_alert removeTopCircle];
  198. _alert.tintTopCircle = NO;
  199. _alert.useLargerIcon = NO;
  200. _alert.iconTintColor = RQ_MAIN_COLOR;
  201. _alert.cornerRadius = 10;
  202. _alert.horizontalButtons = YES;
  203. _alert.showAnimationType = SCLAlertViewShowAnimationFadeIn;
  204. _alert.labelTitle.textColor = RQ_MAIN_TEXT_COLOR_1;
  205. _alert.labelTitle.font = [UIFont boldSystemFontOfSize:20];
  206. CGFloat viewTextWideth = RQ_SCREEN_WIDTH - (20 * 2) - (40 * 2);
  207. CGFloat textHeight = [messageStr heightForFont:[UIFont systemFontOfSize:self.exerciseFontSize] width:viewTextWideth] > RQ_SCREEN_HEIGHT / 2.f? RQ_SCREEN_HEIGHT / 2.f : [messageStr heightForFont:[UIFont systemFontOfSize:self.exerciseFontSize] width:viewTextWideth];
  208. [self.alert.labelTitle mas_makeConstraints:^(MASConstraintMaker *make) {
  209. make.top.mas_offset(20);
  210. make.centerX.mas_offset(0);
  211. make.size.mas_equalTo(CGSizeMake(viewTextWideth, 21.f));
  212. }];
  213. UIImageView *gifImageView = [[UIImageView alloc] initWithFrame:CGRectMake(_alert.labelTitle.rq_x, _alert.labelTitle.rq_y + _alert.labelTitle.rq_height, viewTextWideth, viewTextWideth * 0.5)];
  214. [gifImageView yy_setImageWithURL:[NSURL URLWithString:explainGifUrl] placeholder:RQWebImagePlaceholder() options:RQWebImageOptionAutomatic completion:^(UIImage * _Nullable image, NSURL * _Nonnull url, YYWebImageFromType from, YYWebImageStage stage, NSError * _Nullable error) {
  215. if ([url.path containsString:@".gif"]) {
  216. image = [UIImage qmui_animatedImageWithData:[NSData dataWithContentsOfURL:url]];
  217. }
  218. gifImageView.image = image;
  219. }];
  220. if (RQStringIsNotEmpty(explainGifUrl) && gifImageView.image) {
  221. [_alert addCustomView:gifImageView];
  222. [gifImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  223. make.top.mas_equalTo(_alert.labelTitle.mas_bottom).mas_offset(20);
  224. make.centerX.mas_offset(0);
  225. make.size.mas_equalTo(CGSizeMake(viewTextWideth, viewTextWideth * 0.5));
  226. }];
  227. }
  228. if (RQStringIsNotEmpty(messageStr)) {
  229. UILabel *textViewTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(_alert.labelTitle.rq_x, (RQStringIsNotEmpty(explainGifUrl) && gifImageView.image)? gifImageView.rq_y + gifImageView.rq_height : _alert.labelTitle.rq_y + _alert.labelTitle.rq_height, 100, 18)];
  230. textViewTitleLabel.text = @"本题速记口诀";
  231. textViewTitleLabel.textColor = RQ_MAIN_TEXT_COLOR_1;
  232. textViewTitleLabel.font = [UIFont systemFontOfSize:16];
  233. textViewTitleLabel.textAlignment = NSTextAlignmentCenter;
  234. [_alert addCustomView:textViewTitleLabel];
  235. [textViewTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  236. make.top.mas_equalTo((RQStringIsNotEmpty(explainGifUrl) && gifImageView.image)? gifImageView.mas_bottom : _alert.labelTitle.mas_bottom).mas_offset(20);
  237. make.centerX.mas_offset(0);
  238. make.size.mas_equalTo(CGSizeMake(100, 18));
  239. }];
  240. UIImageView *leftLineImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 20, 1)];
  241. leftLineImageView.backgroundColor = RQ_MAIN_TEXT_COLOR_5;
  242. [_alert addCustomView:leftLineImageView];
  243. [leftLineImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  244. make.centerY.mas_equalTo(textViewTitleLabel);
  245. make.right.mas_equalTo(textViewTitleLabel.mas_left).mas_offset(- 5);
  246. make.size.mas_equalTo(CGSizeMake(20, 1));
  247. }];
  248. UIImageView *rightLineImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 20, 1)];
  249. rightLineImageView.backgroundColor = RQ_MAIN_TEXT_COLOR_5;
  250. [_alert addCustomView:rightLineImageView];
  251. [rightLineImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  252. make.centerY.mas_equalTo(textViewTitleLabel);
  253. make.left.mas_equalTo(textViewTitleLabel.mas_right).mas_offset(5);
  254. make.size.mas_equalTo(CGSizeMake(20, 1));
  255. }];
  256. self.messageTextView = [[UITextView alloc] initWithFrame:CGRectMake(_alert.labelTitle.rq_x, textViewTitleLabel.rq_y + textViewTitleLabel.rq_height, viewTextWideth, textHeight)];
  257. self.messageTextView.font = [UIFont systemFontOfSize:self.exerciseFontSize];
  258. self.messageTextView.editable = NO;
  259. self.messageTextView.textColor = RQ_MAIN_TEXT_COLOR_3;
  260. self.messageTextView.textAlignment = NSTextAlignmentLeft;
  261. [_alert addCustomView:self.messageTextView];
  262. if (RQStringIsNotEmpty(skillkeyword)) {
  263. NSMutableAttributedString *abs = [[NSMutableAttributedString alloc] initWithString:messageStr? : @""];
  264. NSArray *skillArr = [skillkeyword componentsSeparatedByString:@"-"];
  265. __block NSRange lastRange = NSMakeRange(0, 0);
  266. [[skillArr.rac_sequence.signal deliverOnMainThread] subscribeNext:^(NSString * _Nullable skillkeywordStr) {
  267. NSInteger index = [skillArr indexOfObject:skillkeywordStr];
  268. NSRange targetRange = NSMakeRange(0, messageStr.length);
  269. NSRange skillRange = targetRange;
  270. // while (true) {
  271. // if (skillRange.location != NSNotFound) {
  272. //
  273. // } else {
  274. // break;
  275. // }
  276. // }
  277. skillRange = [messageStr rangeOfString:skillkeywordStr options:NSLiteralSearch range:targetRange];
  278. if (skillRange.location > messageStr.length || skillRange.length == 0) {
  279. if (lastRange.length != 0) {
  280. NSRange frontRange = NSMakeRange(NSMaxRange(lastRange), messageStr.length - NSMaxRange(lastRange));
  281. [abs addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:self.exerciseFontSize] range:frontRange];
  282. } else {
  283. [abs addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:self.exerciseFontSize] range:targetRange];
  284. }
  285. return;
  286. }
  287. NSRange frontRange = NSMakeRange(0, skillRange.location);
  288. if (lastRange.length != 0) {
  289. if (skillRange.location > skillRange.location - NSMaxRange(lastRange)) {
  290. frontRange = NSMakeRange(NSMaxRange(lastRange), skillRange.location - NSMaxRange(lastRange));
  291. }
  292. }
  293. [abs addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:self.exerciseFontSize] range:frontRange];
  294. [abs addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:self.exerciseFontSize + 1] range:skillRange];
  295. [abs addAttribute:NSForegroundColorAttributeName value:RQ_MAIN_TEXT_COLOR_RED range:skillRange];
  296. lastRange = skillRange;
  297. if (index + 1 == skillArr.count) {
  298. NSRange backRange = NSMakeRange(NSMaxRange(skillRange), messageStr.length - NSMaxRange(skillRange));
  299. [abs addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:self.exerciseFontSize] range:backRange];
  300. }
  301. } completed:^{
  302. self.messageTextView.attributedText = abs;
  303. }];
  304. } else {
  305. self.messageTextView.text = messageStr;
  306. }
  307. [self.messageTextView mas_makeConstraints:^(MASConstraintMaker *make) {
  308. make.top.mas_equalTo(textViewTitleLabel.mas_bottom).mas_offset(15);
  309. make.centerX.mas_offset(0);
  310. make.size.mas_equalTo(CGSizeMake(viewTextWideth, textHeight)).priority(500);
  311. }];
  312. }
  313. @weakify(self)
  314. self.closeButton = [self.alert addButton:@"关闭" actionBlock:^{
  315. @strongify(self);
  316. if (RQ_Exercise_Module.isAutoRead) {
  317. completeBlock? completeBlock() : nil;
  318. }
  319. [self.alert hideView];
  320. _isShow = NO;
  321. [RQ_Exercise_Module cancleAutoReadQuestion];
  322. }];
  323. self.closeButton.buttonFormatBlock = ^NSDictionary* (void) {
  324. NSMutableDictionary *buttonConfig = [[NSMutableDictionary alloc] init];
  325. buttonConfig[@"cornerRadius"] = @"20.f";
  326. buttonConfig[@"backgroundColor"] = RQ_MAIN_BACKGROUNDCOLOR;
  327. buttonConfig[@"textColor"] = RQ_MAIN_TEXT_COLOR_3;
  328. buttonConfig[@"borderWidth"] = @1.0f;
  329. buttonConfig[@"borderColor"] = RQ_MAIN_TEXT_COLOR_3;
  330. buttonConfig[@"font"] = [UIFont systemFontOfSize:16];
  331. return buttonConfig;
  332. };
  333. [self.closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
  334. if (self.messageTextView) {
  335. make.top.mas_equalTo(self.messageTextView.mas_bottom).mas_offset(20);
  336. } else {
  337. make.top.mas_equalTo((RQStringIsNotEmpty(explainGifUrl) && gifImageView.image)? gifImageView.mas_bottom : _alert.labelTitle.mas_bottom).mas_offset(20);
  338. }
  339. make.left.mas_equalTo(_alert.labelTitle.mas_left);
  340. make.bottom.mas_offset(-20);
  341. make.size.mas_equalTo(CGSizeMake((viewTextWideth - 16) / 2.f, 40.f));
  342. }];
  343. self.rePlayButton = [self.alert addButton:@"语音重播" validationBlock:^BOOL{
  344. [RQ_MUSIC_MANAGER rq_resetStreamerWithURLString:mp3Url];
  345. return NO;
  346. } actionBlock:nil];
  347. self.rePlayButton.buttonFormatBlock = ^NSDictionary* (void) {
  348. NSMutableDictionary *buttonConfig = [[NSMutableDictionary alloc] init];
  349. buttonConfig[@"cornerRadius"] = @"20.f";
  350. buttonConfig[@"backgroundColor"] = RQ_MAIN_COLOR;
  351. buttonConfig[@"textColor"] = RQ_MAIN_TEXT_COLOR_WHITE;
  352. buttonConfig[@"font"] = [UIFont systemFontOfSize:16];
  353. return buttonConfig;
  354. };
  355. [self.rePlayButton mas_makeConstraints:^(MASConstraintMaker *make) {
  356. make.right.mas_equalTo(_alert.labelTitle.mas_right);
  357. make.bottom.mas_offset(-20);
  358. make.size.mas_equalTo(CGSizeMake((viewTextWideth - 16) / 2.f, 40.f));
  359. }];
  360. [_alert showTitle:@"技巧讲解" subTitle:nil style:SCLAlertViewStyleCustom closeButtonTitle:nil duration:0.f];
  361. _isShow = YES;
  362. if (RQ_Exercise_Module.isAutoRead) {
  363. [RQ_MUSIC_MANAGER rq_resetStreamerWithURLString:mp3Url DOUAudioStreamerStatusBlock:^(DOUAudioStreamerStatus status) {
  364. if (status == DOUAudioStreamerFinished) {
  365. completeBlock();
  366. [_alert hideView];
  367. _isShow = NO;
  368. }
  369. }];
  370. } else {
  371. [RQ_MUSIC_MANAGER rq_resetStreamerWithURLString:mp3Url];
  372. }
  373. }
  374. @end