KCSP/ProductApp/ProductApp/ProductMain/首页/链接提取/图片/UrlXiaZaiTPViewController.m

445 lines
16 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// UrlXiaZaiTPViewController.m
// ProductApp
//
// Created by 工作 on 2025/4/2.
//
#import "UrlXiaZaiTPViewController.h"
#import "UrlXiaZaiTPCollectionViewCell.h"
#import "XiaZaiAlter.h"
#import "BaoCunAlterView.h"
#import "ZhuanShiAlterView.h"
#import "ImageSaveManager.h"
#import "NomoAlterView.h"
#import "PublicNetWorkManager.h"
#import "HuiYuanZXViewController.h"
#import "SDImageCache.h"
#import "NetWorkManager.h"
@interface UrlXiaZaiTPViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,DZNEmptyDataSetDelegate,DZNEmptyDataSetSource>
@property (nonatomic , strong) UICollectionView *collect;
///
@property (nonatomic , strong) UIView *viewbottom;
///
@property (nonatomic , strong) UIButton *btquanxuan;
@end
@implementation UrlXiaZaiTPViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self.view setBackgroundColor:RGBCOLOR(20, 20, 20)];
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.minimumLineSpacing = 0;
layout.minimumInteritemSpacing = 0;
UICollectionView *collect = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
[collect setDelegate:self];
[collect setDataSource:self];
[collect setShowsVerticalScrollIndicator:NO];
[collect setBackgroundColor:[UIColor clearColor]];
[self.view addSubview:collect];
[collect mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.top.equalTo(self.view);
make.bottom.equalTo(self.view).offset(-TabHeight-20);
}];
[collect registerClass:[UrlXiaZaiTPCollectionViewCell class] forCellWithReuseIdentifier:@"UrlXiaZaiTPCollectionViewCell"];
[collect setEmptyDataSetDelegate:self];
[collect setEmptyDataSetSource:self];
_collect = collect;
UIView *viewbottom = [[UIView alloc] init];
[viewbottom setBackgroundColor:RGBCOLOR(34, 34, 34)];
[self.view addSubview:viewbottom];
[viewbottom mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(collect.mas_bottom);
make.right.left.equalTo(self.view);
make.bottom.equalTo(self.view);
}];
[viewbottom setHidden:YES];
[self drawbottomView:viewbottom];
_viewbottom = viewbottom;
if(self.arrdata.count>0)
{
if([UserInfoModel PayWXQuanXian])
{
[self.viewbottom setHidden:NO];
}
}
}
-(void)drawbottomView:(UIView *)view
{
UIButton *btquanxuan = [[UIButton alloc] init];
[btquanxuan setTitle:@"全选" forState:UIControlStateNormal];
[btquanxuan setTitleColor:RGBACOLOR(255, 255, 255, 0.9) forState:UIControlStateNormal];
[btquanxuan.titleLabel setFont:[UIFont systemFontOfSize:16]];
[btquanxuan setImage:[UIImage imageNamed:@"xiazai_selectN"] forState:UIControlStateNormal];
[btquanxuan setImage:[UIImage imageNamed:@"xiazai_selectY"] forState:UIControlStateSelected];
[view addSubview:btquanxuan];
[btquanxuan mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.offset(10);
make.left.offset(20);
make.height.offset(40);
make.width.offset(80);
}];
[btquanxuan setIconInLeftWithSpacing:4];
[btquanxuan addTarget:self action:@selector(quanxuanAction:) forControlEvents:UIControlEventTouchUpInside];
_btquanxuan = btquanxuan;
UIButton *btsave = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 120, 40)];
[btsave setTitle:@"保存" forState:UIControlStateNormal];
[btsave setTitleColor:RGBACOLOR(255, 255, 255, 0.9) forState:UIControlStateNormal];
[btsave.titleLabel setFont:[UIFont systemFontOfSize:15]];
[view addSubview:btsave];
[btsave mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.bottom.equalTo(btquanxuan);
make.right.equalTo(view).offset(-16);
make.width.offset(120);
}];
[btsave.layer setMasksToBounds:YES];
[btsave.layer setCornerRadius:20];
[btsave addTarget:self action:@selector(saveAction) forControlEvents:UIControlEventTouchUpInside];
[Tools changedView:btsave colors:@[(id)RGBCOLOR(246, 44, 108).CGColor,(id)RGBCOLOR(252, 79, 84).CGColor] startPoint:CGPointMake(0, 0) endPoint:CGPointMake(1, 0)];
UIButton *btrelay = [[UIButton alloc] init];
[btrelay setTitle:@"转发" forState:UIControlStateNormal];
[btrelay setTitleColor:RGBACOLOR(255, 255, 255, 0.5) forState:UIControlStateNormal];
[btrelay.titleLabel setFont:[UIFont systemFontOfSize:15]];
[view addSubview:btrelay];
[btrelay mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.bottom.equalTo(btquanxuan);
make.right.equalTo(btsave.mas_left).offset(-12);
make.width.offset(120);
}];
[btrelay setBackgroundColor:RGBCOLOR(51, 51, 51)];
[btrelay.layer setMasksToBounds:YES];
[btrelay.layer setCornerRadius:20];
[btrelay addTarget:self action:@selector(relayAction) forControlEvents:UIControlEventTouchUpInside];
}
-(void)quanxuanAction:(UIButton *)sender
{
sender.selected = !sender.selected;
//
for(MaterialModelDataMaterialImage *model in self.arrdata)
{
model.select = sender.selected;
}
[self.collect reloadData];
}
-(void)relayAction
{
if([UserInfoModel pushLoinVC:self ispush:YES]==NO)return;;
[ImageSaveManager getSaveIn:^(BOOL issave) {
dispatch_async(dispatch_get_main_queue(), ^{
if(issave)
{
[self getQuanXian:0];
}
else
{
[NomoAlterView showInfo:@"无相册权限请到设置中开启APP相册权限再保存照片>所有照片 权限" SelectTag:^(NSInteger tag) {
if(tag==1)
{
[Tools pushAppSet];
}
}];
}
});
}];
}
-(void)saveAction
{
if([UserInfoModel pushLoinVC:self ispush:YES]==NO)return;;
[ImageSaveManager getSaveIn:^(BOOL issave) {
dispatch_async(dispatch_get_main_queue(), ^{
if(issave)
{
[self getQuanXian:1];
}
else
{
[NomoAlterView showInfo:@"无相册权限请到设置中开启APP相册权限再保存照片>所有照片 权限" SelectTag:^(NSInteger tag) {
if(tag==1)
{
[Tools pushAppSet];
}
}];
}
});
}];
}
-(void)setArrdata:(NSMutableArray *)arrdata
{
_arrdata = arrdata;
if(arrdata.count>0)
{
if([UserInfoModel PayWXQuanXian])
{
[self.viewbottom setHidden:NO];
}
}
else
{
[self.viewbottom setHidden:YES];
}
[self.collect reloadData];
}
#pragma mark - UICollectionView
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return self.arrdata.count;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UrlXiaZaiTPCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"UrlXiaZaiTPCollectionViewCell" forIndexPath:indexPath];
cell.model = self.arrdata[indexPath.row];
return cell;
}
//定义每个section的间距
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
return UIEdgeInsetsMake(20, 16, 0, 16);
}
//纵向cell间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
return 15;
}
//cell 间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout ForSectionAtIndex:(NSInteger)section{
return 15;
}
// 定义每个UICollectionViewCell 的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
if(self.arrdata.count<=2)
{
return CGSizeMake(UISCREEN_WIDTH-32, 150);///单个视频高43
}
else
{
float fw = (UISCREEN_WIDTH-47)/2.0;
return CGSizeMake(fw, fw);
}
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
///做选中操作
MaterialModelDataMaterialImage *model = self.arrdata[indexPath.row];
model.select = !model.select;
[self.collect reloadData];
NSString *strvalue = @"image";
[UserInfoModel shijianShangBao:0 key:@"client.material.select" value:strvalue extra:[NSString stringWithFormat:@"%@",[NSNumber numberWithBool:model.select]]];
BOOL isqx = [self getQuanXuan];
self.btquanxuan.selected = isqx;
}
-(BOOL)getQuanXuan
{
BOOL isqx = YES;
for(MaterialModelDataMaterialImage *model in self.arrdata)
{
if(model.select == NO)
{
isqx = NO;
break;
}
}
return isqx;
}
-(NSMutableArray *)getSelect
{
NSMutableArray *arr = [NSMutableArray new];
for(MaterialModelDataMaterialImage *model in self.arrdata)
{
if(model.select)
{
[arr addObject:model];
}
}
return arr;
}
#pragma mark - DZNEmptyDataSetSource
- (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
{
NSString *str = @"暂无图片";
return [Tools arrstring:str andstart:0 andend:(int)str.length andfont:[UIFont systemFontOfSize:14] andcolor:RGBCOLOR(158, 158, 158)];
}
- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
{
NSString *strimg = @"jl_暂无图片";
return [UIImage imageNamed:strimg];
}
///权限校验 0 分享 1保存
-(void)getQuanXian:(int)type
{
[PublicNetWorkManager requestUserAuthData:self.view scene:@"download" Callback:^(BOOL state, UserAuthModel *responseObject, NSString * _Nullable describle) {
if(state)
{
if(responseObject.data.auth.boolValue == YES)
{
if(type==0)
{
[self shareData];
}
else
{
[self saveData];
}
}
else
{///跳转充值页
HuiYuanZXViewController *vc = [[HuiYuanZXViewController alloc] init];
vc.source = @"download_material";
[self.navigationController pushViewController:vc animated:YES];
[UserInfoModel shijianShangBao:0 key:@"client.jump.to.member.recharge" value:@"download_material" extra:@""];
}
}
else
{
[HXHud showMessage:describle afterDelayType:0];
}
}];
}
///权限上报
-(void)upDataUserState
{
[PublicNetWorkManager requestUserAuthPostData:self.view scene:@"download" count:@"1" Callback:^(BOOL state, id _Nullable responseObject, NSString * _Nullable describle) {
}];
}
-(void)shareData
{
NSMutableArray *arr = [self getSelect];
if(arr.count==0)
{
[HXHud showMessage:@"请选择分享数据" afterDelayType:0];
return;
}
NSMutableArray *activityItems = [NSMutableArray new];
__block int i = 0;
__block float allSize = 0.0;
for(MaterialModelDataMaterialImage *model in arr)
{
SDImageCache *imageCache = [SDImageCache sharedImageCache];
NSString *imageKey = model.url;
[imageCache queryCacheOperationForKey:imageKey done:^(UIImage * _Nullable image, NSData * _Nullable data, SDImageCacheType cacheType) {
i++;
if(image)
{
NSData *datatemp = UIImageJPEGRepresentation(image, 1);
if(datatemp==nil)
{
datatemp = UIImagePNGRepresentation(image);
}
if(datatemp)
{
allSize+=datatemp.length;
}
else
{
allSize+=1;
}
[activityItems addObject:image];
}
if(i>=arr.count)
{
[self showAlter:activityItems time:0.1];
[UserInfoModel shijianShangBao:0 key:@"client.dialog.confirm.save.file" value:@"图片" extra:@""];
[NetWorkManager requestMaterialUpdataData:self.view logid:self.logid status:@"2" message:@"" size:[NSString stringWithFormat:@"%.0lf",allSize] Callback:^(BOOL state, id _Nullable responseObject, NSString * _Nullable describle) {
}];
}
}];
}
}
-(void)showAlter:(NSMutableArray *)activityItems time:(float)time
{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(time * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
//__weak typeof(self) weakself = self;
activityVC.completionWithItemsHandler = ^(UIActivityType _Nullable activityType, BOOL completed, NSArray * _Nullable returnedItems, NSError * _Nullable activityError) {
//上面判断是写的失败详细内容,若需求不需要这么详细,直接下面这段代码就可以
if (activityType != nil && completed) {
//成功
}else{
//失败
}
};
[self presentViewController:activityVC animated:YES completion:^{
}];
});
}
-(void)saveData
{
NSMutableArray *arr = [self getSelect];
if(arr.count==0)
{
[HXHud showMessage:@"请选择下载数据" afterDelayType:0];
return;
}
[LoadAlterView showView];
[UserInfoModel shijianShangBao:0 key:@"client.download.file" value:@"image" extra:[arr yy_modelToJSONString]];
for(int i=0; i < arr.count; i++){
MaterialModelDataMaterialImage *model = arr[i];
SDImageCache *imageCache = [SDImageCache sharedImageCache];
NSString *imageKey = model.url;
__block float allSize = 0.0;
[imageCache queryCacheOperationForKey:imageKey done:^(UIImage * _Nullable image, NSData * _Nullable data, SDImageCacheType cacheType) {
if(image){
NSData *datatemp = UIImageJPEGRepresentation(image, 1);
if(datatemp==nil)
{
datatemp = UIImagePNGRepresentation(image);
}
if(datatemp)
{
allSize+=datatemp.length;
}
else
{
allSize+=1;
}
[ImageSaveManager save:image back:^(PHAsset * _Nonnull asset) {
}];
}
if(i==arr.count-1){
[self upDataUserState];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[LoadAlterView dismis];
[BaoCunAlterView showName:@"已保存到系统相册中" back:^(NSInteger itag) {
if(itag==1)
{
[Tools gotuxc];
}
}];
[UserInfoModel shijianShangBao:0 key:@"client.dialog.confirm.save.file" value:@"图片" extra:@""];
[NetWorkManager requestMaterialUpdataData:self.view logid:self.logid status:@"2" message:@"" size:[NSString stringWithFormat:@"%.0lf",allSize] Callback:^(BOOL state, id _Nullable responseObject, NSString * _Nullable describle) {
}];
});
}
}];
}
}
@end