marinofaggiana 5 年之前
父節點
當前提交
e503155870

+ 6 - 2
Nextcloud.xcodeproj/project.pbxproj

@@ -487,6 +487,7 @@
 		F7C40C122199BA620004137E /* RealmSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F7C40C112199BA620004137E /* RealmSwift.framework */; };
 		F7C525A01E3B48B700FFE02C /* CCNotification.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7C5259F1E3B48B700FFE02C /* CCNotification.swift */; };
 		F7C525A21E3B6DA800FFE02C /* CCNotification.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F7C525A11E3B6DA800FFE02C /* CCNotification.storyboard */; };
+		F7C7B4E02408037C00481FF6 /* NCViewerImageGif.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7C7B4DF2408037B00481FF6 /* NCViewerImageGif.swift */; };
 		F7C9555321F0C4CA0024296E /* NCActivity.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F7C9555221F0C4CA0024296E /* NCActivity.storyboard */; };
 		F7C9555521F0C5470024296E /* NCActivity.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7C9555421F0C5470024296E /* NCActivity.swift */; };
 		F7CA1ED020E7E3FE002CC65E /* UIImage+PKDownloadButton.m in Sources */ = {isa = PBXBuildFile; fileRef = F7CA1EBC20E7E3FE002CC65E /* UIImage+PKDownloadButton.m */; };
@@ -1219,6 +1220,7 @@
 		F7C525A11E3B6DA800FFE02C /* CCNotification.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = CCNotification.storyboard; path = Notification/CCNotification.storyboard; sourceTree = "<group>"; };
 		F7C742C01E7BD01F00D9C973 /* iOSClient.entitlements */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.entitlements; path = iOSClient.entitlements; sourceTree = "<group>"; };
 		F7C742D01E7BD35B00D9C973 /* Share.entitlements */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.entitlements; path = Share.entitlements; sourceTree = "<group>"; };
+		F7C7B4DF2408037B00481FF6 /* NCViewerImageGif.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCViewerImageGif.swift; sourceTree = "<group>"; };
 		F7C8C1901B482CEA0048180E /* CCGlobal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCGlobal.h; sourceTree = "<group>"; };
 		F7C9555221F0C4CA0024296E /* NCActivity.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = NCActivity.storyboard; sourceTree = "<group>"; };
 		F7C9555421F0C5470024296E /* NCActivity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCActivity.swift; sourceTree = "<group>"; };
@@ -2122,11 +2124,12 @@
 			isa = PBXGroup;
 			children = (
 				F774F5D62407F547000C5E86 /* NCViewerImageAsset.swift */,
-				F774F5CC2407F4EF000C5E86 /* NCViewerImageView.xib */,
+				F7C7B4DF2408037B00481FF6 /* NCViewerImageGif.swift */,
 				F774F5CD2407F4EF000C5E86 /* NCViewerImageView.swift */,
-				F774F5CE2407F4EF000C5E86 /* NCViewerImageCollectionViewCell.xib */,
 				F774F5CF2407F4EF000C5E86 /* NCViewerImageCollectionViewCell.swift */,
 				F774F5D02407F4EF000C5E86 /* NCViewerImageNibLoadingView.swift */,
+				F774F5CE2407F4EF000C5E86 /* NCViewerImageCollectionViewCell.xib */,
+				F774F5CC2407F4EF000C5E86 /* NCViewerImageView.xib */,
 			);
 			path = NCViewerImage;
 			sourceTree = "<group>";
@@ -3412,6 +3415,7 @@
 				F70022EC1EC4C9100080073F /* OCXMLSharedParser.m in Sources */,
 				F7F54D061E5B14C800E19C62 /* MWCaptionView.m in Sources */,
 				F762CB001EACB66200B38484 /* XLFormSegmentedCell.m in Sources */,
+				F7C7B4E02408037C00481FF6 /* NCViewerImageGif.swift in Sources */,
 				F732BA061D76CE1500E9878B /* CCNetworking.m in Sources */,
 				F762CB061EACB66200B38484 /* XLFormTextViewCell.m in Sources */,
 				F78ACD4221903CE00088454D /* NCListCell.swift in Sources */,

+ 6 - 5
iOSClient/Main/NCDetailViewController.swift

@@ -115,15 +115,16 @@ class NCDetailViewController: UIViewController {
         if metadata.typeFile == k_metadataTypeFile_image {
             if let metadatas = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND typeFile == %@", metadata.account, metadata.serverUrl, k_metadataTypeFile_image), sorted: "fileName", ascending: true) {
                 var assets: [NCViewerImageAsset?] = [NCViewerImageAsset]()
+                var index = 0
                 for metadata in metadatas {
-                    let imagePath = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)!
-                    if let image = UIImage(contentsOfFile: imagePath) {
-                        let asset = NCViewerImageAsset(image: image)
-                        assets.append(asset)
+                    let asset = NCViewerImageAsset(metadata: metadata)
+                    assets.append(asset)
+                    if metadata.ocId == self.metadata?.ocId {
+                        viewerImageView.preselectItem(at: index)
                     }
+                    index += 1
                 }
                 viewerImageView.assets = assets
-                //viewerImageView.preselectItem(at: 1)
             }
             return
         }

+ 9 - 12
iOSClient/Viewer/NCViewerImage/NCViewerImageAsset.swift

@@ -1,7 +1,7 @@
 
 import UIKit
 
-public class NCViewerImageAsset: NSObject {
+class NCViewerImageAsset: NSObject {
 
     public enum ImageType {
         case jpg
@@ -15,9 +15,10 @@ public class NCViewerImageAsset: NSObject {
     }
 
     public var url: URL?
-    public var image: UIImage?
+//    public var image: UIImage?
     public var type: ImageType?
     public var caption: String?
+    public var metadata: tableMetadata?
 
     private override init() { }
 
@@ -30,18 +31,16 @@ public class NCViewerImageAsset: NSObject {
         self.caption = caption
     }
 
-    public init(image: UIImage) {
-        self.image = image
-    }
-
-    public init(image: UIImage, caption: String?) {
-        self.image = image
-        self.caption = caption
+   
+    
+    public init(metadata: tableMetadata) {
+        self.metadata = metadata
+        self.caption = metadata.fileNameView
     }
 
     func download(completion:@escaping(_ success: Bool?) -> Void) -> URLSessionDataTask? {
         return NCViewerImageAsset.download(url: url) { (success, image, type)  in
-            self.image = image
+//            self.image = image
             if let type = type {
                 self.type = type
             }
@@ -64,11 +63,9 @@ public class NCViewerImageAsset: NSObject {
                     return
             }
             let type: NCViewerImageAsset.ImageType? = ImageType.from(mimeType: mimeType)
-            /*
             if type == .gif, let gif = UIImage.gif(data: data) {
                 image = gif
             }
-            */
             DispatchQueue.main.async { completion(true, image, type) }
         }
         dataTask.resume()

+ 4 - 3
iOSClient/Viewer/NCViewerImage/NCViewerImageCollectionViewCell.swift

@@ -25,12 +25,13 @@ class NCViewerImageCollectionViewCell: UICollectionViewCell {
     func withImageAsset(_ asset: NCViewerImageAsset?) {
         guard self.dataTask?.state != URLSessionDataTask.State.running else { return }
         guard let asset = asset else { return }
-        if asset.image != nil {
-            self.apply(image: self.fitIntoFrame(image: asset.image, type: asset.type))
+        let imagePath = CCUtility.getDirectoryProviderStorageOcId(asset.metadata!.ocId, fileNameView: asset.metadata!.fileNameView)!
+        if let image = UIImage(contentsOfFile: imagePath) {
+            self.apply(image: self.fitIntoFrame(image: image, type: asset.type))
         } else if asset.url != nil {
             self.galleryImageView.image = nil
             self.dataTask = asset.download(completion: { _ in
-                self.apply(image: self.fitIntoFrame(image: asset.image, type: asset.type))
+                //self.apply(image: self.fitIntoFrame(image: asset.image, type: asset.type))
             })
         }
     }

+ 1 - 1
iOSClient/Viewer/NCViewerImage/NCViewerImageNibLoadingView.swift

@@ -2,7 +2,7 @@
 import UIKit
 
 @IBDesignable
-public class NCViewerImageNibLoadingView: UIView {
+class NCViewerImageNibLoadingView: UIView {
 
     @IBOutlet weak var view: UIView!
 

+ 7 - 4
iOSClient/Viewer/NCViewerImage/NCViewerImageView.swift

@@ -1,17 +1,17 @@
 
 import UIKit
 
-public class NCViewerImageView: NCViewerImageNibLoadingView {
+class NCViewerImageView: NCViewerImageNibLoadingView {
+    
     @IBOutlet weak var collectionView: UICollectionView!
 
+    private var preselectedIndex: Int = -1
     public var assets: [NCViewerImageAsset?]? {
         didSet {
             self.collectionView.reloadData()
         }
     }
 
-    private var preselectedIndex: Int = 0
-
     override public func willMove(toSuperview newSuperview: UIView?) {
         super.willMove(toSuperview: newSuperview)
         self.collectionView.register(UINib.init(nibName: String(describing: NCViewerImageCollectionViewCell.self), bundle: Bundle(for: type(of: self))), forCellWithReuseIdentifier: NCViewerImageCollectionViewCell.reusableIdentifier)
@@ -33,7 +33,10 @@ public class NCViewerImageView: NCViewerImageNibLoadingView {
 
     public override func draw(_ rect: CGRect) {
         super.draw(rect)
-        self.collectionView.scrollToItem(at: IndexPath(row: self.preselectedIndex, section: 0), at: .centeredHorizontally, animated: false)
+        if preselectedIndex != -1 {
+            self.collectionView.scrollToItem(at: IndexPath(row: self.preselectedIndex, section: 0), at: .centeredHorizontally, animated: false)
+            preselectedIndex = -1
+        }
     }
 }