// // JXFileViewController.m // shiku_im // // Created by 1 on 17/7/4. // Copyright © 2017年 Reese. All rights reserved. // #import "JXFileViewController.h" #import "JXShareFileTableViewCell.h" #import "JXShareFileObject.h" #import "JX_DownListView.h" #import "JXFileDetailViewController.h" #import "MCDownloader.h" #import "QBImagePickerController.h" //#import @interface JXFileViewController () @property (nonatomic, strong) NSMutableArray * dataArray; @property (nonatomic, strong) NSIndexPath * currentIndexpath; @property (nonatomic, strong) UIButton * addFileButton; @end @implementation JXFileViewController -(instancetype)init{ self = [super init]; if (self) { self.isGotoBack = YES; self.heightHeader = JX_SCREEN_TOP; self.heightFooter = 0; self.title = Localized(@"JXRoomMemberVC_ShareFile"); _dataArray = [[NSMutableArray alloc] init]; } return self; } - (void)viewDidLoad { [super viewDidLoad]; [self createHeadAndFoot]; [self customView]; _table.separatorStyle = UITableViewCellSeparatorStyleSingleLine; _table.tableFooterView = [[UIView alloc] init]; [_table registerClass:[JXShareFileTableViewCell class] forCellReuseIdentifier:NSStringFromClass([JXShareFileTableViewCell class])]; [self getServerData]; } -(void)customView{ if (!_addFileButton){ NSString *image = THESIMPLESTYLE ? @"im_003_more_button_black" : @"im_003_more_button_normal"; _addFileButton = [UIFactory createButtonWithImage:image highlight:nil target:self selector:@selector(addNewShareFile)]; _addFileButton.frame = CGRectMake(JX_SCREEN_WIDTH-15-18, JX_SCREEN_TOP-15-18, 18, 18); [self.tableHeader addSubview:_addFileButton]; } } -(void)getServerData{ [g_server roomShareListRoomId:_room.roomId userId:nil pageSize:12 pageIndex:_page toView:self]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return _dataArray.count; } - (UITableViewCell *)tableView:(UITableView *)_tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { JXShareFileTableViewCell * cell = [_tableView dequeueReusableCellWithIdentifier:NSStringFromClass([JXShareFileTableViewCell class]) forIndexPath:indexPath]; JXShareFileObject * fileObject = _dataArray[indexPath.row]; [cell setShareFileListCellWith:fileObject indexPath:indexPath]; return cell; } - (CGFloat)tableView:(UITableView *)_tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;{ return 60; } - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { JXShareFileObject * fileObject = _dataArray[indexPath.row]; memberData * myMem = nil; for (memberData * member in _room.members) { if ([[NSString stringWithFormat:@"%ld",member.userId] isEqualToString:g_myself.userId]) { myMem = member; break; } } if ([myMem.role integerValue] <= 2 || [fileObject.userId isEqualToString:g_myself.userId]) { return YES; }else{ return NO; } } - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { JXShareFileObject *obj = _dataArray[indexPath.row]; memberData * myMem = nil; for (memberData * member in _room.members) { if ([[NSString stringWithFormat:@"%ld",member.userId] isEqualToString:g_myself.userId]) { myMem = member; break; } } if ([myMem.role integerValue] <= 2 || [obj.userId isEqualToString:MY_USER_ID]) { return UITableViewCellEditingStyleDelete; } return UITableViewCellEditingStyleNone; } - (void)tableView:(UITableView *)aTableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{ if (editingStyle == UITableViewCellEditingStyleDelete) { JXShareFileObject * fileObject = _dataArray[indexPath.row]; _currentIndexpath = indexPath; [g_server roomShareDeleteRoomId:fileObject.roomId shareId:fileObject.shareId toView:self]; } } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [super tableView:tableView didSelectRowAtIndexPath:indexPath]; JXShareFileObject * shareFile = _dataArray[indexPath.row]; JXFileDetailViewController * detailVC = [[JXFileDetailViewController alloc] init]; detailVC.shareFile = shareFile; // [g_window addSubview:detailVC.view]; [g_navigation pushViewController:detailVC animated:YES]; } #pragma mark - Network -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{ [_wait hide]; [self stopLoading]; if([aDownload.action isEqualToString:act_shareList]){ if (_page == 0) { [_dataArray removeAllObjects]; } NSMutableArray * tempAray = [[NSMutableArray alloc] init]; for (NSDictionary * dict in array1) { JXShareFileObject * shareFile = [JXShareFileObject shareFileWithDict:dict]; [tempAray addObject:shareFile]; } if (tempAray.count > 0) { [_dataArray addObjectsFromArray:tempAray]; } [_table reloadData]; }else if([aDownload.action isEqualToString:act_shareAdd]){ JXShareFileObject * shareFile = [JXShareFileObject shareFileWithDict:dict]; [_dataArray addObject:shareFile]; [_table reloadData]; }else if([aDownload.action isEqualToString:act_shareGet]){ }else if([aDownload.action isEqualToString:act_shareDelete]){ [g_server showMsg:Localized(@"JXFile_deleteRoomFileSuccess")]; [_dataArray removeObjectAtIndex:_currentIndexpath.row]; [_table deleteRowsAtIndexPaths:@[_currentIndexpath] withRowAnimation:UITableViewRowAnimationRight]; }else if ([aDownload.action isEqualToString:act_UploadFile]){ NSArray * listArray = @[@"audios",@"images",@"others",@"videos"]; NSString * fileUrl = nil; NSString * fileName = nil; NSInteger fileType = 0; int tbreak = 0; for (int i = 0; i * myDirectoryEnumerator; myDirectoryEnumerator= [fileManager enumeratorAtPath:strPath]; while (strPath = [myDirectoryEnumerator nextObject]) { for (NSString * namePath in strPath.pathComponents) { NSLog(@"-----AAA-----%@", namePath ); } } } -(void)showSelImagePicker{ UIImagePickerController *ipc = [[UIImagePickerController alloc] init]; ipc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; ipc.delegate = self; ipc.allowsEditing = YES; ipc.modalPresentationStyle = UIModalPresentationFullScreen; // [g_window addSubview:ipc.view]; if (IS_PAD) { UIPopoverController *pop = [[UIPopoverController alloc] initWithContentViewController:ipc]; [pop presentPopoverFromRect:CGRectMake((self.view.frame.size.width - 320) / 2, 0, 300, 300) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; }else { [self presentViewController:ipc animated:YES completion:nil]; } } -(void)showSelVideo{ QBImagePickerController * videoPick = [[QBImagePickerController alloc] init]; videoPick.filterType = QBImagePickerFilterTypeAllVideos; videoPick.delegate = self; videoPick.showsCancelButton = YES; videoPick.fullScreenLayoutEnabled = YES; UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:videoPick]; [self presentViewController:navigationController animated:YES completion:NULL]; // ALAssetsLibrary *library1 = [[ALAssetsLibrary alloc] init]; // [library1 enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) { // if (group) { // [group setAssetsFilter:[ALAssetsFilter allVideos]]; // [group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) { // // if (result) { // AlbumVideoInfo *videoInfo = [[AlbumVideoInfo alloc] init]; // videoInfo.thumbnail = [UIImage imageWithCGImage:result.thumbnail]; // // videoInfo.videoURL = [result valueForProperty:ALAssetPropertyAssetURL]; // videoInfo.videoURL = result.defaultRepresentation.url; // videoInfo.duration = [result valueForProperty:ALAssetPropertyDuration]; // videoInfo.name = [self getFormatedDateStringOfDate:[result valueForProperty:ALAssetPropertyDate]]; // videoInfo.size = result.defaultRepresentation.size; //Bytes // videoInfo.format = [result.defaultRepresentation.filename pathExtension]; // [_albumVideoInfos addObject:videoInfo]; // } // }]; // } else { // //没有更多的group时,即可认为已经加载完成。 // NSLog(@"after load, the total alumvideo count is %ld",_albumVideoInfos.count); // dispatch_async(dispatch_get_main_queue(), ^{ // [self showAlbumVideos]; // }); // } // // } failureBlock:^(NSError *error) { // NSLog(@"Failed."); // }]; } @end