#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)) {
if (file.exists()) {
zimReaderContainer.setZimFile(file);
if (clearHistory) {
requestClearHistoryAfterLoad = true;
}
if (menu != null) {
initAllMenuItems();
if (zimReaderContainer.getZimFileReader() != null) {
if (clearHistory) {
requestClearHistoryAfterLoad = true;
}
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 {
// Menu may not be initialized yet. In this case
// signal to menu create to show
requestInitAllMenuItems = true;
Toast.makeText(this, getResources().getString(R.string.error_file_invalid),
Toast.LENGTH_LONG).show();
showHomePage();
}
openMainPage();
presenter.loadCurrentZimBookmarksUrl();
} else {
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 io.reactivex.Single
import io.reactivex.schedulers.Schedulers
import org.kiwix.kiwixlib.JNIKiwixException
import org.kiwix.kiwixlib.JNIKiwixInt
import org.kiwix.kiwixlib.JNIKiwixReader
import org.kiwix.kiwixlib.JNIKiwixString
@ -51,11 +52,15 @@ class ZimFileReader(
private val sharedPreferenceUtil: SharedPreferenceUtil
) {
interface Factory {
fun create(file: File): ZimFileReader
fun create(file: File): ZimFileReader?
class Impl @Inject constructor(val sharedPreferenceUtil: SharedPreferenceUtil) : Factory {
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
import io.reactivex.Flowable
import io.reactivex.functions.BiFunction
import io.reactivex.schedulers.Schedulers
import org.kiwix.kiwixmobile.database.newdb.dao.FetchDownloadDao
@ -16,10 +17,10 @@ class StorageObserver @Inject constructor(
private val zimReaderFactory: ZimFileReader.Factory
) {
val booksOnFileSystem
val booksOnFileSystem: Flowable<List<BookOnDisk>>
get() = scanFiles()
.withLatestFrom(downloadDao.downloads(), BiFunction(::toFilesThatAreNotDownloading))
.map { it.map(::convertToBookOnDisk) }
.map { it.mapNotNull(::convertToBookOnDisk) }
private fun scanFiles() = fileSearch.scan().subscribeOn(Schedulers.io())
@ -29,5 +30,6 @@ class StorageObserver @Inject constructor(
private fun fileHasNoMatchingDownload(downloads: List<DownloadModel>, file: File) =
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) }
}