// // JXMyFeedVc.m // shiku_im // // Created by 123 on 2020/5/23. // Copyright © 2020 Reese. All rights reserved. // #define insert_photo_tag -100000 #import "JXMyFeedVc.h" #import "JXMyFeedCell.h" #import "addMsgVC.h" #import "RITLPhotosViewController.h" #import "GWLPhotoLibrayController.h" #import "UIView+LK.h" #import "JXFeedShowView.h" #import "JXCameraVC.h" #import "JXMediaObject.h" #import "addMsgVC.h" #import "AppDelegate.h" #import "JXImageView.h" #import "JXServer.h" #import "JXConnection.h" #import "ImageResize.h" #import "UIFactory.h" #import "JXTableView.h" #import "QBImagePickerController.h" #import "SBJsonWriter.h" #import "recordVideoViewController.h" #import "JXTextView.h" #import "JXMediaObject.h" #import "LXActionSheet.h" #import "myMediaVC.h" #import "JXLocationVC.h" #import "JXMapData.h" #import "WhoCanSeeViewController.h" #import "JXSelFriendVC.h" #import "JXSelectFriendsVC.h" #import "RITLPhotosViewController.h" #import "RITLPhotosDataManager.h" #import "JXMyFile.h" #import "UIImageView+FileType.h" #import "JXFileDetailViewController.h" #import "JXShareFileObject.h" #import "webpageVC.h" #import "JXSelectorVC.h" #ifdef Meeting_Version #ifdef Live_Version #import "JXSmallVideoViewController.h" #endif #endif #import "JXActionSheetVC.h" #import "JXCameraVC.h" #import "QCheckBox.h" #import "JXSelectCoverVC.h" @interface JXMyFeedVc () @property (weak, nonatomic) IBOutlet UITableView *tableView; @property (nonatomic,strong) NSMutableArray *dataArr; @property (nonatomic,strong) JXMyModel *strURL; @property (nonatomic, strong) NSMutableArray* imageViewArray; @property (nonatomic, assign) CGPoint startPoint; @property (nonatomic, assign) CGPoint oraginPoint; @property (nonatomic, assign) CGPoint newPoint; @property (nonatomic, assign) CGPoint lastPoint; @property (nonatomic, assign) NSTimeInterval intoBorderTime; @property (nonatomic, assign) NSTimeInterval stayBorderTime; @property (nonatomic, assign) BOOL inBorder; @property (nonatomic, assign) BOOL isUpdateImage; @property (nonatomic, strong) NSMutableDictionary *gifDataDic; @property (weak, nonatomic) IBOutlet UILabel *placeholdL; @property (weak, nonatomic) IBOutlet UITextView *textView; @property (weak, nonatomic) IBOutlet UILabel *addIMGLb; @property (weak, nonatomic) IBOutlet NSLayoutConstraint *textViewH; @property (nonatomic,strong) UIImagePickerController *picker; @property (nonatomic,weak) JXFeedShowView *feedShowView; @property (weak, nonatomic) IBOutlet NSLayoutConstraint *topViewH; @end @implementation JXMyFeedVc - (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [self.navigationController setNavigationBarHidden:NO]; // [self defineNavBar:@"排行榜" andRinghtBtnImg:@""]; } - (IBAction)goBack:(id)sender { [g_navigation dismissViewController:self animated:NO]; } - (void)touchAtlasButtonReturnCover:(UIImage *)img{ } - (void)selectImage:(UIImage *)img toView:(JXSelectCoverVC *)view{ } - (void) selector:(JXSelectorVC*)selector selectorAction:(NSInteger)selectIndex{ } - (void)viewDidLoad { [super viewDidLoad]; self.topViewH.constant=JX_SCREEN_HEIGHT>=812?88:64; //self.view.backgroundColor=kRGBColor246; _dataArr=[NSMutableArray array]; _images = [NSMutableArray array]; _tableView.tableFooterView=[UIView new]; _picker=[UIImagePickerController new]; _textView.delegate=self; CGFloat imagesHH=0; imagesHH=JX_SCREEN_HEIGHT>=812?90:10; svImages = [[UIScrollView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(_addIMGLb.frame)+imagesHH, JX_SCREEN_WIDTH,80)]; svImages.pagingEnabled = YES; svImages.delegate = self; svImages.showsVerticalScrollIndicator = NO; svImages.showsHorizontalScrollIndicator = NO; svImages.backgroundColor = [UIColor whiteColor]; svImages.userInteractionEnabled = YES; [self.view addSubview:svImages]; [self showImages]; self.textView.delegate=self; self.textViewH.constant=JX_SCREEN_HEIGHT>=812?200:140; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardAction:) name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardAction:) name:UIKeyboardWillHideNotification object:nil]; [self loadData]; JXFeedShowView *show=[JXFeedShowView XIBJXFeedShowView]; show.backgroundColor=[UIColor colorWithWhite:0.0 alpha:0.4]; show.frame=[UIScreen mainScreen].bounds; [[UIApplication sharedApplication].keyWindow addSubview:show]; self.feedShowView=show; show.hidden=YES; [show.konwBtn22 addTarget:self action:@selector(goBckBtn) forControlEvents:UIControlEventTouchUpInside]; } - (void)goBckBtn{ [_feedShowView removeFromSuperview]; [g_navigation dismissViewController:self animated:YES]; } - (void)textViewDidChange:(UITextView *)textView{ if (textView.text.length>0) { self.placeholdL.hidden=YES; }else{ self.placeholdL.hidden=NO; } } /** * 加载最新数据 */ - (void)loadData{ long time = (long)[[NSDate date] timeIntervalSince1970]; time = (time *1000 + g_server.timeDifference); NSString *salt = [NSString stringWithFormat:@"%ld", time]; [SVProgressHUD show]; [g_server getact_usermyfeedbacktypes:salt andType:@"" andToView:self]; // [g_server getact_act_usermyfeedSubmit:salt andType:@"1" andToView:self]; } -(void)showImages{ int i; [g_factory removeAllChild:svImages]; NSInteger n = [_images count]; _sendBtn.enabled = n > 1 || _remark.text.length > 0; svImages.contentSize = CGSizeMake((n+1) * 80, svImages.frame.size.height); for(i=0;i8){ [g_App showAlert:Localized(@"addMsgVC_SelNinePhoto")]; return; }else if(_photoIndex==insert_photo_tag){ JXActionSheetVC *actionVC = [[JXActionSheetVC alloc] initWithImages:@[] names:@[Localized(@"JX_ChoosePhoto"),Localized(@"JX_TakePhoto")]]; actionVC.delegate = self; actionVC.tag = 111; [self presentViewController:actionVC animated:NO completion:nil]; return; } LXActionSheet* _menu = [[LXActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:Localized(@"JX_Cencal") destructiveButtonTitle:Localized(@"JX_Update") otherButtonTitles:@[Localized(@"JX_Delete")]]; [g_window addSubview:_menu]; // [_menu release]; } - (void)didClickOnButtonIndex:(LXActionSheet*)sender buttonIndex:(int)buttonIndex{ if(buttonIndex<0) return; _nSelMenu = buttonIndex; [self doOutputMenu]; } -(void)doOutputMenu{ if(_nSelMenu==0){ self.isUpdateImage = YES; [self pickImages:NO]; } if(_nSelMenu==1){ [_images removeObjectAtIndex:_photoIndex]; [self showImages]; } } -(void)pickImages:(BOOL)Multi{ RITLPhotosViewController *photoController = RITLPhotosViewController.photosViewController; if (!self.isUpdateImage) { photoController.configuration.maxCount = 9 - _images.count;//最大的选择数目 }else { photoController.configuration.maxCount = 1;//最大的选择数目 } photoController.configuration.containVideo = NO;//选择类型,目前只选择图片不选择视频 photoController.photo_delegate = self; photoController.thumbnailSize = CGSizeMake(320, 320);//缩略图的尺寸 // photoController.defaultIdentifers = self.saveAssetIds;//记录已经选择过的资源 [self presentViewController:photoController animated:true completion:^{}]; } - (void)displayImages:(NSArray *)images { for (UIImageView *imageView in self.imageViewArray) { [imageView removeFromSuperview]; } if (self.isUpdateImage) { _images[_photoIndex] = images.firstObject; }else { [_images addObjectsFromArray:images.mutableCopy]; } self.gifDataDic = nil; self.gifDataDic = [NSMutableDictionary dictionary]; for (int i = 0; i < images.count; i++) { UIImage *image = images[i]; if (image.images.count > 0) { //NSDictionary *dic = [infos objectAtIndex:i]; //NSData *data = [dic objectForKey:@"gifData"]; //[self.gifDataDic setValue:data forKey:[NSString stringWithFormat:@"%d",i]]; } } [self showImages]; } - (void)actionSheet:(JXActionSheetVC *)actionSheet didButtonWithIndex:(NSInteger)index{ // __weak typeof (self)weakSelf = self; // GWLPhotoLibrayController *photoSelector = [GWLPhotoLibrayController photoLibrayControllerWithBlock:^(NSArray *images) { // [weakSelf displayImages:images]; // }]; // photoSelector.maxCount = 10; // photoSelector.multiAlbumSelect = YES; // [self presentViewController:photoSelector animated:YES completion:nil]; if (index == 0) { RITLPhotosViewController *photoController = RITLPhotosViewController.photosViewController; if (!self.isUpdateImage) { photoController.configuration.maxCount = 9 - _images.count;//最大的选择数目 }else { photoController.configuration.maxCount = 1;//最大的选择数目 } photoController.configuration.containVideo = NO;//选择类型,目前只选择图片不选择视频 photoController.photo_delegate = self; photoController.thumbnailSize = CGSizeMake(320, 320);//缩略图的尺寸 // photoController.defaultIdentifers = self.saveAssetIds;//记录已经选择过的资源 [self presentViewController:photoController animated:YES completion:nil]; self.maxImageCount = self.maxImageCount - (int)[_images count]; self.isUpdateImage = NO; [self pickImages:YES]; }else { JXCameraVC *vc = [JXCameraVC alloc]; vc.cameraDelegate = self; vc.isVideo = NO; vc = [vc init]; [self presentViewController:vc animated:YES completion:nil]; //将sourceType设为UIImagePickerControllerSourceTypeCamera代表拍照或拍视频 // _picker.sourceType=UIImagePickerControllerSourceTypeCamera; // // //设置拍摄照片 // // _picker.cameraCaptureMode=UIImagePickerControllerCameraCaptureModePhoto; // // //设置使用手机的后置摄像头(默认使用后置摄像头) // // _picker.cameraDevice=UIImagePickerControllerCameraDeviceRear; // // //设置使用手机的前置摄像头。 // // //picker.cameraDevice = UIImagePickerControllerCameraDeviceFront; // // //设置拍摄的照片允许编辑 // // _picker.allowsEditing=YES; // // // //显示picker视图控制器 // // [self presentViewController:_picker animated:YES completion:nil]; } } - (void)cameraVC:(JXCameraVC *)vc didFinishWithImage:(UIImage *)image { [_images addObject:image]; [self showImages]; } - (void)cameraVC:(JXCameraVC *)vc didFinishWithVideoPath:(NSString *)filePath timeLen:(NSInteger)timeLen { [_images removeAllObjects]; JXMediaObject* media = [[JXMediaObject alloc] init]; media.userId = MY_USER_ID; media.fileName = filePath; media.isVideo = [NSNumber numberWithBool:YES]; media.timeLen = [NSNumber numberWithInteger:timeLen]; media.createTime = [NSDate date]; // media.photoPath = filePath.absoluteString; [media insert]; NSString* file = media.fileName; UIImage *image = [FileInfo getFirstImageFromVideo:file]; // videoFile = [file copy]; // // file = [NSString stringWithFormat:@"%@.jpg",[file stringByDeletingPathExtension]]; // // [_images addObject:[UIImage imageWithContentsOfFile:file]]; // [_images addObject:image]; // // JXSelectCoverVC *Vc = [[JXSelectCoverVC alloc] initWithVideo:videoFile]; // Vc.delegate = self; // [g_navigation pushViewController:Vc animated:YES]; // // [self showVideos]; } #pragma mark - 发送原图 - (void)photosViewController:(UIViewController *)viewController images:(NSArray *)images infos:(NSArray *)infos { if (self.isUpdateImage) { _images[_photoIndex] = images.firstObject; }else { [_images addObjectsFromArray:images.mutableCopy]; } self.gifDataDic = nil; self.gifDataDic = [NSMutableDictionary dictionary]; for (int i = 0; i < images.count; i++) { UIImage *image = images[i]; if (image.images.count > 0) { NSDictionary *dic = [infos objectAtIndex:i]; NSData *data = [dic objectForKey:@"gifData"]; [self.gifDataDic setValue:data forKey:[NSString stringWithFormat:@"%d",i]]; } } [self showImages]; } #pragma mark - 发送缩略图 - (void)photosViewController:(UIViewController *)viewController thumbnailImages:(NSArray *)thumbnailImages infos:(NSArray *)infos { if (self.isUpdateImage) { _images[_photoIndex] = thumbnailImages.firstObject; }else { [_images addObjectsFromArray:thumbnailImages.mutableCopy]; } [self showImages]; } - (void)getTouchWhenMove:(JXImageView *)imageView withTouch:(NSSet *)touch withEvent:(UIEvent *)event withLongPressGes:(UILongPressGestureRecognizer *)lpGes{ UITouch *mytouch = touch.allObjects.lastObject; CGPoint inWindow = [mytouch locationInView:nil]; if ((inWindow.x > JX_SCREEN_WIDTH - 30 && inWindow.x < JX_SCREEN_WIDTH && svImages.contentOffset.x == 0) || (inWindow.x < 30 && svImages.contentOffset.x > 0)) { if (_inBorder) { _stayBorderTime = mytouch.timestamp - _intoBorderTime; if (_stayBorderTime > 0.3) { [self changeWhenPan:imageView gesture:lpGes]; } }else{ _inBorder = YES; _intoBorderTime = mytouch.timestamp; } }else{ _inBorder = NO; _intoBorderTime = 0; } } - (void)changeWhenPan:(JXImageView *)sender gesture:(UILongPressGestureRecognizer *)sender2{ BOOL isBorderStart = NO; if (sender2.state == UIGestureRecognizerStateBegan) { [svImages setScrollEnabled:NO]; sender.alpha = 0.5; self.startPoint = [sender2 locationInView:svImages]; CGPoint inWindow = [sender2 locationInView:nil]; if ((inWindow.x > JX_SCREEN_WIDTH - 30 && inWindow.x < JX_SCREEN_WIDTH && svImages.contentOffset.x == 0) || (inWindow.x < 30 && svImages.contentOffset.x > 0)) { isBorderStart = YES; }else{ isBorderStart = NO; } self.oraginPoint = sender.center; _lastPoint = _oraginPoint; [self.view bringSubviewToFront:svImages]; [svImages bringSubviewToFront:sender]; }else if (sender2.state == UIGestureRecognizerStateChanged) { self.newPoint = [sender2 locationInView:svImages]; CGFloat xChange = _newPoint.x - _startPoint.x; CGFloat yChange = _newPoint.y - _startPoint.y; sender.center = CGPointMake(_oraginPoint.x + xChange, _oraginPoint.y + yChange); CGPoint inWindow = [sender2 locationInView:nil]; if (isBorderStart) { if ((inWindow.x < JX_SCREEN_WIDTH - 30 && svImages.contentOffset.x == 0) && (inWindow.x > 30 && svImages.contentOffset.x > 0)){ isBorderStart = NO; } } if (inWindow.x < 30 && svImages.contentOffset.x > 0 && !isBorderStart && _stayBorderTime > 0.3) { for (int num = 0; num <_imageViewArray.count; num++) { JXImageView *imgView = _imageViewArray[num]; if (imgView.tag != num) { [_imageViewArray exchangeObjectAtIndex:num withObjectAtIndex:imgView.tag]; } } [UIView animateWithDuration:0.3 animations:^{ [svImages setContentOffset:CGPointMake(0, 0)]; }]; _stayBorderTime = 0; _inBorder = NO; NSInteger index = sender.tag; for (NSInteger i = index - 1; i > -1; i--) { JXImageView *imgView = _imageViewArray[i]; [_images exchangeObjectAtIndex:imgView.tag withObjectAtIndex:imgView.tag + 1]; [UIView animateWithDuration:0.5 animations:^{ imgView.tag = imgView.tag + 1; CGPoint center = imgView.center; imgView.center = _lastPoint; _lastPoint = center; }]; } sender.tag = 0; }else if (inWindow.x > g_window.frame.size.width - 30 && _newPoint.x < svImages.contentSize.width && !isBorderStart && _stayBorderTime > 0.3) { for (int num = 0; num <_imageViewArray.count; num++) { JXImageView *imgView = _imageViewArray[num]; if (imgView.tag != num) { [_imageViewArray exchangeObjectAtIndex:num withObjectAtIndex:imgView.tag]; } } [UIView animateWithDuration:0.3 animations:^{ [svImages setContentOffset:CGPointMake(svImages.contentSize.width - JX_SCREEN_WIDTH, 0)]; }]; _stayBorderTime = 0; _inBorder = NO; NSInteger index = sender.tag; for (NSInteger i = index + 1; i < _imageViewArray.count; i++) { JXImageView *imgView = _imageViewArray[i]; [_images exchangeObjectAtIndex:imgView.tag withObjectAtIndex:imgView.tag - 1]; [UIView animateWithDuration:0.5 animations:^{ imgView.tag = imgView.tag - 1; CGPoint center = imgView.center; imgView.center = _lastPoint; _lastPoint = center; }]; } sender.tag = _imageViewArray.count - 1; }else{ for (int num = 0; num <_imageViewArray.count; num++) { JXImageView *imgView = _imageViewArray[num]; if (imgView.tag != num) { [_imageViewArray exchangeObjectAtIndex:num withObjectAtIndex:imgView.tag]; } } for (NSInteger i = 0;i < _imageViewArray.count; i++) { JXImageView * imgView = _imageViewArray[i]; if (CGRectContainsPoint(imgView.frame, _newPoint)) { if (imgView == sender) { continue; } [UIView animateWithDuration:0.3 animations:^{ CGPoint point = imgView.center; imgView.center = _lastPoint; _lastPoint = point; }]; [_images exchangeObjectAtIndex:imgView.tag withObjectAtIndex:sender.tag]; NSInteger l = imgView.tag; imgView.tag = sender.tag; sender.tag = l; } } if (!CGRectContainsPoint(svImages.bounds, _newPoint)) { [sender2 setState:UIGestureRecognizerStateEnded]; } } }else if(sender2.state == UIGestureRecognizerStateEnded) { sender.alpha = 1; [UIView animateWithDuration:0.3 animations:^{ sender.center = _lastPoint; }]; [svImages setScrollEnabled:YES]; } } /** * 提交 */ - (IBAction)tijiaoBtn:(id)sender { if (_strURL.name.length==0) { [SVProgressHUD showWithStatus:@"请选择您的反馈类型"]; [SVProgressHUD dismissWithDelay:1.0]; return; } [SVProgressHUD show]; if(_images.count){ [g_server uploadFile:_images audio:@"" video:@"" file:@"fileFile" type:2+1 validTime:@"-1" timeLen:0 toView:self gifDic:self.gifDataDic]; }else{ JXMyModel *model=_strURL; long time = (long)[[NSDate date] timeIntervalSince1970]; time = (time *1000 + g_server.timeDifference); NSString *salt = [NSString stringWithFormat:@"%ld", time]; [g_server getMyFeedSubmit:salt type:model.id desc:_textView.text img:@"" targetUserId:g_server.myself.userId andToView:self]; } } #pragma mark --- 请求成功 -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{ [SVProgressHUD dismiss]; //NSLog(@"dict: %@ --- arry: %@",dict ,array1 ); if([aDownload.action isEqualToString:act_usermyfeedbacktypes]) { _dataArr=[JXMyModel mj_objectArrayWithKeyValuesArray:array1]; [_tableView reloadData]; [_tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:YES scrollPosition:UITableViewScrollPositionTop]; } else if([aDownload.action isEqualToString:act_feedbacksubmit]) { _feedShowView.hidden=NO; } else if([aDownload.action isEqualToString:act_UploadFile]) //上传图片 { NSDictionary *dataD; NSMutableArray *array = [NSMutableArray arrayWithArray:[dict objectForKey:@"images"]]; dataD = dict; NSMutableString *stringM=[NSMutableString string]; [array enumerateObjectsUsingBlock:^(NSDictionary * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { [stringM appendFormat:@",%@",obj[@"tUrl"]]; }]; [stringM deleteCharactersInRange:NSMakeRange(0,1)]; // [g_server addMessage:@"text" type:3 data:dataD flag:3 visible:_visible lookArray:@[] coor:_coor location:nil remindArray:@[] lable:[UILabel new] isAllowComment:YES toView:self]; JXMyModel *model=_strURL; long time = (long)[[NSDate date] timeIntervalSince1970]; time = (time *1000 + g_server.timeDifference); NSString *salt = [NSString stringWithFormat:@"%ld", time]; [g_server getMyFeedSubmit:salt type:model.id desc:_textView.text img:[stringM copy] targetUserId:g_server.myself.userId andToView:self]; } } - (NSString *)getNumberFromStr:(NSString *)str { NSCharacterSet *nonDigitCharacterSet = [[NSCharacterSet decimalDigitCharacterSet] invertedSet]; return[[str componentsSeparatedByCharactersInSet:nonDigitCharacterSet] componentsJoinedByString:@""]; } -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{ [SVProgressHUD dismiss]; NSString * errorCode = [NSString stringWithFormat:@"%@",[dict objectForKey:@"resultMsg"]]; if([errorCode isEqualToString:@"权限验证失败"]) { if ([aDownload.action isEqualToString:act_GetBalanceRedTimes]) { }else{ } } return [errorCode intValue]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return _dataArr.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ JXMyFeedCell *cell=[JXMyFeedCell cellWithTableView:tableView]; JXMyModel *nameStr=_dataArr[indexPath.row]; _strURL=[_dataArr firstObject]; cell.model=nameStr; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ JXMyModel *nameStr=_dataArr[indexPath.row]; _strURL=nameStr; } -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ [self.view endEditing:YES]; } - (void)scrollViewDidScroll:(UIScrollView *)scrollView{ [self.view endEditing:YES]; } // 键盘监听事件 - (void)keyboardAction:(NSNotification*)sender{ // 通过通知对象获取键盘frame: [value CGRectValue] NSDictionary *useInfo = [sender userInfo]; NSValue *value = [useInfo objectForKey:UIKeyboardFrameEndUserInfoKey]; if([sender.name isEqualToString:UIKeyboardWillShowNotification]){ int aa = [value CGRectValue].size.height; self.view.xmg_y=-120; }else{ self.view.xmg_y=0; //self.view.frame = CGRectMake(0, 44, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT-JX_SCREEN_TOP-44); } } @end