KCSP/KuaiCunShiPin/KuaiCunShiPin/Main/首页/ShiPingHao/view/ShiPingHaoSPView.m

647 lines
24 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.

//
// ShiPingHaoSPView.m
// ProductApp
//
// Created by pgj on 2025/4/3.
//
#import "ShiPingHaoSPView.h"
#import "ShiPingZBHFVideoCollectionViewCell.h"
#import "ImagesConnectManager.h"
#import "NomoAlterView.h"
#import "GongGongNetManager.h"
#import "HuiYuanZXViewController.h"
#import "SDImageCache.h"
#import "XiaZaiManager.h"
#import "BaoCunAlterView.h"
#import "KCSPNetManager.h"
#import "XLPhotoBrowser.h"
#import "DynamicVideoViewController.h"
#import "IJKPlayerPlayViewController.h"
@interface ShiPingHaoSPView ()<DZNEmptyDataSetDelegate,DZNEmptyDataSetSource,UICollectionViewDelegate,UICollectionViewDataSource>
///
@property (nonatomic , strong) UICollectionView *collect;
///
@property (nonatomic , strong) UIView *viewbottom;
///
@property (nonatomic , strong) UIButton *btquanxuan;
@end
@implementation ShiPingHaoSPView
-(id)initWithFrame:(CGRect)frame
{
if(self = [super initWithFrame:frame])
{
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 addSubview:collect];
[collect mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.top.equalTo(self);
make.bottom.equalTo(self).offset(-TabHeight-20);
}];
[collect registerClass:[ShiPingZBHFVideoCollectionViewCell class] forCellWithReuseIdentifier:@"ShiPingZBHFVideoCollectionViewCell"];
[collect setEmptyDataSetDelegate:self];
[collect setEmptyDataSetSource:self];
_collect = collect;
collect.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
self.backRef();
[self.collect.mj_header endRefreshing];
}];
UIView *viewbottom = [[UIView alloc] init];
[viewbottom setBackgroundColor:RGBCOLOR(34, 34, 34)];
[self addSubview:viewbottom];
[viewbottom mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(collect.mas_bottom);
make.right.left.bottom.equalTo(self);
}];
[viewbottom setHidden:YES];
[self drawbottomView:viewbottom];
_viewbottom = viewbottom;
}
return self;
}
-(void)setArrdata:(NSMutableArray *)arrdata
{
_arrdata = arrdata;
///
if(arrdata.count>0)
{
if([UserDetailModel zhiFuState])
{
[self.viewbottom setHidden:NO];
}
}
else
{
[self.viewbottom setHidden:YES];
}
if(arrdata.count==1)
{
KCSPMaterialsModelDataMaterialImage *model = self.arrdata[0];
model.select = YES;
}
self.btquanxuan.selected = NO;
[self.collect reloadData];
}
-(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(KCSPMaterialsModelDataMaterialImage *model in self.arrdata)
{
model.select = sender.selected;
}
[self.collect reloadData];
}
-(void)relayAction
{
if([UserDetailModel pushDengLuVC:self.viewController ispush:YES]==NO)return;;
[ImagesConnectManager getXCQuanXian:^(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([UserDetailModel pushDengLuVC:self.viewController ispush:YES]==NO)return;;
[ImagesConnectManager getXCQuanXian:^(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)delAction:(UIButton *)sender
{
if(sender.tag>=self.arrdata.count)return;
[NomoAlterView showInfo:@"是否删除提取的视频" SelectTag:^(NSInteger tag) {
if(tag==1)
{
KCSPMaterialsModelDataMaterialImage *model = self.arrdata[sender.tag];
///请求接口
[KCSPNetManager requestWeixinVideoLogDelData:self logId:model.logid Callback:^(BOOL state, BaseModel *responseObject, NSString * _Nullable describle) {
if(state)
{
[self.arrdata removeObject:model];
[self.collect reloadData];
}
else
{
[HXHud showMessage:responseObject.message afterDelayType:1];
}
}];
}
}];
}
-(void)bofangAction:(UIButton *)sender
{
if(sender.tag>=self.arrdata.count)return;
KCSPMaterialsModelDataMaterialImage *model = self.arrdata[sender.tag];
if([Tools isStringnil:model.origin_url].length==0&&[Tools isStringnil:model.url].length==0)return;
if((model.headers==nil || model.headers.allKeys.count==0) && model.play.intValue == 1)
{
// DynamicVideoViewController *vc = [[DynamicVideoViewController alloc] init];
//
// [vc setdataArray:[NSMutableArray arrayWithObject:model.url] index:0];
//
// [vc.navigationView setTitle:model.title titleColor:[UIColor whiteColor]];
// [self.viewController.navigationController pushViewController:vc animated:NO];
// [vc show];
IJKPlayerPlayViewController *vc = [[IJKPlayerPlayViewController alloc] init];
vc.strurl = model.url;
[self.viewController.navigationController pushViewController:vc animated:YES];
}
}
#pragma mark - UICollectionView
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return self.arrdata.count;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
ShiPingZBHFVideoCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ShiPingZBHFVideoCollectionViewCell" forIndexPath:indexPath];
cell.type = self.type;
cell.model = self.arrdata[indexPath.row];
[cell.btdel setTag:indexPath.row];
[cell.btdel addTarget:self action:@selector(delAction:) forControlEvents:UIControlEventTouchUpInside];
[cell.btbofang setTag:indexPath.row];
[cell.btbofang addTarget:self action:@selector(bofangAction:) forControlEvents:UIControlEventTouchUpInside];
return cell;
}
//定义每个section的间距
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
return UIEdgeInsetsMake(0, 16, 0, 16);
}
//纵向cell间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
return 10;
}
//cell 间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout ForSectionAtIndex:(NSInteger)section{
return 10;
}
// 定义每个UICollectionViewCell 的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
float fw = (UISCREEN_WIDTH-42)/2.0;
return CGSizeMake(fw, fw*260/167.0);
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
///做选中操作
KCSPMaterialsModelDataMaterialImage *model = self.arrdata[indexPath.row];
model.select = !model.select;
[self.collect reloadData];
NSString *strvalue = @"image";
if(self.type==1)
{
strvalue = @"video";
}
[UserDetailModel pushActionInfo:0 key:@"client.material.select" value:strvalue extra:[NSString stringWithFormat:@"%@",[NSNumber numberWithBool:model.select]]];
BOOL isqx = [self getQuanXuan];
self.btquanxuan.selected = isqx;
if([UserDetailModel zhiFuState]==NO&&self.type==0)
{
[XLPhotoBrowser showPhotoBrowserWithImages:[NSMutableArray arrayWithObject:model.url] currentImageIndex:0];
}
}
-(BOOL)getQuanXuan
{
BOOL isqx = YES;
for(KCSPMaterialsModelDataMaterialImage *model in self.arrdata)
{
if(model.select == NO)
{
isqx = NO;
break;
}
}
return isqx;
}
#pragma mark - DZNEmptyDataSetSource
- (UIView *)customViewForEmptyDataSet:(UIScrollView *)scrollView
{
UIView *viewback = [[UIView alloc] init];
NSLayoutConstraint *heightConstraint = [NSLayoutConstraint constraintWithItem:viewback attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:UISCREEN_HEIGHT];
[viewback addConstraint:heightConstraint];
[viewback setBackgroundColor:[UIColor clearColor]];
[viewback setUserInteractionEnabled:YES];
UILabel *lbname = [[UILabel alloc] init];
[lbname setText:@"操作步骤:"];
[lbname setTextColor:RGBACOLOR(255, 255, 255, 0.9)];
[lbname setTextAlignment:NSTextAlignmentLeft];
[lbname setFont:[UIFont systemFontOfSize:14]];
[viewback addSubview:lbname];
[lbname mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.offset(26);
make.top.offset(100);
}];
UILabel *lbone = [[UILabel alloc] init];
[lbone setText:@"1、点击【添加助手】跳转进入微信自动添加快存助手。"];
[lbone setTextColor:RGBACOLOR(255, 255, 255, 0.6)];
[lbone setTextAlignment:NSTextAlignmentLeft];
[lbone setFont:[UIFont systemFontOfSize:12]];
[lbone setNumberOfLines:0];
[viewback addSubview:lbone];
[lbone mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(lbname);
make.right.equalTo(viewback).offset(-26);
make.top.equalTo(lbname.mas_bottom).offset(9);
}];
UILabel *lbtwo = [[UILabel alloc] init];
[lbtwo setText:@"2、进入微信视频号选择视频分享至-客服消息-快存助手。"];
[lbtwo setTextColor:RGBACOLOR(255, 255, 255, 0.6)];
[lbtwo setTextAlignment:NSTextAlignmentLeft];
[lbtwo setFont:[UIFont systemFontOfSize:12]];
[lbtwo setNumberOfLines:0];
[viewback addSubview:lbtwo];
[lbtwo mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(lbname);
make.right.equalTo(viewback).offset(-26);
make.top.equalTo(lbone.mas_bottom).offset(8);
}];
UILabel *lbthree = [[UILabel alloc] init];
[lbthree setText:@"3、返回【快存视频APP】微信视频号页面下拉刷新即可 微信号视频。"];
[lbthree setTextColor:RGBACOLOR(255, 255, 255, 0.6)];
[lbthree setTextAlignment:NSTextAlignmentLeft];
[lbthree setFont:[UIFont systemFontOfSize:12]];
[lbthree setNumberOfLines:0];
[viewback addSubview:lbthree];
[lbthree mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(lbname);
make.right.equalTo(viewback).offset(-26);
make.top.equalTo(lbtwo.mas_bottom).offset(8);
}];
return viewback;
}
- (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView
{
return YES;
}
-(NSMutableArray *)getSelect
{
NSMutableArray *arr = [NSMutableArray new];
for(KCSPMaterialsModelDataMaterialImage *model in self.arrdata)
{
if(model.select)
{
[arr addObject:model];
}
}
return arr;
}
///权限校验 0 分享 1保存
-(void)getQuanXian:(int)type
{
[GongGongNetManager getUserAuthinfoData:self scene:@"wechat" Callback:^(BOOL state, KCSPUserRZModel *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_wechat_video";
[self.viewController.navigationController pushViewController:vc animated:YES];
[UserDetailModel pushActionInfo:0 key:@"client.jump.to.member.recharge" value:@"download_wechat_video" extra:@""];
}
}
else
{
[HXHud showMessage:describle afterDelayType:0];
}
}];
}
///权限上报
-(void)upDataUserState
{
[GongGongNetManager postUserAuthPostinfoData:self scene:@"wechat" count:@"1" Callback:^(BOOL state, id _Nullable responseObject, NSString * _Nullable describle) {
}];
}
-(void)shareData
{
NSMutableArray *activityItems = [NSMutableArray new];
if(self.type==0)
{
NSMutableArray *arr = [self getSelect];
if(arr.count==0)
{
[HXHud showMessage:@"请选择分享数据" afterDelayType:0];
return;
}
__block int i = 0;
__block float allSize = 0.0;
for(KCSPMaterialsModelDataMaterialImage *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 upDataUserState];
[self showAlter:activityItems time:0.1];
[UserDetailModel pushActionInfo:0 key:@"client.dialog.confirm.save.file" value:@"图片" extra:@""];
}
}];
}
}
else if(self.type==1)
{
NSMutableArray *arr = [self getSelect];
if(arr.count>1)
{
[HXHud showMessage:@"每次只能转发一个视频" afterDelayType:0];
return;
}
if(arr.count==0)
{
[HXHud showMessage:@"请选择分享数据" afterDelayType:0];
return;
}
KCSPMaterialsModelDataMaterialImage *modeltt = arr.firstObject;
[[XiaZaiManager shareManager] xiaZaiManagerInfo:arr logid:modeltt.logid Success:^(NSMutableArray * _Nonnull arrPath) {
if(arrPath.count==0)return;
[self upDataUserState];
if([arrPath[0] isKindOfClass:[PHAsset class]])
{
PHAsset *asset = arrPath[0];
NSArray *arr = [asset.localIdentifier componentsSeparatedByString:@"/"];
if(arr.count>0)
{
NSString *strtmpe = [NSString stringWithFormat:@"assets-library://asset/asset.MP4?id=%@&ext=MP4",arr[0]];
[self showAlter:[NSMutableArray arrayWithObject:[NSURL URLWithString:strtmpe]] time:0.01];
}
else
{
PHVideoRequestOptions *optionV = [[PHVideoRequestOptions alloc] init];
[[PHImageManager defaultManager] requestAVAssetForVideo:asset options:optionV resultHandler:^(AVAsset * _Nullable asset, AVAudioMix * _Nullable audioMix, NSDictionary * _Nullable info) {
AVURLAsset *assettemp = (AVURLAsset *)asset;
dispatch_async(dispatch_get_main_queue(), ^{
NSString *strtmpe = assettemp.URL.absoluteString;
[self showAlter:[NSMutableArray arrayWithObject:[NSURL URLWithString:strtmpe]] time:0.01];
});
}];
}
}
else
{
if(arr.count>0)
{
NSMutableArray *arrtemp = [NSMutableArray array];
[arrtemp addObject:arrPath.firstObject];
[self showAlter:arrtemp time:0.01];
}
}
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
self.backRef();
});
} issave:NO];
}
}
-(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.viewController presentViewController:activityVC animated:YES completion:^{
}];
});
}
-(void)saveData
{
switch (self.type) {
case 0:
{
NSMutableArray *arr = [self getSelect];
if(arr.count==0)
{
[HXHud showMessage:@"请选择 数据" afterDelayType:0];
return;
}
[KCSPHUDAlterView showView:[UIApplication sharedApplication].delegate.window frame:CGSizeMake(280, 200) title:@""];
[UserDetailModel pushActionInfo:0 key:@"client.download.file" value:@"image" extra:[arr yy_modelToJSONString]];
for(int i=0; i < arr.count; i++){
KCSPMaterialsModelDataMaterialImage *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;
}
[ImagesConnectManager saveItem: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(), ^{
[KCSPHUDAlterView dismis];
[BaoCunAlterView showName:@"已保存到系统相册中" back:^(NSInteger itag) {
if(itag==1)
{
[Tools gotuxc];
}
}];
[UserDetailModel pushActionInfo:0 key:@"client.dialog.confirm.save.file" value:@"图片" extra:@""];
});
}
}];
}
}
break;
case 1:
{///视频 处理 记得header
NSMutableArray *arr = [self getSelect];
if(arr.count==0)
{
[HXHud showMessage:@"请选择 数据" afterDelayType:0];
return;
}
[[XiaZaiManager shareManager] xiaZaiManagerInfo:arr Success:^(NSMutableArray * _Nonnull arrPath) {
[self upDataUserState];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
self.backRef();
});
} issave:YES];
}
break;
default:
break;
}
}
@end