123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- //
- // MyApprovalFileCell.m
- // smartRhino
- //
- // Created by tederen on 2019/11/27.
- // Copyright © 2019 tederen. All rights reserved.
- //
- #import "MyApprovalFileCell.h"
- #import "MyWordCell.h"
- #import <QuickLook/QuickLook.h>
- #import "DownFileViewController.h"
- @interface MyApprovalFileCell()<UICollectionViewDelegate,UICollectionViewDataSource,QLPreviewControllerDataSource>
- @property (strong, nonatomic)QLPreviewController *previewController;
- @property (copy, nonatomic)NSURL *fileURL;
- @property (weak, nonatomic) IBOutlet UICollectionView *mycolletionView;
- @property (nonatomic, strong) NSMutableArray <FlowAttachmentsModel *> *sourceData;
- @end
- @implementation MyApprovalFileCell
- - (void)awakeFromNib {
- [super awakeFromNib];
- [self.mycolletionView registerNib:[UINib nibWithNibName:@"MyWordCell" bundle:nil] forCellWithReuseIdentifier:@"MyWordCell"];
- self.previewController = [[QLPreviewController alloc] init];
- self.previewController.dataSource = self;
- }
- #pragma mark - QLPreviewControllerDataSource
- -(id<QLPreviewItem>)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index {
- return self.fileURL;
- }
-
- - (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)previewController{
- return 1;
- }
- - (void)loadFile:(NSString *)keyValue forWithImageArray:(NSArray<FlowAttachmentsModel *> *)array{
- self.sourceData = [NSMutableArray arrayWithArray:array];
- [self.mycolletionView reloadData];
- }
- - (NSMutableArray<FlowAttachmentsModel *> *)sourceData{
- if (!_sourceData) {
- _sourceData = [NSMutableArray array];
- }
- return _sourceData;
- }
- - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
- return 1;
- }
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
- return self.sourceData.count;
- }
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
- MyWordCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:[MyWordCell className] forIndexPath:indexPath];
- cell.deleteButton.hidden = YES;
- [cell loadImageImageFlowModel:self.sourceData[indexPath.item]];
- return cell;
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
- NSLog(@"点中的附件信息%@",self.sourceData[indexPath.item]);
- // NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
- //
- // AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
- FlowAttachmentsModel * model = self.sourceData[indexPath.item];
- if (self.ClickCellBlock) {
- self.ClickCellBlock(model.Url);
- }
- if (self.ClickCellModelBlock) {
- self.ClickCellModelBlock(model);
- }
- //
- // NSString *fileName = [urlStr lastPathComponent]; //获取文件名称
- // NSURL *URL = [NSURL URLWithString:urlStr];
- // NSURLRequest *request = [NSURLRequest requestWithURL:URL];
-
- //判断是否存在
- // if([self isFileExist:fileName]) {
- // NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
- // NSURL *url = [documentsDirectoryURL URLByAppendingPathComponent:fileName];
- //// self.fileURL = url;
- // [[UIApplication sharedApplication].windows.firstObject.rootViewController presentViewController:self.previewController animated:YES completion:nil];
- // }else {
- // SHOWLOADING
- // NSURLSessionDownloadTask *downloadTask = [manager downloadTaskWithRequest:request progress:^(NSProgress *downloadProgress){
- //
- // } destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {
- // NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
- // NSURL *url = [documentsDirectoryURL URLByAppendingPathComponent:fileName];
- // return url;
- // } completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) {
- // REMOVESHOW
- // NSLog(@"%@",response);
- // self.fileURL = filePath;
- // WorkFlowFileModel *mdoel = [[WorkFlowFileModel alloc]init];
- // mdoel.PreviewUrl = filePath.absoluteString;
- // mdoel.DownloadUrl = filePath.absoluteString;
- // DownFileViewController *vc = [[DownFileViewController alloc]init];
- // vc.model = mdoel;
- // vc.modalPresentationStyle = UIModalPresentationFullScreen;
- // [[UIApplication sharedApplication].windows.firstObject.rootViewController presentViewController:vc animated:YES completion:nil];
- // }];
- // [downloadTask resume];
- // }
- }
- //判断文件是否已经在沙盒中存在
- -(BOOL) isFileExist:(NSString *)fileName
- {
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- NSString *path = [paths objectAtIndex:0];
- NSString *filePath = [path stringByAppendingPathComponent:fileName];
- NSFileManager *fileManager = [NSFileManager defaultManager];
- BOOL result = [fileManager fileExistsAtPath:filePath];
- return result;
- }
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
- [super setSelected:selected animated:animated];
- // Configure the view for the selected state
- }
- @end
|