From 1d9633c6a44066ab6ead1bb215c3dd66165c4474 Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Fri, 22 Aug 2025 19:02:52 +0530 Subject: [PATCH] Removed all ObjectBox code from every variant except the Play Store version. --- app/build.gradle.kts | 1 - .../ObjectBoxToLibkiwixMigratorTest.kt | 2 - .../ObjectBoxToRoomMigratorTest.kt | 1 - .../core/di/components/TestComponent.kt | 4 +- core/build.gradle.kts | 6 --- .../core/dao/entities/LanguageEntity.kt | 54 ------------------- .../data/ObjectBoxDataMigrationHandler.kt | 23 ++++++++ .../core/di/components/CoreComponent.kt | 10 ++-- .../core/di/modules/ApplicationModule.kt | 10 ---- .../core/di/modules/DatabaseModule.kt | 15 ------ .../core/di/modules/MigrationModule.kt | 24 +++++++++ .../kiwixmobile/core/main/CoreMainActivity.kt | 14 ++--- .../page/bookmark/adapter/BookmarkItem.kt | 11 ---- .../bookmark/adapter/LibkiwixBookmarkItem.kt | 15 ------ .../page/history/adapter/HistoryListItem.kt | 14 ----- .../core/page/notes/adapter/NoteListItem.kt | 11 ---- .../fileselect_view/BooksOnDiskListItem.kt | 12 ----- defaultMigration/.gitignore | 1 + defaultMigration/build.gradle.kts | 28 ++++++++++ defaultMigration/consumer-rules.pro | 0 defaultMigration/proguard-rules.pro | 21 ++++++++ defaultMigration/src/main/AndroidManifest.xml | 4 ++ .../DefaultMigrationComponent.kt | 17 +++--- .../DefaultMigrationHandler.kt | 28 ++++++++++ .../DefaultMigrationModule.kt | 30 +++++++++++ objectboxmigration/.gitignore | 1 + objectboxmigration/build.gradle.kts | 45 ++++++++++++++++ .../objectbox-models/default.json | 38 +++---------- .../objectbox-models/default.json.bak | 0 objectboxmigration/proguard-rules.pro | 21 ++++++++ .../src/main/AndroidManifest.xml | 4 ++ .../ObjectBoxMigrationHandler.kt | 34 ++++++++++++ .../data}/ObjectBoxToLibkiwixMigrator.kt | 29 +++++++--- .../data}/ObjectBoxToRoomMigrator.kt | 38 ++++++++++--- .../di/MigrationComponent.kt | 41 ++++++++++++++ .../objectboxmigration/di/MigrationScope.kt | 25 +++++++++ .../di/module/DatabaseModule.kt | 42 +++++++++++++++ .../di/module/ObjectBoxMigrationModule.kt | 46 ++++++++++++++++ .../entities/BookOnDiskEntity.kt | 2 +- .../entities/BookmarkEntity.kt | 2 +- .../entities/HistoryEntity.kt | 9 ++-- .../entities/NotesEntity.kt | 2 +- .../entities/RecentSearchEntity.kt | 2 +- settings.gradle.kts | 5 +- 44 files changed, 505 insertions(+), 237 deletions(-) delete mode 100644 core/src/main/java/org/kiwix/kiwixmobile/core/dao/entities/LanguageEntity.kt create mode 100644 core/src/main/java/org/kiwix/kiwixmobile/core/data/ObjectBoxDataMigrationHandler.kt create mode 100644 core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/MigrationModule.kt create mode 100644 defaultMigration/.gitignore create mode 100644 defaultMigration/build.gradle.kts create mode 100644 defaultMigration/consumer-rules.pro create mode 100644 defaultMigration/proguard-rules.pro create mode 100644 defaultMigration/src/main/AndroidManifest.xml rename core/src/main/java/org/kiwix/kiwixmobile/core/base/adapter/BaseViewHolder.kt => defaultMigration/src/main/java/org/kiwix/kiwixmobile/defaultmigration/DefaultMigrationComponent.kt (63%) create mode 100644 defaultMigration/src/main/java/org/kiwix/kiwixmobile/defaultmigration/DefaultMigrationHandler.kt create mode 100644 defaultMigration/src/main/java/org/kiwix/kiwixmobile/defaultmigration/DefaultMigrationModule.kt create mode 100644 objectboxmigration/.gitignore create mode 100644 objectboxmigration/build.gradle.kts rename {core => objectboxmigration}/objectbox-models/default.json (92%) rename {core => objectboxmigration}/objectbox-models/default.json.bak (100%) create mode 100644 objectboxmigration/proguard-rules.pro create mode 100644 objectboxmigration/src/main/AndroidManifest.xml create mode 100644 objectboxmigration/src/main/java/org/kiwix/kiwixmobile/objectboxmigration/ObjectBoxMigrationHandler.kt rename {core/src/main/java/org/kiwix/kiwixmobile/core/data/remote => objectboxmigration/src/main/java/org/kiwix/kiwixmobile/objectboxmigration/data}/ObjectBoxToLibkiwixMigrator.kt (84%) rename {core/src/main/java/org/kiwix/kiwixmobile/core/data/remote => objectboxmigration/src/main/java/org/kiwix/kiwixmobile/objectboxmigration/data}/ObjectBoxToRoomMigrator.kt (73%) create mode 100644 objectboxmigration/src/main/java/org/kiwix/kiwixmobile/objectboxmigration/di/MigrationComponent.kt create mode 100644 objectboxmigration/src/main/java/org/kiwix/kiwixmobile/objectboxmigration/di/MigrationScope.kt create mode 100644 objectboxmigration/src/main/java/org/kiwix/kiwixmobile/objectboxmigration/di/module/DatabaseModule.kt create mode 100644 objectboxmigration/src/main/java/org/kiwix/kiwixmobile/objectboxmigration/di/module/ObjectBoxMigrationModule.kt rename {core/src/main/java/org/kiwix/kiwixmobile/core/dao => objectboxmigration/src/main/java/org/kiwix/kiwixmobile/objectboxmigration}/entities/BookOnDiskEntity.kt (98%) rename {core/src/main/java/org/kiwix/kiwixmobile/core/dao => objectboxmigration/src/main/java/org/kiwix/kiwixmobile/objectboxmigration}/entities/BookmarkEntity.kt (96%) rename {core/src/main/java/org/kiwix/kiwixmobile/core/dao => objectboxmigration/src/main/java/org/kiwix/kiwixmobile/objectboxmigration}/entities/HistoryEntity.kt (90%) rename {core/src/main/java/org/kiwix/kiwixmobile/core/dao => objectboxmigration/src/main/java/org/kiwix/kiwixmobile/objectboxmigration}/entities/NotesEntity.kt (96%) rename {core/src/main/java/org/kiwix/kiwixmobile/core/dao => objectboxmigration/src/main/java/org/kiwix/kiwixmobile/objectboxmigration}/entities/RecentSearchEntity.kt (94%) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index b6833f1c3..1ba644d95 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -1,4 +1,3 @@ -import com.android.build.gradle.internal.tasks.factory.dependsOn import com.slack.keeper.optInToKeeper import org.w3c.dom.Element import plugin.KiwixConfigurationPlugin diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/ObjectBoxToLibkiwixMigratorTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/ObjectBoxToLibkiwixMigratorTest.kt index 935b9d481..66a5b00a0 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/ObjectBoxToLibkiwixMigratorTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/ObjectBoxToLibkiwixMigratorTest.kt @@ -40,8 +40,6 @@ import org.junit.jupiter.api.Assertions.assertNotNull import org.junit.jupiter.api.Assertions.assertTrue import org.kiwix.kiwixmobile.core.CoreApp import org.kiwix.kiwixmobile.core.dao.entities.BookOnDiskEntity -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.entity.LibkiwixBook import org.kiwix.kiwixmobile.core.page.bookmark.adapter.LibkiwixBookmarkItem diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/ObjectBoxToRoomMigratorTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/ObjectBoxToRoomMigratorTest.kt index eb1ef31b4..09368862b 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/ObjectBoxToRoomMigratorTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/ObjectBoxToRoomMigratorTest.kt @@ -47,7 +47,6 @@ import org.kiwix.kiwixmobile.core.dao.entities.HistoryEntity import org.kiwix.kiwixmobile.core.dao.entities.NotesEntity import org.kiwix.kiwixmobile.core.dao.entities.RecentSearchEntity import org.kiwix.kiwixmobile.core.data.KiwixRoomDatabase -import org.kiwix.kiwixmobile.core.data.remote.ObjectBoxToRoomMigrator import org.kiwix.kiwixmobile.core.di.modules.DatabaseModule import org.kiwix.kiwixmobile.core.page.notes.adapter.NoteListItem import org.kiwix.kiwixmobile.core.utils.LanguageUtils diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/core/di/components/TestComponent.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/core/di/components/TestComponent.kt index 509204a37..dd00453fc 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/core/di/components/TestComponent.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/core/di/components/TestComponent.kt @@ -26,6 +26,7 @@ import org.kiwix.kiwixmobile.core.data.DataModule import org.kiwix.kiwixmobile.core.di.modules.ApplicationModule import org.kiwix.kiwixmobile.core.di.modules.CoreViewModelModule import org.kiwix.kiwixmobile.core.di.modules.JNIModule +import org.kiwix.kiwixmobile.core.di.modules.MigrationModule import org.kiwix.kiwixmobile.core.di.modules.MutexModule import org.kiwix.kiwixmobile.core.di.modules.SearchModule import org.kiwix.kiwixmobile.core.di.modules.TestNetworkModule @@ -44,7 +45,8 @@ import javax.inject.Singleton DataModule::class, CoreViewModelModule::class, SearchModule::class, - MutexModule::class + MutexModule::class, + MigrationModule::class ] ) interface TestComponent : CoreComponent { diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 0299c67dc..76853c9a2 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -6,16 +6,11 @@ buildscript { mavenCentral() maven { setUrl("https://jitpack.io") } } - - dependencies { - classpath(Libs.objectbox_gradle_plugin) - } } plugins { `android-library` } plugins.apply(KiwixConfigurationPlugin::class) -apply(plugin = "io.objectbox") android { defaultConfig { @@ -62,7 +57,6 @@ dependencies { debugImplementation(Libs.leakcanary_android) implementation(Libs.android_arch_lifecycle_extensions) - implementation(Libs.objectbox_kotlin) implementation(Libs.webkit) testImplementation(Libs.kotlinx_coroutines_test) implementation(Libs.kotlinx_coroutines_android) diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/dao/entities/LanguageEntity.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/dao/entities/LanguageEntity.kt deleted file mode 100644 index 26690ebf9..000000000 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/dao/entities/LanguageEntity.kt +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Kiwix Android - * Copyright (c) 2019 Kiwix - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package org.kiwix.kiwixmobile.core.dao.entities - -import io.objectbox.annotation.Convert -import io.objectbox.annotation.Entity -import io.objectbox.annotation.Id -import io.objectbox.converter.PropertyConverter -import org.kiwix.kiwixmobile.core.compat.CompatHelper.Companion.convertToLocal -import org.kiwix.kiwixmobile.core.zim_manager.Language -import java.util.Locale - -@Entity -data class LanguageEntity( - @Id var id: Long = 0, - @Convert(converter = StringToLocaleConverter::class, dbType = String::class) - val locale: Locale = Locale.ENGLISH, - val active: Boolean = false, - val occurencesOfLanguage: Int = 0 -) { - constructor(language: Language) : this( - 0, - language.languageCode.convertToLocal(), - language.active, - language.occurencesOfLanguage - ) - - fun toLanguageModel() = - Language(locale, active, occurencesOfLanguage, id) -} - -class StringToLocaleConverter : PropertyConverter { - override fun convertToDatabaseValue(entityProperty: Locale?): String = - entityProperty?.isO3Language ?: Locale.ENGLISH.isO3Language - - override fun convertToEntityProperty(databaseValue: String?): Locale = - databaseValue?.convertToLocal() ?: Locale.ENGLISH -} diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/data/ObjectBoxDataMigrationHandler.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/data/ObjectBoxDataMigrationHandler.kt new file mode 100644 index 000000000..d0a622163 --- /dev/null +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/data/ObjectBoxDataMigrationHandler.kt @@ -0,0 +1,23 @@ +/* + * Kiwix Android + * Copyright (c) 2025 Kiwix + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package org.kiwix.kiwixmobile.core.data + +interface ObjectBoxDataMigrationHandler { + suspend fun migrate() +} diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/di/components/CoreComponent.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/di/components/CoreComponent.kt index 4c61dc2a7..5d21599be 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/di/components/CoreComponent.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/di/components/CoreComponent.kt @@ -37,11 +37,10 @@ import org.kiwix.kiwixmobile.core.dao.WebViewHistoryRoomDao import org.kiwix.kiwixmobile.core.data.DataModule import org.kiwix.kiwixmobile.core.data.DataSource import org.kiwix.kiwixmobile.core.data.remote.KiwixService -import org.kiwix.kiwixmobile.core.data.remote.ObjectBoxToLibkiwixMigrator -import org.kiwix.kiwixmobile.core.data.remote.ObjectBoxToRoomMigrator import org.kiwix.kiwixmobile.core.di.modules.ApplicationModule import org.kiwix.kiwixmobile.core.di.modules.CoreViewModelModule import org.kiwix.kiwixmobile.core.di.modules.JNIModule +import org.kiwix.kiwixmobile.core.di.modules.MigrationModule import org.kiwix.kiwixmobile.core.di.modules.MutexModule import org.kiwix.kiwixmobile.core.di.modules.NetworkModule import org.kiwix.kiwixmobile.core.di.modules.SearchModule @@ -65,7 +64,8 @@ import javax.inject.Singleton DataModule::class, CoreViewModelModule::class, SearchModule::class, - MutexModule::class + MutexModule::class, + MigrationModule::class ] ) interface CoreComponent { @@ -88,14 +88,12 @@ interface CoreComponent { fun dataSource(): DataSource fun downloadRoomDao(): DownloadRoomDao fun connectivityManager(): ConnectivityManager - fun objectBoxToLibkiwixMigrator(): ObjectBoxToLibkiwixMigrator fun libkiwixBookmarks(): LibkiwixBookmarks fun libkiwixBooks(): LibkiwixBookOnDisk fun recentSearchRoomDao(): RecentSearchRoomDao fun historyRoomDao(): HistoryRoomDao fun webViewHistoryRoomDao(): WebViewHistoryRoomDao fun noteRoomDao(): NotesRoomDao - fun objectBoxToRoomMigrator(): ObjectBoxToRoomMigrator fun context(): Context fun downloader(): Downloader fun notificationManager(): NotificationManager @@ -107,7 +105,5 @@ interface CoreComponent { fun inject(kiwixWebView: KiwixWebView) fun inject(errorActivity: ErrorActivity) - fun inject(objectBoxToLibkiwixMigrator: ObjectBoxToLibkiwixMigrator) - fun inject(objectBoxToRoomMigrator: ObjectBoxToRoomMigrator) fun coreServiceComponent(): CoreServiceComponent.Builder } diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/ApplicationModule.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/ApplicationModule.kt index 719a143cc..b5925ff10 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/ApplicationModule.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/ApplicationModule.kt @@ -25,8 +25,6 @@ import android.os.storage.StorageManager import dagger.Module import dagger.Provides import org.kiwix.kiwixmobile.core.DarkModeConfig -import org.kiwix.kiwixmobile.core.data.remote.ObjectBoxToLibkiwixMigrator -import org.kiwix.kiwixmobile.core.data.remote.ObjectBoxToRoomMigrator import org.kiwix.kiwixmobile.core.downloader.DownloadMonitor import org.kiwix.kiwixmobile.core.downloader.downloadManager.DownloadManagerMonitor import org.kiwix.kiwixmobile.core.reader.ZimFileReader @@ -54,14 +52,6 @@ class ApplicationModule { @Singleton internal fun provideBookUtils(): BookUtils = BookUtils() - @Provides - @Singleton - fun provideObjectBoxToLibkiwixMigrator() = ObjectBoxToLibkiwixMigrator() - - @Provides - @Singleton - fun provideObjectBoxToRoomMigrator() = ObjectBoxToRoomMigrator() - @Provides @Singleton internal fun provideDownloadMonitor( diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/DatabaseModule.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/DatabaseModule.kt index 263834dbc..3f50c79ea 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/DatabaseModule.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/DatabaseModule.kt @@ -20,27 +20,12 @@ package org.kiwix.kiwixmobile.core.di.modules import android.content.Context import dagger.Module import dagger.Provides -import io.objectbox.BoxStore import org.kiwix.kiwixmobile.core.dao.LibkiwixBookOnDisk -import org.kiwix.kiwixmobile.core.dao.entities.MyObjectBox import org.kiwix.kiwixmobile.core.data.KiwixRoomDatabase import javax.inject.Singleton @Module open class DatabaseModule { - companion object { - var boxStore: BoxStore? = null - } - - @Suppress("UnsafeCallOnNullableType") - // NOT RECOMMENDED TODO use custom runner to load TestApplication - @Provides @Singleton fun providesBoxStore(context: Context): BoxStore { - if (boxStore == null) { - boxStore = MyObjectBox.builder().androidContext(context).build() - } - return boxStore!! - } - @Singleton @Provides fun provideYourDatabase( diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/MigrationModule.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/MigrationModule.kt new file mode 100644 index 000000000..084aba521 --- /dev/null +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/MigrationModule.kt @@ -0,0 +1,24 @@ +/* + * Kiwix Android + * Copyright (c) 2025 Kiwix + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package org.kiwix.kiwixmobile.core.di.modules + +import dagger.Module + +@Module +abstract class MigrationModule diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreMainActivity.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreMainActivity.kt index 32ad9a03e..a199aff56 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreMainActivity.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreMainActivity.kt @@ -47,8 +47,7 @@ import org.kiwix.kiwixmobile.core.CoreApp import org.kiwix.kiwixmobile.core.R import org.kiwix.kiwixmobile.core.base.BaseActivity import org.kiwix.kiwixmobile.core.base.FragmentActivityExtensions -import org.kiwix.kiwixmobile.core.data.remote.ObjectBoxToLibkiwixMigrator -import org.kiwix.kiwixmobile.core.data.remote.ObjectBoxToRoomMigrator +import org.kiwix.kiwixmobile.core.data.ObjectBoxDataMigrationHandler import org.kiwix.kiwixmobile.core.di.components.CoreActivityComponent import org.kiwix.kiwixmobile.core.downloader.DownloadMonitor import org.kiwix.kiwixmobile.core.downloader.downloadManager.APP_NAME_KEY @@ -165,9 +164,8 @@ abstract class CoreMainActivity : BaseActivity(), WebViewProvider { abstract val mainActivity: AppCompatActivity abstract val appName: String - @Inject lateinit var objectBoxToLibkiwixMigrator: ObjectBoxToLibkiwixMigrator - - @Inject lateinit var objectBoxToRoomMigrator: ObjectBoxToRoomMigrator + @Inject + lateinit var objectBoxDataMigrationHandler: ObjectBoxDataMigrationHandler @Inject lateinit var downloadMonitor: DownloadMonitor @@ -194,11 +192,7 @@ abstract class CoreMainActivity : BaseActivity(), WebViewProvider { setMainActivityToCoreApp() // run the migration on background thread to avoid any UI related issues. CoroutineScope(Dispatchers.IO).launch { - objectBoxToLibkiwixMigrator.migrateObjectBoxDataToLibkiwix() - } - // run the migration on background thread to avoid any UI related issues. - CoroutineScope(Dispatchers.IO).launch { - objectBoxToRoomMigrator.migrateObjectBoxDataToRoom() + objectBoxDataMigrationHandler.migrate() } lifecycleScope.launch(Dispatchers.IO) { createApplicationShortcuts() diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/page/bookmark/adapter/BookmarkItem.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/page/bookmark/adapter/BookmarkItem.kt index 473c3f4ac..0246506f3 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/page/bookmark/adapter/BookmarkItem.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/page/bookmark/adapter/BookmarkItem.kt @@ -18,7 +18,6 @@ package org.kiwix.kiwixmobile.core.page.bookmark.adapter -import org.kiwix.kiwixmobile.core.dao.entities.BookmarkEntity import org.kiwix.kiwixmobile.core.page.adapter.Page import org.kiwix.kiwixmobile.core.reader.ZimFileReader import org.kiwix.kiwixmobile.core.reader.ZimReaderSource @@ -35,16 +34,6 @@ data class BookmarkItem( override val url: String = bookmarkUrl, override val id: Long = databaseId ) : Page { - constructor(entity: BookmarkEntity) : this( - entity.id, - entity.zimId, - entity.zimName, - entity.zimReaderSource, - entity.bookmarkUrl, - entity.bookmarkTitle, - entity.favicon - ) - constructor( title: String, url: String, diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/page/bookmark/adapter/LibkiwixBookmarkItem.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/page/bookmark/adapter/LibkiwixBookmarkItem.kt index e70390870..17b060856 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/page/bookmark/adapter/LibkiwixBookmarkItem.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/page/bookmark/adapter/LibkiwixBookmarkItem.kt @@ -18,7 +18,6 @@ package org.kiwix.kiwixmobile.core.page.bookmark.adapter -import org.kiwix.kiwixmobile.core.dao.entities.BookmarkEntity import org.kiwix.kiwixmobile.core.page.adapter.Page import org.kiwix.kiwixmobile.core.reader.ZimFileReader import org.kiwix.kiwixmobile.core.reader.ZimReaderSource @@ -71,20 +70,6 @@ data class LibkiwixBookmarkItem( libKiwixBook = libKiwixBook ) - constructor( - bookmarkEntity: BookmarkEntity, - libkiwixBook: Book? - ) : this( - zimId = bookmarkEntity.zimId, - zimFilePath = bookmarkEntity.zimReaderSource?.toDatabase(), - zimReaderSource = bookmarkEntity.zimReaderSource, - zimName = bookmarkEntity.zimName, - bookmarkUrl = bookmarkEntity.bookmarkUrl, - title = bookmarkEntity.bookmarkTitle, - favicon = bookmarkEntity.favicon, - libKiwixBook = libkiwixBook - ) - constructor( zimId: String, bookmarkUrl: String diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/page/history/adapter/HistoryListItem.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/page/history/adapter/HistoryListItem.kt index 03f4aa5f4..29229b515 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/page/history/adapter/HistoryListItem.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/page/history/adapter/HistoryListItem.kt @@ -17,7 +17,6 @@ */ package org.kiwix.kiwixmobile.core.page.history.adapter -import org.kiwix.kiwixmobile.core.dao.entities.HistoryEntity import org.kiwix.kiwixmobile.core.dao.entities.HistoryRoomEntity import org.kiwix.kiwixmobile.core.page.adapter.Page import org.kiwix.kiwixmobile.core.page.adapter.PageRelated @@ -56,19 +55,6 @@ sealed class HistoryListItem : PageRelated { timeStamp = timeStamp ) - constructor(historyEntity: HistoryEntity) : this( - historyEntity.id, - historyEntity.zimId, - historyEntity.zimName, - historyEntity.zimReaderSource, - historyEntity.favicon, - historyEntity.historyUrl, - historyEntity.historyTitle, - historyEntity.dateString, - historyEntity.timeStamp, - false - ) - constructor(historyRoomEntity: HistoryRoomEntity) : this( historyRoomEntity.id, historyRoomEntity.zimId, diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/page/notes/adapter/NoteListItem.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/page/notes/adapter/NoteListItem.kt index d2b6e4178..440e62e20 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/page/notes/adapter/NoteListItem.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/page/notes/adapter/NoteListItem.kt @@ -1,6 +1,5 @@ package org.kiwix.kiwixmobile.core.page.notes.adapter -import org.kiwix.kiwixmobile.core.dao.entities.NotesEntity import org.kiwix.kiwixmobile.core.dao.entities.NotesRoomEntity import org.kiwix.kiwixmobile.core.page.adapter.Page import org.kiwix.kiwixmobile.core.reader.ZimReaderSource @@ -18,16 +17,6 @@ data class NoteListItem( override val url: String = zimUrl, override val id: Long = databaseId ) : Page, Serializable { - constructor(notesEntity: NotesEntity) : this( - notesEntity.id, - notesEntity.zimId, - notesEntity.noteTitle, - notesEntity.zimReaderSource, - notesEntity.zimUrl, - notesEntity.noteFilePath, - notesEntity.favicon - ) - constructor( zimId: String, title: String, diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/zim_manager/fileselect_view/BooksOnDiskListItem.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/zim_manager/fileselect_view/BooksOnDiskListItem.kt index ea0c69081..45226f98c 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/zim_manager/fileselect_view/BooksOnDiskListItem.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/zim_manager/fileselect_view/BooksOnDiskListItem.kt @@ -19,7 +19,6 @@ package org.kiwix.kiwixmobile.core.zim_manager.fileselect_view import org.kiwix.kiwixmobile.core.compat.CompatHelper.Companion.convertToLocal -import org.kiwix.kiwixmobile.core.dao.entities.BookOnDiskEntity import org.kiwix.kiwixmobile.core.dao.entities.DownloadRoomEntity import org.kiwix.kiwixmobile.core.entity.LibkiwixBook import org.kiwix.kiwixmobile.core.reader.ZimFileReader @@ -54,17 +53,6 @@ sealed class BooksOnDiskListItem { book.language.convertToLocal() } - @Deprecated( - "Now we are using the libkiwix to store and retrieve the local " + - "books so this constructor is no longer used." - ) - constructor(bookOnDiskEntity: BookOnDiskEntity) : this( - databaseId = bookOnDiskEntity.id, - file = bookOnDiskEntity.file, - book = bookOnDiskEntity.toBook(), - zimReaderSource = bookOnDiskEntity.zimReaderSource - ) - constructor(downloadRoomEntity: DownloadRoomEntity) : this( book = downloadRoomEntity.toBook(), zimReaderSource = ZimReaderSource(File(downloadRoomEntity.file)) diff --git a/defaultMigration/.gitignore b/defaultMigration/.gitignore new file mode 100644 index 000000000..42afabfd2 --- /dev/null +++ b/defaultMigration/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/defaultMigration/build.gradle.kts b/defaultMigration/build.gradle.kts new file mode 100644 index 000000000..6d965de2e --- /dev/null +++ b/defaultMigration/build.gradle.kts @@ -0,0 +1,28 @@ +import plugin.KiwixConfigurationPlugin + +plugins { + id("com.android.library") + id("org.jetbrains.kotlin.android") +} +plugins.apply(KiwixConfigurationPlugin::class) +android { + namespace = "org.kiwix.kiwixmobile.defaultmigration" + + defaultConfig { + minSdk = 25 + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles("consumer-rules.pro") + } + + buildTypes { + release { + isMinifyEnabled = false + proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") + } + } +} + +dependencies { + implementation(project(":core")) +} diff --git a/defaultMigration/consumer-rules.pro b/defaultMigration/consumer-rules.pro new file mode 100644 index 000000000..e69de29bb diff --git a/defaultMigration/proguard-rules.pro b/defaultMigration/proguard-rules.pro new file mode 100644 index 000000000..481bb4348 --- /dev/null +++ b/defaultMigration/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/defaultMigration/src/main/AndroidManifest.xml b/defaultMigration/src/main/AndroidManifest.xml new file mode 100644 index 000000000..8bdb7e14b --- /dev/null +++ b/defaultMigration/src/main/AndroidManifest.xml @@ -0,0 +1,4 @@ + + + + diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/base/adapter/BaseViewHolder.kt b/defaultMigration/src/main/java/org/kiwix/kiwixmobile/defaultmigration/DefaultMigrationComponent.kt similarity index 63% rename from core/src/main/java/org/kiwix/kiwixmobile/core/base/adapter/BaseViewHolder.kt rename to defaultMigration/src/main/java/org/kiwix/kiwixmobile/defaultmigration/DefaultMigrationComponent.kt index 8bd8f9c4f..48312c56e 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/base/adapter/BaseViewHolder.kt +++ b/defaultMigration/src/main/java/org/kiwix/kiwixmobile/defaultmigration/DefaultMigrationComponent.kt @@ -1,6 +1,6 @@ /* * Kiwix Android - * Copyright (c) 2019 Kiwix + * Copyright (c) 2025 Kiwix * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or @@ -16,16 +16,11 @@ * */ -package org.kiwix.kiwixmobile.core.base.adapter +package org.kiwix.kiwixmobile.defaultmigration -import android.view.View -import androidx.recyclerview.widget.RecyclerView.ViewHolder -import kotlinx.android.extensions.LayoutContainer +import dagger.Component -abstract class BaseViewHolder(override val containerView: View) : - ViewHolder( - containerView - ), - LayoutContainer { - abstract fun bind(item: ITEM) +@Component(modules = [DefaultMigrationModule::class]) +interface DefaultMigrationComponent { + // Do nothing } diff --git a/defaultMigration/src/main/java/org/kiwix/kiwixmobile/defaultmigration/DefaultMigrationHandler.kt b/defaultMigration/src/main/java/org/kiwix/kiwixmobile/defaultmigration/DefaultMigrationHandler.kt new file mode 100644 index 000000000..06565d854 --- /dev/null +++ b/defaultMigration/src/main/java/org/kiwix/kiwixmobile/defaultmigration/DefaultMigrationHandler.kt @@ -0,0 +1,28 @@ +/* + * Kiwix Android + * Copyright (c) 2025 Kiwix + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package org.kiwix.kiwixmobile.defaultmigration + +import org.kiwix.kiwixmobile.core.data.ObjectBoxDataMigrationHandler +import javax.inject.Inject + +class DefaultMigrationHandler @Inject constructor() : ObjectBoxDataMigrationHandler { + override suspend fun migrate() { + // Do nothing + } +} diff --git a/defaultMigration/src/main/java/org/kiwix/kiwixmobile/defaultmigration/DefaultMigrationModule.kt b/defaultMigration/src/main/java/org/kiwix/kiwixmobile/defaultmigration/DefaultMigrationModule.kt new file mode 100644 index 000000000..29a751049 --- /dev/null +++ b/defaultMigration/src/main/java/org/kiwix/kiwixmobile/defaultmigration/DefaultMigrationModule.kt @@ -0,0 +1,30 @@ +/* + * Kiwix Android + * Copyright (c) 2025 Kiwix + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package org.kiwix.kiwixmobile.defaultmigration + +import dagger.Module +import dagger.Provides +import org.kiwix.kiwixmobile.core.data.ObjectBoxDataMigrationHandler + +@Module +class DefaultMigrationModule { + @Provides + fun provideMigrationHandler(): ObjectBoxDataMigrationHandler = + DefaultMigrationHandler() +} diff --git a/objectboxmigration/.gitignore b/objectboxmigration/.gitignore new file mode 100644 index 000000000..42afabfd2 --- /dev/null +++ b/objectboxmigration/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/objectboxmigration/build.gradle.kts b/objectboxmigration/build.gradle.kts new file mode 100644 index 000000000..5e59ca5c7 --- /dev/null +++ b/objectboxmigration/build.gradle.kts @@ -0,0 +1,45 @@ +import org.gradle.kotlin.dsl.apply +import plugin.KiwixConfigurationPlugin + +plugins { + id("com.android.library") + id("org.jetbrains.kotlin.android") +} + +buildscript { + repositories { + google() + mavenCentral() + maven { setUrl("https://jitpack.io") } + } + + dependencies { + classpath(Libs.objectbox_gradle_plugin) + } +} + +plugins.apply(KiwixConfigurationPlugin::class) +apply(plugin = "io.objectbox") + +android { + namespace = "org.kiwix.kiwixmobile.objectboxmigration" + + defaultConfig { + minSdk = 25 + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles("consumer-rules.pro") + } + + buildTypes { + release { + isMinifyEnabled = false + proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") + } + } +} + +dependencies { + implementation(Libs.objectbox_kotlin) + implementation(project(":core")) +} diff --git a/core/objectbox-models/default.json b/objectboxmigration/objectbox-models/default.json similarity index 92% rename from core/objectbox-models/default.json rename to objectboxmigration/objectbox-models/default.json index ceb473092..d7589ca1f 100644 --- a/core/objectbox-models/default.json +++ b/objectboxmigration/objectbox-models/default.json @@ -98,35 +98,6 @@ ], "relations": [] }, - { - "id": "4:6278838675135543734", - "lastPropertyId": "4:8812214350305159407", - "name": "LanguageEntity", - "properties": [ - { - "id": "1:7795244654012809404", - "name": "id", - "type": 6, - "flags": 1 - }, - { - "id": "2:9116495537035444904", - "name": "locale", - "type": 9 - }, - { - "id": "3:452531964346972307", - "name": "active", - "type": 1 - }, - { - "id": "4:8812214350305159407", - "name": "occurencesOfLanguage", - "type": 5 - } - ], - "relations": [] - }, { "id": "5:3222423958972105425", "lastPropertyId": "11:6493253695033019145", @@ -324,7 +295,8 @@ 349148274283701276, 7257718270326155947, 7394649290555378565, - 8093454424037540087 + 8093454424037540087, + 6278838675135543734 ], "retiredIndexUids": [ 1293695782925933448, @@ -399,7 +371,11 @@ 5555873126720275555, 2724607601244650879, 5485468735259326535, - 4272820830206771469 + 4272820830206771469, + 7795244654012809404, + 9116495537035444904, + 452531964346972307, + 8812214350305159407 ], "retiredRelationUids": [], "version": 1 diff --git a/core/objectbox-models/default.json.bak b/objectboxmigration/objectbox-models/default.json.bak similarity index 100% rename from core/objectbox-models/default.json.bak rename to objectboxmigration/objectbox-models/default.json.bak diff --git a/objectboxmigration/proguard-rules.pro b/objectboxmigration/proguard-rules.pro new file mode 100644 index 000000000..481bb4348 --- /dev/null +++ b/objectboxmigration/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/objectboxmigration/src/main/AndroidManifest.xml b/objectboxmigration/src/main/AndroidManifest.xml new file mode 100644 index 000000000..8bdb7e14b --- /dev/null +++ b/objectboxmigration/src/main/AndroidManifest.xml @@ -0,0 +1,4 @@ + + + + diff --git a/objectboxmigration/src/main/java/org/kiwix/kiwixmobile/objectboxmigration/ObjectBoxMigrationHandler.kt b/objectboxmigration/src/main/java/org/kiwix/kiwixmobile/objectboxmigration/ObjectBoxMigrationHandler.kt new file mode 100644 index 000000000..67059b60c --- /dev/null +++ b/objectboxmigration/src/main/java/org/kiwix/kiwixmobile/objectboxmigration/ObjectBoxMigrationHandler.kt @@ -0,0 +1,34 @@ +/* + * Kiwix Android + * Copyright (c) 2025 Kiwix + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package org.kiwix.kiwixmobile.objectboxmigration + +import org.kiwix.kiwixmobile.core.data.ObjectBoxDataMigrationHandler +import org.kiwix.kiwixmobile.objectboxmigration.data.ObjectBoxToLibkiwixMigrator +import org.kiwix.kiwixmobile.objectboxmigration.data.ObjectBoxToRoomMigrator +import javax.inject.Inject + +class ObjectBoxMigrationHandler @Inject constructor( + private val objectBoxToRoomMigrator: ObjectBoxToRoomMigrator, + private val objectBoxToLibkiwixMigrator: ObjectBoxToLibkiwixMigrator +) : ObjectBoxDataMigrationHandler { + override suspend fun migrate() { + objectBoxToRoomMigrator.migrateObjectBoxDataToRoom() + objectBoxToLibkiwixMigrator.migrateObjectBoxDataToLibkiwix() + } +} diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/data/remote/ObjectBoxToLibkiwixMigrator.kt b/objectboxmigration/src/main/java/org/kiwix/kiwixmobile/objectboxmigration/data/ObjectBoxToLibkiwixMigrator.kt similarity index 84% rename from core/src/main/java/org/kiwix/kiwixmobile/core/data/remote/ObjectBoxToLibkiwixMigrator.kt rename to objectboxmigration/src/main/java/org/kiwix/kiwixmobile/objectboxmigration/data/ObjectBoxToLibkiwixMigrator.kt index 37bc9f213..12b6dcca1 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/data/remote/ObjectBoxToLibkiwixMigrator.kt +++ b/objectboxmigration/src/main/java/org/kiwix/kiwixmobile/objectboxmigration/data/ObjectBoxToLibkiwixMigrator.kt @@ -16,23 +16,22 @@ * */ -package org.kiwix.kiwixmobile.core.data.remote +package org.kiwix.kiwixmobile.objectboxmigration.data import io.objectbox.Box import io.objectbox.BoxStore import io.objectbox.kotlin.boxFor import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock -import org.kiwix.kiwixmobile.core.CoreApp import org.kiwix.kiwixmobile.core.dao.LibkiwixBookOnDisk import org.kiwix.kiwixmobile.core.dao.LibkiwixBookmarks -import org.kiwix.kiwixmobile.core.dao.entities.BookOnDiskEntity -import org.kiwix.kiwixmobile.core.dao.entities.BookmarkEntity import org.kiwix.kiwixmobile.core.page.bookmark.adapter.LibkiwixBookmarkItem import org.kiwix.kiwixmobile.core.reader.ZimReaderSource import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil import org.kiwix.kiwixmobile.core.utils.files.Log import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.BooksOnDiskListItem.BookOnDisk +import org.kiwix.kiwixmobile.objectboxmigration.entities.BookOnDiskEntity +import org.kiwix.kiwixmobile.objectboxmigration.entities.BookmarkEntity import org.kiwix.libkiwix.Book import org.kiwix.libzim.Archive import java.io.File @@ -53,7 +52,7 @@ class ObjectBoxToLibkiwixMigrator { private val migrationMutex = Mutex() suspend fun migrateObjectBoxDataToLibkiwix() { - CoreApp.coreComponent.inject(this) + // CoreApp.coreComponent.inject(this) if (!sharedPreferenceUtil.prefIsBookmarksMigrated) { migrateBookMarks(boxStore.boxFor()) } @@ -73,7 +72,12 @@ class ObjectBoxToLibkiwixMigrator { bookOnDiskEntity.zimReaderSource = zimReaderSource } } - BookOnDisk(bookOnDiskEntity) + BookOnDisk( + databaseId = bookOnDiskEntity.id, + file = bookOnDiskEntity.file, + book = bookOnDiskEntity.toBook(), + zimReaderSource = bookOnDiskEntity.zimReaderSource + ) } migrationMutex.withLock { runCatching { @@ -118,13 +122,22 @@ class ObjectBoxToLibkiwixMigrator { // to display them on the bookmark screen. null } - } ?: kotlin.run { + } ?: run { // 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 } libkiwixBookmarks.saveBookmark( - LibkiwixBookmarkItem(bookmarkEntity, libkiwixBook), + LibkiwixBookmarkItem( + zimId = bookmarkEntity.zimId, + zimFilePath = bookmarkEntity.zimReaderSource?.toDatabase(), + zimReaderSource = bookmarkEntity.zimReaderSource, + zimName = bookmarkEntity.zimName, + bookmarkUrl = bookmarkEntity.bookmarkUrl, + title = bookmarkEntity.bookmarkTitle, + favicon = bookmarkEntity.favicon, + libKiwixBook = libkiwixBook + ), shouldWriteBookmarkToFile = index == bookMarksList.size - 1 ) archive?.dispose() diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/data/remote/ObjectBoxToRoomMigrator.kt b/objectboxmigration/src/main/java/org/kiwix/kiwixmobile/objectboxmigration/data/ObjectBoxToRoomMigrator.kt similarity index 73% rename from core/src/main/java/org/kiwix/kiwixmobile/core/data/remote/ObjectBoxToRoomMigrator.kt rename to objectboxmigration/src/main/java/org/kiwix/kiwixmobile/objectboxmigration/data/ObjectBoxToRoomMigrator.kt index 6b31f04b0..bcfc4c7c7 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/data/remote/ObjectBoxToRoomMigrator.kt +++ b/objectboxmigration/src/main/java/org/kiwix/kiwixmobile/objectboxmigration/data/ObjectBoxToRoomMigrator.kt @@ -16,15 +16,14 @@ * */ -package org.kiwix.kiwixmobile.core.data.remote +package org.kiwix.kiwixmobile.objectboxmigration.data import io.objectbox.Box import io.objectbox.BoxStore import io.objectbox.kotlin.boxFor -import org.kiwix.kiwixmobile.core.CoreApp -import org.kiwix.kiwixmobile.core.dao.entities.HistoryEntity -import org.kiwix.kiwixmobile.core.dao.entities.NotesEntity -import org.kiwix.kiwixmobile.core.dao.entities.RecentSearchEntity +import org.kiwix.kiwixmobile.objectboxmigration.entities.HistoryEntity +import org.kiwix.kiwixmobile.objectboxmigration.entities.NotesEntity +import org.kiwix.kiwixmobile.objectboxmigration.entities.RecentSearchEntity 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 @@ -39,7 +38,7 @@ class ObjectBoxToRoomMigrator { @Inject lateinit var sharedPreferenceUtil: SharedPreferenceUtil suspend fun migrateObjectBoxDataToRoom() { - CoreApp.coreComponent.inject(this) + // CoreApp.coreComponent.inject(this) if (!sharedPreferenceUtil.prefIsRecentSearchMigrated) { migrateRecentSearch(boxStore.boxFor()) } @@ -71,7 +70,20 @@ class ObjectBoxToRoomMigrator { val historyEntityList = box.all historyEntityList.forEachIndexed { _, historyEntity -> kiwixRoomDatabase.historyRoomDao() - .saveHistory(HistoryListItem.HistoryItem(historyEntity)) + .saveHistory( + HistoryListItem.HistoryItem( + historyEntity.id, + historyEntity.zimId, + historyEntity.zimName, + historyEntity.zimReaderSource, + historyEntity.favicon, + historyEntity.historyUrl, + historyEntity.historyTitle, + historyEntity.dateString, + historyEntity.timeStamp, + false + ) + ) // removing the single entity from the object box after migration. box.remove(historyEntity.id) } @@ -81,7 +93,17 @@ class ObjectBoxToRoomMigrator { suspend fun migrateNotes(box: Box) { val notesEntityList = box.all notesEntityList.forEachIndexed { _, notesEntity -> - kiwixRoomDatabase.notesRoomDao().saveNote(NoteListItem(notesEntity)) + kiwixRoomDatabase.notesRoomDao().saveNote( + NoteListItem( + notesEntity.id, + notesEntity.zimId, + notesEntity.noteTitle, + notesEntity.zimReaderSource, + notesEntity.zimUrl, + notesEntity.noteFilePath, + notesEntity.favicon + ) + ) // removing the single entity from the object box after migration. box.remove(notesEntity.id) } diff --git a/objectboxmigration/src/main/java/org/kiwix/kiwixmobile/objectboxmigration/di/MigrationComponent.kt b/objectboxmigration/src/main/java/org/kiwix/kiwixmobile/objectboxmigration/di/MigrationComponent.kt new file mode 100644 index 000000000..c0081d41e --- /dev/null +++ b/objectboxmigration/src/main/java/org/kiwix/kiwixmobile/objectboxmigration/di/MigrationComponent.kt @@ -0,0 +1,41 @@ +/* + * Kiwix Android + * Copyright (c) 2025 Kiwix + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package org.kiwix.kiwixmobile.objectboxmigration.di + +import dagger.Component +import org.kiwix.kiwixmobile.core.di.components.CoreComponent +import org.kiwix.kiwixmobile.objectboxmigration.data.ObjectBoxToLibkiwixMigrator +import org.kiwix.kiwixmobile.objectboxmigration.data.ObjectBoxToRoomMigrator +import org.kiwix.kiwixmobile.objectboxmigration.di.module.DatabaseModule +import org.kiwix.kiwixmobile.objectboxmigration.di.module.ObjectBoxMigrationModule + +@MigrationScope +@Component( + dependencies = [CoreComponent::class], + modules = [ObjectBoxMigrationModule::class, DatabaseModule::class] +) +interface MigrationComponent { + fun objectBoxToRoomMigrator(): ObjectBoxToRoomMigrator + fun objectBoxToLibkiwixMigrator(): ObjectBoxToLibkiwixMigrator + + @Component.Factory + interface Factory { + fun create(coreComponent: CoreComponent): MigrationComponent + } +} diff --git a/objectboxmigration/src/main/java/org/kiwix/kiwixmobile/objectboxmigration/di/MigrationScope.kt b/objectboxmigration/src/main/java/org/kiwix/kiwixmobile/objectboxmigration/di/MigrationScope.kt new file mode 100644 index 000000000..200ed6353 --- /dev/null +++ b/objectboxmigration/src/main/java/org/kiwix/kiwixmobile/objectboxmigration/di/MigrationScope.kt @@ -0,0 +1,25 @@ +/* + * Kiwix Android + * Copyright (c) 2025 Kiwix + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package org.kiwix.kiwixmobile.objectboxmigration.di + +import javax.inject.Scope + +@Scope +@Retention(AnnotationRetention.RUNTIME) +annotation class MigrationScope diff --git a/objectboxmigration/src/main/java/org/kiwix/kiwixmobile/objectboxmigration/di/module/DatabaseModule.kt b/objectboxmigration/src/main/java/org/kiwix/kiwixmobile/objectboxmigration/di/module/DatabaseModule.kt new file mode 100644 index 000000000..1f3a10c45 --- /dev/null +++ b/objectboxmigration/src/main/java/org/kiwix/kiwixmobile/objectboxmigration/di/module/DatabaseModule.kt @@ -0,0 +1,42 @@ +/* + * Kiwix Android + * Copyright (c) 2025 Kiwix + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package org.kiwix.kiwixmobile.objectboxmigration.di.module + +import android.content.Context +import dagger.Module +import dagger.Provides +import io.objectbox.BoxStore +import org.kiwix.kiwixmobile.objectboxmigration.entities.MyObjectBox +import javax.inject.Singleton + +@Module +class DatabaseModule { + companion object { + var boxStore: BoxStore? = null + } + + @Suppress("UnsafeCallOnNullableType") + // NOT RECOMMENDED TODO use custom runner to load TestApplication + @Provides @Singleton fun providesBoxStore(context: Context): BoxStore { + if (boxStore == null) { + boxStore = MyObjectBox.builder().androidContext(context).build() + } + return boxStore!! + } +} diff --git a/objectboxmigration/src/main/java/org/kiwix/kiwixmobile/objectboxmigration/di/module/ObjectBoxMigrationModule.kt b/objectboxmigration/src/main/java/org/kiwix/kiwixmobile/objectboxmigration/di/module/ObjectBoxMigrationModule.kt new file mode 100644 index 000000000..783a826be --- /dev/null +++ b/objectboxmigration/src/main/java/org/kiwix/kiwixmobile/objectboxmigration/di/module/ObjectBoxMigrationModule.kt @@ -0,0 +1,46 @@ +/* + * Kiwix Android + * Copyright (c) 2025 Kiwix + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package org.kiwix.kiwixmobile.objectboxmigration.di.module + +import dagger.Module +import dagger.Provides +import org.kiwix.kiwixmobile.core.data.ObjectBoxDataMigrationHandler +import org.kiwix.kiwixmobile.objectboxmigration.ObjectBoxMigrationHandler +import org.kiwix.kiwixmobile.objectboxmigration.data.ObjectBoxToLibkiwixMigrator +import org.kiwix.kiwixmobile.objectboxmigration.data.ObjectBoxToRoomMigrator +import org.kiwix.kiwixmobile.objectboxmigration.di.MigrationScope + +@Module +class ObjectBoxMigrationModule { + @Provides + @MigrationScope + fun provideObjectBoxToLibkiwixMigrator() = ObjectBoxToLibkiwixMigrator() + + @Provides + @MigrationScope + fun provideObjectBoxToRoomMigrator() = ObjectBoxToRoomMigrator() + + @Provides + @MigrationScope + fun provideMigrationHandler( + objectBoxToRoomMigrator: ObjectBoxToRoomMigrator, + objectBoxToLibkiwixMigrator: ObjectBoxToLibkiwixMigrator + ): ObjectBoxDataMigrationHandler = + ObjectBoxMigrationHandler(objectBoxToRoomMigrator, objectBoxToLibkiwixMigrator) +} diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/dao/entities/BookOnDiskEntity.kt b/objectboxmigration/src/main/java/org/kiwix/kiwixmobile/objectboxmigration/entities/BookOnDiskEntity.kt similarity index 98% rename from core/src/main/java/org/kiwix/kiwixmobile/core/dao/entities/BookOnDiskEntity.kt rename to objectboxmigration/src/main/java/org/kiwix/kiwixmobile/objectboxmigration/entities/BookOnDiskEntity.kt index b2cd22680..e843b9eb8 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/dao/entities/BookOnDiskEntity.kt +++ b/objectboxmigration/src/main/java/org/kiwix/kiwixmobile/objectboxmigration/entities/BookOnDiskEntity.kt @@ -16,7 +16,7 @@ * */ -package org.kiwix.kiwixmobile.core.dao.entities +package org.kiwix.kiwixmobile.objectboxmigration.entities import io.objectbox.annotation.Convert import io.objectbox.annotation.Entity diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/dao/entities/BookmarkEntity.kt b/objectboxmigration/src/main/java/org/kiwix/kiwixmobile/objectboxmigration/entities/BookmarkEntity.kt similarity index 96% rename from core/src/main/java/org/kiwix/kiwixmobile/core/dao/entities/BookmarkEntity.kt rename to objectboxmigration/src/main/java/org/kiwix/kiwixmobile/objectboxmigration/entities/BookmarkEntity.kt index 22c765646..17581b396 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/dao/entities/BookmarkEntity.kt +++ b/objectboxmigration/src/main/java/org/kiwix/kiwixmobile/objectboxmigration/entities/BookmarkEntity.kt @@ -15,7 +15,7 @@ * along with this program. If not, see . * */ -package org.kiwix.kiwixmobile.core.dao.entities +package org.kiwix.kiwixmobile.objectboxmigration.entities import io.objectbox.annotation.Convert import io.objectbox.annotation.Entity diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/dao/entities/HistoryEntity.kt b/objectboxmigration/src/main/java/org/kiwix/kiwixmobile/objectboxmigration/entities/HistoryEntity.kt similarity index 90% rename from core/src/main/java/org/kiwix/kiwixmobile/core/dao/entities/HistoryEntity.kt rename to objectboxmigration/src/main/java/org/kiwix/kiwixmobile/objectboxmigration/entities/HistoryEntity.kt index e5e791f20..5e9160c29 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/dao/entities/HistoryEntity.kt +++ b/objectboxmigration/src/main/java/org/kiwix/kiwixmobile/objectboxmigration/entities/HistoryEntity.kt @@ -1,6 +1,6 @@ /* * Kiwix Android - * Copyright (c) 2019 Kiwix + * Copyright (c) 2025 Kiwix * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or @@ -15,12 +15,13 @@ * along with this program. If not, see . * */ -package org.kiwix.kiwixmobile.core.dao.entities + +package org.kiwix.kiwixmobile.objectboxmigration.entities import io.objectbox.annotation.Convert import io.objectbox.annotation.Entity import io.objectbox.annotation.Id -import org.kiwix.kiwixmobile.core.page.history.adapter.HistoryListItem.HistoryItem +import org.kiwix.kiwixmobile.core.page.history.adapter.HistoryListItem import org.kiwix.kiwixmobile.core.reader.ZimReaderSource @Entity @@ -38,7 +39,7 @@ data class HistoryEntity( val dateString: String, val timeStamp: Long ) { - constructor(historyItem: HistoryItem) : this( + constructor(historyItem: HistoryListItem.HistoryItem) : this( historyItem.databaseId, historyItem.zimId, historyItem.zimName, diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/dao/entities/NotesEntity.kt b/objectboxmigration/src/main/java/org/kiwix/kiwixmobile/objectboxmigration/entities/NotesEntity.kt similarity index 96% rename from core/src/main/java/org/kiwix/kiwixmobile/core/dao/entities/NotesEntity.kt rename to objectboxmigration/src/main/java/org/kiwix/kiwixmobile/objectboxmigration/entities/NotesEntity.kt index 8d1709996..63ef0c630 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/dao/entities/NotesEntity.kt +++ b/objectboxmigration/src/main/java/org/kiwix/kiwixmobile/objectboxmigration/entities/NotesEntity.kt @@ -16,7 +16,7 @@ * */ -package org.kiwix.kiwixmobile.core.dao.entities +package org.kiwix.kiwixmobile.objectboxmigration.entities import io.objectbox.annotation.Convert import io.objectbox.annotation.Entity diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/dao/entities/RecentSearchEntity.kt b/objectboxmigration/src/main/java/org/kiwix/kiwixmobile/objectboxmigration/entities/RecentSearchEntity.kt similarity index 94% rename from core/src/main/java/org/kiwix/kiwixmobile/core/dao/entities/RecentSearchEntity.kt rename to objectboxmigration/src/main/java/org/kiwix/kiwixmobile/objectboxmigration/entities/RecentSearchEntity.kt index c767ed0a7..8a7c85c9c 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/dao/entities/RecentSearchEntity.kt +++ b/objectboxmigration/src/main/java/org/kiwix/kiwixmobile/objectboxmigration/entities/RecentSearchEntity.kt @@ -15,7 +15,7 @@ * along with this program. If not, see . * */ -package org.kiwix.kiwixmobile.core.dao.entities +package org.kiwix.kiwixmobile.objectboxmigration.entities import io.objectbox.annotation.Entity import io.objectbox.annotation.Id diff --git a/settings.gradle.kts b/settings.gradle.kts index 7e820e31a..ba19fdfa7 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -2,6 +2,9 @@ include( ":core", ":app", ":custom", - ":install_time_asset" + ":install_time_asset", + ":objectboxmigration", + ":defaultMigration" ) rootProject.name = "kiwix-android" +include(":objectboxmigration2")