// // YOUPAILCBigCastSetVC.m // LiveChat // // Created by 张灿 on 2018/8/30. // Copyright © 2018年 caicai. All rights reserved. // #import "YOUPAILCBigCastSetVC.h" #import "YOUPAILCSkillView.h" #import "YOUPAILZBigCastAudioSetVC.h" #import "FSAudioStream.h" #import "YOUPAIZYNobleSaleWindow.h" #import "UIViewController+TFPresent.h" #import "YOUPAIZYNobleDetailModel.h" @interface YOUPAILCBigCastSetVC () @property(nonatomic,strong)UIView* youpaiptopView; /// 设置价格背景View @property(nonatomic,strong)YOUPAILCSkillModel* youpaipcurrentModel; @property (nonatomic, weak)UIView *youpaipaudioBgV;/// 音频背景View @property (nonatomic, weak)UIButton *youpaipaudioPlayBtn; // 播放音频按钮 @property (nonatomic, weak)UILabel *youpaiptimerL; @property (nonatomic, weak)UIImageView *youpaipanimationImgV; @property (nonatomic, weak)UIView *youpaiphiddenCallCountBgV; // 是否隐藏通话次数背景View @property (nonatomic, weak)UIView *youpaiptfBgV; /// 输入价格背景View @property (nonatomic, weak)UITextField *youpaippriceTF; // 语音播放器 @property (nonatomic, strong)FSAudioStream *youpaipaudioStream; @property (nonatomic, strong)NSTimer *youpaiptimer; @end @implementation YOUPAILCBigCastSetVC - (void)dealloc{ [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [self youpaifrefreshData]; } - (void)viewDidDisappear:(BOOL)animated{ [super viewDidDisappear:animated]; [self stopPlay]; } - (void)viewDidLoad { [super viewDidLoad]; self.title = @"女神设置"; [self youpaifinitData]; [self _setupPriceView]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifkeyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifkeyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; } - (void)youpaifinitData{ [LCHttpHelper requestWithURLString:AnchorSet parameters:nil needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) { NSMutableArray* skillArray = [YOUPAILCSkillModel mj_objectArrayWithKeyValuesArray:[dict objectForKey:@"data"]]; if (skillArray.count>0) { self.youpaipcurrentModel = skillArray[0]; [self youpaifsetupView]; } } } failure:^(NSError *error) { }]; } - (void)youpaifrefreshData{ [LCHttpHelper requestWithURLString:UserCenter parameters:nil needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) {//成功 NSDictionary *anchor = [[dict objectForKey:@"data"]objectForKey:@"anchor"]; NSDictionary *info = [[dict objectForKey:@"data"]objectForKey:@"userinfo"]; if ([[anchor allKeys] containsObject:@"open_video_status"]) { if ([[anchor objectForKey:@"open_video_status"] integerValue] == 0) {//0 未开启 1 已开启 [LCSaveData saveVideoOpenStatu:NO]; }else{ [LCSaveData saveVideoOpenStatu:YES]; } } if ([[anchor allKeys] containsObject:@"order_switch"]) { if ([[anchor objectForKey:@"order_switch"] integerValue] == 1) {//1隐藏 2不隐藏 [LCSaveData saveOrderOpenStatu:YES]; }else{ [LCSaveData saveOrderOpenStatu:NO]; } } if ([[info allKeys] containsObject:@"is_msg_refuse"]) { if ([[info objectForKey:@"is_msg_refuse"] integerValue] == 1) {//1开启 0关闭 [LCSaveData saveProfileWuraoStatus:YES]; }else{ [LCSaveData saveProfileWuraoStatus:NO]; } } YOUPAILCBaseInfo* userinfo = [YOUPAILCBaseInfo mj_objectWithKeyValues:[[dict objectForKey:@"data"]objectForKey:@"userinfo"]]; YOUPAILCUserModel* userModel = [LCSaveModel getUserModel]; userModel.youpaipuserinfo = userinfo; [LCSaveModel saveUserModel:userModel]; [self youpaifsetupView]; } } failure:^(NSError *error) { }]; } - (void)_setupPriceView{ UIView *tfBgV = [[UIView alloc] initWithFrame:CGRectMake(0.0f, KScreenHeight, KScreenWidth, 48.0f)]; tfBgV.backgroundColor = HexColorFromRGB(0xCFD3DB); [self.view addSubview:tfBgV]; self.youpaiptfBgV = tfBgV; [LCTools clipCorner:UIRectCornerTopLeft|UIRectCornerTopRight View:tfBgV size:CGSizeMake(KScreenWidth, 48)]; UITextField *priceTF = [[UITextField alloc] init]; priceTF.placeholder = @"请输入价格"; priceTF.font = LCFont15; priceTF.textColor = HexColorFromRGB(0x333333); priceTF.tintColor = ZYPinkColor; priceTF.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10.0f, 0.0f)]; priceTF.leftViewMode = UITextFieldViewModeAlways; priceTF.rightView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10.0f, 0.0f)]; priceTF.rightViewMode = UITextFieldViewModeAlways; priceTF.backgroundColor = [UIColor whiteColor]; priceTF.keyboardType = UIKeyboardTypeNumberPad; priceTF.layer.cornerRadius = 17.0f; priceTF.clipsToBounds = YES; [tfBgV addSubview:priceTF]; self.youpaippriceTF = priceTF; UIButton *confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom]; UIImage *bgImage = [LCTools ColorImage:CGSizeMake(62.0f, 33.0f) FromColors:@[HexColorFromRGB(0xFF0084),HexColorFromRGB(0xFF3A00)] ByGradientType:GradientLeftToRight]; [confirmBtn setBackgroundImage:bgImage forState:UIControlStateNormal]; [confirmBtn setBackgroundImage:bgImage forState:UIControlStateHighlighted]; confirmBtn.layer.cornerRadius = 16.5f; confirmBtn.clipsToBounds = YES; confirmBtn.titleLabel.font = LCFont14; [confirmBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [confirmBtn setTitle:@"确定" forState:UIControlStateNormal]; [confirmBtn addTarget:self action:@selector(youpaifconfirmBtnClick) forControlEvents:UIControlEventTouchUpInside]; [tfBgV addSubview:confirmBtn]; [confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.offset(-14.0f); make.centerY.equalTo(tfBgV.mas_centerY); make.size.mas_offset(CGSizeMake(62.0f, 33.0f)); }]; [priceTF mas_makeConstraints:^(MASConstraintMaker *make) { make.top.offset(7.0f); make.bottom.offset(-7.0f); make.left.offset(14.0f); make.right.equalTo(confirmBtn.mas_left).offset(-8.0f); }]; } - (void)youpaifsetupView{ [self.youpaiptopView removeFromSuperview]; self.youpaiptopView = nil; UIView* topView = [[UIView alloc]initWithFrame:CGRectMake(14, NavBarHeight + 34, KScreenWidth-28,119.0f)]; [self.view addSubview:topView]; UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0,0.0f, topView.mj_w, 17)]; label.text = @"视频通话价格"; label.font = LCFont15; label.textColor = HexColorFromRGB(0x9F9DA5); [topView addSubview:label]; YOUPAILCSkillView* skill = [[YOUPAILCSkillView alloc]initWithFrame:CGRectMake(0.0f,label.mj_h + 14.0f, topView.mj_w,88.0f) skillModel:self.youpaipcurrentModel]; [skill.youpaippriceBtn addTarget:self action:@selector(setSkillPriceClick) forControlEvents:(UIControlEventTouchUpInside)]; [skill.youpaipnobleSaleBtn addTarget:self action:@selector(nobleSaleBtnClick) forControlEvents:(UIControlEventTouchUpInside)]; [topView addSubview:skill]; self.youpaiptopView = topView; /// 音频View [self.youpaipaudioBgV removeFromSuperview]; self.youpaipaudioBgV = nil; UIView *audioBgV = [[UIView alloc] init]; audioBgV.backgroundColor = HexColorFromRGB(0x2A2935); audioBgV.layer.cornerRadius = 5.0f; audioBgV.clipsToBounds = YES; [self.view addSubview:audioBgV]; self.youpaipaudioBgV = audioBgV; [audioBgV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(14.0f); make.right.offset(-14.0f); make.top.equalTo(topView.mas_bottom).offset(10.0f); make.height.offset(49.0f); }]; UILabel *audioDescL = [[UILabel alloc] init]; // audioDescL.text = @"声音展示"; audioDescL.font = LCFont14; audioDescL.textColor = [UIColor whiteColor]; [audioBgV addSubview:audioDescL]; [audioDescL mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(12.0f); make.centerY.equalTo(audioBgV.mas_centerY); }]; YOUPAILCBaseInfo *userinfo = [LCSaveModel getUserModel].youpaipuserinfo; //审核状态:0=未审核,1=审核通过,2=审核未通过,4=初始状态 BOOL showArrow = NO; NSString *redText = @""; if (userinfo.youpaipvoice_status == 0) { redText = @"(审核中)"; }else if (userinfo.youpaipvoice_status == 1){ }else if (userinfo.youpaipvoice_status == 2){ showArrow = YES; }else{ showArrow = YES; } NSString *text = [NSString stringWithFormat:@"声音展示%@",redText]; NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:text]; [str addAttribute:NSForegroundColorAttributeName value:HexColorFromRGB(0xF4003F) range:[text rangeOfString:redText]]; [str addAttribute:NSFontAttributeName value:LCFont12 range:[text rangeOfString:redText]]; audioDescL.attributedText = str; if (showArrow) { UIImageView *audioArrowImgV = [[UIImageView alloc] init]; audioArrowImgV.image = [UIImage imageNamed:@"vqu_images_D_profile_item_arrow"]; [audioBgV addSubview:audioArrowImgV]; [audioArrowImgV mas_makeConstraints:^(MASConstraintMaker *make) { make.right.offset(-12.0f); make.width.height.offset(16.0f); make.centerY.equalTo(audioBgV.mas_centerY); }]; UITapGestureRecognizer * tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(addAudioEvent:)]; [audioBgV addGestureRecognizer:tapGesture]; }else{ UIButton *removeAudioBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [removeAudioBtn setImage:[UIImage imageNamed:@"vqu_images_big_cast_remove_audio"] forState:UIControlStateNormal]; [removeAudioBtn addTarget:self action:@selector(removeAudioBtnClick) forControlEvents:UIControlEventTouchUpInside]; [audioBgV addSubview:removeAudioBtn]; [removeAudioBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.offset(0.0f); make.top.bottom.offset(0.0f); make.width.offset(37.0f); }]; UIView *aBgV = [[UIView alloc] init]; aBgV.layer.cornerRadius = 13.5f; aBgV.clipsToBounds = YES; aBgV.layer.borderWidth = 0.5f; aBgV.layer.borderColor = [UIColor whiteColor].CGColor; [audioBgV addSubview:aBgV]; [aBgV mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(removeAudioBtn.mas_left).offset(0.0f); make.centerY.equalTo(audioBgV.mas_centerY); make.size.mas_offset(CGSizeMake(73.0f, 27.0f)); }]; UITapGestureRecognizer * tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(youpaifplayAudioEvent:)]; [aBgV addGestureRecognizer:tapGesture]; UIButton *audioPlayBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [audioPlayBtn setImage:[UIImage imageNamed:@"vqu_images_big_cast_audio_play"] forState:UIControlStateSelected]; [audioPlayBtn setImage:[UIImage imageNamed:@"vqu_images_big_cast_audio_none-1"] forState:UIControlStateNormal]; audioPlayBtn.userInteractionEnabled = NO; [aBgV addSubview:audioPlayBtn]; self.youpaipaudioPlayBtn = audioPlayBtn; [audioPlayBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(5.0f); make.centerY.equalTo(aBgV.mas_centerY); make.size.mas_offset(CGSizeMake(19.0f, 19.0f)); }]; UILabel *timerL = [[UILabel alloc] init]; timerL.font = LCFont(12); timerL.textColor = [UIColor whiteColor]; timerL.text = [NSString stringWithFormat:@"%@\"",@(userinfo.youpaipvoice_time)]; [aBgV addSubview:timerL]; self.youpaiptimerL = timerL; [timerL mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(audioPlayBtn.mas_right).offset(5.0f); make.centerY.equalTo(aBgV); }]; UIImageView *animationImgV = [[UIImageView alloc] init]; animationImgV.image = [UIImage imageNamed:@"vqu_images_IM_im_left_3"]; NSMutableArray * animationArray = [NSMutableArray array]; for (NSInteger i = 0; i < 3; i ++) { [animationArray addObject:[UIImage imageNamed:[NSString stringWithFormat:@"vqu_images_IM_im_left_%@",@(i + 1)]]]; } //设置动画数组 [animationImgV setAnimationImages:animationArray]; //设置动画播放次数 [animationImgV setAnimationRepeatCount:INT32_MAX]; //设置动画播放时间 [animationImgV setAnimationDuration:3*0.35]; [aBgV addSubview:animationImgV]; self.youpaipanimationImgV = animationImgV; [animationImgV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(timerL.mas_right).offset(5.0f); make.centerY.equalTo(aBgV); make.size.mas_offset(CGSizeMake(19.0f, 19.0f)); }]; } // 是否隐藏通话次数View [self.youpaiphiddenCallCountBgV removeFromSuperview]; self.youpaiphiddenCallCountBgV = nil; UIView *hiddenCallCountBgV = [[UIView alloc] init]; hiddenCallCountBgV.backgroundColor = HexColorFromRGB(0x2A2935); hiddenCallCountBgV.layer.cornerRadius = 5.0f; hiddenCallCountBgV.clipsToBounds = YES; [self.view addSubview:hiddenCallCountBgV]; self.youpaiphiddenCallCountBgV = hiddenCallCountBgV; [hiddenCallCountBgV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(14.0f); make.right.offset(-14.0f); make.top.equalTo(audioBgV.mas_bottom).offset(10.0f); make.height.offset(49.0f); }]; UILabel *hiddenCallCountDescL = [[UILabel alloc] init]; hiddenCallCountDescL.text = @"是否隐藏通话次数"; hiddenCallCountDescL.font = LCFont14; hiddenCallCountDescL.textColor = [UIColor whiteColor]; [hiddenCallCountBgV addSubview:hiddenCallCountDescL]; [hiddenCallCountDescL mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(12.0f); make.centerY.equalTo(hiddenCallCountBgV.mas_centerY); }]; UIButton *hiddenCallCountSwitch = [UIButton buttonWithType:UIButtonTypeCustom]; [hiddenCallCountSwitch setImage:[UIImage imageNamed:@"vqu_images_ic_profile_siwch_on"] forState:UIControlStateSelected]; [hiddenCallCountSwitch setImage:[UIImage imageNamed:@"vqu_images_ic_profile_siwch_off"] forState:UIControlStateNormal]; [hiddenCallCountSwitch addTarget:self action:@selector(hiddenCallCountSwitchBtnClick:) forControlEvents:UIControlEventTouchUpInside]; [hiddenCallCountBgV addSubview:hiddenCallCountSwitch]; [hiddenCallCountSwitch mas_makeConstraints:^(MASConstraintMaker *make) { make.right.offset(-12.0f); make.centerY.equalTo(hiddenCallCountBgV.mas_centerY); make.size.mas_offset(CGSizeMake(27.5f, 44.0f)); }]; if ([LCSaveData getOrderOpenStatu]) { hiddenCallCountSwitch.selected = YES; }else{ hiddenCallCountSwitch.selected = NO; } } - (void)setSkillPriceClick{ [self.youpaippriceTF becomeFirstResponder]; } -(void)nobleSaleBtnClick//贵族优惠查看 { [LCHttpHelper requestWithURLString:NobleDetail parameters:nil needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) {//成功 NSMutableArray* dataArray = [YOUPAIZYNobleDetailModel mj_objectArrayWithKeyValuesArray:[dict objectForKey:@"data"]]; YOUPAIZYNobleSaleWindow *vc= [[YOUPAIZYNobleSaleWindow alloc]init]; vc.vWidth = 313.0f; vc.vHeight = 95.0f + dataArray.count * 35 + 103.5f; vc.youpaipdataArray = dataArray; // vc.delegate = self; vc.isTouchDismiss = YES; [self TFPresentVC:vc completion:^{}]; } } failure:^(NSError *error) { }]; } - (void)youpaifconfirmBtnClick{ [LCHttpHelper requestWithURLString:SetSkillPrice parameters:@{@"price":@([self.youpaippriceTF.text floatValue]),@"skill_id":@(self.youpaipcurrentModel.youpaipskill_id)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) {//成功 [ZCHUDHelper showTitle:@"价格设置成功"]; [self youpaifinitData]; dispatch_async(dispatch_get_main_queue(), ^{ [self.view endEditing:YES]; self.youpaippriceTF.text = @""; }); } } failure:^(NSError *error) { }]; } - (void)removeAudioBtnClick{ [LCHttpHelper requestWithURLString:VoiceDelete parameters:@{} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) {//成功 [self youpaifrefreshData]; } } failure:^(NSError *error) { }]; } - (void)addAudioEvent:(UITapGestureRecognizer *)gesture{ YOUPAILZBigCastAudioSetVC *vc = [[YOUPAILZBigCastAudioSetVC alloc] init]; [self.navigationController pushViewController:vc animated:YES]; } - (void)youpaifplayAudioEvent:(UITapGestureRecognizer *)gesture{ self.youpaipaudioPlayBtn.selected = !self.youpaipaudioPlayBtn.selected; if (self.youpaipaudioPlayBtn.selected) { [self startPlay]; [self startTimer]; }else{ [self stopPlay]; } } - (void)hiddenCallCountSwitchBtnClick:(UIButton *)sender{ NSInteger status = 1; if (sender.selected != YES) {//将状态置为1 隐藏 status = 1; }else{ status = 0; } [LCHttpHelper requestWithURLString:BigCastSetOrderStatus parameters:@{@"status":@(status)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) { if (status==1) { [LCSaveData saveOrderOpenStatu:YES]; sender.selected = YES; }else{ [LCSaveData saveOrderOpenStatu:NO]; sender.selected = NO; } } } failure:^(NSError *error) { }]; } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ [self.view endEditing:YES]; } //键盘即将隐藏 - (void)youpaifkeyboardWillHide:(NSNotification *)note{ [UIView animateWithDuration:0.25f animations:^{ self.youpaiptfBgV.mj_y = KScreenHeight; }]; } //键盘即将弹出 - (void)youpaifkeyboardWillShow:(NSNotification *)note{ CGRect keyboardF = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue]; CGFloat keyboardH = keyboardF.size.height; [UIView animateWithDuration:0.25f animations:^{ self.youpaiptfBgV.mj_y = KScreenHeight - keyboardH - self.youpaiptfBgV.mj_h; }]; } /// 开始播放语音 - (void)startPlay{ NSURL *url = [LCTools getImageUrlWithAddress:[LCSaveModel getUserModel].youpaipuserinfo.youpaipvoice]; self.youpaipaudioStream.url = url; [self.youpaipaudioStream play]; [self.youpaipanimationImgV startAnimating]; } /// 停止播放语音 - (void)stopPlay{ self.youpaipaudioPlayBtn.selected = NO; self.youpaiptimerL.text = [NSString stringWithFormat:@"%@\"",@([LCSaveModel getUserModel].youpaipuserinfo.youpaipvoice_time)]; // 停止播放 if ([self.youpaipaudioStream isPlaying]) { [self.youpaipaudioStream stop]; } [self youpaifstopTimer]; [self.youpaipanimationImgV stopAnimating]; } - (FSAudioStream *)youpaipaudioStream{ if (_youpaipaudioStream == nil) { _youpaipaudioStream = [[FSAudioStream alloc] init]; WeakSelf; _youpaipaudioStream.onFailure = ^(FSAudioStreamError error,NSString *description){ [weakSelf stopPlay]; }; _youpaipaudioStream.onCompletion = ^(){ [weakSelf stopPlay]; }; [_youpaipaudioStream setVolume:0.7];//设置声音 _youpaipaudioStream.strictContentTypeChecking = NO; _youpaipaudioStream.defaultContentType = @"audio/mpeg"; } return _youpaipaudioStream; } // 开始计时 - (void)startTimer{ self.youpaiptimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerAction) userInfo:nil repeats:YES]; [[NSRunLoop currentRunLoop] addTimer:self.youpaiptimer forMode:NSRunLoopCommonModes]; } // 结束计时 - (void)youpaifstopTimer{ [self.youpaiptimer invalidate]; self.youpaiptimer = nil; } - (void)timerAction{ NSInteger timer = [LCSaveModel getUserModel].youpaipuserinfo.youpaipvoice_time - self.youpaipaudioStream.currentTimePlayed.playbackTimeInSeconds; self.youpaiptimerL.text = [NSString stringWithFormat:@"%@\"",@(timer)]; } @end