Skip to content

Commit 7b5e718

Browse files
NMC 2248 - Image video upload customisation
1 parent 09dd9a1 commit 7b5e718

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
@@ -181,6 +181,7 @@ struct UploadAssetsView: View {
181181
}
182182

183183
private func setFileNameMaskForPreview(fileName: String?) -> String {
184+
let utilityFileSystem = NCUtilityFileSystem()
184185
guard let asset = uploadAssets.assets.first?.phAsset else { return "" }
185186
var preview: String = ""
186187
let creationDate = asset.creationDate ?? Date()
@@ -200,8 +201,30 @@ struct UploadAssetsView: View {
200201
)
201202

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

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

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

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

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

0 commit comments

Comments
 (0)