From 946b5cc2606e37dc13f396b9f9826cbf70a0b980 Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Tue, 8 Oct 2024 17:01:17 +0530 Subject: [PATCH] Improved the `getFilePathWithFolderFromUri`, and `getFullFilePathFromFilePath` methods to properly resolve the other folders uri. --- .../org/kiwix/kiwixmobile/core/utils/files/FileUtils.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/utils/files/FileUtils.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/utils/files/FileUtils.kt index 707b3df02..e621ccf93 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/utils/files/FileUtils.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/utils/files/FileUtils.kt @@ -186,7 +186,9 @@ object FileUtils { var actualFilePath: String? = null if (filePath?.isNotEmpty() == true) { getStorageVolumesList(context).forEach { volume -> - val file = File("$volume/$filePath") + // Check if the volume is part of the file path and remove it + val trimmedFilePath = filePath.removePrefix(volume) + val file = File("$volume/$trimmedFilePath") if (file.isFileExist()) { actualFilePath = file.path } @@ -283,7 +285,9 @@ object FileUtils { if (pathSegments.isNotEmpty()) { // Returns the path of the folder containing the file with the specified fileName, // from which the user selects the file. - return pathSegments.drop(1).joinToString(separator = "/") + return pathSegments.drop(1) + .filterNot { it.startsWith("0") } // remove the prefix of primary storage device + .joinToString(separator = "/") } return null }