Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed: Create only one reader and use it everywhere. #3624

Merged
merged 19 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
571d940
Created ZimReaderSource for creating the zimFileReader object at one …
MohitMaliDeveloper Aug 24, 2024
8fffb10
Refctored the ZimFileReader and ZimReaderContainer to use ZimReaderSo…
MohitMaliDeveloper Aug 24, 2024
da51cfc
Refactored the entities, and dao to use the ZimReaderSource instead o…
MohitMaliDeveloper Aug 24, 2024
811e37b
Refactored the whole code to use ZimReaderSource
MohitMaliDeveloper Aug 24, 2024
6f2c3a4
Fixed the test cases and some code
MohitMaliDeveloper Aug 24, 2024
58cbd5d
Fixed some compliation errors
MohitMaliDeveloper Aug 24, 2024
31991bd
Fixed adding books to library while importing the bookmarks. Also imp…
MohitMaliDeveloper Aug 24, 2024
b667553
Fixed Migration is not properly running for HistoryRoomEntity
MohitMaliDeveloper Aug 24, 2024
3ffe4cc
Fixed instrumentation test case compilation errors
MohitMaliDeveloper Aug 24, 2024
dbead86
Fixed SearchFragmentTestForCustomApp test case
MohitMaliDeveloper Aug 24, 2024
ac36538
Fixed static analysis failure
MohitMaliDeveloper Aug 24, 2024
3d976d9
Fixed all unit coverage failures.
MohitMaliDeveloper Aug 24, 2024
769aaee
Fixed ObjectBoxToLibkiwixMigratorTest was failing.
MohitMaliDeveloper Aug 25, 2024
5e8abe1
Fixed zim file is not showing when we open it from the notes screen.
MohitMaliDeveloper Aug 25, 2024
561ff40
Fixed: Zim File was not opening if we opened it through the DeepLinking.
MohitMaliDeveloper Aug 25, 2024
a86de10
Improved the saving of the zim file in the local library when we open…
MohitMaliDeveloper Aug 25, 2024
4e3f662
Fixed: Previously saved books are not showing on the LocalLibraryScreen.
MohitMaliDeveloper Aug 25, 2024
1cdd683
Improved the `books()` method to properly return the new books along …
MohitMaliDeveloper Aug 25, 2024
2d0bc48
* Fixed: Deleting files was not working in the local library.
MohitMaliDeveloper Aug 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import org.kiwix.kiwixmobile.core.dao.entities.RecentSearchRoomEntity
import org.kiwix.kiwixmobile.core.data.KiwixRoomDatabase
import org.kiwix.kiwixmobile.core.page.history.adapter.HistoryListItem
import org.kiwix.kiwixmobile.core.page.notes.adapter.NoteListItem
import org.kiwix.kiwixmobile.core.reader.ZimReaderSource
import java.io.File

@RunWith(AndroidJUnit4::class)
class KiwixRoomDatabaseTest {
Expand Down Expand Up @@ -112,7 +114,7 @@ class KiwixRoomDatabaseTest {
assertThat(zimId, equalTo(historyItem.zimId))
assertThat(zimName, equalTo(historyItem.zimName))
assertThat(historyUrl, equalTo(historyItem.historyUrl))
assertThat(zimFilePath, equalTo(historyItem.zimFilePath))
assertThat(zimReaderSource, equalTo(historyItem.zimReaderSource))
assertThat(favicon, equalTo(historyItem.favicon))
assertThat(dateString, equalTo(historyItem.dateString))
assertThat(timeStamp, equalTo(historyItem.timeStamp))
Expand Down Expand Up @@ -152,7 +154,7 @@ class KiwixRoomDatabaseTest {
assertThat(zimId, equalTo(noteItem.zimId))
assertThat(zimUrl, equalTo(noteItem.zimUrl))
assertThat(title, equalTo(noteItem.title))
assertThat(zimFilePath, equalTo(noteItem.zimFilePath))
assertThat(zimReaderSource, equalTo(noteItem.zimReaderSource))
assertThat(noteFilePath, equalTo(noteItem.noteFilePath))
assertThat(favicon, equalTo(noteItem.favicon))
}
Expand Down Expand Up @@ -186,7 +188,9 @@ class KiwixRoomDatabaseTest {
databaseId: Long = 0L,
zimId: String = "1f88ab6f-c265-b-3ff-8f49-b7f4429503800",
zimName: String = "alpinelinux_en_all",
zimFilePath: String = "/storage/emulated/0/Download/alpinelinux_en_all_maxi_2023-01.zim",
zimReaderSource: ZimReaderSource = ZimReaderSource(
File("/storage/emulated/0/Download/alpinelinux_en_all_maxi_2023-01.zim")
),
timeStamp: Long = System.currentTimeMillis()
): HistoryListItem.HistoryItem =
HistoryListItem.HistoryItem(
Expand All @@ -195,7 +199,7 @@ class KiwixRoomDatabaseTest {
zimName = zimName,
historyUrl = historyUrl,
title = title,
zimFilePath = zimFilePath,
zimReaderSource = zimReaderSource,
favicon = null,
dateString = dateString,
timeStamp = timeStamp
Expand All @@ -205,14 +209,16 @@ class KiwixRoomDatabaseTest {
databaseId: Long = 0L,
zimId: String = "1f88ab6f-c265-b-3ff-8f49-b7f4429503800",
title: String = "Alpine Wiki",
zimFilePath: String = "/storage/emulated/0/Download/alpinelinux_en_all_maxi_2023-01.zim",
zimReaderSource: ZimReaderSource = ZimReaderSource(
File("/storage/emulated/0/Download/alpinelinux_en_all_maxi_2023-01.zim")
),
zimUrl: String,
noteFilePath: String = "/storage/emulated/0/Download/Notes/Alpine linux/AlpineNote.txt"
): NoteListItem = NoteListItem(
databaseId = databaseId,
zimId = zimId,
title = title,
zimFilePath = zimFilePath,
zimReaderSource = zimReaderSource,
zimUrl = zimUrl,
noteFilePath = noteFilePath,
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import org.kiwix.kiwixmobile.core.dao.entities.BookmarkEntity
import org.kiwix.kiwixmobile.core.data.remote.ObjectBoxToLibkiwixMigrator
import org.kiwix.kiwixmobile.core.di.modules.DatabaseModule
import org.kiwix.kiwixmobile.core.page.bookmark.adapter.LibkiwixBookmarkItem
import org.kiwix.kiwixmobile.core.reader.ZimReaderSource
import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.handleLocaleChange
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
import org.kiwix.kiwixmobile.main.KiwixMainActivity
Expand Down Expand Up @@ -74,6 +75,7 @@ class ObjectBoxToLibkiwixMigratorTest : BaseActivityTest() {
expectedZimId,
expectedZimName,
expectedZimFilePath,
ZimReaderSource(File(expectedZimFilePath)),
expectedBookmarkUrl,
expectedTitle,
expectedFavicon
Expand Down Expand Up @@ -156,7 +158,7 @@ class ObjectBoxToLibkiwixMigratorTest : BaseActivityTest() {
val actualDataAfterMigration =
objectBoxToLibkiwixMigrator.libkiwixBookmarks.bookmarks().blockingFirst()
assertEquals(1, actualDataAfterMigration.size)
assertEquals(actualDataAfterMigration[0].zimFilePath, expectedZimFilePath)
assertEquals(actualDataAfterMigration[0].zimReaderSource?.toDatabase(), expectedZimFilePath)
assertEquals(actualDataAfterMigration[0].zimId, expectedZimId)
assertEquals(actualDataAfterMigration[0].title, expectedTitle)
assertEquals(actualDataAfterMigration[0].url, expectedBookmarkUrl)
Expand Down Expand Up @@ -185,6 +187,7 @@ class ObjectBoxToLibkiwixMigratorTest : BaseActivityTest() {
expectedZimId,
expectedZimName,
expectedZimFilePath,
ZimReaderSource(File(expectedZimFilePath)),
existingBookmarkUrl,
existingTitle,
expectedFavicon
Expand Down Expand Up @@ -226,6 +229,7 @@ class ObjectBoxToLibkiwixMigratorTest : BaseActivityTest() {
expectedZimId,
expectedZimName,
expectedZimFilePath,
ZimReaderSource(File(expectedZimFilePath)),
"https://alpine_linux/search_$i",
"title_$i",
expectedFavicon
Expand All @@ -250,6 +254,7 @@ class ObjectBoxToLibkiwixMigratorTest : BaseActivityTest() {
expectedZimId,
expectedZimName,
null,
null,
expectedBookmarkUrl,
expectedTitle,
expectedFavicon
Expand All @@ -261,7 +266,7 @@ class ObjectBoxToLibkiwixMigratorTest : BaseActivityTest() {
val actualDataAfterMigration =
objectBoxToLibkiwixMigrator.libkiwixBookmarks.bookmarks().blockingFirst()
assertEquals(1, actualDataAfterMigration.size)
assertEquals(actualDataAfterMigration[0].zimFilePath, null)
assertEquals(actualDataAfterMigration[0].zimReaderSource?.toDatabase(), null)
assertEquals(actualDataAfterMigration[0].zimId, expectedZimId)
assertEquals(actualDataAfterMigration[0].title, expectedTitle)
assertEquals(actualDataAfterMigration[0].url, expectedBookmarkUrl)
Expand All @@ -278,6 +283,7 @@ class ObjectBoxToLibkiwixMigratorTest : BaseActivityTest() {
expectedZimId,
expectedZimName,
nonExistingPath,
ZimReaderSource(File(nonExistingPath)),
expectedBookmarkUrl,
expectedTitle,
expectedFavicon
Expand All @@ -289,7 +295,7 @@ class ObjectBoxToLibkiwixMigratorTest : BaseActivityTest() {
val actualDataAfterMigration =
objectBoxToLibkiwixMigrator.libkiwixBookmarks.bookmarks().blockingFirst()
assertEquals(1, actualDataAfterMigration.size)
assertEquals(actualDataAfterMigration[0].zimFilePath, null)
assertEquals(actualDataAfterMigration[0].zimReaderSource?.toDatabase(), null)
assertEquals(actualDataAfterMigration[0].zimId, expectedZimId)
assertEquals(actualDataAfterMigration[0].title, expectedTitle)
assertEquals(actualDataAfterMigration[0].url, expectedBookmarkUrl)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class ObjectBoxToRoomMigratorTest {
assertThat(zimId, equalTo(historyItem.zimId))
assertThat(zimName, equalTo(historyItem.zimName))
assertThat(historyUrl, equalTo(historyItem.historyUrl))
assertThat(zimFilePath, equalTo(historyItem.zimFilePath))
assertThat(zimReaderSource, equalTo(historyItem.zimReaderSource))
assertThat(favicon, equalTo(historyItem.favicon))
assertThat(dateString, equalTo(historyItem.dateString))
assertThat(timeStamp, equalTo(historyItem.timeStamp))
Expand Down Expand Up @@ -325,7 +325,7 @@ class ObjectBoxToRoomMigratorTest {
assertThat(zimId, equalTo(noteItem.zimId))
assertThat(zimUrl, equalTo(noteItem.zimUrl))
assertThat(title, equalTo(noteItem.title))
assertThat(zimFilePath, equalTo(noteItem.zimFilePath))
assertThat(zimReaderSource, equalTo(noteItem.zimReaderSource))
assertThat(noteFilePath, equalTo(noteItem.noteFilePath))
assertThat(favicon, equalTo(noteItem.favicon))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ import org.junit.Test
import org.kiwix.kiwixmobile.BaseActivityTest
import org.kiwix.kiwixmobile.core.DarkModeConfig
import org.kiwix.kiwixmobile.core.reader.ZimFileReader
import org.kiwix.kiwixmobile.core.reader.ZimReaderSource
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
import org.kiwix.kiwixmobile.main.KiwixMainActivity
import org.kiwix.kiwixmobile.testutils.TestUtils.closeSystemDialogs
import org.kiwix.kiwixmobile.testutils.TestUtils.isSystemUINotRespondingDialogVisible
import org.kiwix.libzim.Archive
import org.kiwix.libzim.SuggestionSearcher
import java.io.File
import java.io.FileOutputStream
Expand Down Expand Up @@ -81,12 +81,11 @@ class MimeTypeTest : BaseActivityTest() {
}
}
}
val archive = Archive(zimFile.canonicalPath)
val zimSource = ZimReaderSource(zimFile)
val archive = zimSource.createArchive()
val zimFileReader = ZimFileReader(
zimFile,
emptyList(),
null,
archive,
zimSource,
archive!!,
DarkModeConfig(SharedPreferenceUtil(context), context),
SuggestionSearcher(archive)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class LibkiwixBookmarkTest : BaseActivityTest() {
LibkiwixBookmarkItem(
bookmark,
coreReaderFragment.zimReaderContainer?.zimFileReader?.favicon,
coreReaderFragment.zimReaderContainer?.zimFileReader?.zimFile?.canonicalPath
coreReaderFragment.zimReaderContainer?.zimFileReader?.zimReaderSource
)
coreReaderFragment.libkiwixBookmarks?.saveBookmark(libkiwixItem).also {
bookmarkList.add(libkiwixItem)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ import org.junit.Test
import org.kiwix.kiwixmobile.BaseActivityTest
import org.kiwix.kiwixmobile.core.DarkModeConfig
import org.kiwix.kiwixmobile.core.reader.ZimFileReader
import org.kiwix.kiwixmobile.core.reader.ZimReaderSource
import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.handleLocaleChange
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
import org.kiwix.kiwixmobile.main.KiwixMainActivity
import org.kiwix.kiwixmobile.testutils.TestUtils
import org.kiwix.libzim.Archive
import org.kiwix.libzim.SuggestionSearcher
import java.io.File
import java.io.FileOutputStream
Expand Down Expand Up @@ -89,12 +89,11 @@ class EncodedUrlTest : BaseActivityTest() {
}
}
}
val archive = Archive(zimFile.canonicalPath)
val zimReaderSource = ZimReaderSource(zimFile)
val archive = zimReaderSource.createArchive()
val zimFileReader = ZimFileReader(
zimFile,
emptyList(),
null,
archive,
zimReaderSource,
archive!!,
DarkModeConfig(SharedPreferenceUtil(context), context),
SuggestionSearcher(archive)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ import org.kiwix.kiwixmobile.BaseActivityTest
import org.kiwix.kiwixmobile.R
import org.kiwix.kiwixmobile.core.DarkModeConfig
import org.kiwix.kiwixmobile.core.reader.ZimFileReader
import org.kiwix.kiwixmobile.core.reader.ZimReaderSource
import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.handleLocaleChange
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
import org.kiwix.kiwixmobile.main.KiwixMainActivity
import org.kiwix.kiwixmobile.nav.destination.library.LocalLibraryFragmentDirections
import org.kiwix.kiwixmobile.page.history.navigationHistory
import org.kiwix.kiwixmobile.testutils.RetryRule
import org.kiwix.kiwixmobile.testutils.TestUtils
import org.kiwix.libzim.Archive
import org.kiwix.libzim.SuggestionSearcher
import java.io.File
import java.io.FileOutputStream
Expand Down Expand Up @@ -118,12 +118,11 @@ class ZimFileReaderWithSplittedZimFileTest : BaseActivityTest() {
fun testWithExtraZeroSizeFile() {
createAndGetSplitedZimFile(true)?.let { zimFile ->
// test the articleCount and mediaCount of this zim file.
val archive = Archive(zimFile.canonicalPath)
val zimReaderSource = ZimReaderSource(zimFile)
val archive = zimReaderSource.createArchive()
val zimFileReader = ZimFileReader(
zimFile,
emptyList(),
null,
archive,
zimReaderSource,
archive!!,
DarkModeConfig(SharedPreferenceUtil(context), context),
SuggestionSearcher(archive)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class HistoryRoomDaoTest {
assertThat(zimId, equalTo(historyItem.zimId))
assertThat(zimName, equalTo(historyItem.zimName))
assertThat(historyUrl, equalTo(historyItem.historyUrl))
assertThat(zimFilePath, equalTo(historyItem.zimFilePath))
assertThat(zimReaderSource, equalTo(historyItem.zimReaderSource))
assertThat(favicon, equalTo(historyItem.favicon))
assertThat(dateString, equalTo(historyItem.dateString))
assertThat(timeStamp, equalTo(historyItem.timeStamp))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class NoteRoomDaoTest {
assertThat(zimId, equalTo(noteItem.zimId))
assertThat(zimUrl, equalTo(noteItem.zimUrl))
assertThat(title, equalTo(noteItem.title))
assertThat(zimFilePath, equalTo(noteItem.zimFilePath))
assertThat(zimReaderSource, equalTo(noteItem.zimReaderSource))
assertThat(noteFilePath, equalTo(noteItem.noteFilePath))
assertThat(favicon, equalTo(noteItem.favicon))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@
{
intent.getStringExtra(DOWNLOAD_NOTIFICATION_TITLE)?.let {
newBookDao.bookMatching(it)?.let { bookOnDiskEntity ->
openZimFromFilePath(bookOnDiskEntity.file.path)
openZimFromFilePath(bookOnDiskEntity.zimReaderSource.toDatabase())

Check warning on line 223 in app/src/main/java/org/kiwix/kiwixmobile/main/KiwixMainActivity.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/java/org/kiwix/kiwixmobile/main/KiwixMainActivity.kt#L223

Added line #L223 was not covered by tests
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@
import com.google.android.material.bottomnavigation.BottomNavigationView
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.kiwix.kiwixmobile.R
import org.kiwix.kiwixmobile.core.R.string
import org.kiwix.kiwixmobile.cachedComponent
import org.kiwix.kiwixmobile.core.R.string
import org.kiwix.kiwixmobile.core.base.BaseActivity
import org.kiwix.kiwixmobile.core.base.BaseFragment
import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.isManageExternalStoragePermissionGranted
Expand All @@ -75,6 +77,7 @@
import org.kiwix.kiwixmobile.core.navigateToAppSettings
import org.kiwix.kiwixmobile.core.navigateToSettings
import org.kiwix.kiwixmobile.core.reader.ZimFileReader
import org.kiwix.kiwixmobile.core.reader.ZimReaderSource
import org.kiwix.kiwixmobile.core.utils.LanguageUtils
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
import org.kiwix.kiwixmobile.core.utils.SimpleRecyclerViewScrollListener
Expand Down Expand Up @@ -404,10 +407,10 @@
// local library screen. Since our application is already aware of this opened ZIM file,
// we can directly add it to the database.
// See https://github.com/kiwix/kiwix-android/issues/3650
runBlocking {
zimReaderFactory.create(file)
CoroutineScope(Dispatchers.IO).launch {
zimReaderFactory.create(ZimReaderSource(file))

Check warning on line 411 in app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryFragment.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryFragment.kt#L410-L411

Added lines #L410 - L411 were not covered by tests
?.let { zimFileReader ->
BookOnDisk(file, zimFileReader).also {
BookOnDisk(zimFileReader).also {

Check warning on line 413 in app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryFragment.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryFragment.kt#L413

Added line #L413 was not covered by tests
mainRepositoryActions.saveBook(it)
zimFileReader.dispose()
}
Expand Down
Loading
Loading