From 9e45aedc7aaa1f09adadfdc95e2db2000a5016af Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Thu, 10 Oct 2024 10:05:51 +0200 Subject: [PATCH 1/2] Warn when file extension is renamed Signed-off-by: tobiasKaminsky --- .../ui/dialog/RenameFileDialogFragment.kt | 16 ++++++++++++++++ app/src/main/res/values/strings.xml | 3 +-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/ui/dialog/RenameFileDialogFragment.kt b/app/src/main/java/com/owncloud/android/ui/dialog/RenameFileDialogFragment.kt index 0ca1cde470..bdedacdc75 100644 --- a/app/src/main/java/com/owncloud/android/ui/dialog/RenameFileDialogFragment.kt +++ b/app/src/main/java/com/owncloud/android/ui/dialog/RenameFileDialogFragment.kt @@ -37,6 +37,7 @@ import com.owncloud.android.ui.activity.FileDisplayActivity import com.owncloud.android.utils.DisplayUtils import com.owncloud.android.utils.KeyboardUtils import com.owncloud.android.utils.theme.ViewThemeUtils +import java.io.File import javax.inject.Inject /** @@ -178,9 +179,13 @@ class RenameFileDialogFragment : DialogFragment(), DialogInterface.OnClickListen if (isFileHidden(newFileName)) { binding.userInputContainer.error = getText(R.string.hidden_file_name_warning) + positiveButton?.isEnabled = true } else if (errorMessage != null) { binding.userInputContainer.error = errorMessage positiveButton?.isEnabled = false + } else if (checkExtensionRenamed(newFileName)) { + binding.userInputContainer.error = getText(R.string.warn_rename_extension) + positiveButton?.isEnabled = true } else if (binding.userInputContainer.error != null) { binding.userInputContainer.error = null // Called to remove extra padding @@ -191,6 +196,17 @@ class RenameFileDialogFragment : DialogFragment(), DialogInterface.OnClickListen override fun afterTextChanged(s: Editable) = Unit + private fun checkExtensionRenamed(newFileName: String): Boolean { + mTargetFile?.fileName?.let { + val previousExtension = File(it).extension + val newExtension = File(newFileName).extension + + return previousExtension != newExtension + } + + return false + } + companion object { private const val ARG_TARGET_FILE = "TARGET_FILE" private const val ARG_PARENT_FOLDER = "PARENT_FOLDER" diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bbf49635e8..83c91ed75f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1268,11 +1268,10 @@ Please select a server… Unread notifications exist Remove folder from internal two way sync - Two way sync not set up To set up a two way sync folder, please enable it in the details tab of the folder in question. Internal two way sync Disable for all folders - Pending Remove Operation + Renaming extension might make the file unusable From dc1d5dfa19e327412ab4dde53b56c4c26b19c971 Mon Sep 17 00:00:00 2001 From: Tobias Kaminsky Date: Thu, 24 Oct 2024 09:48:14 +0200 Subject: [PATCH 2/2] Update app/src/main/java/com/owncloud/android/ui/dialog/RenameFileDialogFragment.kt Co-authored-by: Tom <70907959+ZetaTom@users.noreply.github.com> Signed-off-by: Tobias Kaminsky Signed-off-by: tobiasKaminsky --- .../owncloud/android/ui/dialog/RenameFileDialogFragment.kt | 4 ++-- app/src/main/res/values/strings.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/ui/dialog/RenameFileDialogFragment.kt b/app/src/main/java/com/owncloud/android/ui/dialog/RenameFileDialogFragment.kt index bdedacdc75..38c74ca57e 100644 --- a/app/src/main/java/com/owncloud/android/ui/dialog/RenameFileDialogFragment.kt +++ b/app/src/main/java/com/owncloud/android/ui/dialog/RenameFileDialogFragment.kt @@ -197,8 +197,8 @@ class RenameFileDialogFragment : DialogFragment(), DialogInterface.OnClickListen override fun afterTextChanged(s: Editable) = Unit private fun checkExtensionRenamed(newFileName: String): Boolean { - mTargetFile?.fileName?.let { - val previousExtension = File(it).extension + mTargetFile?.fileName?.let { previousFileName -> + val previousExtension = File(previousFileName).extension val newExtension = File(newFileName).extension return previousExtension != newExtension diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 83c91ed75f..60a5c33418 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1273,5 +1273,5 @@ Internal two way sync Disable for all folders Pending Remove Operation - Renaming extension might make the file unusable + Changing the extension might cause this file to open in a different application