Changes after review

This commit is contained in:
MohitMali 2022-04-21 17:42:10 +05:30
parent 5630f96951
commit b305ef0905
4 changed files with 30 additions and 11 deletions

View File

@ -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)
}
}

View File

@ -6,4 +6,5 @@
<string name="cannot_open_file">Failed to open file\nPlease try looking for this file in the Device Tab of your Library</string>
<string name="send_files_title">Send Files</string>
<string name="receive_files_title">Receive Files</string>
<string name="no_app_found_to_open" translatable="false">No app found to select zim file!</string>
</resources>

View File

@ -0,0 +1,22 @@
/*
* Kiwix Android
* Copyright (c) 2022 Kiwix <android.kiwix.org>
* 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 <http://www.gnu.org/licenses/>.
*
*/
package org.kiwix.kiwixmobile.core.extensions
fun String.getStringBefore(suffix: String): String =
this.substringBefore(suffix)

View File

@ -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))
}