mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 18:56:44 -04:00
Merge pull request #1521 from kiwix/feature/macgills/#1519-exception-opening-zim-file
#1519 JniKiwixException opening Zim file
This commit is contained in:
commit
ee4c707942
@ -99,6 +99,7 @@ import org.kiwix.kiwixmobile.R;
|
||||
import org.kiwix.kiwixmobile.base.BaseActivity;
|
||||
import org.kiwix.kiwixmobile.bookmark.BookmarkItem;
|
||||
import org.kiwix.kiwixmobile.bookmark.BookmarksActivity;
|
||||
import org.kiwix.kiwixmobile.extensions.ContextExtensionsKt;
|
||||
import org.kiwix.kiwixmobile.help.HelpActivity;
|
||||
import org.kiwix.kiwixmobile.history.HistoryActivity;
|
||||
import org.kiwix.kiwixmobile.history.HistoryListItem;
|
||||
@ -1090,24 +1091,26 @@ 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;
|
||||
ContextExtensionsKt.toast(this, R.string.error_file_invalid, Toast.LENGTH_LONG);
|
||||
showHomePage();
|
||||
}
|
||||
openMainPage();
|
||||
presenter.loadCurrentZimBookmarksUrl();
|
||||
} else {
|
||||
Log.w(TAG_KIWIX, "ZIM file doesn't exist at " + file.getAbsolutePath());
|
||||
|
||||
Toast.makeText(this, getResources().getString(R.string.error_file_not_found),
|
||||
Toast.LENGTH_LONG)
|
||||
.show();
|
||||
ContextExtensionsKt.toast(this, R.string.error_file_not_found, Toast.LENGTH_LONG);
|
||||
showHomePage();
|
||||
}
|
||||
} else {
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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) }
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user