mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 18:56:44 -04:00
seperate two method and chaning name
This commit is contained in:
parent
bcd49946fa
commit
ebe8641ec7
@ -173,29 +173,34 @@ class LocalLibraryFragment : BaseFragment() {
|
|||||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||||
when (requestCode) {
|
when (requestCode) {
|
||||||
FILE_SELECT_CODE -> {
|
FILE_SELECT_CODE -> {
|
||||||
data?.data
|
data?.data?.let { uri ->
|
||||||
?.let(::validateFileFromUriAndNavigateToReaderFragment)
|
getZimFileFromUri(uri)?.let(::navigateToReaderFragment)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else -> super.onActivityResult(requestCode, resultCode, data)
|
else -> super.onActivityResult(requestCode, resultCode, data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun validateFileFromUriAndNavigateToReaderFragment(
|
private fun getZimFileFromUri(
|
||||||
uri: Uri
|
uri: Uri
|
||||||
) {
|
): File? {
|
||||||
val filePath = FileUtils.getLocalFilePathByUri(
|
val filePath = FileUtils.getLocalFilePathByUri(
|
||||||
requireActivity().applicationContext, uri
|
requireActivity().applicationContext, uri
|
||||||
)
|
)
|
||||||
if (filePath == null || !File(filePath).exists()) {
|
if (filePath == null || !File(filePath).exists()) {
|
||||||
activity.toast(R.string.error_file_not_found)
|
activity.toast(R.string.error_file_not_found)
|
||||||
return
|
return null
|
||||||
}
|
}
|
||||||
val file = File(filePath)
|
val file = File(filePath)
|
||||||
if (!FileUtils.isValidZimFile(file.path)) {
|
return if (!FileUtils.isValidZimFile(file.path)) {
|
||||||
activity.toast(R.string.error_file_invalid)
|
activity.toast(R.string.error_file_invalid)
|
||||||
return
|
null
|
||||||
|
} else {
|
||||||
|
file
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun navigateToReaderFragment(file: File) {
|
||||||
if (!file.canRead()) {
|
if (!file.canRead()) {
|
||||||
activity.toast(R.string.unable_to_read_zim_file)
|
activity.toast(R.string.unable_to_read_zim_file)
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user