// // shareRecordDetailsHWViewController.m // 双子星云手机 // // Created by xd h on 2024/5/15. // #import "shareRecordDetailsHWViewController.h" @interface shareRecordDetailsHWViewController () @property (nonatomic,strong)UIView *whiteBgView; @property (nonatomic,strong)UILabel *shareTitleLabel; @property (nonatomic,strong)UILabel *shareBeginDateLabel; @property (nonatomic,strong)UIImageView *shareQRCodeImageView; @property (nonatomic,strong)UIButton*checkShareLinkButton; @property (nonatomic,strong)UIView *extractCodeBgView; @property (nonatomic,strong)UILabel *extractCodeTip2Lab; @property (nonatomic,strong)UILabel *shareEndDateLabel; @property (nonatomic,strong)UIButton*cancelShareLinkButton; @property (nonatomic,strong)UIButton*shareLinkCopyButton; @end @implementation shareRecordDetailsHWViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self.toolBar setHidden:YES]; [self.navigationBar setHidden:YES]; [self.navBarBGView setHidden:NO]; self.navBarBGView.backgroundColor = [UIColor whiteColor]; [self.view setBackgroundColor:[UIColor hwColor:@"#F5F7FA"]]; self.titleLabel.text = NSLocalizedString(@"share_record_title",nil); [self drawAnyView]; } - (void)drawAnyView{ // _whiteBgView = [[UIView alloc] init]; _whiteBgView.backgroundColor = [UIColor whiteColor]; [self.view addSubview:_whiteBgView]; _whiteBgView.layer.cornerRadius = 8; _whiteBgView.layer.masksToBounds = YES; [_whiteBgView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(15); make.right.mas_equalTo(-15); make.top.equalTo(self.navBarBGView.mas_bottom).offset(40.f); make.height.mas_equalTo(448); }]; //文件夹图标 UIImageView *folderImageView = [[UIImageView alloc] init]; folderImageView.image = [UIImage imageNamed:@"uploadFile_file_icon"]; folderImageView.backgroundColor = [UIColor whiteColor]; [self.view addSubview:folderImageView]; folderImageView.layer.cornerRadius = 44; folderImageView.layer.masksToBounds = YES; [folderImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.navBarBGView.mas_bottom).offset(10.f); make.centerX.mas_equalTo(self.view.mas_centerX); make.width.mas_equalTo(88); make.height.mas_equalTo(88); }]; _shareTitleLabel = [[UILabel alloc] init]; //_shareTitleLabel.text = @"banner.png等多个文件"; _shareTitleLabel.textAlignment = NSTextAlignmentCenter; _shareTitleLabel.textColor = HW0A132BColor; _shareTitleLabel.font = [UIFont systemFontOfSize:14.0]; [_whiteBgView addSubview:_shareTitleLabel]; [_shareTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(folderImageView.mas_bottom).offset(5.f); make.left.mas_equalTo(15); make.right.mas_equalTo(-15); make.height.mas_equalTo(20); }]; _shareBeginDateLabel = [[UILabel alloc] init]; //_shareBeginDateLabel.text = @"2024/04/25 19:45"; _shareBeginDateLabel.textAlignment = NSTextAlignmentCenter; _shareBeginDateLabel.textColor = HW666666Color; _shareBeginDateLabel.font = [UIFont systemFontOfSize:12.0]; [_whiteBgView addSubview:_shareBeginDateLabel]; [_shareBeginDateLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(_shareTitleLabel.mas_bottom).offset(25.f); make.left.mas_equalTo(15); make.right.mas_equalTo(-15); make.height.mas_equalTo(15); }]; UIImageView *QRCodeEdgingImageView = [[UIImageView alloc] init]; QRCodeEdgingImageView.image = [UIImage imageNamed:@"share_QRCode_edging"]; [_whiteBgView addSubview:QRCodeEdgingImageView]; [QRCodeEdgingImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(_shareBeginDateLabel.mas_bottom).offset(10.f); make.centerX.mas_equalTo(self.view.mas_centerX); make.width.mas_equalTo(208); make.height.mas_equalTo(208); }]; _shareQRCodeImageView = [[UIImageView alloc] init]; //_shareQRCodeImageView.backgroundColor = [UIColor lightGrayColor]; [QRCodeEdgingImageView addSubview:_shareQRCodeImageView]; [_shareQRCodeImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(20); make.bottom.mas_equalTo(-20); make.left.mas_equalTo(20); make.right.mas_equalTo(-20); }]; //_shareQRCodeImageView.image = [self generateQRCodeWithInputMessage:@"http://baidu.com" Width:168 Height:168]; _checkShareLinkButton = [[UIButton alloc] init]; [_checkShareLinkButton setTitle:NSLocalizedString(@"check_share_link_title",nil) forState:UIControlStateNormal]; [_checkShareLinkButton setTitleColor:[UIColor hwColor:@"#01B7EA"] forState:UIControlStateNormal]; _checkShareLinkButton.titleLabel.font = [UIFont systemFontOfSize:14.0]; [_checkShareLinkButton addTarget:self action:@selector(didClickButtonFun:) forControlEvents:UIControlEventTouchUpInside]; _checkShareLinkButton.tag = 1; [self.view addSubview:_checkShareLinkButton]; [_checkShareLinkButton mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(15); make.right.mas_equalTo(-15); make.top.equalTo(QRCodeEdgingImageView.mas_bottom).offset(0.f); make.height.mas_equalTo(30); }]; //提取码 _extractCodeBgView = [[UIView alloc] init]; _extractCodeBgView.backgroundColor = [UIColor hwColor:@"#F9F9F9"]; [_whiteBgView addSubview:_extractCodeBgView]; _extractCodeBgView.layer.cornerRadius = 8; _extractCodeBgView.layer.masksToBounds = YES; [_extractCodeBgView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(50); make.right.mas_equalTo(-50); make.top.equalTo(_checkShareLinkButton.mas_bottom).offset(15); make.height.mas_equalTo(40); }]; UILabel *extractCodeTipLab = [[UILabel alloc] init]; extractCodeTipLab.font = [UIFont systemFontOfSize:14.f]; [extractCodeTipLab setTextColor:HW0A132BColor]; extractCodeTipLab.text = NSLocalizedString(@"share_Extract_code_tip",nil); [_extractCodeBgView addSubview:extractCodeTipLab]; [extractCodeTipLab mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(15); make.right.mas_equalTo(_extractCodeBgView.mas_centerX); make.top.mas_equalTo(0); make.bottom.mas_equalTo(0); }]; _extractCodeTip2Lab = [[UILabel alloc] init]; _extractCodeTip2Lab.font = [UIFont systemFontOfSize:14.f]; //[_extractCodeTip2Lab setTextAlignment:(NSTextAlignmentRight)]; [_extractCodeTip2Lab setTextAlignment:(NSTextAlignmentCenter)]; [_extractCodeTip2Lab setTextColor:[UIColor hwColor:@"#01B7EA" alpha:1.0]]; [_extractCodeBgView addSubview:_extractCodeTip2Lab]; //extractCodeTip2Lab.text = _addShareMod.data.extractionCode; [_extractCodeTip2Lab mas_makeConstraints:^(MASConstraintMaker *make) { //make.left.mas_equalTo(extractCodeTipLab.mas_right); make.left.mas_equalTo(20); make.right.mas_equalTo(-20); make.top.mas_equalTo(0); make.bottom.mas_equalTo(0); }]; _shareEndDateLabel = [[UILabel alloc] init]; //_shareEndDateLabel.text = @"2024/04/25 19:45"; _shareEndDateLabel.textAlignment = NSTextAlignmentCenter; _shareEndDateLabel.textColor = HW0A132BColor; _shareEndDateLabel.font = [UIFont systemFontOfSize:14.0]; [_whiteBgView addSubview:_shareEndDateLabel]; [_shareEndDateLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(_extractCodeBgView.mas_bottom).offset(15.f); make.left.mas_equalTo(15); make.right.mas_equalTo(-15); make.height.mas_equalTo(15); }]; _cancelShareLinkButton = [[UIButton alloc] init]; [_cancelShareLinkButton setTitle:NSLocalizedString(@"cancel_share_title",nil) forState:UIControlStateNormal]; [_cancelShareLinkButton setTitleColor:HW0A132BColor forState:UIControlStateNormal]; _cancelShareLinkButton.titleLabel.font = [UIFont systemFontOfSize:14.0]; [_cancelShareLinkButton addTarget:self action:@selector(didClickButtonFun:) forControlEvents:UIControlEventTouchUpInside]; _cancelShareLinkButton.tag = 2; [self.view addSubview:_cancelShareLinkButton]; _cancelShareLinkButton.layer.cornerRadius = 8; _cancelShareLinkButton.layer.masksToBounds = YES; _cancelShareLinkButton.backgroundColor = [UIColor hwColor:@"#E3E8F1"]; [_cancelShareLinkButton mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(15); make.width.mas_equalTo(130); make.top.equalTo(_whiteBgView.mas_bottom).offset(25); make.height.mas_equalTo(48); }]; _shareLinkCopyButton = [[UIButton alloc] init]; CGFloat w_btn = SCREEN_W-130 -15 -10 -15; // gradient CAGradientLayer *gl = [CAGradientLayer layer]; gl.frame = CGRectMake(0,0,w_btn,48.f); gl.startPoint = CGPointMake(0, 0.5); gl.endPoint = CGPointMake(1, 0.5); gl.colors = @[(__bridge id)HW0CDEFDColor.CGColor, (__bridge id)HW058DFBColor.CGColor]; gl.locations = @[@(0), @(1.0f)]; [_shareLinkCopyButton.layer addSublayer:gl]; [_shareLinkCopyButton setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)]; [_shareLinkCopyButton addTarget:self action:@selector(didClickButtonFun:) forControlEvents:(UIControlEventTouchUpInside)]; [_shareLinkCopyButton setTitle:NSLocalizedString(@"copy_share_link_title",nil) forState:(UIControlStateNormal)]; [_shareLinkCopyButton.titleLabel setFont:[UIFont systemFontOfSize:14.f]]; [_shareLinkCopyButton.layer setCornerRadius:8.f]; _shareLinkCopyButton.clipsToBounds = YES; _shareLinkCopyButton.tag = 11; [self.view addSubview:_shareLinkCopyButton]; [_shareLinkCopyButton mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-15); make.width.mas_equalTo(w_btn); make.top.equalTo(_whiteBgView.mas_bottom).offset(25); make.height.mas_equalTo(48); }]; } // 生成二维码 - (UIImage *)generateQRCodeWithInputMessage:(NSString *)inputMessage Width:(CGFloat)width Height:(CGFloat)height{ NSData *inputData = [inputMessage dataUsingEncoding:NSUTF8StringEncoding]; CIFilter *filter = [CIFilter filterWithName:@"CIQRCodeGenerator"]; [filter setValue:inputData forKey:@"inputMessage"]; // [filter setValue:@"H" forKey:@"inputCorrectionLevel"]; // 设置二维码不同级别的容错率 CIImage *ciImage = filter.outputImage; // 消除模糊 CGFloat scaleX = MIN(width, height)/ciImage.extent.size.width; CGFloat scaleY = MIN(width, height)/ciImage.extent.size.height; ciImage = [ciImage imageByApplyingTransform:CGAffineTransformScale(CGAffineTransformIdentity, scaleX, scaleY)]; UIImage *returnImage = [UIImage imageWithCIImage:ciImage]; return returnImage; } - (void)didClickButtonFun:(UIButton*)but { NSInteger tag = but.tag; if(tag == 1){ NSString *serUrl = shareService; NSString *shareUrl = [[NSString alloc] initWithFormat:@"%@%@",serUrl,_dataModel.token]; NSURL *URL = [NSURL URLWithString:shareUrl]; [[UIApplication sharedApplication] openURL:URL]; } else if(tag == 10){ [self showCancelAlearViewFun]; } else if(tag == 11){ [self copyShareLinkFun]; } } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self handleDataFun]; } //- (void)setDataModel:(ShareRecordListModel *)dataModel - (void)handleDataFun { //_dataModel = dataModel; if(!_dataModel.expirationStatus){ _cancelShareLinkButton.hidden = NO; _shareLinkCopyButton.hidden = NO; //失效时间 NSString *tipStr = NSLocalizedString(@"copy_share_link_Invalid_tip3",nil); _shareEndDateLabel.text = [[NSString alloc] initWithFormat:@"%@: %@",tipStr,_dataModel.expirationTime]; } else{ _cancelShareLinkButton.hidden = YES; _shareLinkCopyButton.hidden = YES; //失效时间 NSString *tipStr = NSLocalizedString(@"copy_share_link_Invalid_tip3",nil); NSString *tipStr2 = NSLocalizedString(@"copy_share_link_Invalid_tip",nil); _shareEndDateLabel.text = [[NSString alloc] initWithFormat:@"%@: %@",tipStr,tipStr2]; } ShareFileDataModel *fileModel = _dataModel.fileListVOS.firstObject; NSString *titleStr = [[NSString alloc] initWithFormat:@"%@%@%ld%@",fileModel.fileName,NSLocalizedString(@"share_file_more_tip",nil), _dataModel.fileListVOS.count,NSLocalizedString(@"share_file_Numbers_tip",nil)]; if(_dataModel.fileListVOS.count == 1){ titleStr = fileModel.fileName; } _shareTitleLabel.text = titleStr; _shareBeginDateLabel.text = _dataModel.createTime; NSString *serUrl = shareService; NSString *shareUrl = [[NSString alloc] initWithFormat:@"%@%@",serUrl,_dataModel.token]; _shareQRCodeImageView.image = [self generateQRCodeWithInputMessage:shareUrl Width:168 Height:168]; _extractCodeTip2Lab.text = _dataModel.extractionCode; if(_dataModel.platformType == 4){ [_whiteBgView mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(15); make.right.mas_equalTo(-15); make.top.equalTo(self.navBarBGView.mas_bottom).offset(40.f); make.height.mas_equalTo(508); }]; _extractCodeBgView.hidden = NO; [_shareEndDateLabel mas_remakeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(_extractCodeBgView.mas_bottom).offset(15.f); make.left.mas_equalTo(15); make.right.mas_equalTo(-15); make.height.mas_equalTo(15); }]; } else{ [_whiteBgView mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(15); make.right.mas_equalTo(-15); make.top.equalTo(self.navBarBGView.mas_bottom).offset(40.f); make.height.mas_equalTo(448); }]; _extractCodeBgView.hidden = YES; [_shareEndDateLabel mas_remakeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(_checkShareLinkButton.mas_bottom).offset(15.f); make.left.mas_equalTo(15); make.right.mas_equalTo(-15); make.height.mas_equalTo(15); }]; } } #pragma mark 取消分享 - (void)showCancelAlearViewFun { NSString *tipStr = NSLocalizedString(@"cancel_share_Tip_msg",nil); KWeakSelf ComontAlretViewController *curAlretVC= [[ComontAlretViewController alloc] initWithTiTle:nil msg:tipStr imageStr:nil cancelTitle:NSLocalizedString(@"other_cancel",nil) okTitle:NSLocalizedString(@"other_confirm",nil) isOkBtnHighlight:YES didClickOk:^{ [weakSelf cancelShareLinkFun]; } didClickCancel:^{ }]; curAlretVC.modalPresentationStyle = UIModalPresentationCustom; [self presentViewController:curAlretVC animated:YES completion:^{ curAlretVC.view.superview.backgroundColor = [UIColor clearColor]; }]; } - (void)cancelShareLinkFun { NSMutableDictionary *paraDict = [NSMutableDictionary new]; if(_dataModel.addShareId){ //[paraDict setValue:_dataModel.addShareId forKey:@"id"]; [paraDict setValue:@[_dataModel.addShareId] forKey:@"idList"]; } [paraDict setValue:@1 forKey:@"expirationStatus"]; KWeakSelf [self showNewIndicatorWithCanBack:NO canTouch:NO]; [[netWorkManager shareInstance] CommonPostCallBackCode:updateShareInfoFun Parameters:paraDict success:^(id _Nonnull responseObject) { [weakSelf removeNewIndicator]; SuperModel *model = [[SuperModel alloc] initWithDictionary:responseObject error:nil]; if(model && model.code == 0){ [[iToast makeText:NSLocalizedString(@"cancel_share_suc_msg",nil)] show]; [weakSelf getShareOneFileListFun]; } else{ [[iToast makeText:NSLocalizedString(@"cancel_share_fail_msg",nil)] show]; } } failure:^(NSError * _Nonnull error) { [weakSelf removeNewIndicator]; [[iToast makeText:NSLocalizedString(@"cancel_share_fail_msg",nil)] show]; }]; } #pragma mark 分享信息重新获取 - (void)getShareOneFileListFun { _dataModel.expirationStatus = 1; [self handleDataFun]; if(_didCancelShareLinkFun){ _didCancelShareLinkFun(); } } - (void)copyShareLinkFun { if(_dataModel.fileListVOS.count <=0 ){ return; } ShareFileDataModel *dataModel = _dataModel.fileListVOS.firstObject; NSString *copyStr1 = [[NSString alloc] initWithFormat:@"%@%@%@%ld%@",NSLocalizedString(@"share_secret_titile_1_1",nil),dataModel.fileName,NSLocalizedString(@"share_file_more_tip",nil), _dataModel.fileListVOS.count,NSLocalizedString(@"share_file_Numbers_tip",nil)]; if(_dataModel.fileListVOS.count == 1){ copyStr1 = [[NSString alloc] initWithFormat:@"%@%@",NSLocalizedString(@"share_secret_titile_1",nil),dataModel.fileName]; } if(_dataModel.platformType == 4) { copyStr1 = [[NSString alloc] initWithFormat:@"%@%@",NSLocalizedString(@"share_secret_titile_1",nil),copyStr1]; } NSString *serUrl = shareService; NSString *shareUrl = [[NSString alloc] initWithFormat:@"%@%@",serUrl,_dataModel.token]; NSString *copyStr2 = [[NSString alloc] initWithFormat:@"%@%@",NSLocalizedString(@"share_secret_titile_2",nil),shareUrl]; NSString *copyStr3 = [[NSString alloc] initWithFormat:@"%@%@",NSLocalizedString(@"share_secret_titile_3",nil),_dataModel.extractionCode]; NSString *copyStr4 = NSLocalizedString(@"share_secret_titile_4",nil); NSString *copyTotalStr = [[NSString alloc] initWithFormat:@"%@\n%@\n%@\n%@",copyStr1,copyStr2,copyStr3,copyStr4]; if(_dataModel.platformType != 4) { copyTotalStr = [[NSString alloc] initWithFormat:@"%@\n%@\n%@",copyStr1,copyStr2,copyStr4]; } UIPasteboard* pasteboard = [UIPasteboard generalPasteboard]; pasteboard.string = copyTotalStr; [[iToast makeText:NSLocalizedString(@"copy_share_link_suc_tip",nil)] show]; } @end