123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468 |
- //
- // YOUPAIMessageTemplateEdit.m
- // MSYOUPAI
- //
- // Created by admin on 2022/3/11.
- // Copyright © 2022 MS. All rights reserved.
- //
- #import "YOUPAIMessageTemplateEdit.h"
- #import "UIViewController+YOUPAIVideo.h"
- #import "UIViewController+YOUPAIUPImage.h"
- #import "YOUPAIZYEditUserShowAlertWindow.h"
- #import "UIViewController+TFPresent.h"
- #import "UIViewController+YOUPAIYBImageBrowser.h"
- @interface YOUPAIMessageTemplateEdit ()<ZYEditUserShowAlertWindowDelegate>
- @property (strong, nonatomic) NSMutableDictionary* youpaipRequestData;
- @property (strong, nonatomic) UIBarButtonItem* rightItem;
- @end
- @implementation YOUPAIMessageTemplateEdit
- - (void)viewDidDisappear:(BOOL)animated{
- [super viewDidDisappear:animated];
- [self.soundRecordView youpaifstopSoundRecord];
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self.soundRecordView youpaifstopSoundRecord];
- self.youpaipRequestData = [[NSMutableDictionary alloc] init];
- self.view.backgroundColor = UIColor.whiteColor;
- self.title = @"新建模板";
- self.navigationItem.rightBarButtonItem = self.rightItem;
- [self youpaifMakeUI];
- [self youpaifMakeLayout];
-
- }
- -(void)viewWillAppear:(BOOL)animated{
- [super viewWillAppear:animated];
- [self reloadData];
- }
- -(UIBarButtonItem *)rightItem{
- if (_rightItem == nil){
- UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
- [button addTarget:self action:@selector(youpaifcommit) forControlEvents:UIControlEventTouchUpInside];
- button.frame = CGRectMake(0, 0, 56, 24);
- [button setTitle:@"提交审核" forState:0];
- [button setTitleColor:LZ7C69FEColor forState:0];
- button.titleLabel.font = LCFont14;
- button.layer.cornerRadius = 12;
- button.layer.masksToBounds = YES;
- [self.view addSubview:button];
- _rightItem = [[UIBarButtonItem alloc] initWithCustomView:button];
- }
- return _rightItem;
- }
- -(UIScrollView *)youpaipScrollView{
- if(_youpaipScrollView == nil){
- _youpaipScrollView = [UIScrollView new];
- }
- return _youpaipScrollView;
- }
- -(YOUPAILZTextView *)youpaiptextView{
- if(_youpaiptextView == nil){
- _youpaiptextView = [[YOUPAILZTextView alloc] initWithMaxCount:50];
- _youpaiptextView.frame = CGRectMake(19,62, KScreenWidth-38,170);
- [_youpaiptextView ms_radius:8];
- [_youpaiptextView setBackgroundColor:LZF7F8FAColor];
- _youpaiptextView.youpaiptextViewPadding = UIEdgeInsetsMake(12, 12, 12, 12);
-
- _youpaiptextView.youpaiptextLengthDefaultColor = LZD3D1D7Color;
- _youpaiptextView.youpaiptextLengthHigtColor = LZ7C69FEColor;
- _youpaiptextView.youpaiptextLengthFont = LCFont(14.0f);
- _youpaiptextView.youpaiptextLengthRight = 14.0f;
- _youpaiptextView.youpaiptextLengthBottom = 14.0f;
- _youpaiptextView.youpaiptextView.placeholderFont = LCFont(14.0f);
- _youpaiptextView.youpaiptextView.placeholderTextColor = LZD3D1D7Color;
- _youpaiptextView.youpaiptextView.placeholderText = @"请输入文字内容文案";
- _youpaiptextView.youpaiptextView.font = LCFont(14.0f);
-
- _youpaiptextView.tintColor = LZ7C69FEColor;
- _youpaiptextView.youpaiptextView.textColor = UIColor.blackColor;
-
-
- }
- return _youpaiptextView;
- }
- -(YOUPAIMessageEditHeaderView *)youpaipimageHeader{
- if(_youpaipimageHeader == nil){
- _youpaipimageHeader = [YOUPAIMessageEditHeaderView new];
- _youpaipimageHeader.youpaiptitleLab.text = @"添加图片";
- _youpaipimageHeader.youpaipremarkLab.text = @"(仅可添加一张)";
- }
- return _youpaipimageHeader;
- }
- - (UIImageView *)youpaipimageView{
- if(_youpaipimageView == nil){
- _youpaipimageView = [UIImageView new];
- _youpaipimageView.image = [UIImage imageNamed:@"icon_180_up_plus"];
- _youpaipimageView.contentMode = UIViewContentModeCenter;
- _youpaipimageView.backgroundColor = LZF7F8FAColor;
- [_youpaipimageView ms_radius:10];
- _youpaipimageView.userInteractionEnabled = true;
- UITapGestureRecognizer *gest = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(youpaifSelectImage:)];
- [_youpaipimageView addGestureRecognizer:gest];
- }
- return _youpaipimageView;
- }
- -(YOUPAIMessageEditHeaderView *)youpaipvideoHeader{
- if(_youpaipvideoHeader == nil){
- _youpaipvideoHeader = [YOUPAIMessageEditHeaderView new];
- _youpaipvideoHeader.youpaiptitleLab.text = @"添加视频";
- _youpaipvideoHeader.youpaipremarkLab.text = @"(限制15s以内)";
- }
- return _youpaipvideoHeader;
- }
- - (UIImageView *)youpaipvideoView{
- if(_youpaipvideoView == nil){
- _youpaipvideoView = [UIImageView new];
- _youpaipvideoView.image = [UIImage imageNamed:@"icon_180_up_plus"];
- [_youpaipvideoView ms_radius:10];
- _youpaipvideoView.userInteractionEnabled = true;
- _youpaipvideoView.contentMode = UIViewContentModeCenter;
- _youpaipvideoView.backgroundColor = LZF7F8FAColor;
- UITapGestureRecognizer *gest = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(youpaiSelectVideo:)];
- [_youpaipvideoView addGestureRecognizer:gest];
- }
- return _youpaipvideoView;
- }
- -(UIImageView *)youpaipplayerImageView{
- if (_youpaipplayerImageView == nil){
- _youpaipplayerImageView = [UIImageView new];
- [_youpaipplayerImageView ms_radius:10];
- UIImage *img = [UIImage imageNamed:@"vqu_images_D_video_play"];
- _youpaipplayerImageView.image = img;
- [_youpaipplayerImageView ms_radius:img.size.width/2];
- _youpaipplayerImageView.contentMode = UIViewContentModeCenter;
- }
- return _youpaipplayerImageView;
- }
- -(YOUPAIMessageEditHeaderView *)youpaipvoiceHeader{
- if(_youpaipvoiceHeader == nil){
- _youpaipvoiceHeader = [YOUPAIMessageEditHeaderView new];
- _youpaipvoiceHeader.youpaiptitleLab.text = @"添加语音";
- _youpaipvoiceHeader.youpaipremarkLab.text = @"(限制5~15秒)";
-
- }
- return _youpaipvoiceHeader;
- }
- -(YOUPAILZSoundRecordView *)soundRecordView{
-
- if(_soundRecordView == nil){
- _soundRecordView = [[YOUPAILZSoundRecordView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, KScreenWidth, 195.0f)];
- _soundRecordView.youpaipminTimer = 5;
- _soundRecordView.youpaipmaxTimer = 15;
- _soundRecordView.youpaiptype = LZAudioTypeWithAAC;
- }
- return _soundRecordView;
- }
- -(void)youpaifMakeUI{
- UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(keyboardHide:)];
- tapGestureRecognizer.cancelsTouchesInView = NO;
- [self.view addGestureRecognizer:tapGestureRecognizer];
- [self.view addSubview:self.youpaipScrollView];
- [self.youpaipScrollView addSubview:self.youpaiptextView];
- [self.youpaipScrollView addSubview:self.youpaipvideoView];
- [self.youpaipScrollView addSubview:self.youpaipvoiceHeader];
- [self.youpaipScrollView addSubview:self.youpaipimageHeader];
- [self.youpaipScrollView addSubview:self.youpaipimageView];
- [self.youpaipScrollView addSubview:self.youpaipvideoHeader];
- [self.youpaipScrollView addSubview:self.youpaipvideoView];
- [self.youpaipScrollView addSubview:self.youpaipvoiceHeader];
- [self.youpaipScrollView addSubview:self.soundRecordView];
- [self.youpaipvideoView addSubview:self.youpaipplayerImageView];
-
-
- }
- -(void)keyboardHide:(UITapGestureRecognizer*)tap{
- dispatch_async(dispatch_get_main_queue(), ^{
- [self.view endEditing:YES];
- });
- }
- -(void)reloadData{
- NSString *videostr = self.youpaipRequestData[@"video_file"];
- if ([videostr length]>0){
- NSURL *videourl = [LCTools getImageUrlWithAddress:videostr];
- _youpaipvideoView.image = [UIImage imageWithVideo:videourl];
- self.youpaipvideoView.contentMode = UIViewContentModeScaleAspectFill;
- [self.youpaipplayerImageView setHidden:false];
- }else{
- _youpaipvideoView.image = [UIImage imageNamed:@"icon_180_up_plus"];
- _youpaipvideoView.contentMode = UIViewContentModeCenter;
- [self.youpaipplayerImageView setHidden:true];
- }
-
- NSString *imagestr = self.youpaipRequestData[@"file"];
- if ([imagestr length]>0){
- NSURL *imagesurl = [[LCTools getImageUrlWithAddress:imagestr] urlWithImageScale:60];
- [_youpaipimageView sd_setImageWithURL:imagesurl placeholderImage:[UIImage imageNamed:@"icon_180_up_plus"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
- if(error){
- self.youpaipimageView.contentMode = UIViewContentModeCenter;
- }else{
- self.youpaipimageView.contentMode = UIViewContentModeScaleAspectFill;
- }
- }];
- }else{
- _youpaipimageView.image = [UIImage imageNamed:@"icon_180_up_plus"];
- _youpaipimageView.contentMode = UIViewContentModeCenter;
- }
- }
- -(void)youpaifMakeLayout{
-
- [_youpaiptextView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(25);
- make.left.mas_equalTo(12);
- make.right.mas_equalTo(-12);
- make.height.mas_equalTo(148);
- make.width.mas_equalTo(KScreenWidth-24);
- }];
- [_youpaipimageHeader mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.youpaiptextView.mas_bottom);
- make.left.mas_equalTo(12);
- make.right.mas_equalTo(-12);
- make.height.mas_equalTo(54);
- }];
- [_youpaipimageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.youpaipimageHeader.mas_bottom);
- make.left.mas_equalTo(12);
- make.size.mas_equalTo(111);
- }];
- [_youpaipvideoHeader mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.youpaipimageView.mas_bottom);
- make.left.mas_equalTo(12);
- make.right.mas_equalTo(-12);
- make.height.mas_equalTo(54);
- }];
- [_youpaipvideoView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.youpaipvideoHeader.mas_bottom);
- make.left.mas_equalTo(12);
- make.size.mas_equalTo(111);
- }];
- [_youpaipvoiceHeader mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.youpaipvideoView.mas_bottom);
- make.left.mas_equalTo(12);
- make.right.mas_equalTo(-12);
- make.height.mas_equalTo(54);
-
- }];
- [_youpaipScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.bottom.mas_equalTo(0);
- make.width.mas_equalTo(KScreenWidth);
- make.height.mas_equalTo(self.view);
- make.top.mas_equalTo(self.view).offset(NavBarHeight);
-
- }];
- [_soundRecordView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.mas_equalTo(self.view);
- make.height.mas_equalTo(195.0f);
- make.width.mas_equalTo(self.view);
- make.top.mas_equalTo(self.youpaipvoiceHeader.mas_bottom).offset(10);
- // make.bottom.mas_equalTo(0).offset(-(90+SafeHeight));
- }];
- [_youpaipplayerImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.mas_equalTo(0);
- }];
-
- [self.view layoutIfNeeded];
- self.youpaipScrollView.contentSize = CGSizeMake(0.0f, CGRectGetMaxY(_soundRecordView.frame) + SafeHeight + NavBarHeight + 30.0f);
- }
- // MARK: 选择图片
- -(void)youpaifSelectImage:(UITapGestureRecognizer*)gestureRecognizer{
- NSString * file = _youpaipRequestData[@"file"];
- if (file.length>0){
- YOUPAIZYEditUserShowAlertWindow *vc= [[YOUPAIZYEditUserShowAlertWindow alloc]init];
- vc.youpaipbtntitleArr = @[@"查看",@"更换",@"取消"];
- vc.youpaipdelegate = self;
- vc.isTouchDismiss = YES;
- vc.info = @{@"tag":@(1002)};
- [self TFPresentVC:vc completion:^{}];
- }else{
- [self youpaifgetImage];
- }
-
- }
- -(void)youpaifgetImage{
- @weakify(self);
- [self youpaifUploadImgType:@"greet/img" configTZ:nil uploadBlock:nil fineshBlock:^(NSArray * _Nullable imgurls, NSError * _Nullable error) {
-
- @strongify(self);
- if (error){
- [ZCHUDHelper showTitle:@"上传失败"];
- }else{
-
- self.youpaipRequestData[@"file"] = imgurls.firstObject;
- [self reloadData];
- }
-
- }];
- }
- // MARK: 选择视频
- - (void)youpaiSelectVideo:(UITapGestureRecognizer *)gestureRecognizer
- {
- NSString * video_file = _youpaipRequestData[@"video_file"];
- if (video_file.length>0){
- YOUPAIZYEditUserShowAlertWindow *vc= [[YOUPAIZYEditUserShowAlertWindow alloc]init];
- vc.youpaipbtntitleArr = @[@"查看",@"更换",@"取消"];
- vc.youpaipdelegate = self;
- vc.isTouchDismiss = YES;
- vc.info = @{@"tag":@(1001)};
- [self TFPresentVC:vc completion:^{}];
- }else{
- [self youpaifgetVideo];
- }
- }
- -(void)youpaifgetVideo{
- @weakify(self);
- [self youpaifTZSelectVideo:nil didSelect:^(UIImage * _Nullable coverImage, AVURLAsset * _Nullable asset, NSError * _Nullable error) {
- @strongify(self);
- if(error){
- [ZCHUDHelper showTitle:error.localizedDescription];
- return;
- }
- // 视频时长
- CMTime time = [asset duration];
- int seconds = ceil(time.value/time.timescale);
- seconds = MIN(15, seconds);
- [ZCHUDHelper showWithStatus:@"正在裁剪..."];
- [self youpaifCutVideo:asset start:0 end:seconds completion:^(NSURL * outputURL, Float64 videoDuration, NSError * error) {
- @strongify(self);
- if(error){
- [ZCHUDHelper showTitle:error.localizedDescription];
- return;
- }
- [ZCHUDHelper showTitle:@"裁剪完成"];
-
- [self updateVideo:outputURL coverImage:coverImage];
-
- }];
-
- } ];
- }
- -(void)updateVideo:(NSURL*)path coverImage:(UIImage*) coverImage{
- NSString *urlstr = path.resourceSpecifier;
- [ZCHUDHelper showWithStatus:@"正在上传..."];
- @weakify(self);
- [LCCommonHttp uploadWithVideoPath:urlstr Type:@"greet/video" successBlock:^(NSString *ossFilePath) {
-
- @strongify(self);
- self.youpaipRequestData[@"video_file"] = ossFilePath;
- [ZCHUDHelper showTitle:@"上传完成"];
- [self reloadData];
- }];
- }
- // mark: 提交
- -(void)youpaifcommit{
- dispatch_async(dispatch_get_main_queue(), ^{
- [self.view endEditing:YES];
- });
- NSString *title = _youpaiptextView.youpaiptextView.text;
- _youpaipRequestData[@"is_multi"] = @(1);
- _youpaipRequestData[@"title"] = title;
- //youpaipaudioTime
- NSURL *voiceurl = [self.soundRecordView getSubmitSound];
- NSInteger voicelength = self.soundRecordView.youpaipaudioTime;
- @weakify(self);
- [ZCHUDHelper showWithStatus:@"上传中..."];
- dispatch_group_t group = dispatch_group_create();
- __block NSInteger code = 0;
- if (voiceurl){
- dispatch_group_enter(group);
- dispatch_group_async(group, dispatch_get_main_queue(), ^{
- [LCCommonHttp uploadWithAudioPath:voiceurl.resourceSpecifier Type:@"greet/mp3" successBlock:^(NSString *ossFilePath) {
- @strongify(self);
-
- if (ossFilePath.length != 0) {
-
- self.youpaipRequestData[@"voice_file"] = ossFilePath;
- self.youpaipRequestData[@"length"] = @(voicelength);
-
- }else{
- code = -1;
- }
- dispatch_group_leave(group);
- }];
-
- });
- }
- dispatch_group_notify(group, dispatch_get_main_queue(), ^{
- if (code!=0) {
- [ZCHUDHelper showTitle:@"语音上传失败"];
- return;
- }
- [LCHttpHelper requestWithURLString:GreetAdd parameters:self.youpaipRequestData needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
- @strongify(self);
-
- NSString *code = responseObject[@"code"];
- NSString *msg = responseObject[@"msg"];
- if (code.integerValue == 0){
- [ZCHUDHelper dismiss];
- [self.navigationController popViewControllerAnimated:true];
- }else{
- [ZCHUDHelper showTitle:msg];
- }
- } failure:^(NSError *error) {
- [ZCHUDHelper showTitle:error.localizedDescription];
- }];
- });
-
- }
- // MARK: ZYEditUserShowAlertWindowDelegate
- -(void)youpaifimSessionMoreWindowAction:(YOUPAIZYEditUserShowAlertWindow *)alert
- type:(NSString *)type
- tag:(NSInteger)tag
- andUserId:(NSString *)user_id{
-
- NSDictionary *info = alert.info;
- NSInteger tagvalue = [info[@"tag"] intValue];
- // 视频
- if (tagvalue == 1001){
- if (tag==1){
- NSString * video_file = _youpaipRequestData[@"video_file"];
- NSURL *url = [LCTools getImageUrlWithAddress:video_file];
- [self youpaifAVPlayer:url];
- }else if (tag==2){
- [self youpaifgetVideo];
- }
- }
- // 照片
- else{
- if (tag==1){
- NSString * file = _youpaipRequestData[@"file"];
- // NSURL *url = [LCTools getImageUrlWithAddress:file];
- [self youpaiScanImages:@[file] currentPage:0 view:nil];
- }else if (tag==2){
- [self youpaifgetImage];
- }
-
- }
- }
- @end
|