mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-24 05:04:50 -04:00
Bug fix in boxstore
This commit is contained in:
parent
0b91c0dfd1
commit
c56af0ca85
@ -26,23 +26,23 @@ import io.objectbox.BoxStore
|
|||||||
import io.objectbox.kotlin.boxFor
|
import io.objectbox.kotlin.boxFor
|
||||||
import org.kiwix.kiwixmobile.core.dao.NewRecentSearchRoomDao
|
import org.kiwix.kiwixmobile.core.dao.NewRecentSearchRoomDao
|
||||||
import org.kiwix.kiwixmobile.core.dao.entities.RecentSearchRoomEntity
|
import org.kiwix.kiwixmobile.core.dao.entities.RecentSearchRoomEntity
|
||||||
import javax.inject.Inject
|
|
||||||
|
|
||||||
@Suppress("UnnecessaryAbstractClass")
|
@Suppress("UnnecessaryAbstractClass")
|
||||||
@Database(entities = [RecentSearchRoomEntity::class], version = 19)
|
@Database(entities = [RecentSearchRoomEntity::class], version = 19)
|
||||||
abstract class KiwixRoomDatabase : RoomDatabase() {
|
abstract class KiwixRoomDatabase : RoomDatabase() {
|
||||||
abstract fun newRecentSearchRoomDao(): NewRecentSearchRoomDao
|
abstract fun newRecentSearchRoomDao(): NewRecentSearchRoomDao
|
||||||
@Inject lateinit var boxStore: BoxStore
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private var db: KiwixRoomDatabase? = null
|
private var db: KiwixRoomDatabase? = null
|
||||||
fun getInstance(context: Context): KiwixRoomDatabase {
|
fun getInstance(context: Context, boxStore: BoxStore): KiwixRoomDatabase {
|
||||||
return db ?: synchronized(KiwixRoomDatabase::class) {
|
return db ?: synchronized(KiwixRoomDatabase::class) {
|
||||||
return@getInstance db
|
return@getInstance db
|
||||||
?: Room.databaseBuilder(context, KiwixRoomDatabase::class.java, "KiwixRoom.db")
|
?: Room.databaseBuilder(context, KiwixRoomDatabase::class.java, "KiwixRoom.db")
|
||||||
// We have already database name called kiwix.db in order to avoid complexity we named as
|
// We have already database name called kiwix.db in order to avoid complexity we named as
|
||||||
// kiwixRoom.db
|
// kiwixRoom.db
|
||||||
.build().also(KiwixRoomDatabase::migrateRecentSearch)
|
.build().also {
|
||||||
|
it.migrateRecentSearch(boxStore)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ abstract class KiwixRoomDatabase : RoomDatabase() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun migrateRecentSearch() {
|
fun migrateRecentSearch(boxStore: BoxStore) {
|
||||||
newRecentSearchRoomDao().migrationToRoomInsert(boxStore.boxFor())
|
newRecentSearchRoomDao().migrationToRoomInsert(boxStore.boxFor())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,6 +65,7 @@ class ApplicationModule {
|
|||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
|
|
||||||
internal fun provideBookUtils(): BookUtils = BookUtils()
|
internal fun provideBookUtils(): BookUtils = BookUtils()
|
||||||
|
|
||||||
@IO
|
@IO
|
||||||
|
@ -77,12 +77,15 @@ open class DatabaseModule {
|
|||||||
@Singleton
|
@Singleton
|
||||||
@Provides
|
@Provides
|
||||||
fun provideYourDatabase(
|
fun provideYourDatabase(
|
||||||
context: Context
|
context: Context,
|
||||||
|
boxStore: BoxStore
|
||||||
) =
|
) =
|
||||||
KiwixRoomDatabase.getInstance(context = context)// The reason we can construct a database for the repo
|
KiwixRoomDatabase.getInstance(
|
||||||
|
context = context,
|
||||||
|
boxStore
|
||||||
|
)// The reason we can construct a database for the repo
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
@Provides
|
@Provides
|
||||||
fun provideYourDao(db: KiwixRoomDatabase) = db.newRecentSearchRoomDao()
|
fun provideYourDao(db: KiwixRoomDatabase) = db.newRecentSearchRoomDao()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user