// // YMEditProfileVoiceView.m // MSYOUPAI // // Created by YoMi on 2024/2/18. // Copyright © 2024 MS. All rights reserved. // #import "YMEditProfileVoiceView.h" #import "YMEditProfileViewModel.h" @interface YMEditProfileVoiceView () /// 编辑资料VM @property (nonatomic, strong) YMEditProfileViewModel *viewModel; /// 标题标签 @property (nonatomic, strong) UILabel *titleLb; /// 审核标签 @property (nonatomic, strong) UILabel *underReviewLb; //审核状态:0=未审核,1=审核通过,2=审核未通过,4=初始状态 /// 展示语音视图 @property (nonatomic, strong) UIImageView *showcaseVoiceView; /// 展示语音秒数 @property (nonatomic, strong) UILabel *showcaseVoiceSecondsLb; /// 提示标签 @property (nonatomic, strong) UILabel *contentLb; /// 箭头图标 @property (nonatomic, strong) UIImageView *arrowIcon; @end @implementation YMEditProfileVoiceView - (void)ym_setupViews{ [self addSubview:self.titleLb]; [self addSubview:self.underReviewLb]; [self addSubview:self.showcaseVoiceView]; [self.showcaseVoiceView addSubview:self.showcaseVoiceSecondsLb]; [self addSubview:self.contentLb]; [self addSubview:self.arrowIcon]; [self setNeedsUpdateConstraints]; [self updateConstraintsIfNeeded]; } - (void)updateConstraints{ [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self).offset(adapt(10)); make.left.equalTo(self).offset(adapt(15)); make.bottom.equalTo(self).offset(adapt(-10)); make.height.mas_equalTo(adapt(25)); }]; [self.underReviewLb mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self.mas_centerY); make.left.equalTo(self.titleLb.mas_right).offset(adapt(5)); make.width.mas_equalTo(adapt(47)); make.height.mas_equalTo(adapt(17)); }]; [self.showcaseVoiceView mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self.mas_centerY); make.width.mas_equalTo(adapt(73)); make.height.mas_equalTo(adapt(28)); make.right.equalTo(self.contentLb.mas_left).offset(adapt(-10)); }]; [self.showcaseVoiceSecondsLb mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self.showcaseVoiceView.mas_centerY); make.right.equalTo(self.showcaseVoiceView).offset(adapt(-5)); }]; [self.contentLb mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self.titleLb.mas_centerY); make.right.equalTo(self.arrowIcon.mas_left).offset(adapt(-10)); }]; [self.arrowIcon mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self.titleLb.mas_centerY); make.right.equalTo(self).offset(adapt(-15)); make.width.mas_equalTo(adapt(10)); make.height.mas_equalTo(adapt(9)); }]; [super updateConstraints]; } - (void)ym_bindViewModel:(YMEditProfileViewModel *)viewModel{ if (!viewModel) { return; } _viewModel = viewModel; @weakify(self) [[[[RACObserve(self.viewModel, userVoiceDuration) distinctUntilChanged] deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSNumber * userVoiceDuration) { @strongify(self) self.showcaseVoiceView.hidden = [userVoiceDuration intValue] == 0 ? YES : NO; self.showcaseVoiceSecondsLb.text = stringFormat(@"%d",[userVoiceDuration intValue]); if ([userVoiceDuration intValue] <= 0) { self.contentLb.text = @"去录制"; } else { self.contentLb.text = @"重新录制"; } }]; [[[[RACObserve(self.viewModel, isHideUserVoiceUnderReview) distinctUntilChanged] deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSNumber * isHideUserVoiceUnderReview) { @strongify(self) self.underReviewLb.hidden = [isHideUserVoiceUnderReview boolValue]; }]; } - (UILabel *)titleLb{ if (!_titleLb) { _titleLb = [[UILabel alloc]init]; _titleLb.font = LCBoldFont(16); _titleLb.textColor = HexColorFromRGB(0x333333); _titleLb.textAlignment = NSTextAlignmentLeft; _titleLb.text = @"声音展示"; } return _titleLb; } - (UILabel *)underReviewLb{ if (!_underReviewLb) { _underReviewLb = [[UILabel alloc]init]; _underReviewLb.font = LCFont(11); _underReviewLb.textColor = HexColorFromRGB(0xFFFFFF); _underReviewLb.textAlignment = NSTextAlignmentCenter; _underReviewLb.text = @"审核中"; _underReviewLb.backgroundColor = HexColorFromRGBA(0x000000,0.5); _underReviewLb.layer.cornerRadius = adapt(15)/2; _underReviewLb.layer.masksToBounds = YES; _underReviewLb.hidden = YES; } return _underReviewLb; } - (UIImageView *)showcaseVoiceView{ if (!_showcaseVoiceView) { _showcaseVoiceView = [[UIImageView alloc]init]; _showcaseVoiceView.image = ImageByName(@"ym_personal_call_bg"); _showcaseVoiceView.userInteractionEnabled = true; WS(weakSelf) UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init]; [_showcaseVoiceView addGestureRecognizer:tap]; [[[tap rac_gestureSignal] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) { if (!OCStringIsEmpty(weakSelf.viewModel.userVoiceUrl)){ [YMAudioPlayer sharedInstance].playUrlStr = [LCTools getImageUrlWithAddress:weakSelf.viewModel.userVoiceUrl].absoluteString; }else{ NSLog(@"路径错误"); } }]; } return _showcaseVoiceView; } - (UILabel *)showcaseVoiceSecondsLb{ if (!_showcaseVoiceSecondsLb) { _showcaseVoiceSecondsLb = [[UILabel alloc]init]; _showcaseVoiceSecondsLb.font = LCFont(12); _showcaseVoiceSecondsLb.textColor = HexColorFromRGB(0xFFFFFF); _showcaseVoiceSecondsLb.textAlignment = NSTextAlignmentCenter; _showcaseVoiceSecondsLb.text = @"**"; } return _showcaseVoiceSecondsLb; } - (UILabel *)contentLb{ if (!_contentLb) { _contentLb = [[UILabel alloc]init]; _contentLb.font = LCFont(13); _contentLb.textColor = HexColorFromRGB(0x9c9c9c); _contentLb.textAlignment = NSTextAlignmentRight; _contentLb.text = @"去录制"; } return _contentLb; } - (UIImageView *)arrowIcon{ if (!_arrowIcon) { _arrowIcon = [[UIImageView alloc]init]; _arrowIcon.image = ImageByName(@"ym_edit_profile_arrow_icon"); } return _arrowIcon; } @end