Skip to content

Commit

Permalink
Fixed: Migration of bookmarks is not working with recent versions of …
Browse files Browse the repository at this point in the history
…custom apps.

* Recent version of custom apps usages the `assetFileDescriptor` which does not have any path that's why migration is not working in these versions of custom apps. However, with apk version of custom apps migration is working fine. So to address this issue we have adjusted our code to work with assetFileDescriptor as well.
  • Loading branch information
MohitMaliDeveloper authored and kelson42 committed Mar 19, 2024
1 parent 09c6621 commit affa922
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,22 @@ class ObjectBoxToLibkiwixMigrator {
try {
// for saving book to library, otherwise it does not save the
// favicon and zimFilePath in library.
val archive = Archive(bookmarkEntity.zimFilePath)
val libkiwixBook = Book().apply {
update(archive)
var archive: Archive? = null

Check warning on line 58 in core/src/main/java/org/kiwix/kiwixmobile/core/data/remote/ObjectBoxToLibkiwixMigrator.kt

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/kiwix/kiwixmobile/core/data/remote/ObjectBoxToLibkiwixMigrator.kt#L58

Added line #L58 was not covered by tests
val libkiwixBook = bookmarkEntity.zimFilePath?.let {
archive = Archive(bookmarkEntity.zimFilePath)
Book().apply {
update(archive)
}
} ?: kotlin.run {

Check warning on line 64 in core/src/main/java/org/kiwix/kiwixmobile/core/data/remote/ObjectBoxToLibkiwixMigrator.kt

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/kiwix/kiwixmobile/core/data/remote/ObjectBoxToLibkiwixMigrator.kt#L60-L64

Added lines #L60 - L64 were not covered by tests
// for migrating bookmarks for recent custom apps since in recent version of
// custom app we are using the `assetFileDescriptor` which does not have the filePath.
null

Check warning on line 67 in core/src/main/java/org/kiwix/kiwixmobile/core/data/remote/ObjectBoxToLibkiwixMigrator.kt

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/kiwix/kiwixmobile/core/data/remote/ObjectBoxToLibkiwixMigrator.kt#L67

Added line #L67 was not covered by tests
}
libkiwixBookmarks.saveBookmark(
LibkiwixBookmarkItem(bookmarkEntity, libkiwixBook),
shouldWriteBookmarkToFile = index == bookMarksList.size - 1
)
archive.dispose()
archive?.dispose()
// TODO should we remove data from objectBox?
// removing the single entity from the object box after migration.
// box.query {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ data class LibkiwixBookmarkItem(

constructor(
bookmarkEntity: BookmarkEntity,
libkiwixBook: Book
libkiwixBook: Book?
) : this(
zimId = bookmarkEntity.zimId,
zimFilePath = bookmarkEntity.zimFilePath,
Expand Down

0 comments on commit affa922

Please sign in to comment.