Skip to content

Commit

Permalink
Fixed: Saving bookmarks in the zim-split splitted ZIM files are crash…
Browse files Browse the repository at this point in the history
…ing the application, when there is a 0 size extra zim chunk.

* Catching the exception thrown by the libkiwix with splitted ZIM files when there is an 0 size extra zim chunk.
  • Loading branch information
MohitMaliDeveloper authored and kelson42 committed Jun 7, 2024
1 parent f702249 commit 7849021
Showing 1 changed file with 27 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1752,32 +1752,38 @@ abstract class CoreReaderFragment :
@Suppress("NestedBlockDepth")
@OnClick(R2.id.bottom_toolbar_bookmark)
fun toggleBookmark() {
getCurrentWebView()?.url?.let { articleUrl ->
zimReaderContainer?.zimFileReader?.let { zimFileReader ->
val libKiwixBook = Book().apply {
update(zimFileReader.jniKiwixReader)
}
if (isBookmarked) {
repositoryActions?.deleteBookmark(libKiwixBook.id, articleUrl)
snackBarRoot?.snack(R.string.bookmark_removed)
} else {
getCurrentWebView()?.title?.let {
repositoryActions?.saveBookmark(
LibkiwixBookmarkItem(it, articleUrl, zimFileReader, libKiwixBook)
)
snackBarRoot?.snack(
stringId = R.string.bookmark_added,
actionStringId = R.string.open,
actionClick = {
goToBookmarks()
Unit
}
)
try {
getCurrentWebView()?.url?.let { articleUrl ->
zimReaderContainer?.zimFileReader?.let { zimFileReader ->
val libKiwixBook = Book().apply {
update(zimFileReader.jniKiwixReader)
}
if (isBookmarked) {
repositoryActions?.deleteBookmark(libKiwixBook.id, articleUrl)
snackBarRoot?.snack(R.string.bookmark_removed)
} else {
getCurrentWebView()?.title?.let {
repositoryActions?.saveBookmark(
LibkiwixBookmarkItem(it, articleUrl, zimFileReader, libKiwixBook)
)
snackBarRoot?.snack(
stringId = R.string.bookmark_added,
actionStringId = R.string.open,
actionClick = {
goToBookmarks()
Unit
}
)
}
}
}
} ?: kotlin.run {
requireActivity().toast(R.string.unable_to_add_to_bookmarks, Toast.LENGTH_SHORT)
}
} catch (ignore: Exception) {
// Catch the exception while saving the bookmarks for splitted zim files.
// we have an issue with split zim files, see #3827
requireActivity().toast(R.string.unable_to_add_to_bookmarks, Toast.LENGTH_SHORT)
}
}

Expand Down

0 comments on commit 7849021

Please sign in to comment.