@@ -181,6 +181,7 @@ struct UploadAssetsView: View {
181
181
}
182
182
183
183
private func setFileNameMaskForPreview( fileName: String ? ) -> String {
184
+ let utilityFileSystem = NCUtilityFileSystem ( )
184
185
guard let asset = uploadAssets. assets. first? . phAsset else { return " " }
185
186
var preview : String = " "
186
187
let creationDate = asset. creationDate ?? Date ( )
@@ -200,8 +201,30 @@ struct UploadAssetsView: View {
200
201
)
201
202
202
203
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
+ }
203
226
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
205
228
}
206
229
207
230
private func save( completion: @escaping ( _ metadatasNOConflict: [ tableMetadata ] , _ metadatasUploadInConflict: [ tableMetadata ] ) -> Void ) {
@@ -339,74 +362,48 @@ struct UploadAssetsView: View {
339
362
NavigationView {
340
363
ZStack ( alignment: . top) {
341
364
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)
404
376
}
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)
405
384
}
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)
406
403
}
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 ) ) ) {
410
407
Toggle ( isOn: $isMaintainOriginalFilename, label: {
411
408
Text ( NSLocalizedString ( " _maintain_original_filename_ " , comment: " " ) )
412
409
. font ( . system( size: 15 ) )
@@ -419,99 +416,52 @@ struct UploadAssetsView: View {
419
416
. font ( . system( size: 15 ) )
420
417
} )
421
418
. 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 {
441
419
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)
458
430
}
459
431
}
460
- . contentShape ( Rectangle ( ) )
461
- . onTapGesture {
462
- isPresentedSelect = true
463
- }
464
432
}
465
- }
466
433
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
489
435
view. listRowSeparator ( . hidden)
490
436
}
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)
512
437
}
438
+ . listStyle ( GroupedListStyle ( ) )
513
439
. navigationTitle ( NSLocalizedString ( " _upload_photos_videos_ " , comment: " " ) )
514
440
. 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
+ }
515
465
516
466
HUDView ( showHUD: $uploadAssets. showHUD, textLabel: NSLocalizedString ( " _wait_ " , comment: " " ) , image: " doc.badge.arrow.up " )
517
467
. offset ( y: uploadAssets. showHUD ? 5 : - 200 )
0 commit comments