// // editShareView.m // 双子星云手机 // // Created by xd h on 2024/5/14. // #import "editShareView.h" #import "addShareModel.h" #import "customShareManageTool.h" #import "shareBySecretView.h" @interface editShareView () @property(nonatomic,strong) UIButton*day7Button; @property(nonatomic,strong) UIButton*dayForeverButton; @property(nonatomic,strong) UIButton*PrivacyShareButton; @end @implementation editShareView - (id)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; self.backgroundColor = [UIColor hwColor:@"#000000" alpha:0.6]; [self drawAnyView]; return self; } - (void)drawAnyView{ UIView *whiteBgView = [[UIView alloc] init]; whiteBgView.backgroundColor = [UIColor whiteColor]; [self addSubview:whiteBgView]; whiteBgView.layer.cornerRadius = 32; whiteBgView.layer.masksToBounds = YES; [whiteBgView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.bottom.mas_equalTo(0); make.height.mas_equalTo(315 -50+ AdaptTabHeight); }]; UILabel *titleLabel = [[UILabel alloc] init]; titleLabel.font = [UIFont systemFontOfSize:18.0]; titleLabel.textColor = [UIColor hwColor:@"#0A132B" alpha:1.0]; [whiteBgView addSubview:titleLabel]; NSString *leftText = NSLocalizedString(@"share_title_left",nil); NSString *rightText = NSLocalizedString(@"share_title_right",nil); NSString *totalStr = [[NSString alloc] initWithFormat:@"%@ %@",leftText,rightText]; NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:totalStr]; NSRange redRange = NSMakeRange([totalStr rangeOfString:rightText].location, [totalStr rangeOfString:rightText].length); UIColor *noteColor =[UIColor hwColor:@"#959799" alpha:1.0]; [attrStr addAttribute:NSForegroundColorAttributeName value:noteColor range:redRange]; [attrStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12.0] range:redRange]; titleLabel.attributedText = attrStr; [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(25); make.right.mas_equalTo(0); make.top.mas_equalTo(20); make.height.mas_equalTo(40); }]; NSString *secondTitleStr = NSLocalizedString(@"share_expiration_date",nil); UILabel *secondTitleLabel = [[UILabel alloc] init]; secondTitleLabel.font = [UIFont systemFontOfSize:14.0]; secondTitleLabel.textColor = [UIColor hwColor:@"#666666" alpha:1.0]; secondTitleLabel.text = secondTitleStr; [whiteBgView addSubview:secondTitleLabel]; CGFloat secondWith = [secondTitleStr boundingRectWithSize:CGSizeMake(300, 20) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14.0]} context:nil].size.width; [secondTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(25); make.width.mas_equalTo(secondWith); make.top.equalTo(titleLabel.mas_bottom).offset(10); make.height.mas_equalTo(25); }]; _day7Button = [[UIButton alloc] init]; [_day7Button setImage:[UIImage imageNamed:@"common_did_check"] forState:UIControlStateSelected]; [_day7Button setImage:[UIImage imageNamed:@"common_un_check"] forState:UIControlStateNormal]; [_day7Button setTitle:NSLocalizedString(@"share_expiration_date_7",nil) forState:UIControlStateNormal]; [_day7Button setTitleColor:[UIColor hwColor:@"#0A132B"] forState:UIControlStateNormal]; [_day7Button addTarget:self action:@selector(didClickButFun:) forControlEvents:UIControlEventTouchUpInside]; _day7Button.titleLabel.font = [UIFont boldSystemFontOfSize:14]; _day7Button.tag = 1; [whiteBgView addSubview:_day7Button]; _day7Button.selected = YES; [_day7Button mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(secondTitleLabel.mas_right).offset(5); make.width.mas_equalTo(100); make.top.equalTo(secondTitleLabel.mas_top).offset(0); make.height.mas_equalTo(25); }]; _dayForeverButton = [[UIButton alloc] init]; [_dayForeverButton setImage:[UIImage imageNamed:@"common_did_check"] forState:UIControlStateSelected]; [_dayForeverButton setImage:[UIImage imageNamed:@"common_un_check"] forState:UIControlStateNormal]; [_dayForeverButton setTitle:NSLocalizedString(@"share_expiration_date_forever",nil) forState:UIControlStateNormal]; [_dayForeverButton setTitleColor:[UIColor hwColor:@"#0A132B"] forState:UIControlStateNormal]; [_dayForeverButton addTarget:self action:@selector(didClickButFun:) forControlEvents:UIControlEventTouchUpInside]; _dayForeverButton.titleLabel.font = [UIFont boldSystemFontOfSize:14]; _dayForeverButton.tag = 2; [whiteBgView addSubview:_dayForeverButton]; [_dayForeverButton mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(_day7Button.mas_right).offset(15); make.width.mas_equalTo(100); make.top.equalTo(secondTitleLabel.mas_top).offset(0); make.height.mas_equalTo(25); }]; NSArray *titleArr = @[NSLocalizedString(@"share_by_weixin",nil), NSLocalizedString(@"share_by_QQ",nil), NSLocalizedString(@"share_by_timeLine",nil), NSLocalizedString(@"share_by_secret",nil)]; NSArray *imageStrArr = @[@"share_weixin_icon", @"share_qq_icon", @"share_weixin_Timeline_icon", @"share_secret_icon"]; CGFloat curButFullWidth = SCREEN_W/4.0; for (int i = 0; i< titleArr.count; i++) { UIButton*curButton = [[UIButton alloc] init]; [curButton addTarget:self action:@selector(didClickButFun:) forControlEvents:UIControlEventTouchUpInside]; curButton.tag = 10+i; [whiteBgView addSubview:curButton]; [curButton mas_makeConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(curButFullWidth); make.left.mas_equalTo(i*curButFullWidth); make.height.mas_equalTo(80); make.top.equalTo(secondTitleLabel.mas_bottom).offset(20); }]; if(i== titleArr.count -1){ _PrivacyShareButton = curButton; } UIView *imageBgView = [[UIView alloc] init]; imageBgView.backgroundColor = [UIColor hwColor:@"#F5F7FA"]; imageBgView.layer.cornerRadius = 8; imageBgView.layer.masksToBounds = YES; [curButton addSubview:imageBgView]; imageBgView.userInteractionEnabled = NO; [imageBgView mas_makeConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(64); make.height.mas_equalTo(52); make.centerX.equalTo(curButton.mas_centerX); make.top.mas_equalTo(0); }]; UIImageView *leftImageV = [[UIImageView alloc] init]; leftImageV.image = [UIImage imageNamed:imageStrArr[i]]; [imageBgView addSubview:leftImageV]; [leftImageV mas_makeConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(25); make.height.mas_equalTo(25); make.centerX.equalTo(imageBgView.mas_centerX); make.centerY.equalTo(imageBgView.mas_centerY).offset(0); }]; UILabel *leftLabel = [[UILabel alloc] init]; leftLabel.textColor = [UIColor hwColor:@"#0A132B"]; leftLabel.textAlignment = NSTextAlignmentCenter; leftLabel.font = [UIFont systemFontOfSize:12.0]; leftLabel.text = titleArr[i]; [curButton addSubview:leftLabel]; [leftLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(curButFullWidth); make.height.mas_equalTo(25); make.centerX.equalTo(curButton.mas_centerX); //make.top.equalTo(imageBgView.mas_bottom).offset(10); make.bottom.mas_equalTo(0); }]; } UIButton*cancelButton = [[UIButton alloc] init]; [cancelButton setTitle:NSLocalizedString(@"other_cancel",nil) forState:UIControlStateNormal]; [cancelButton setTitleColor:[UIColor hwColor:@"#0A132B"] forState:UIControlStateNormal]; [cancelButton addTarget:self action:@selector(didClickButFun:) forControlEvents:UIControlEventTouchUpInside]; cancelButton.titleLabel.font = [UIFont boldSystemFontOfSize:14]; cancelButton.tag = 100; [whiteBgView addSubview:cancelButton]; [cancelButton mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.bottom.mas_equalTo(-AdaptTabHeight); make.height.mas_equalTo(40); }]; UIView *lineView = [[UIView alloc] init]; lineView.backgroundColor = [UIColor hwColor:@"#EAEAEA"]; [whiteBgView addSubview:lineView]; [lineView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(25); make.right.mas_equalTo(-25); make.bottom.equalTo(cancelButton.mas_top).offset(-5); make.height.mas_equalTo(1); }]; } - (void)didClickButFun:(UIButton*)but { NSInteger tag = but.tag; if(tag==1 && !_day7Button.selected){ _day7Button.selected = YES; _dayForeverButton.selected = NO; //私密分享 _PrivacyShareButton.hidden = NO; } else if(tag==2 && !_dayForeverButton.selected){ _day7Button.selected = NO; _dayForeverButton.selected = YES; //私密分享 _PrivacyShareButton.hidden = YES; } else if(tag == 100){ [self removeFromSuperview]; } else{ //请求服务器处理分享数据 [self addShareDataBy:tag]; } } //添加分享 - (void)addShareDataBy:(NSInteger)tag { NSString *curSn = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.changeSn; NSString *platformType = [[NSString alloc] initWithFormat:@"%ld", tag - 9]; //_shareFileType NSInteger expirationDay = _day7Button.selected ? 7 : 0; NSMutableArray * boxShareFileDTOList = [NSMutableArray new]; for (NASFilePicDataArrModel*dataModel in _didSelectListArr) { NSMutableDictionary *modelDict = [NSMutableDictionary new]; if(dataModel.name){ [modelDict setValue:dataModel.name forKey:@"fileName"]; NSArray * nameArr = [dataModel.name componentsSeparatedByString:@"."]; if(nameArr.count >= 2){ NSString*fileSuffix = nameArr.lastObject; if(fileSuffix && fileSuffix.length > 0){ [modelDict setValue:fileSuffix forKey:@"fileSuffix"]; } } } if(dataModel.size >= 0){ [modelDict setValue:[NSNumber numberWithLong:dataModel.size] forKey:@"fileSize"]; } if(dataModel.time){ [modelDict setValue:dataModel.time forKey:@"fileTime"]; } if(dataModel.path){ NSString *filePath = dataModel.path; NSString *urlStr = ksharedAppDelegate.NASShareFileService; NSString *headUrl = [[NSString alloc] initWithFormat:@"%@getThumbnail?path=%@",urlStr,filePath]; NSString *fileUrl = [[NSString alloc] initWithFormat:@"%@getFile?path=%@",urlStr,filePath]; if(headUrl){ [modelDict setValue:headUrl forKey:@"headUrl"]; } if(headUrl){ [modelDict setValue:fileUrl forKey:@"fileUrl"]; } } [boxShareFileDTOList addObject:modelDict]; } NSMutableDictionary *paraDict = [NSMutableDictionary new]; if(!curSn){ return; } [paraDict setValue:curSn forKey:@"sn"]; [paraDict setValue:platformType forKey:@"platformType"]; if(_shareFileType){ [paraDict setValue:_shareFileType forKey:@"fileType"]; } [paraDict setValue:[NSNumber numberWithInteger:expirationDay] forKey:@"expirationDay"]; [paraDict setValue:boxShareFileDTOList forKey:@"boxShareFileDTOList"]; KWeakSelf //[ showNewIndicatorWithCanBack:NO canTouch:NO]; [[netWorkManager shareInstance] CommonPostCallBackCode:addShareInfoFun Parameters:paraDict success:^(id _Nonnull responseObject) { addShareModel *model = [[addShareModel alloc] initWithDictionary:responseObject error:nil]; if(model && model.code == 0){ [weakSelf gotoShareFunWith:tag with:model]; } else{ [[iToast makeText:NSLocalizedString(@"share_fail_msg",nil)] show];// } } failure:^(NSError * _Nonnull error) { [[iToast makeText:NSLocalizedString(@"share_fail_msg",nil)] show]; }]; } - (void)gotoShareFunWith:(NSInteger)tag with:(addShareModel*)model { //type1 朋友圈 2 微信好友 3 QQ NSInteger shareType = 1; if(tag == 10){ shareType =2; } else if(tag == 11){ shareType = 3; } else if(tag == 12){ shareType = 1; } else if(tag == 13){ [self showSecretShareViewFunwith:model]; return;; } NSString *serUrl = shareService; NSString *shareUrl = [[NSString alloc] initWithFormat:@"%@%@",serUrl,model.data.token]; //NSString *shareTitle = [[NSString alloc] initWithFormat:@"Private-X%@",NSLocalizedString(@"common_edit_share",nil)]; NSString *shareTitle = @"Private-X分享"; NSString *firstname = nil; if (_didSelectListArr.count > 0) { NASFilePicDataArrModel*dataModel = _didSelectListArr[0]; firstname = dataModel.name; } //我正在使用Private-X魔盒,给大家分享 文件名称文件名称.jpg 等 2 个文件 ,快来看看吧~ NSString *shareContent = [[NSString alloc] initWithFormat:@"我正在使用Private-X魔盒,给大家分享%@等%ld个文件 ,快来看看吧~",firstname,_didSelectListArr.count]; if(_didSelectListArr.count == 1){ shareContent = [[NSString alloc] initWithFormat:@"我正在使用Private-X魔盒,给大家分享%@ ,快来看看吧~",firstname]; } [[customShareManageTool sharedManager] shareType:shareType withShareUrl:shareUrl withShareTitle:shareTitle withShareContent:shareContent]; } - (void)showSecretShareViewFunwith:(addShareModel*)model { [self removeFromSuperview]; shareBySecretView *secretView = [[shareBySecretView alloc] init]; secretView.addShareMod = model; secretView.didSelectListArr = _didSelectListArr; [ksharedAppDelegate.window addSubview:secretView]; [secretView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.top.mas_equalTo(0); make.bottom.mas_equalTo(0); }]; } @end