diff --git a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryFragment.kt b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryFragment.kt
index b08499dee..5b1c6bd44 100644
--- a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryFragment.kt
+++ b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryFragment.kt
@@ -32,6 +32,7 @@ import android.view.MenuInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
+import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.view.ActionMode
import androidx.appcompat.widget.Toolbar
@@ -163,7 +164,7 @@ class LocalLibraryFragment : BaseFragment() {
FILE_SELECT_CODE
)
} catch (ex: ActivityNotFoundException) {
- ex.printStackTrace()
+ activity.toast(resources.getString(R.string.no_app_found_to_open), Toast.LENGTH_SHORT)
}
}
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 96761d289..f9c519e82 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -6,4 +6,5 @@
Failed to open file\nPlease try looking for this file in the Device Tab of your Library
Send Files
Receive Files
+ No app found to select zim file!
diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/extensions/StringExtensions.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/extensions/StringExtensions.kt
new file mode 100644
index 000000000..47701033f
--- /dev/null
+++ b/core/src/main/java/org/kiwix/kiwixmobile/core/extensions/StringExtensions.kt
@@ -0,0 +1,22 @@
+/*
+ * Kiwix Android
+ * Copyright (c) 2022 Kiwix
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+
+package org.kiwix.kiwixmobile.core.extensions
+
+fun String.getStringBefore(suffix: String): String =
+ this.substringBefore(suffix)
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 cc076714c..b66c19932 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
@@ -27,6 +27,7 @@ import org.kiwix.kiwixmobile.core.R
import org.kiwix.kiwixmobile.core.downloader.ChunkUtils
import org.kiwix.kiwixmobile.core.entity.LibraryNetworkEntity.Book
import org.kiwix.kiwixmobile.core.extensions.get
+import org.kiwix.kiwixmobile.core.extensions.getStringBefore
import java.io.BufferedReader
import java.io.File
import java.io.IOException
@@ -103,7 +104,7 @@ object FileUtils {
}
return try {
"${getSdCardMainPath(context)}/${documentId[1]}"
- } catch (e: Exception) {
+ } catch (ignore: Exception) {
null
}
} else if ("com.android.providers.downloads.documents" == uri.authority)
@@ -243,13 +244,7 @@ object FileUtils {
return false
}
- @JvmStatic fun getSdCardMainPath(context: Context): String {
- var path = "${context.getExternalFilesDirs("")[1]}"
- val separator: String = context.getString(R.string.android_directory_seperator)
- val sepPos = path.indexOf(separator)
- if (sepPos != -1) {
- path = path.substring(0, sepPos)
- }
- return path
- }
+ @JvmStatic fun getSdCardMainPath(context: Context): String =
+ "${context.getExternalFilesDirs("")[1]}"
+ .getStringBefore(context.getString(R.string.android_directory_seperator))
}