浏览代码

Livephoto (#2666)

* add livePhotoFile

Signed-off-by: Marino Faggiana <8616947+marinofaggiana@users.noreply.github.com>
Co-authored-by: Marino Faggiana <8616947+marinofaggiana@users.noreply.github.com>
Marino Faggiana 1 年之前
父节点
当前提交
d1bf4e9967

+ 1 - 1
Brand/Database.swift

@@ -26,4 +26,4 @@ import Foundation
 // Database Realm
 //
 let databaseName                    = "nextcloud.realm"
-let databaseSchemaVersion: UInt64   = 322
+let databaseSchemaVersion: UInt64   = 323

+ 6 - 0
Nextcloud.xcodeproj/project.pbxproj

@@ -219,6 +219,9 @@
 		F7239871253D86B600257F49 /* NCEmptyDataSet.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7239870253D86B600257F49 /* NCEmptyDataSet.swift */; };
 		F7239877253D86D300257F49 /* NCEmptyView.xib in Resources */ = {isa = PBXBuildFile; fileRef = F7239876253D86D300257F49 /* NCEmptyView.xib */; };
 		F723B3DD22FC6D1D00301EFE /* NCShareCommentsCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = F723B3DC22FC6D1C00301EFE /* NCShareCommentsCell.xib */; };
+		F72429362AFE39860040AEF3 /* NCLivePhoto.swift in Sources */ = {isa = PBXBuildFile; fileRef = F70968A324212C4E00ED60E5 /* NCLivePhoto.swift */; };
+		F72429372AFE39980040AEF3 /* NCLivePhoto.swift in Sources */ = {isa = PBXBuildFile; fileRef = F70968A324212C4E00ED60E5 /* NCLivePhoto.swift */; };
+		F72429382AFE39A80040AEF3 /* NCLivePhoto.swift in Sources */ = {isa = PBXBuildFile; fileRef = F70968A324212C4E00ED60E5 /* NCLivePhoto.swift */; };
 		F7245924289BB50C00474787 /* ThreadSafeDictionary.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7245923289BB50B00474787 /* ThreadSafeDictionary.swift */; };
 		F7245925289BB59100474787 /* ThreadSafeDictionary.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7245923289BB50B00474787 /* ThreadSafeDictionary.swift */; };
 		F7245926289BB59300474787 /* ThreadSafeDictionary.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7245923289BB50B00474787 /* ThreadSafeDictionary.swift */; };
@@ -3501,6 +3504,7 @@
 				F79EC78926316AC4004E59D6 /* NCPopupViewController.swift in Sources */,
 				F7C30DFB291BCF790017149B /* NCNetworkingE2EECreateFolder.swift in Sources */,
 				F7817CFB29801A3500FFBC65 /* Data+Extension.swift in Sources */,
+				F72429362AFE39860040AEF3 /* NCLivePhoto.swift in Sources */,
 				AF4BF61F27562B3F0081CEEF /* NCManageDatabase+Activity.swift in Sources */,
 				F7A0D1362591FBC5008F8A13 /* String+Extension.swift in Sources */,
 				F7EDE4D6262D7B9600414FE6 /* NCListCell.swift in Sources */,
@@ -3616,6 +3620,7 @@
 				F711A4DD2AF92CAE00095DD8 /* NCUtility+Date.swift in Sources */,
 				F77ED59328C9CEA000E24ED0 /* ToolbarWidgetProvider.swift in Sources */,
 				F72A17D828B221E300F3F159 /* DashboardWidgetView.swift in Sources */,
+				F72429382AFE39A80040AEF3 /* NCLivePhoto.swift in Sources */,
 				F77ED59528C9CEA400E24ED0 /* ToolbarWidgetView.swift in Sources */,
 				F78302FB28B4C3EE00B84583 /* NCManageDatabase+Video.swift in Sources */,
 				F72EA95228B7BA2A00C88F0C /* DashboardWidgetProvider.swift in Sources */,
@@ -3676,6 +3681,7 @@
 				F771E3D720E2392D00AFB62D /* FileProviderEnumerator.swift in Sources */,
 				F74AF3A6247FB6AE00AC767B /* NCUtilityFileSystem.swift in Sources */,
 				F7817CFC29801A3500FFBC65 /* Data+Extension.swift in Sources */,
+				F72429372AFE39980040AEF3 /* NCLivePhoto.swift in Sources */,
 				F7A76DCD256A71CE00119AB3 /* UIImage+Extension.swift in Sources */,
 				F771E3F820E239B500AFB62D /* FileProviderExtension+Thumbnail.swift in Sources */,
 				F343A4BF2A1E734600DDA874 /* Optional+Extension.swift in Sources */,

+ 2 - 0
iOSClient/Data/NCManageDatabase+Metadata.swift

@@ -61,6 +61,7 @@ class tableMetadata: Object, NCUserBaseUrl {
     @objc dynamic var iconUrl = ""
     @objc dynamic var isExtractFile: Bool = false
     @objc dynamic var livePhoto: Bool = false
+    @objc dynamic var livePhotoFile = ""
     @objc dynamic var mountType = ""
     @objc dynamic var name = ""                                             // for unifiedSearch is the provider.id
     @objc dynamic var note = ""
@@ -338,6 +339,7 @@ extension NCManageDatabase {
         metadata.longitude = file.longitude
         metadata.height = file.height
         metadata.width = file.width
+        metadata.livePhotoFile = file.livePhotoFile
 
         // E2EE find the fileName for fileNameView
         if isDirectoryE2EE || file.e2eEncrypted {

+ 3 - 0
iOSClient/Networking/NCNetworking.swift

@@ -690,6 +690,9 @@ class NCNetworking: NSObject, NKCommonDelegate {
                 utilityFileSystem.removeFile(atPath: utilityFileSystem.getDirectoryProviderStorageOcId(ocIdTemp))
             }
 
+            //TODO: SET SERVER LIVEPHOTO
+            NCLivePhoto().setLivephoto(metadata: metadata)
+
             NextcloudKit.shared.nkCommonInstance.writeLog("[SUCCESS] Upload complete " + serverUrl + "/" + fileName + ", result: success(\(size) bytes)")
             NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterUploadedFile, userInfo: ["ocId": metadata.ocId, "serverUrl": metadata.serverUrl, "account": metadata.account, "fileName": metadata.fileName, "ocIdTemp": ocIdTemp, "error": error])
 

+ 1 - 0
iOSClient/Utility/NCCameraRoll.swift

@@ -284,6 +284,7 @@ class NCCameraRoll: NSObject {
                                                                                url: "",
                                                                                contentType: "",
                                                                                isLivePhoto: true)
+
                 metadataLivePhoto.classFile = NKCommon.TypeClassFile.video.rawValue
                 metadataLivePhoto.isExtractFile = true
                 metadataLivePhoto.session = metadata.session

+ 38 - 0
iOSClient/Utility/NCLivePhoto.swift

@@ -10,9 +10,13 @@ import UIKit
 import AVFoundation
 import MobileCoreServices
 import Photos
+import NextcloudKit
 
 class NCLivePhoto {
 
+    var livePhotoFile = ""
+    var livePhotoFile2 = ""
+
     // MARK: PUBLIC
     typealias LivePhotoResources = (pairedImage: URL, pairedVideo: URL)
     /// Returns the paired image and video for the given PHLivePhoto
@@ -463,3 +467,37 @@ fileprivate extension AVAsset {
         }
     }
 }
+
+extension NCLivePhoto {
+
+
+    func setLivephoto(metadata: tableMetadata) {
+
+        livePhotoFile = metadata.livePhotoFile
+        livePhotoFile2 = metadata.fileName
+
+        if livePhotoFile.isEmpty {
+            if metadata.classFile == NKCommon.TypeClassFile.image.rawValue {
+                livePhotoFile = (metadata.fileName as NSString).deletingPathExtension + ".mov"
+            } else if metadata.classFile == NKCommon.TypeClassFile.video.rawValue {
+                livePhotoFile = (metadata.fileName as NSString).deletingPathExtension + ".jpg"
+            }
+        }
+
+        guard metadata.livePhoto,
+              !livePhotoFile.isEmpty,
+              let metadata2 = NCManageDatabase.shared.getMetadata(predicate: NSPredicate(format: "account == %@ AND urlBase == %@ AND path == %@ AND fileName == %@ AND status == %d", metadata.account, metadata.urlBase, metadata.path, livePhotoFile, NCGlobal.shared.metadataStatusNormal)) else { return }
+
+        let serverUrlfileNamePath1 = metadata.urlBase + metadata.path + metadata.fileName
+        let serverUrlfileNamePath2 = metadata2.urlBase + metadata2.path + livePhotoFile
+
+        Task {
+            if metadata.livePhotoFile.isEmpty {
+                _ = await NextcloudKit.shared.setLivephoto(serverUrlfileNamePath: serverUrlfileNamePath1, livePhotoFile: livePhotoFile)
+            }
+            if metadata2.livePhotoFile.isEmpty {
+                _ = await NextcloudKit.shared.setLivephoto(serverUrlfileNamePath: serverUrlfileNamePath2, livePhotoFile: livePhotoFile2)
+            }
+        }
+    }
+}