Skip to content

Commit

Permalink
restore maintain original filename (#2972)
Browse files Browse the repository at this point in the history
Signed-off-by: Marino Faggiana <[email protected]>
  • Loading branch information
marinofaggiana authored Jul 2, 2024
1 parent e97f47b commit 00529b8
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 13 deletions.
8 changes: 4 additions & 4 deletions Nextcloud.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -5348,7 +5348,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 9;
CURRENT_PROJECT_VERSION = 0;
DEBUG_INFORMATION_FORMAT = dwarf;
DEVELOPMENT_TEAM = NKUJUXUJ3B;
ENABLE_STRICT_OBJC_MSGSEND = YES;
Expand All @@ -5375,7 +5375,7 @@
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 5.4.0;
MARKETING_VERSION = 5.4.1;
ONLY_ACTIVE_ARCH = YES;
OTHER_CFLAGS = "-v";
OTHER_LDFLAGS = "";
Expand Down Expand Up @@ -5414,7 +5414,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 9;
CURRENT_PROJECT_VERSION = 0;
DEVELOPMENT_TEAM = NKUJUXUJ3B;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
Expand All @@ -5438,7 +5438,7 @@
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 5.4.0;
MARKETING_VERSION = 5.4.1;
ONLY_ACTIVE_ARCH = YES;
OTHER_CFLAGS = "-v";
OTHER_LDFLAGS = "";
Expand Down
9 changes: 7 additions & 2 deletions iOSClient/Settings/Advanced/File Name/NCFileNameModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ class NCFileNameModel: ObservableObject, ViewOnAppearHandling {
/// A shared global instance for managing application-wide settings.
private let globalKey = NCGlobal.shared
/// A boolean indicating whether to maintain the original file name.
@Published var maintainFilename: Bool = false
@Published var maintainFilenameOriginal: Bool = NCKeychain().fileNameOriginal
/// A boolean indicating whether to specify a custom file name.
@Published var specifyFilename: Bool = false
@Published var addFileNameType: Bool = NCKeychain().fileNameType
/// The changed file name.
@Published var changedName: String = ""
/// The complete new file name.
Expand Down Expand Up @@ -63,6 +63,11 @@ class NCFileNameModel: ObservableObject, ViewOnAppearHandling {
keychain.fileNameType = newValue
}

/// Toggles maintain original asset filename.
func toggleMaintainFilenameOriginal(newValue: Bool) {
keychain.fileNameOriginal = newValue
}

/// Submits the changed file name.
func submitChangedName() {
let fileNameWithoutForbiddenChars = NCUtility().removeForbiddenCharacters(changedName)
Expand Down
20 changes: 14 additions & 6 deletions iOSClient/Settings/Advanced/File Name/NCFileNameView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,31 @@ struct NCFileNameView: View {
Form {
/// Specify Filename
Section(header: Text(NSLocalizedString("_mode_filename_", comment: ""))) {
///
Toggle(NSLocalizedString("_maintain_original_filename_", comment: ""), isOn: $model.maintainFilenameOriginal)
.font(.system(size: 16))
.tint(Color(NCBrandColor.shared.brandElement))
.onChange(of: model.maintainFilenameOriginal, perform: { newValue in
model.toggleMaintainFilenameOriginal(newValue: newValue)
model.getFileName()
})
/// Filename
if !model.maintainFilename {
Toggle(NSLocalizedString("_add_filenametype_", comment: ""), isOn: $model.specifyFilename)
if !model.maintainFilenameOriginal {
Toggle(NSLocalizedString("_add_filenametype_", comment: ""), isOn: $model.addFileNameType)
.font(.system(size: 16))
.tint(Color(NCBrandColor.shared.brandElement))
.onChange(of: model.specifyFilename, perform: { newValue in
.onChange(of: model.addFileNameType, perform: { newValue in
model.toggleAddFilenameType(newValue: newValue)
model.getFileName()
})
}
}
.transition(.slide)
.animation(.easeInOut, value: model.maintainFilename)
.animation(.easeInOut, value: model.maintainFilenameOriginal)

/// Filename Preview
fileNamePreview
.animation(.easeInOut, value: model.specifyFilename)
.animation(.easeInOut, value: model.addFileNameType)
}
.navigationBarTitle(NSLocalizedString("_mode_filename_", comment: ""))
.defaultViewModifier(model)
Expand All @@ -56,7 +64,7 @@ struct NCFileNameView: View {

@ViewBuilder
var fileNamePreview: some View {
if !model.maintainFilename {
if !model.maintainFilenameOriginal {
Section(content: {
HStack {
Text(NSLocalizedString("_filename_", comment: ""))
Expand Down
12 changes: 12 additions & 0 deletions iOSClient/Settings/NCKeychain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,18 @@ import KeychainAccess
}
}

var fileNameOriginal: Bool {
get {
if let value = try? keychain.get("fileNameOriginal"), let result = Bool(value) {
return result
}
return false
}
set {
keychain["fileNameOriginal"] = String(newValue)
}
}

var fileNameMask: String {
get {
if let value = try? keychain.get("fileNameMask") {
Expand Down
12 changes: 11 additions & 1 deletion iOSClient/Utility/NCUtilityFileSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -430,11 +430,21 @@ class NCUtilityFileSystem: NSObject {
func createFileName(_ fileName: String, fileDate: Date, fileType: PHAssetMediaType, notUseMask: Bool = false) -> String {
var fileName = fileName
let keychain = NCKeychain()
let addFileNameType: Bool = keychain.fileNameType
var addFileNameType: Bool = keychain.fileNameType
let useFileNameOriginal: Bool = keychain.fileNameOriginal
var numberFileName: String = ""
var fileNameType = ""
let fileNameExt = (fileName as NSString).pathExtension.lowercased()

/// Original FileName
if useFileNameOriginal {
addFileNameType = false
if !notUseMask {
return fileName
}
}

/// Get counter
if fileName.count > 8 {
let index = fileName.index(fileName.startIndex, offsetBy: 4)
numberFileName = String(fileName[index..<fileName.index(index, offsetBy: 4)])
Expand Down

0 comments on commit 00529b8

Please sign in to comment.