Skip to content

Commit 1fda763

Browse files
NMC 2248 - Image video upload customisation
1 parent f72360b commit 1fda763

File tree

2 files changed

+135
-149
lines changed

2 files changed

+135
-149
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//
2+
// AssetUploadTest.swift
3+
// NextcloudTests
4+
//
5+
// Created by A200020526 on 12/06/23.
6+
// Copyright © 2023 Marino Faggiana. All rights reserved.
7+
//
8+
9+
import XCTest
10+
11+
final class AssetUploadTest: XCTestCase {
12+
13+
override func setUpWithError() throws {
14+
// Put setup code here. This method is called before the invocation of each test method in the class.
15+
}
16+
17+
override func tearDownWithError() throws {
18+
// Put teardown code here. This method is called after the invocation of each test method in the class.
19+
}
20+
21+
func testExample() throws {
22+
// This is an example of a functional test case.
23+
// Use XCTAssert and related functions to verify your tests produce the correct results.
24+
// Any test you write for XCTest can be annotated as throws and async.
25+
// Mark your test throws to produce an unexpected failure when your test encounters an uncaught error.
26+
// Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards.
27+
}
28+
29+
func testPerformanceExample() throws {
30+
// This is an example of a performance test case.
31+
self.measure {
32+
// Put the code you want to measure the time of here.
33+
}
34+
}
35+
36+
}

iOSClient/Main/Create cloud/NCUploadAssets.swift

Lines changed: 99 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ struct UploadAssetsView: View {
180180
}
181181

182182
private func setFileNameMaskForPreview(fileName: String?) -> String {
183-
183+
let utilityFileSystem = NCUtilityFileSystem()
184184
guard let asset = uploadAssets.assets.first?.phAsset else { return "" }
185185
var preview: String = ""
186186
let creationDate = asset.creationDate ?? Date()
@@ -200,8 +200,30 @@ struct UploadAssetsView: View {
200200
)
201201

202202
let trimmedPreview = preview.trimmingCharacters(in: .whitespacesAndNewlines)
203+
204+
if !(fileName?.isEmpty ?? false) {
205+
206+
NCKeychain().setFileNameMask(key: fileName ?? "", mask: NCGlobal.shared.keyFileNameMask)
207+
preview = CCUtility.createFileName(asset.value(forKey: "filename") as? String,
208+
fileDate: creationDate, fileType: asset.mediaType,
209+
keyFileName: NCGlobal.shared.keyFileNameMask,
210+
keyFileNameType: NCGlobal.shared.keyFileNameType,
211+
keyFileNameOriginal: NCGlobal.shared.keyFileNameOriginal,
212+
forcedNewFileName: false)
213+
214+
} else {
215+
216+
NCKeychain().setFileNameMask(key: "", mask: NCGlobal.shared.keyFileNameMask)
217+
preview = CCUtility.createFileName(asset.value(forKey: "filename") as? String,
218+
fileDate: creationDate,
219+
fileType: asset.mediaType,
220+
keyFileName: nil,
221+
keyFileNameType: NCGlobal.shared.keyFileNameType,
222+
keyFileNameOriginal: NCGlobal.shared.keyFileNameOriginal,
223+
forcedNewFileName: false)
224+
}
203225

204-
return String(format: NSLocalizedString("_preview_filename_", comment: ""), "MM, MMM, DD, YY, YYYY, HH, hh, mm, ss, ampm") + ":" + "\n\n" + (trimmedPreview as NSString).deletingPathExtension
226+
return (!isMaintainOriginalFilename ? (String(format: NSLocalizedString("_preview_filename_", comment: ""), "MM, MMM, DD, YY, YYYY, HH, hh, mm, ss, ampm") + ":" + "\n\n") : #"\#(NSLocalizedString("_filename_", comment: "") ): "#) + preview
205227
}
206228

207229
private func save(completion: @escaping (_ metadatasNOConflict: [tableMetadata], _ metadatasUploadInConflict: [tableMetadata]) -> Void) {
@@ -343,74 +365,48 @@ struct UploadAssetsView: View {
343365
NavigationView {
344366
ZStack(alignment: .top) {
345367
List {
346-
Section(footer: Text(NSLocalizedString("_modify_image_desc_", comment: ""))) {
347-
ScrollView(.horizontal) {
348-
LazyHGrid(rows: gridItems, alignment: .center, spacing: 10) {
349-
ForEach(0..<uploadAssets.previewStore.count, id: \.self) { index in
350-
let item = uploadAssets.previewStore[index]
351-
Menu {
352-
Button(action: {
353-
renameFileName = uploadAssets.previewStore[index].fileName
354-
renameIndex = index
355-
isPresentedAlert = true
356-
}) {
357-
Label(NSLocalizedString("_rename_", comment: ""), systemImage: "pencil")
358-
}
359-
if item.asset.type == .photo || item.asset.type == .livePhoto {
360-
Button(action: {
361-
presentedQuickLook(index: index)
362-
}) {
363-
Label(NSLocalizedString("_modify_", comment: ""), systemImage: "pencil.tip.crop.circle")
364-
}
365-
}
366-
if item.data != nil {
367-
Button(action: {
368-
if let image = uploadAssets.previewStore[index].asset.fullResolutionImage?.resizeImage(size: CGSize(width: 300, height: 300), isAspectRation: true) {
369-
uploadAssets.previewStore[index].image = image
370-
uploadAssets.previewStore[index].data = nil
371-
uploadAssets.previewStore[index].assetType = uploadAssets.previewStore[index].asset.type
372-
}
373-
}) {
374-
Label(NSLocalizedString("_undo_modify_", comment: ""), systemImage: "arrow.uturn.backward.circle")
375-
}
376-
}
377-
if item.data == nil && item.asset.type == .livePhoto && item.assetType == .livePhoto {
378-
Button(action: {
379-
uploadAssets.previewStore[index].assetType = .photo
380-
}) {
381-
Label(NSLocalizedString("_disable_livephoto_", comment: ""), systemImage: "livephoto.slash")
382-
}
383-
} else if item.data == nil && item.asset.type == .livePhoto && item.assetType == .photo {
384-
Button(action: {
385-
uploadAssets.previewStore[index].assetType = .livePhoto
386-
}) {
387-
Label(NSLocalizedString("_enable_livephoto_", comment: ""), systemImage: "livephoto")
388-
}
389-
}
390-
Button(role: .destructive, action: {
391-
deleteAsset(index: index)
392-
}) {
393-
Label(NSLocalizedString("_remove_", comment: ""), systemImage: "trash")
394-
}
395-
} label: {
396-
ImageAsset(uploadAssets: uploadAssets, index: index)
397-
.alert(NSLocalizedString("_rename_file_", comment: ""), isPresented: $isPresentedAlert) {
398-
TextField(NSLocalizedString("_enter_filename_", comment: ""), text: $renameFileName)
399-
.autocapitalization(.none)
400-
.autocorrectionDisabled()
401-
Button(NSLocalizedString("_rename_", comment: ""), action: {
402-
uploadAssets.previewStore[renameIndex].fileName = renameFileName.trimmingCharacters(in: .whitespacesAndNewlines)
403-
})
404-
Button(NSLocalizedString("_cancel_", comment: ""), role: .cancel, action: {})
405-
}
406-
}
407-
}
368+
//Save Path
369+
Section(header: Text(NSLocalizedString("_save_path_", comment: "").uppercased()), footer: Text(NSLocalizedString("_auto_upload_help_text_", comment: ""))) {
370+
HStack {
371+
if utilityFileSystem.getHomeServer(urlBase: uploadAssets.userBaseUrl.urlBase, userId: uploadAssets.userBaseUrl.userId) == uploadAssets.serverUrl {
372+
Text(NSLocalizedString("_prefix_upload_path_", comment: ""))
373+
.font(.system(size: 15))
374+
.frame(maxWidth: .infinity, alignment: .leading)
375+
} else {
376+
Text(self.getTextServerUrl(uploadAssets.serverUrl))
377+
.font(.system(size: 15))
378+
.frame(maxWidth: .infinity, alignment: .leading)
408379
}
380+
381+
Image("folder")
382+
.renderingMode(.template)
383+
.resizable()
384+
.scaledToFit()
385+
.foregroundColor(Color(NCBrandColor.shared.brand))
386+
.frame(width: 25, height: 25, alignment: .trailing)
409387
}
388+
.onTapGesture {
389+
isPresentedSelect = true
390+
}
391+
392+
393+
Toggle(isOn: $uploadAssets.isUseAutoUploadFolder, label: {
394+
Text(NSLocalizedString("_use_folder_auto_upload_", comment: ""))
395+
.font(.system(size: 15))
396+
})
397+
.toggleStyle(SwitchToggleStyle(tint: Color(NCBrandColor.shared.brand)))
398+
399+
Toggle(isOn: $uploadAssets.isUseAutoUploadSubFolder, label: {
400+
Text(NSLocalizedString("_autoupload_create_subfolder_", comment: ""))
401+
.font(.system(size: 15))
402+
.disabled(!uploadAssets.isUseAutoUploadFolder)
403+
})
404+
.toggleStyle(SwitchToggleStyle(tint: Color(NCBrandColor.shared.brand)))
405+
.disabled(!uploadAssets.isUseAutoUploadFolder)
410406
}
411-
.redacted(reason: uploadAssets.previewStore.isEmpty ? .placeholder : [])
412-
413-
Section {
407+
408+
//File Name
409+
Section(header: Text(NSLocalizedString("_filename_", comment: "").uppercased()), footer: Text(setFileNameMaskForPreview(fileName: fileName))) {
414410
Toggle(isOn: $isMaintainOriginalFilename, label: {
415411
Text(NSLocalizedString("_maintain_original_filename_", comment: ""))
416412
.font(.system(size: 15))
@@ -423,98 +419,52 @@ struct UploadAssetsView: View {
423419
.font(.system(size: 15))
424420
})
425421
.toggleStyle(SwitchToggleStyle(tint: Color(NCBrandColor.shared.brand)))
426-
}
427-
}
428-
429-
Section {
430-
Toggle(isOn: $uploadAssets.isUseAutoUploadFolder, label: {
431-
Text(NSLocalizedString("_use_folder_auto_upload_", comment: ""))
432-
.font(.system(size: 15))
433-
})
434-
.toggleStyle(SwitchToggleStyle(tint: Color(NCBrandColor.shared.brand)))
435-
436-
if uploadAssets.isUseAutoUploadFolder {
437-
Toggle(isOn: $uploadAssets.isUseAutoUploadSubFolder, label: {
438-
Text(NSLocalizedString("_autoupload_create_subfolder_", comment: ""))
439-
.font(.system(size: 15))
440-
})
441-
.toggleStyle(SwitchToggleStyle(tint: Color(NCBrandColor.shared.brand)))
442-
}
443-
444-
if !uploadAssets.isUseAutoUploadFolder {
445422
HStack {
446-
Label {
447-
if utilityFileSystem.getHomeServer(urlBase: uploadAssets.userBaseUrl.urlBase, userId: uploadAssets.userBaseUrl.userId) == uploadAssets.serverUrl {
448-
Text("/")
449-
.font(.system(size: 15))
450-
.frame(maxWidth: .infinity, alignment: .trailing)
451-
} else {
452-
Text(self.getTextServerUrl(uploadAssets.serverUrl))
453-
.font(.system(size: 15))
454-
.frame(maxWidth: .infinity, alignment: .trailing)
455-
}
456-
} icon: {
457-
Image("folder")
458-
.renderingMode(.template)
459-
.resizable()
460-
.scaledToFit()
461-
.foregroundColor(Color(NCBrandColor.shared.brand))
423+
if isMaintainOriginalFilename {
424+
Text(getOriginalFilenameForPreview() as? String ?? "")
425+
.font(.system(size: 15))
426+
.frame(maxWidth: .infinity, alignment: .leading)
427+
.foregroundColor(Color.gray)
428+
} else {
429+
TextField(NSLocalizedString("_enter_filename_", comment: ""), text: $fileName)
430+
.font(.system(size: 15))
431+
.modifier(TextFieldClearButton(text: $fileName))
432+
.multilineTextAlignment(.leading)
462433
}
463434
}
464-
.contentShape(Rectangle())
465-
.onTapGesture {
466-
isPresentedSelect = true
467-
}
468435
}
469-
}
470436

471-
Section {
472-
HStack {
473-
Text(NSLocalizedString("_filename_", comment: ""))
474-
if isMaintainOriginalFilename {
475-
Text(getOriginalFilenameForPreview().deletingPathExtension)
476-
.font(.system(size: 15))
477-
.frame(maxWidth: .infinity, alignment: .trailing)
478-
.foregroundColor(Color.gray)
479-
} else {
480-
TextField(NSLocalizedString("_enter_filename_", comment: ""), text: $fileName)
481-
.font(.system(size: 15))
482-
.modifier(TextFieldClearButton(text: $fileName))
483-
.multilineTextAlignment(.trailing)
484-
}
485-
}
486-
if !isMaintainOriginalFilename {
487-
Text(setFileNameMaskForPreview(fileName: fileName))
488-
.font(.system(size: 11))
489-
.foregroundColor(Color.gray)
490-
}
491-
}
492-
.complexModifier { view in
437+
}.complexModifier { view in
493438
view.listRowSeparator(.hidden)
494439
}
495-
496-
Button(NSLocalizedString("_save_", comment: "")) {
497-
if uploadAssets.isUseAutoUploadFolder, uploadAssets.isUseAutoUploadSubFolder {
498-
uploadAssets.showHUD = true
499-
}
500-
uploadAssets.uploadInProgress.toggle()
501-
save { metadatasNOConflict, metadatasUploadInConflict in
502-
if metadatasUploadInConflict.isEmpty {
503-
uploadAssets.dismissCreateFormUploadConflict(metadatas: metadatasNOConflict)
504-
} else {
505-
uploadAssets.metadatasNOConflict = metadatasNOConflict
506-
uploadAssets.metadatasUploadInConflict = metadatasUploadInConflict
507-
isPresentedUploadConflict = true
508-
}
509-
}
510-
}
511-
.frame(maxWidth: .infinity)
512-
.buttonStyle(ButtonRounded(disabled: uploadAssets.uploadInProgress))
513-
.listRowBackground(Color(UIColor.systemGroupedBackground))
514-
.disabled(uploadAssets.uploadInProgress)
515440
}
441+
.listStyle(GroupedListStyle())
516442
.navigationTitle(NSLocalizedString("_upload_photos_videos_", comment: ""))
517443
.navigationBarTitleDisplayMode(.inline)
444+
.toolbar{
445+
ToolbarItem(placement: .navigationBarLeading) {
446+
Button(NSLocalizedString("_cancel_", comment: "")) {
447+
self.uploadAssets.dismiss = true
448+
}.foregroundColor(Color(NCBrandColor.shared.brand))
449+
}
450+
ToolbarItem(placement: .navigationBarTrailing) {
451+
Button(NSLocalizedString("_save_", comment: "")) {
452+
if uploadAssets.isUseAutoUploadFolder, uploadAssets.isUseAutoUploadSubFolder {
453+
uploadAssets.showHUD = true
454+
}
455+
uploadAssets.uploadInProgress.toggle()
456+
save { metadatasNOConflict, metadatasUploadInConflict in
457+
if metadatasUploadInConflict.isEmpty {
458+
uploadAssets.dismissCreateFormUploadConflict(metadatas: metadatasNOConflict)
459+
} else {
460+
uploadAssets.metadatasNOConflict = metadatasNOConflict
461+
uploadAssets.metadatasUploadInConflict = metadatasUploadInConflict
462+
isPresentedUploadConflict = true
463+
}
464+
}
465+
}.foregroundColor(Color(NCBrandColor.shared.brand))
466+
}
467+
}
518468

519469
HUDView(showHUD: $uploadAssets.showHUD, textLabel: NSLocalizedString("_wait_", comment: ""), image: "doc.badge.arrow.up")
520470
.offset(y: uploadAssets.showHUD ? 5 : -200)

0 commit comments

Comments
 (0)