554 lines
26 KiB
Objective-C
554 lines
26 KiB
Objective-C
//
|
|
// DDDynamicSendViewController.m
|
|
// DingDangApp
|
|
//
|
|
// Created by apple on 2023/6/2.
|
|
//
|
|
|
|
#import "DDDynamicSendViewController.h"
|
|
#import "ZLShowMultimedia.h"
|
|
#import "ZLPhotoActionSheet.h"
|
|
#import "ZLPhotoManager.h"
|
|
#import "DDDynamicAddPicView.h"
|
|
#import "DDDynamicPicItemView.h"
|
|
#import "FileToolsObject.h"
|
|
#import "DynamicSendLocationView.h"
|
|
#import "TZLocationManager.h"
|
|
#import "UITextView+Placeholder.h"
|
|
#import "Api+DDDynamicApi.h"
|
|
@interface DDDynamicSendViewController ()<UITextViewDelegate>
|
|
// 1:文本 2:视频 3:图片
|
|
@property (nonatomic,assign) NSInteger releaseType;
|
|
@property (nonatomic,assign) BOOL isUploading;
|
|
@property (nonatomic,strong) UIScrollView * dynamicScrollView;
|
|
@property (nonatomic,strong) DDDynamicAddPicView * itemList;
|
|
@property (nonatomic, strong) DDDynamicPicItemView *item;
|
|
@property (nonatomic, strong) DynamicSendLocationView * locationView;
|
|
//资源数组
|
|
@property (nonatomic, strong) NSArray * SelectedImgArr;
|
|
//本地图片数组
|
|
@property (nonatomic, strong) NSMutableArray * imageFileArr;
|
|
//本地图片数组
|
|
@property (nonatomic, strong) NSMutableArray * imageArr;
|
|
//视频本地首帧
|
|
@property (nonatomic,copy)NSString *VideoThumbUrl;
|
|
//视频本地地址
|
|
@property(nonatomic,copy)NSString *VideofileUrl;
|
|
//视频首帧
|
|
@property (nonatomic,copy)NSString *ReleaseVideoThumbUrl;
|
|
//视频地址
|
|
@property(nonatomic,copy)NSString *ReleaseVideoUrl;
|
|
//宽高比
|
|
@property (nonatomic, assign) CGFloat proportion;
|
|
@property (nonatomic, strong) ZLPhotoActionSheet *photoActionSheet;
|
|
@property (nonatomic,strong) UITextView * textView;
|
|
@property (nonatomic,strong) UILabel * textCountLabel;
|
|
@property (nonatomic, strong) UIButton * cancelBtn;
|
|
@property (nonatomic, assign) BOOL isLocation;
|
|
@property (nonatomic,assign) CLAuthorizationStatus authStatus;
|
|
|
|
@end
|
|
|
|
@implementation DDDynamicSendViewController
|
|
- (void)appDidBecomeActiveNotification {
|
|
if ([CLLocationManager authorizationStatus] == self.authStatus || self.authStatus == -1) {
|
|
return;
|
|
}
|
|
[self getLocation];
|
|
}
|
|
-(void)dealloc
|
|
{
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil];
|
|
}
|
|
-(DynamicSendLocationView *)locationView
|
|
{
|
|
if (!_locationView) {
|
|
_locationView = [[DynamicSendLocationView alloc]initWithFrame:CGRectMake(0, self.itemList.y + 10, kWidth, 55)];
|
|
WeakSelf(weakSelf)
|
|
_locationView.locationSwitchChangeValueBlock = ^(BOOL isLocation) {
|
|
if (isLocation && [AppDelegate getAppdelegate].isLocation == NO) {
|
|
weakSelf.locationView.itemSwitch.on = NO;
|
|
NSURL * url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
|
|
if([[UIApplication sharedApplication] canOpenURL:url]) {
|
|
NSURL*url =[NSURL URLWithString:UIApplicationOpenSettingsURLString];
|
|
if (@available(iOS 10.0, *)) {
|
|
[[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) {
|
|
}];
|
|
} else {
|
|
[[UIApplication sharedApplication] openURL:url];
|
|
}
|
|
}
|
|
}else{
|
|
weakSelf.isLocation = isLocation;
|
|
|
|
}
|
|
};
|
|
}
|
|
return _locationView;
|
|
}
|
|
- (UITextView *)textView{
|
|
if (!_textView){
|
|
_textView = [[UITextView alloc] initWithFrame:CGRectMake(10, 10, kWidth-20, 200)];
|
|
_textView.textColor = [UIColor jk_colorWithHexString:@"#333333"];
|
|
_textView.placeholder = @"请输入内容~";
|
|
_textView.placeholderColor = [UIColor jk_colorWithHexString:@"#999999"];
|
|
_textView.font = [UIFont systemFontOfSize:14];
|
|
_textView.delegate = self;
|
|
_textView.layer.cornerRadius = 7;
|
|
_textView.clipsToBounds = YES;
|
|
_textView.userInteractionEnabled = YES;
|
|
}return _textView;
|
|
}
|
|
- (UILabel *)textCountLabel{
|
|
if (!_textCountLabel){
|
|
_textCountLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, self.textView.bottom+5, kWidth-20, 40)];
|
|
_textCountLabel.textColor = [UIColor jk_colorWithHexString:@"#666666"];
|
|
_textCountLabel.font = [UIFont boldSystemFontOfSize:14];
|
|
_textCountLabel.text = @"0/300";
|
|
_textCountLabel.textAlignment = NSTextAlignmentRight;
|
|
}return _textCountLabel;
|
|
}
|
|
- (void)textViewDidChange:(UITextView *)textView{
|
|
self.textCountLabel.text = [NSString stringWithFormat:@"%lu/300",[textView.text length]];
|
|
}
|
|
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
|
|
NSString *str = [NSString stringWithFormat:@"%@%@", textView.text, text];
|
|
if (str.length > 300) {
|
|
return NO;
|
|
}
|
|
return YES;
|
|
}
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
// Do any additional setup after loading the view.
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appDidBecomeActiveNotification) name:UIApplicationDidBecomeActiveNotification object:nil];
|
|
|
|
[self getLocation];
|
|
[self defaultNavTitle:@"发布动态" hideLine:NO];
|
|
[self.customNavBar wr_setRightButtonWithTitle:@"发布" titleColor:[UIColor jk_colorWithHexString:@"#333333"]];
|
|
[self.customNavBar wr_setLeftButtonWithTitle:@"取消" titleColor:[UIColor jk_colorWithHexString:@"#333333"]];
|
|
WeakSelf(weakSelf)
|
|
self.customNavBar.onClickRightButton = ^{
|
|
if (weakSelf.isUploading) {
|
|
[ToolsObject addPopVieToText:@"正在发布中,请不要重复提交"];
|
|
return;
|
|
}
|
|
[weakSelf.view endEditing:YES];
|
|
[weakSelf releaseDynamic];
|
|
};
|
|
self.customNavBar.onClickLeftButton = ^{
|
|
[weakSelf.navigationController popViewControllerAnimated:YES];
|
|
};
|
|
self.view.backgroundColor = UIColor.whiteColor;
|
|
|
|
[self.view addSubview:self.dynamicScrollView];
|
|
[self.dynamicScrollView addSubview:self.textView];
|
|
[self.dynamicScrollView addSubview:self.textCountLabel];
|
|
[self.dynamicScrollView addSubview:self.itemList];
|
|
[self.itemList addItem:self.item];
|
|
[self.dynamicScrollView addSubview:self.locationView];
|
|
[self updateHeaderViewHeight];
|
|
|
|
self.item.playButtonClick = ^{
|
|
ZLShowMultimedia *media = [[ZLShowMultimedia alloc] init];
|
|
NSMutableArray *infos = [NSMutableArray new];
|
|
ZLMediaInfo *info = [[ZLMediaInfo alloc] init];
|
|
info.type = ZLMediaInfoTypeVideo;
|
|
info.localVideoUrl = weakSelf.VideofileUrl;
|
|
info.isLocal = YES;
|
|
[infos addObject:info];
|
|
media.infos = infos;
|
|
media.currentIndex = 0;
|
|
[media show];
|
|
};
|
|
}
|
|
- (void)getLocation {
|
|
[[TZLocationManager manager] startLocation];
|
|
self.authStatus = [CLLocationManager authorizationStatus];
|
|
if ([CLLocationManager locationServicesEnabled] == NO) {
|
|
self.authStatus = -1;
|
|
return;
|
|
}
|
|
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied ||
|
|
[CLLocationManager authorizationStatus] == kCLAuthorizationStatusRestricted) {
|
|
[AppDelegate getAppdelegate].isLocation = NO;
|
|
self.isLocation = NO;
|
|
self.locationView.itemSwitch.on = [AppDelegate getAppdelegate].isLocation;
|
|
self.isLocation = [AppDelegate getAppdelegate].isLocation;
|
|
[ToolsObject ddUploadMyLocation];
|
|
}
|
|
WeakSelf(weakSelf)
|
|
[[TZLocationManager manager] startLocationWithSuccessBlock:^(NSArray<CLLocation *> *locations) {
|
|
|
|
} failureBlock:^(NSError *error) {
|
|
|
|
} geocoderBlock:^(NSArray *geocoderArray) {
|
|
if (geocoderArray.count > 0) {
|
|
CLPlacemark * placemark = geocoderArray[0];
|
|
[AppDelegate getAppdelegate].longitude = [NSString stringWithFormat:@"%f",placemark.location.coordinate.longitude];
|
|
[AppDelegate getAppdelegate].latitude = [NSString stringWithFormat:@"%f",placemark.location.coordinate.latitude];
|
|
[AppDelegate getAppdelegate].locationCity = [NSString stringWithFormat:@"%@",placemark.locality];
|
|
[AppDelegate getAppdelegate].provinceStr = [NSString stringWithFormat:@"%@",placemark.administrativeArea];
|
|
[AppDelegate getAppdelegate].countyStr = @"";
|
|
[AppDelegate getAppdelegate].addressStr = [NSString stringWithFormat:@"%@%@%@",[ToolsObject IsNullWithObject:[AppDelegate getAppdelegate].provinceStr]?@"":[AppDelegate getAppdelegate].provinceStr,[ToolsObject IsNullWithObject:[AppDelegate getAppdelegate].locationCity]?@"":[AppDelegate getAppdelegate].locationCity,placemark.name];
|
|
weakSelf.locationView.cityLabel.text = [AppDelegate getAppdelegate].isLocation ? [AppDelegate getAppdelegate].locationCity:@"";
|
|
if (![AppDelegate getAppdelegate].isLocation) {//多次调用,只执行一次
|
|
[AppDelegate getAppdelegate].isLocation = YES;
|
|
weakSelf.isLocation = YES;
|
|
weakSelf.locationView.itemSwitch.on = [AppDelegate getAppdelegate].isLocation;
|
|
weakSelf.isLocation = [AppDelegate getAppdelegate].isLocation;
|
|
[ToolsObject ddUploadMyLocation];
|
|
}
|
|
}
|
|
}];
|
|
|
|
}
|
|
/*
|
|
#pragma mark - Navigation
|
|
|
|
// In a storyboard-based application, you will often want to do a little preparation before navigation
|
|
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
|
|
// Get the new view controller using [segue destinationViewController].
|
|
// Pass the selected object to the new view controller.
|
|
}
|
|
*/
|
|
-(void)uploadImg:(NSArray *)image andimage:(NSArray *)imageArr{
|
|
if ([ToolsObject IsNullWithObject:image]) {
|
|
return;
|
|
}
|
|
self.SelectedImgArr = image;
|
|
PHAsset *asset = image[0];
|
|
if (asset.mediaType == PHAssetMediaTypeVideo) {
|
|
self.releaseType = 2;
|
|
if (imageArr.count != 0) {
|
|
for (UIImage *images in imageArr) {
|
|
self.item.itemImage.image = images;
|
|
self.item.playButton.center = CGPointMake(self.item.size.width/2, self.item.size.height/2);
|
|
self.item.playButton.hidden = NO;
|
|
self.item.isAdd = NO;
|
|
self.item.removeButton.hidden = NO;
|
|
self.itemList.maxItem = 1;
|
|
[self.itemList addItem:self.item];
|
|
}
|
|
}
|
|
|
|
PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
|
|
options.version = PHImageRequestOptionsVersionCurrent;
|
|
options.deliveryMode = PHVideoRequestOptionsDeliveryModeAutomatic;
|
|
WeakSelf(weakSelf)
|
|
[ZLPhotoManager requestAssetFileUrl:asset complete:^(NSString * _Nonnull filePath) {
|
|
NSDictionary *opts = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:AVURLAssetPreferPreciseDurationAndTimingKey];
|
|
AVURLAsset *urlAsset = [AVURLAsset URLAssetWithURL:[NSURL URLWithString:filePath] options:opts];
|
|
NSString *path = [FileToolsObject libraryDir];
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
UIImage *coverImage = [ToolsObject getVideoFirstViewImage:[NSURL URLWithString:filePath]];
|
|
weakSelf.proportion = floor((coverImage.size.width/coverImage.size.height)*100)/100;
|
|
NSString * thumbImagePath = [NSString stringWithFormat:@"source/Dynamic/video/%@.jpg",[ToolsObject dateChangeRealtimestamp]];
|
|
weakSelf.VideoThumbUrl = [path stringByAppendingPathComponent:thumbImagePath];
|
|
[FileToolsObject createFileAtPath:weakSelf.VideoThumbUrl overwrite:YES];
|
|
NSData * thumbImageData =UIImageJPEGRepresentation(coverImage, 1.0);
|
|
[FileToolsObject writeFileAtPath:weakSelf.VideoThumbUrl content:thumbImageData];
|
|
});
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
@autoreleasepool {
|
|
[ToolsObject dd_movieFileMP4:urlAsset.URL completion:^(NSURL *Mp4FilePath) {
|
|
NSString * thumbImagePath1 = [NSString stringWithFormat:@"source/Dynamic/video/%@.mp4",[ToolsObject dateChangeRealtimestamp]];
|
|
weakSelf.VideofileUrl = [path stringByAppendingPathComponent:thumbImagePath1];
|
|
[FileToolsObject createFileAtPath:weakSelf.VideofileUrl overwrite:YES];
|
|
NSData * mp4Data = [NSData dataWithContentsOfURL:urlAsset.URL];
|
|
[FileToolsObject writeFileAtPath:weakSelf.VideofileUrl content:mp4Data];
|
|
}];
|
|
}
|
|
});
|
|
}];
|
|
}else if (asset.mediaType == PHAssetMediaTypeImage){
|
|
self.releaseType = 3;
|
|
self.item.playButton.hidden = YES;
|
|
self.item.isAdd = YES;
|
|
self.itemList.maxItem = 9;
|
|
if (imageArr.count != 0) {
|
|
for (UIImage *image in imageArr) {
|
|
DDDynamicPicItemView *item = [[DDDynamicPicItemView alloc] init];
|
|
item.itemImage.image = image;
|
|
item.removeButton.hidden = NO;
|
|
|
|
[self.itemList addItem:item];
|
|
}
|
|
}
|
|
[self updateHeaderViewHeight];
|
|
}
|
|
}
|
|
|
|
#pragma mark ---发动态
|
|
-(void)releaseDynamic
|
|
{
|
|
if ([ToolsObject IsNullWithObject:self.textView.text]) {
|
|
[ToolsObject addPopVieToText:@"请输入文字"];
|
|
return;
|
|
}
|
|
// [ToolsObject ShowSVProgressHUD:@"上传中"];
|
|
// WeakSelf(weakSelf)
|
|
// if (self.itemList.itemArray.count == 1 && self.releaseType == 2) {
|
|
// [ToolsObject uploadImageWithArr:@[self.VideoThumbUrl].mutableCopy WithRecourseType:(OSSUploadType_DynamicImage) completionHandler:^(NSMutableArray * _Nonnull urlArr) {
|
|
// weakSelf.ReleaseVideoThumbUrl = urlArr.firstObject;
|
|
// [ToolsObject uploadVideoWithFileUrl:weakSelf.VideofileUrl WithRecourseType:(OSSUploadType_DynamicVideo) completionHandler:^(id _Nonnull urlString) {
|
|
// [ToolsObject DismissSVProgressHUD];
|
|
// weakSelf.ReleaseVideoUrl = urlString;
|
|
// [weakSelf publishReuqest];
|
|
// return;
|
|
// }];
|
|
// }];
|
|
// return;
|
|
// }
|
|
// if (self.itemList.itemArray.count >0 && self.releaseType == 3) {
|
|
// NSString *path = [FileToolsObject libraryDir];
|
|
// NSMutableArray *array = [[NSMutableArray alloc] initWithArray:self.itemList.itemArray];
|
|
// [self.imageFileArr removeAllObjects];
|
|
//
|
|
// for (int i = 0; i<array.count; i++) {
|
|
// DDDynamicPicItemView *item = array[i];
|
|
// if(!item.isAdd){
|
|
// NSString * imgUrl = [NSString stringWithFormat:@"source/Dynamic/image/%@%d.jpg",[ToolsObject dateChangeRealtimestamp],i];
|
|
// [FileToolsObject createFileAtPath:[path stringByAppendingPathComponent:imgUrl] overwrite:YES];
|
|
// if (i == 0) {
|
|
// UIImage *firstImage = item.itemImage.image;
|
|
// self.proportion = floor((firstImage.size.width/firstImage.size.height)*100)/100;
|
|
// }
|
|
// NSData * thumbImageData =UIImageJPEGRepresentation(item.itemImage.image, 1.0);
|
|
// [self.imageFileArr addObject:[path stringByAppendingPathComponent:imgUrl]];
|
|
// [FileToolsObject writeFileAtPath:[path stringByAppendingPathComponent:imgUrl] content:thumbImageData];
|
|
// }
|
|
// }
|
|
// [ToolsObject uploadImageWithArr:self.imageFileArr WithRecourseType:(OSSUploadType_DynamicImage) completionHandler:^(NSMutableArray * _Nonnull urlArr) {
|
|
// [ToolsObject DismissSVProgressHUD];
|
|
// [weakSelf.imageArr removeAllObjects];
|
|
// [weakSelf.imageArr addObjectsFromArray:urlArr];
|
|
// [weakSelf publishReuqest];
|
|
// return;
|
|
// }];
|
|
// return;
|
|
// }
|
|
[self publishReuqest];
|
|
}
|
|
-(void)updateHeaderViewHeight
|
|
{
|
|
self.locationView.top = self.itemList.y + self.itemList.itemListH +10;
|
|
self.dynamicScrollView.contentSize = CGSizeMake(kWidth, self.locationView.bottom + 20);
|
|
|
|
}
|
|
-(void)publishReuqest
|
|
{
|
|
|
|
[ToolsObject ShowSVProgressHUD:@"发布中"];
|
|
NSString * uid = [AccountInfoStorage instance].getUid;
|
|
NSString * typeStr = [NSString stringWithFormat:@"%d", 0];
|
|
[Api monentsPublish:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
|
|
[ToolsObject addPopVieToText:@"发布成功"];
|
|
[self.navigationController popViewControllerAnimated:YES];
|
|
} uid:uid type:typeStr worldId:@"" content:self.textView.text resList:@[@"https://scpic.chinaz.net/files/pic/pic9/202005/zzpic24899.jpg"]];
|
|
return;
|
|
NSMutableDictionary * requestDic = [NSMutableDictionary dictionary];
|
|
[ToolsObject ShowSVProgressHUD:@"发布中"];
|
|
if (self.releaseType == 2 && ![ToolsObject IsNullWithObject:self.ReleaseVideoUrl] && ![ToolsObject IsNullWithObject:self.ReleaseVideoThumbUrl]) {
|
|
[requestDic setObject:self.ReleaseVideoUrl forKey:@"video"];
|
|
[requestDic setObject:self.ReleaseVideoThumbUrl forKey:@"cover_img"];
|
|
[requestDic setObject:@(self.proportion) forKey:@"proportion"];
|
|
[requestDic setObject:@"video" forKey:@"type_name"];
|
|
}else if (self.releaseType == 3 && self.imageArr.count>0) {
|
|
NSString *imgStr = @"";
|
|
for (int i = 0; i<self.imageArr.count; i++) {
|
|
if (i == self.imageArr.count-1) {
|
|
imgStr = [imgStr stringByAppendingString:self.imageArr[i]];
|
|
}else{
|
|
imgStr = [imgStr stringByAppendingString:self.imageArr[i]];
|
|
imgStr = [imgStr stringByAppendingString:@","];
|
|
}
|
|
}
|
|
[requestDic setObject:imgStr forKey:@"imgs"];
|
|
if (self.imageArr.count == 1) {
|
|
[requestDic setObject:@(self.proportion) forKey:@"proportion"];
|
|
}
|
|
[requestDic setObject:@"imgs" forKey:@"type_name"];
|
|
}else{
|
|
[requestDic setObject:@"text" forKey:@"type_name"];
|
|
}
|
|
if (![ToolsObject IsNullWithObject:self.textView.text]) {
|
|
[requestDic setObject:self.textView.text forKey:@"content"];
|
|
}
|
|
if (self.isLocation) {
|
|
[requestDic setObject:@(1) forKey:@"is_show_location"];
|
|
[requestDic setObject:[ToolsObject IsNullWithObject:[AppDelegate getAppdelegate].locationCity]?@"火星":[AppDelegate getAppdelegate].locationCity forKey:@"name"];
|
|
[requestDic setObject:[ToolsObject IsNullWithObject:[AppDelegate getAppdelegate].longitude]?@"":[AppDelegate getAppdelegate].longitude forKey:@"lng"];
|
|
[requestDic setObject:[ToolsObject IsNullWithObject:[AppDelegate getAppdelegate].latitude]?@"":[AppDelegate getAppdelegate].latitude forKey:@"lat"];
|
|
}else{
|
|
[requestDic setObject:@(0) forKey:@"is_show_location"];
|
|
}
|
|
|
|
WeakSelf(weakSelf)
|
|
[NetworkRequest requestPOST:@"/dynamic/publish/info" parameters:requestDic block:^(BaseResponse * _Nonnull response) {
|
|
[ToolsObject DismissSVProgressHUD];
|
|
if (response.code == 200){
|
|
[ToolsObject addPopVieToText:@"发布成功"];
|
|
for (DDDynamicPicItemView *item in weakSelf.itemList.itemArray) {
|
|
[weakSelf.itemList deleteItem:item];
|
|
}
|
|
weakSelf.textView.text= @"";
|
|
weakSelf.textCountLabel.text = @"0/300";
|
|
[weakSelf.imageArr removeAllObjects];
|
|
[weakSelf.imageFileArr removeAllObjects];
|
|
weakSelf.ReleaseVideoUrl = @"";
|
|
weakSelf.ReleaseVideoThumbUrl = @"";
|
|
weakSelf.proportion = 1;
|
|
[weakSelf.navigationController popViewControllerAnimated:YES];
|
|
}else{
|
|
weakSelf.isUploading = NO;
|
|
}
|
|
}];
|
|
|
|
}
|
|
-(DDDynamicAddPicView *)itemList
|
|
{
|
|
if (!_itemList) {
|
|
_itemList = [[DDDynamicAddPicView alloc] initWithFrame:CGRectMake(10, self.textCountLabel.bottom, kWidth-20, 0)];
|
|
_itemList.itemMargin = 0;
|
|
_itemList.scaleItemInSort = 1.3;
|
|
_itemList.isSort = YES;
|
|
_itemList.isFitItemListH = YES;
|
|
WeakSelf(weakSelf)
|
|
[_itemList setClickItemBlock:^(DDDynamicPicItemView *item) {
|
|
NSMutableArray *images = [NSMutableArray new];
|
|
for (DDDynamicPicItemView *item in weakSelf.itemList.itemArray) {
|
|
if (!item.isAdd) {
|
|
[images addObject:item];
|
|
}
|
|
}
|
|
if (item.isAdd) {
|
|
if (weakSelf.SelectedImgArr.count) {
|
|
PHAsset *asset = weakSelf.SelectedImgArr[0];
|
|
if (asset.mediaType == PHAssetMediaTypeVideo) {
|
|
weakSelf.releaseType = 2;
|
|
weakSelf.photoActionSheet.configuration.allowTakePhotoInLibrary = NO;
|
|
weakSelf.photoActionSheet.configuration.allowSelectImage = NO;
|
|
weakSelf.photoActionSheet.configuration.allowSelectVideo = YES;
|
|
weakSelf.photoActionSheet.configuration.maxVideoDuration = 15.0f;
|
|
weakSelf.photoActionSheet.configuration.maxSelectCount = 1;
|
|
[weakSelf.photoActionSheet showPhotoLibrary];
|
|
}else if (asset.mediaType == PHAssetMediaTypeImage) {
|
|
weakSelf.releaseType = 3;
|
|
weakSelf.photoActionSheet.configuration.allowTakePhotoInLibrary = NO;
|
|
weakSelf.photoActionSheet.configuration.maxSelectCount = 9 - images.count;
|
|
weakSelf.photoActionSheet.configuration.allowSelectImage = YES;
|
|
weakSelf.photoActionSheet.configuration.allowSelectVideo = NO;
|
|
[weakSelf.photoActionSheet showPhotoLibrary];
|
|
}
|
|
}else{
|
|
weakSelf.photoActionSheet.configuration.allowSelectImage = YES;
|
|
weakSelf.photoActionSheet.configuration.allowSelectVideo = YES;
|
|
weakSelf.photoActionSheet.configuration.maxSelectCount = 9;
|
|
weakSelf.photoActionSheet.configuration.mutuallyExclusiveSelectInMix = YES;
|
|
[weakSelf.photoActionSheet showPhotoLibrary];
|
|
}
|
|
}else{
|
|
if (weakSelf.SelectedImgArr.count) {
|
|
PHAsset *asset = weakSelf.SelectedImgArr[0];
|
|
if (asset.mediaType == PHAssetMediaTypeImage) {
|
|
if (images.count != 0) {
|
|
ZLShowMultimedia *media = [[ZLShowMultimedia alloc] init];
|
|
NSMutableArray *infos = [NSMutableArray new];
|
|
for (DDDynamicPicItemView *item in images) {
|
|
ZLMediaInfo *info = [[ZLMediaInfo alloc] init];
|
|
info.type = ZLMediaInfoTypePhoto;
|
|
info.image = item.itemImage.image;
|
|
info.isLocal = YES;
|
|
[infos addObject:info];
|
|
}
|
|
media.infos = infos;
|
|
media.currentIndex = item.tag;
|
|
[media show];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}];
|
|
|
|
_itemList.deleteItemBlock = ^(DDDynamicPicItemView *item) {
|
|
DDDynamicPicItemView *lastItem = [weakSelf.itemList.itemArray lastObject];
|
|
NSMutableArray *images = [NSMutableArray new];
|
|
for (DDDynamicPicItemView *item in weakSelf.itemList.itemArray) {
|
|
if (!item.isAdd) {
|
|
[images addObject:item];
|
|
}
|
|
}
|
|
if (images.count ==0) {
|
|
weakSelf.SelectedImgArr = nil;
|
|
}
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
if (!lastItem.isAdd) {
|
|
DDDynamicPicItemView *item = [[DDDynamicPicItemView alloc] init];
|
|
item.backgroundColor = [UIColor clearColor];
|
|
item.itemImage.image = [UIImage imageNamed:@"myinfo_43"];
|
|
item.isAdd = YES;
|
|
[weakSelf.itemList addItem:item];
|
|
}
|
|
[weakSelf updateHeaderViewHeight];
|
|
});
|
|
};
|
|
}
|
|
return _itemList;
|
|
}
|
|
|
|
-(DDDynamicPicItemView *)item
|
|
{
|
|
if (!_item) {
|
|
_item = [[DDDynamicPicItemView alloc] init];
|
|
_item.itemImage.image = [UIImage imageNamed:@"myinfo_43"];
|
|
_item.isAdd = YES;
|
|
}
|
|
return _item;
|
|
}
|
|
-(ZLPhotoActionSheet *)photoActionSheet
|
|
{
|
|
if (!_photoActionSheet) {
|
|
_photoActionSheet = [[ZLPhotoActionSheet alloc] init];
|
|
_photoActionSheet.configuration.allowSelectImage = YES;
|
|
_photoActionSheet.configuration.allowSelectGif = NO;
|
|
_photoActionSheet.configuration.allowSelectVideo = YES;
|
|
_photoActionSheet.configuration.maxSelectCount = 9;
|
|
_photoActionSheet.configuration.mutuallyExclusiveSelectInMix = YES;
|
|
_photoActionSheet.configuration.bottomBtnsNormalBgColor = [UIColor jk_colorWithHexString:@"#f9f9f9"];
|
|
_photoActionSheet.configuration.bottomBtnsDisableBgColor = [UIColor jk_colorWithHexString:@"#f9f9f9"];
|
|
_photoActionSheet.configuration.indexLabelBgColor = [UIColor jk_colorWithHexString:@"#f9f9f9"];
|
|
_photoActionSheet.configuration.maxVideoDuration = 30.0f;
|
|
_photoActionSheet.sender = self;
|
|
WeakSelf(weakSelf)
|
|
[_photoActionSheet setSelectImageBlock:^(NSArray<UIImage *> * _Nonnull images, NSArray<PHAsset *> * _Nonnull assets, BOOL isOriginal) {
|
|
[weakSelf uploadImg:assets andimage:images];
|
|
}];
|
|
}
|
|
return _photoActionSheet;
|
|
}
|
|
-(NSMutableArray *)imageFileArr
|
|
{
|
|
if (!_imageFileArr) {
|
|
_imageFileArr = [NSMutableArray array];
|
|
}
|
|
return _imageFileArr;
|
|
}
|
|
-(NSMutableArray *)imageArr
|
|
{
|
|
if (!_imageArr) {
|
|
_imageArr = [NSMutableArray array];
|
|
}
|
|
return _imageArr;
|
|
}
|
|
- (UIScrollView *)dynamicScrollView{
|
|
if (!_dynamicScrollView){
|
|
_dynamicScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, DDNavigationBarHeight(), kWidth, kHeight - DDNavigationBarHeight()-KTABBAR_H-20)];
|
|
_dynamicScrollView.backgroundColor = UIColor.whiteColor;
|
|
}return _dynamicScrollView;
|
|
}
|
|
@end
|