Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/ios.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarinofaggiana <marino@marinofaggiana.com>2020-12-15 18:12:07 +0300
committermarinofaggiana <marino@marinofaggiana.com>2020-12-15 18:12:07 +0300
commite8d49d3004fcfdd0d3d874a728aaa14ba57b71d9 (patch)
treea3cfa76a0e359d683ac0ae2abeccb28ed35e11b7 /iOSClient/Utility
parent4bbbeea8847671f298cf0356427efc41037271d3 (diff)
clear code
Diffstat (limited to 'iOSClient/Utility')
-rw-r--r--iOSClient/Utility/CCGraphics.h34
-rw-r--r--iOSClient/Utility/CCGraphics.m115
-rw-r--r--iOSClient/Utility/CCUtility.h1
-rw-r--r--iOSClient/Utility/CCUtility.m1
-rw-r--r--iOSClient/Utility/NCUtility.swift49
-rw-r--r--iOSClient/Utility/NCUtilityFileSystem.swift6
6 files changed, 55 insertions, 151 deletions
diff --git a/iOSClient/Utility/CCGraphics.h b/iOSClient/Utility/CCGraphics.h
deleted file mode 100644
index a97530008..000000000
--- a/iOSClient/Utility/CCGraphics.h
+++ /dev/null
@@ -1,34 +0,0 @@
-//
-// CCGraphics.h
-// Nextcloud
-//
-// Created by Marino Faggiana on 04/02/16.
-// Copyright (c) 2016 Marino Faggiana. All rights reserved.
-//
-// Author Marino Faggiana <marino.faggiana@nextcloud.com>
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see <http://www.gnu.org/licenses/>.
-//
-
-#import <UIKit/UIKit.h>
-#import <Foundation/Foundation.h>
-#import <AssetsLibrary/AssetsLibrary.h>
-#import <AVFoundation/AVFoundation.h>
-
-@interface CCGraphics : NSObject
-
-+ (UIImage *)thumbnailImageForVideo:(NSURL *)videoURL atTime:(NSTimeInterval)time;
-+ (void)createNewImageFrom:(NSString *)fileName ocId:(NSString *)ocId etag:(NSString *)etag typeFile:(NSString *)typeFile;
-
-@end
diff --git a/iOSClient/Utility/CCGraphics.m b/iOSClient/Utility/CCGraphics.m
deleted file mode 100644
index be618910b..000000000
--- a/iOSClient/Utility/CCGraphics.m
+++ /dev/null
@@ -1,115 +0,0 @@
-//
-// CCGraphics.m
-// Nextcloud
-//
-// Created by Marino Faggiana on 04/02/16.
-// Copyright (c) 2016 Marino Faggiana. All rights reserved.
-//
-// Author Marino Faggiana <marino.faggiana@nextcloud.com>
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see <http://www.gnu.org/licenses/>.
-//
-
-#import "CCGraphics.h"
-#import "CCUtility.h"
-#import "NCBridgeSwift.h"
-
-@implementation CCGraphics
-
-+ (UIImage *)thumbnailImageForVideo:(NSURL *)videoURL atTime:(NSTimeInterval)time
-{
- AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:videoURL options:nil];
- NSParameterAssert(asset);
- AVAssetImageGenerator *assetIG =
- [[AVAssetImageGenerator alloc] initWithAsset:asset];
- assetIG.appliesPreferredTrackTransform = YES;
- assetIG.apertureMode = AVAssetImageGeneratorApertureModeEncodedPixels;
-
- CGImageRef thumbnailImageRef = NULL;
- CFTimeInterval thumbnailImageTime = time;
- NSError *igError = nil;
- thumbnailImageRef =
- [assetIG copyCGImageAtTime:CMTimeMake(thumbnailImageTime, 60) actualTime:NULL error:&igError];
-
- if (!thumbnailImageRef) NSLog(@"[LOG] thumbnailImageGenerationError %@", igError );
-
- UIImage *thumbnailImage = thumbnailImageRef ? [[UIImage alloc] initWithCGImage:thumbnailImageRef] : nil;
-
- return thumbnailImage;
-}
-
-+ (UIImage *)generateImageFromVideo:(NSString *)videoPath
-{
- NSURL *url = [NSURL fileURLWithPath:videoPath];
- NSError *error = NULL;
-
- AVURLAsset* asset = [AVURLAsset URLAssetWithURL:url options:nil];
- AVAssetImageGenerator* imageGenerator = [AVAssetImageGenerator assetImageGeneratorWithAsset:asset];
- imageGenerator.appliesPreferredTrackTransform = YES;
- // CMTime time = CMTimeMake(1, 65);
- CGImageRef cgImage = [imageGenerator copyCGImageAtTime:CMTimeMake(0, 1) actualTime:nil error:&error];
- if(error) return nil;
- UIImage* image = [UIImage imageWithCGImage:cgImage];
- CGImageRelease(cgImage);
-
- return image;
-}
-
-+ (void)createNewImageFrom:(NSString *)fileName ocId:(NSString *)ocId etag:(NSString *)etag typeFile:(NSString *)typeFile
-{
- UIImage *originalImage;
- UIImage *scaleImagePreview;
- UIImage *scaleImageIcon;
- NSString *fileNamePath = [CCUtility getDirectoryProviderStorageOcId:ocId fileNameView:fileName];
- NSString *fileNamePathPreview = [CCUtility getDirectoryProviderStoragePreviewOcId:ocId etag:etag];
- NSString *fileNamePathIcon = [CCUtility getDirectoryProviderStorageIconOcId:ocId etag:etag];
-
- if (![CCUtility fileProviderStorageExists:ocId fileNameView:fileName]) return;
-
- // only viedo / image
- if (![typeFile isEqualToString: NCBrandGlobal.shared.metadataTypeFileImage] && ![typeFile isEqualToString: NCBrandGlobal.shared.metadataTypeFileVideo]) return;
-
- if ([typeFile isEqualToString: NCBrandGlobal.shared.metadataTypeFileImage]) {
-
- originalImage = [UIImage imageWithContentsOfFile:fileNamePath];
- if (originalImage == nil) { return; }
- }
-
- if ([typeFile isEqualToString: NCBrandGlobal.shared.metadataTypeFileVideo]) {
-
- // create symbolik link for read video file in temp
- [[NSFileManager defaultManager] removeItemAtPath:[NSTemporaryDirectory() stringByAppendingString:@"tempvideo.mp4"] error:nil];
- [[NSFileManager defaultManager] linkItemAtPath:fileNamePath toPath:[NSTemporaryDirectory() stringByAppendingString:@"tempvideo.mp4"] error:nil];
-
- originalImage = [self generateImageFromVideo:[NSTemporaryDirectory() stringByAppendingString:@"tempvideo.mp4"]];
- }
-
- scaleImagePreview = [originalImage resizeImageWithSize:CGSizeMake(NCBrandGlobal.shared.sizePreview, NCBrandGlobal.shared.sizePreview)];
-
- scaleImageIcon = [originalImage resizeImageWithSize:CGSizeMake(NCBrandGlobal.shared.sizeIcon, NCBrandGlobal.shared.sizeIcon)];
-
- scaleImagePreview = [UIImage imageWithData:UIImageJPEGRepresentation(scaleImagePreview, 0.5f)];
- scaleImageIcon = [UIImage imageWithData:UIImageJPEGRepresentation(scaleImageIcon, 0.5f)];
-
- // it is request write photo ?
- if (scaleImagePreview && scaleImageIcon) {
-
- [UIImageJPEGRepresentation(scaleImagePreview, 0.5) writeToFile:fileNamePathPreview atomically:true];
- [UIImageJPEGRepresentation(scaleImageIcon, 0.5) writeToFile:fileNamePathIcon atomically:true];
- }
-
- return;
-}
-
-@end
diff --git a/iOSClient/Utility/CCUtility.h b/iOSClient/Utility/CCUtility.h
index 6127e6dd7..01d57a6a6 100644
--- a/iOSClient/Utility/CCUtility.h
+++ b/iOSClient/Utility/CCUtility.h
@@ -29,7 +29,6 @@
#import <MessageUI/MessageUI.h>
#import <UICKeyChainStore/UICKeyChainStore.h>
#import <Photos/Photos.h>
-#import "CCGraphics.h"
@class tableMetadata;
diff --git a/iOSClient/Utility/CCUtility.m b/iOSClient/Utility/CCUtility.m
index eee6a631b..8874393eb 100644
--- a/iOSClient/Utility/CCUtility.m
+++ b/iOSClient/Utility/CCUtility.m
@@ -22,7 +22,6 @@
//
#import "CCUtility.h"
-#import "CCGraphics.h"
#import "NCBridgeSwift.h"
#import "NSNotificationCenter+MainThread.h"
#import <OpenSSL/OpenSSL.h>
diff --git a/iOSClient/Utility/NCUtility.swift b/iOSClient/Utility/NCUtility.swift
index 50dbd17bd..a346d81d0 100644
--- a/iOSClient/Utility/NCUtility.swift
+++ b/iOSClient/Utility/NCUtility.swift
@@ -640,5 +640,54 @@ class NCUtility: NSObject {
NCBrandColor.shared.brandElement = NCBrandColor.shared.brand
}
}
+
+ func imageFromVideo(url: URL, at time: TimeInterval) -> UIImage? {
+
+ let asset = AVURLAsset(url: url)
+ let assetIG = AVAssetImageGenerator(asset: asset)
+
+ assetIG.appliesPreferredTrackTransform = true
+ assetIG.apertureMode = AVAssetImageGenerator.ApertureMode.encodedPixels
+
+ let cmTime = CMTime(seconds: time, preferredTimescale: 60)
+ let thumbnailImageRef: CGImage
+ do {
+ thumbnailImageRef = try assetIG.copyCGImage(at: cmTime, actualTime: nil)
+ } catch let error {
+ print("Error: \(error)")
+ return nil
+ }
+
+ return UIImage(cgImage: thumbnailImageRef)
+ }
+
+ func createImageFrom(fileName: String, ocId: String, etag: String, typeFile: String) {
+
+ var originalImage: UIImage?
+
+ let fileNamePath = CCUtility.getDirectoryProviderStorageOcId(ocId, fileNameView: fileName)!
+ let fileNamePathPreview = CCUtility.getDirectoryProviderStoragePreviewOcId(ocId, etag: etag)!
+ let fileNamePathIcon = CCUtility.getDirectoryProviderStorageIconOcId(ocId, etag: etag)!
+
+ if !CCUtility.fileProviderStorageExists(ocId, fileNameView: fileName) { return }
+ if typeFile != NCBrandGlobal.shared.metadataTypeFileImage && typeFile != NCBrandGlobal.shared.metadataTypeFileVideo { return }
+
+ if typeFile == NCBrandGlobal.shared.metadataTypeFileImage {
+ originalImage = UIImage.init(contentsOfFile: fileNamePath)
+ } else if typeFile == NCBrandGlobal.shared.metadataTypeFileVideo {
+ let videoPath = NSTemporaryDirectory()+"tempvideo.mp4"
+ NCUtilityFileSystem.shared.linkItem(atPath: fileNamePath, toPath: videoPath)
+ originalImage = imageFromVideo(url: URL(fileURLWithPath: videoPath), at: 1)
+ }
+
+ if let image = originalImage {
+ if let scaleImagePreview = image.resizeImage(size: CGSize(width: NCBrandGlobal.shared.sizePreview, height: NCBrandGlobal.shared.sizePreview)) {
+ try? scaleImagePreview.jpegData(compressionQuality: 0.5)?.write(to: URL(fileURLWithPath: fileNamePathPreview))
+ }
+ if let scaleImageIcon = image.resizeImage(size: CGSize(width: NCBrandGlobal.shared.sizeIcon, height: NCBrandGlobal.shared.sizeIcon)) {
+ try? scaleImageIcon.jpegData(compressionQuality: 0.5)?.write(to: URL(fileURLWithPath: fileNamePathIcon))
+ }
+ }
+ }
}
diff --git a/iOSClient/Utility/NCUtilityFileSystem.swift b/iOSClient/Utility/NCUtilityFileSystem.swift
index e41161f9c..98d7df04f 100644
--- a/iOSClient/Utility/NCUtilityFileSystem.swift
+++ b/iOSClient/Utility/NCUtilityFileSystem.swift
@@ -117,5 +117,11 @@ class NCUtilityFileSystem: NSObject {
try? FileManager.default.removeItem(atPath: atPath)
}
}
+
+ @objc func linkItem(atPath: String, toPath: String) {
+
+ try? FileManager.default.removeItem(atPath: toPath)
+ try? FileManager.default.linkItem(atPath: atPath, toPath: toPath)
+ }
}