YMEditProfileVoiceView.m 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. //
  2. // YMEditProfileVoiceView.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/2/18.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMEditProfileVoiceView.h"
  9. #import "YMEditProfileViewModel.h"
  10. @interface YMEditProfileVoiceView ()
  11. /// 编辑资料VM
  12. @property (nonatomic, strong) YMEditProfileViewModel *viewModel;
  13. /// 标题标签
  14. @property (nonatomic, strong) UILabel *titleLb;
  15. /// 审核标签
  16. @property (nonatomic, strong) UILabel *underReviewLb;
  17. //审核状态:0=未审核,1=审核通过,2=审核未通过,4=初始状态
  18. /// 展示语音视图
  19. @property (nonatomic, strong) UIImageView *showcaseVoiceView;
  20. /// 展示语音秒数
  21. @property (nonatomic, strong) UILabel *showcaseVoiceSecondsLb;
  22. /// 提示标签
  23. @property (nonatomic, strong) UILabel *contentLb;
  24. /// 箭头图标
  25. @property (nonatomic, strong) UIImageView *arrowIcon;
  26. @end
  27. @implementation YMEditProfileVoiceView
  28. - (void)ym_setupViews{
  29. [self addSubview:self.titleLb];
  30. [self addSubview:self.underReviewLb];
  31. [self addSubview:self.showcaseVoiceView];
  32. [self.showcaseVoiceView addSubview:self.showcaseVoiceSecondsLb];
  33. [self addSubview:self.contentLb];
  34. [self addSubview:self.arrowIcon];
  35. [self setNeedsUpdateConstraints];
  36. [self updateConstraintsIfNeeded];
  37. }
  38. - (void)updateConstraints{
  39. [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
  40. make.top.equalTo(self).offset(adapt(10));
  41. make.left.equalTo(self).offset(adapt(15));
  42. make.bottom.equalTo(self).offset(adapt(-10));
  43. make.height.mas_equalTo(adapt(25));
  44. }];
  45. [self.underReviewLb mas_makeConstraints:^(MASConstraintMaker *make) {
  46. make.centerY.equalTo(self.mas_centerY);
  47. make.left.equalTo(self.titleLb.mas_right).offset(adapt(5));
  48. make.width.mas_equalTo(adapt(47));
  49. make.height.mas_equalTo(adapt(17));
  50. }];
  51. [self.showcaseVoiceView mas_makeConstraints:^(MASConstraintMaker *make) {
  52. make.centerY.equalTo(self.mas_centerY);
  53. make.width.mas_equalTo(adapt(73));
  54. make.height.mas_equalTo(adapt(28));
  55. make.right.equalTo(self.contentLb.mas_left).offset(adapt(-10));
  56. }];
  57. [self.showcaseVoiceSecondsLb mas_makeConstraints:^(MASConstraintMaker *make) {
  58. make.centerY.equalTo(self.showcaseVoiceView.mas_centerY);
  59. make.right.equalTo(self.showcaseVoiceView).offset(adapt(-5));
  60. }];
  61. [self.contentLb mas_makeConstraints:^(MASConstraintMaker *make) {
  62. make.centerY.equalTo(self.titleLb.mas_centerY);
  63. make.right.equalTo(self.arrowIcon.mas_left).offset(adapt(-10));
  64. }];
  65. [self.arrowIcon mas_makeConstraints:^(MASConstraintMaker *make) {
  66. make.centerY.equalTo(self.titleLb.mas_centerY);
  67. make.right.equalTo(self).offset(adapt(-15));
  68. make.width.mas_equalTo(adapt(10));
  69. make.height.mas_equalTo(adapt(9));
  70. }];
  71. [super updateConstraints];
  72. }
  73. - (void)ym_bindViewModel:(YMEditProfileViewModel *)viewModel{
  74. if (!viewModel) {
  75. return;
  76. }
  77. _viewModel = viewModel;
  78. @weakify(self)
  79. [[[[RACObserve(self.viewModel, userVoiceDuration) distinctUntilChanged] deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSNumber * userVoiceDuration) {
  80. @strongify(self)
  81. self.showcaseVoiceView.hidden = [userVoiceDuration intValue] == 0 ? YES : NO;
  82. self.showcaseVoiceSecondsLb.text = stringFormat(@"%d",[userVoiceDuration intValue]);
  83. if ([userVoiceDuration intValue] <= 0) {
  84. self.contentLb.text = @"去录制";
  85. } else {
  86. self.contentLb.text = @"重新录制";
  87. }
  88. }];
  89. [[[[RACObserve(self.viewModel, isHideUserVoiceUnderReview) distinctUntilChanged] deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSNumber * isHideUserVoiceUnderReview) {
  90. @strongify(self)
  91. self.underReviewLb.hidden = [isHideUserVoiceUnderReview boolValue];
  92. }];
  93. }
  94. - (UILabel *)titleLb{
  95. if (!_titleLb) {
  96. _titleLb = [[UILabel alloc]init];
  97. _titleLb.font = LCBoldFont(16);
  98. _titleLb.textColor = HexColorFromRGB(0x333333);
  99. _titleLb.textAlignment = NSTextAlignmentLeft;
  100. _titleLb.text = @"声音展示";
  101. }
  102. return _titleLb;
  103. }
  104. - (UILabel *)underReviewLb{
  105. if (!_underReviewLb) {
  106. _underReviewLb = [[UILabel alloc]init];
  107. _underReviewLb.font = LCFont(11);
  108. _underReviewLb.textColor = HexColorFromRGB(0xFFFFFF);
  109. _underReviewLb.textAlignment = NSTextAlignmentCenter;
  110. _underReviewLb.text = @"审核中";
  111. _underReviewLb.backgroundColor = HexColorFromRGBA(0x000000,0.5);
  112. _underReviewLb.layer.cornerRadius = adapt(15)/2;
  113. _underReviewLb.layer.masksToBounds = YES;
  114. _underReviewLb.hidden = YES;
  115. }
  116. return _underReviewLb;
  117. }
  118. - (UIImageView *)showcaseVoiceView{
  119. if (!_showcaseVoiceView) {
  120. _showcaseVoiceView = [[UIImageView alloc]init];
  121. _showcaseVoiceView.image = ImageByName(@"ym_personal_call_bg");
  122. _showcaseVoiceView.userInteractionEnabled = true;
  123. WS(weakSelf)
  124. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
  125. [_showcaseVoiceView addGestureRecognizer:tap];
  126. [[[tap rac_gestureSignal] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
  127. if (!OCStringIsEmpty(weakSelf.viewModel.userVoiceUrl)){
  128. [YMAudioPlayer sharedInstance].playUrlStr = [LCTools getImageUrlWithAddress:weakSelf.viewModel.userVoiceUrl].absoluteString;
  129. }else{
  130. NSLog(@"路径错误");
  131. }
  132. }];
  133. }
  134. return _showcaseVoiceView;
  135. }
  136. - (UILabel *)showcaseVoiceSecondsLb{
  137. if (!_showcaseVoiceSecondsLb) {
  138. _showcaseVoiceSecondsLb = [[UILabel alloc]init];
  139. _showcaseVoiceSecondsLb.font = LCFont(12);
  140. _showcaseVoiceSecondsLb.textColor = HexColorFromRGB(0xFFFFFF);
  141. _showcaseVoiceSecondsLb.textAlignment = NSTextAlignmentCenter;
  142. _showcaseVoiceSecondsLb.text = @"**";
  143. }
  144. return _showcaseVoiceSecondsLb;
  145. }
  146. - (UILabel *)contentLb{
  147. if (!_contentLb) {
  148. _contentLb = [[UILabel alloc]init];
  149. _contentLb.font = LCFont(13);
  150. _contentLb.textColor = HexColorFromRGB(0x9c9c9c);
  151. _contentLb.textAlignment = NSTextAlignmentRight;
  152. _contentLb.text = @"去录制";
  153. }
  154. return _contentLb;
  155. }
  156. - (UIImageView *)arrowIcon{
  157. if (!_arrowIcon) {
  158. _arrowIcon = [[UIImageView alloc]init];
  159. _arrowIcon.image = ImageByName(@"ym_edit_profile_arrow_icon");
  160. }
  161. return _arrowIcon;
  162. }
  163. @end