#1519 JniKiwixException opening Zim file

This commit is contained in:
Sean Mac Gillicuddy 2019-09-26 11:17:37 +01:00
parent cca60df69f
commit 9548333ea8
3 changed files with 28 additions and 15 deletions

View File

@ -1090,18 +1090,24 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
&& Build.VERSION.SDK_INT != 23)) { && Build.VERSION.SDK_INT != 23)) {
if (file.exists()) { if (file.exists()) {
zimReaderContainer.setZimFile(file); zimReaderContainer.setZimFile(file);
if (clearHistory) { if (zimReaderContainer.getZimFileReader() != null) {
requestClearHistoryAfterLoad = true; if (clearHistory) {
} requestClearHistoryAfterLoad = true;
if (menu != null) { }
initAllMenuItems(); if (menu != null) {
initAllMenuItems();
} else {
// Menu may not be initialized yet. In this case
// signal to menu create to show
requestInitAllMenuItems = true;
}
openMainPage();
presenter.loadCurrentZimBookmarksUrl();
} else { } else {
// Menu may not be initialized yet. In this case Toast.makeText(this, getResources().getString(R.string.error_file_invalid),
// signal to menu create to show Toast.LENGTH_LONG).show();
requestInitAllMenuItems = true; showHomePage();
} }
openMainPage();
presenter.loadCurrentZimBookmarksUrl();
} else { } else {
Log.w(TAG_KIWIX, "ZIM file doesn't exist at " + file.getAbsolutePath()); Log.w(TAG_KIWIX, "ZIM file doesn't exist at " + file.getAbsolutePath());

View File

@ -26,6 +26,7 @@ import android.webkit.MimeTypeMap
import androidx.core.net.toUri import androidx.core.net.toUri
import io.reactivex.Single import io.reactivex.Single
import io.reactivex.schedulers.Schedulers import io.reactivex.schedulers.Schedulers
import org.kiwix.kiwixlib.JNIKiwixException
import org.kiwix.kiwixlib.JNIKiwixInt import org.kiwix.kiwixlib.JNIKiwixInt
import org.kiwix.kiwixlib.JNIKiwixReader import org.kiwix.kiwixlib.JNIKiwixReader
import org.kiwix.kiwixlib.JNIKiwixString import org.kiwix.kiwixlib.JNIKiwixString
@ -51,11 +52,15 @@ class ZimFileReader(
private val sharedPreferenceUtil: SharedPreferenceUtil private val sharedPreferenceUtil: SharedPreferenceUtil
) { ) {
interface Factory { interface Factory {
fun create(file: File): ZimFileReader fun create(file: File): ZimFileReader?
class Impl @Inject constructor(val sharedPreferenceUtil: SharedPreferenceUtil) : Factory { class Impl @Inject constructor(val sharedPreferenceUtil: SharedPreferenceUtil) : Factory {
override fun create(file: File) = override fun create(file: File) =
ZimFileReader(file, sharedPreferenceUtil = sharedPreferenceUtil) try {
ZimFileReader(file, sharedPreferenceUtil = sharedPreferenceUtil)
} catch (ignore: JNIKiwixException) {
null
}
} }
} }

View File

@ -1,5 +1,6 @@
package org.kiwix.kiwixmobile.zim_manager.fileselect_view package org.kiwix.kiwixmobile.zim_manager.fileselect_view
import io.reactivex.Flowable
import io.reactivex.functions.BiFunction import io.reactivex.functions.BiFunction
import io.reactivex.schedulers.Schedulers import io.reactivex.schedulers.Schedulers
import org.kiwix.kiwixmobile.database.newdb.dao.FetchDownloadDao import org.kiwix.kiwixmobile.database.newdb.dao.FetchDownloadDao
@ -16,10 +17,10 @@ class StorageObserver @Inject constructor(
private val zimReaderFactory: ZimFileReader.Factory private val zimReaderFactory: ZimFileReader.Factory
) { ) {
val booksOnFileSystem val booksOnFileSystem: Flowable<List<BookOnDisk>>
get() = scanFiles() get() = scanFiles()
.withLatestFrom(downloadDao.downloads(), BiFunction(::toFilesThatAreNotDownloading)) .withLatestFrom(downloadDao.downloads(), BiFunction(::toFilesThatAreNotDownloading))
.map { it.map(::convertToBookOnDisk) } .map { it.mapNotNull(::convertToBookOnDisk) }
private fun scanFiles() = fileSearch.scan().subscribeOn(Schedulers.io()) private fun scanFiles() = fileSearch.scan().subscribeOn(Schedulers.io())
@ -29,5 +30,6 @@ class StorageObserver @Inject constructor(
private fun fileHasNoMatchingDownload(downloads: List<DownloadModel>, file: File) = private fun fileHasNoMatchingDownload(downloads: List<DownloadModel>, file: File) =
downloads.firstOrNull { file.absolutePath.endsWith(it.fileNameFromUrl) } == null downloads.firstOrNull { file.absolutePath.endsWith(it.fileNameFromUrl) } == null
private fun convertToBookOnDisk(file: File) = BookOnDisk(file, zimReaderFactory.create(file)) private fun convertToBookOnDisk(file: File) =
zimReaderFactory.create(file)?.let { BookOnDisk(file, it) }
} }