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 committed Jun 3, 2024
1 parent 5cf0881 commit 9447868
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) {

Check warning on line 1783 in core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt#L1783

Added line #L1783 was not covered by tests
// 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)

Check warning on line 1786 in core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt#L1786

Added line #L1786 was not covered by tests
}
}

Expand Down

0 comments on commit 9447868

Please sign in to comment.