From 2cbd36b797cc40c0e18f889cec186023fac8ab1b Mon Sep 17 00:00:00 2001 From: alperozturk Date: Tue, 24 Sep 2024 15:01:21 +0200 Subject: [PATCH] Simplify return Signed-off-by: alperozturk --- .../com/nextcloud/utils/autoRename/AutoRename.kt | 13 ++++++------- .../utils/extensions/OCCapabilityExtensions.kt | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/nextcloud/utils/autoRename/AutoRename.kt b/app/src/main/java/com/nextcloud/utils/autoRename/AutoRename.kt index 4c897c21fdca..b4266c20e3bd 100644 --- a/app/src/main/java/com/nextcloud/utils/autoRename/AutoRename.kt +++ b/app/src/main/java/com/nextcloud/utils/autoRename/AutoRename.kt @@ -10,7 +10,7 @@ package com.nextcloud.utils.autoRename import com.nextcloud.utils.extensions.StringConstants import com.nextcloud.utils.extensions.forbiddenFilenameCharacters import com.nextcloud.utils.extensions.forbiddenFilenameExtension -import com.nextcloud.utils.extensions.shouldRemoveNonPrintableUnicodeCharacters +import com.nextcloud.utils.extensions.shouldRemoveNonPrintableUnicodeCharactersAndConvertToUTF8 import com.owncloud.android.datamodel.OCFile import com.owncloud.android.lib.resources.status.NextcloudVersion import com.owncloud.android.lib.resources.status.OCCapability @@ -65,14 +65,13 @@ object AutoRename { } } - var result = pathSegments.joinToString(OCFile.PATH_SEPARATOR) - - if (capability.shouldRemoveNonPrintableUnicodeCharacters()) { + val result = pathSegments.joinToString(OCFile.PATH_SEPARATOR) + return if (capability.shouldRemoveNonPrintableUnicodeCharactersAndConvertToUTF8()) { val utf8Result = convertToUTF8(result) - result = removeNonPrintableUnicodeCharacters(utf8Result) + removeNonPrintableUnicodeCharacters(utf8Result) + } else { + result } - - return result } private fun convertToUTF8(filename: String): String { diff --git a/app/src/main/java/com/nextcloud/utils/extensions/OCCapabilityExtensions.kt b/app/src/main/java/com/nextcloud/utils/extensions/OCCapabilityExtensions.kt index aa9efc1616fc..e153e8900f9a 100644 --- a/app/src/main/java/com/nextcloud/utils/extensions/OCCapabilityExtensions.kt +++ b/app/src/main/java/com/nextcloud/utils/extensions/OCCapabilityExtensions.kt @@ -21,7 +21,7 @@ fun OCCapability.forbiddenFilenameExtension(): List = jsonToList(forbidd fun OCCapability.forbiddenFilenameBaseNames(): List = jsonToList(forbiddenFilenameBaseNamesJson) -fun OCCapability.shouldRemoveNonPrintableUnicodeCharacters(): Boolean { +fun OCCapability.shouldRemoveNonPrintableUnicodeCharactersAndConvertToUTF8(): Boolean { return forbiddenFilenames().isNotEmpty() || forbiddenFilenameCharacters().isNotEmpty() || forbiddenFilenameExtension().isNotEmpty() ||