Эх сурвалжийг харах

add localizable

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
Marino Faggiana 2 жил өмнө
parent
commit
0103b04c6f

+ 31 - 14
iOSClient/Main/Create cloud/NCUploadAssets.swift

@@ -38,13 +38,19 @@ class NCHostingUploadAssetsView: NSObject {
 
 // MARK: - Class
 
+struct PreviewStore {
+    var image: UIImage
+    var localIdentifier: String
+    var modify: Bool
+}
+
 class NCUploadAssets: NSObject, ObservableObject, NCCreateFormUploadConflictDelegate {
 
     @Published var serverUrl: String
     @Published var assets: [TLPHAsset]
     @Published var userBaseUrl: NCUserBaseUrl
     @Published var dismiss = false
-    @Published var images: [UIImage] = []
+    @Published var previewStore: [PreviewStore] = []
 
     var metadatasNOConflict: [tableMetadata] = []
     var metadatasUploadInConflict: [tableMetadata] = []
@@ -59,8 +65,8 @@ class NCUploadAssets: NSObject, ObservableObject, NCCreateFormUploadConflictDele
     func loadImages() {
         DispatchQueue.global().async {
             for asset in self.assets {
-                guard asset.type == .photo, let image = asset.fullResolutionImage else { continue }
-                self.images.append(image)
+                guard asset.type == .photo, let image = asset.fullResolutionImage, let localIdentifier = asset.phAsset?.localIdentifier else { continue }
+                self.previewStore.append(PreviewStore(image: image, localIdentifier: localIdentifier, modify: false))
             }
         }
     }
@@ -200,6 +206,18 @@ struct UploadAssetsView: View {
             metadata.sessionSelector = NCGlobal.shared.selectorUploadFile
             metadata.status = NCGlobal.shared.metadataStatusWaitUpload
 
+            // Modified
+            if let previewStore = uploadAssets.previewStore.first(where: {$0.localIdentifier == asset.localIdentifier && $0.modify == true }), let data = previewStore.image.jpegData(compressionQuality: 1) {
+                let fileNamePath = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)!
+                do {
+                    try data.write(to: URL(fileURLWithPath: fileNamePath))
+                    metadata.isExtractFile = true
+                    metadata.size = NCUtilityFileSystem.shared.getFileSize(filePath: fileNamePath)
+                    metadata.creationDate = asset.creationDate as? NSDate ?? (Date() as NSDate)
+                    metadata.date = asset.modificationDate as? NSDate ?? (Date() as NSDate)
+                } catch {  }
+            }
+
             if let result = NCManageDatabase.shared.getMetadataConflict(account: uploadAssets.userBaseUrl.account, serverUrl: serverUrl, fileNameView: fileName) {
                 metadata.fileName = result.fileName
                 metadatasUploadInConflict.append(metadata)
@@ -221,13 +239,13 @@ struct UploadAssetsView: View {
         NavigationView {
             List {
 
-                if !uploadAssets.images.isEmpty {
-                    Section(header: Text(NSLocalizedString("_crop_", comment: "")), footer: Text(NSLocalizedString("_crop_description_", comment: ""))) {
+                if !uploadAssets.previewStore.isEmpty {
+                    Section(header: Text(NSLocalizedString("_crop_", comment: "")), footer: Text(NSLocalizedString("_modify_crop_desc_", comment: ""))) {
                         ScrollView(.horizontal) {
                             LazyHGrid(rows: gridItems, alignment: .center, spacing: 10) {
-                                ForEach(0..<uploadAssets.images.count, id: \.self) { index in
+                                ForEach(0..<uploadAssets.previewStore.count, id: \.self) { index in
                                     VStack {
-                                        Image(uiImage: uploadAssets.images[index])
+                                        Image(uiImage: uploadAssets.previewStore[index].image)
                                             .resizable()
                                             .frame(width: 100, height: 100, alignment: .center)
                                             .cornerRadius(10)
@@ -320,7 +338,7 @@ struct UploadAssetsView: View {
             .navigationBarTitleDisplayMode(.inline)
         }
         .sheet(isPresented: $isPresentedCrop) {
-            ImageCropper(images: $uploadAssets.images, index: $index, cropShapeType: $cropShapeType, presetFixedRatioType: $presetFixedRatioType)
+            ImageCropper(previewStore: $uploadAssets.previewStore, index: $index, cropShapeType: $cropShapeType, presetFixedRatioType: $presetFixedRatioType)
                 .ignoresSafeArea()
         }
         .sheet(isPresented: $isPresentedSelect) {
@@ -341,7 +359,7 @@ struct UploadAssetsView: View {
 
 struct ImageCropper: UIViewControllerRepresentable {
 
-    @Binding var images: [UIImage]
+    @Binding var previewStore: [PreviewStore]
     @Binding var index: Int
     @Binding var cropShapeType: Mantis.CropShapeType
     @Binding var presetFixedRatioType: Mantis.PresetFixedRatioType
@@ -357,7 +375,8 @@ struct ImageCropper: UIViewControllerRepresentable {
         }
 
         func cropViewControllerDidCrop(_ cropViewController: CropViewController, cropped: UIImage, transformation: Transformation, cropInfo: CropInfo) {
-            parent.images[parent.index] = cropped
+            parent.previewStore[parent.index].image = cropped
+            parent.previewStore[parent.index].modify = true
             parent.presentationMode.wrappedValue.dismiss()
         }
 
@@ -382,15 +401,13 @@ struct ImageCropper: UIViewControllerRepresentable {
         var config = Mantis.Config()
         config.cropViewConfig.cropShapeType = cropShapeType
         config.presetFixedRatioType = presetFixedRatioType
-        let image = images[index]
+        let image = previewStore[index].image
         let cropViewController = Mantis.cropViewController(image: image, config: config)
         cropViewController.delegate = context.coordinator
         return cropViewController
     }
 
-    func updateUIViewController(_ uiViewController: CropViewController, context: Context) {
-
-    }
+    func updateUIViewController(_ uiViewController: CropViewController, context: Context) { }
 }
 
 // MARK: - Preview

+ 2 - 0
iOSClient/Supporting Files/en.lproj/Localizable.strings

@@ -917,6 +917,8 @@
 "_mobile_config_"           = "Download the configuration profile";
 "_calendar_contacts_footer_"    = "After the downloading you need to go to the Settings app to install it. If a profile is not installed within 8 minutes of downloading it, it is automatically deleted";
 "_preview_"                 = "Preview";
+"_crop_"                    = "Crop photo";
+"_modify_crop_desc_"        = "Tap the image for cropping";
 
 // Video
 "_select_trace_"            = "Select the trace";