Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
27 changes: 17 additions & 10 deletions app/src/main/java/com/duckduckgo/app/di/DatabaseModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@
package com.duckduckgo.app.di

import android.content.Context
import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.room.RoomDatabase.JournalMode.TRUNCATE
import com.duckduckgo.app.bookmarks.migration.AppDatabaseBookmarksMigrationCallbackProvider
import com.duckduckgo.app.browser.DefaultWebViewDatabaseProvider
import com.duckduckgo.app.browser.WebViewDatabaseProvider
import com.duckduckgo.app.global.db.AppDatabase
import com.duckduckgo.app.global.db.MigrationsProvider
import com.duckduckgo.app.settings.db.SettingsDataStore
import com.duckduckgo.appbuildconfig.api.*
import com.duckduckgo.data.store.api.DatabaseProvider
import com.duckduckgo.data.store.api.RoomDatabaseConfig
import com.duckduckgo.di.scopes.AppScope
import dagger.Lazy
import dagger.Module
Expand All @@ -52,17 +53,23 @@ object DatabaseModule {
@Provides
@SingleInstanceIn(AppScope::class)
fun provideAppDatabase(
context: Context,
migrationsProvider: MigrationsProvider,
databaseBookmarksMigrationCallbackProvider: AppDatabaseBookmarksMigrationCallbackProvider,
databaseProvider: DatabaseProvider,
): AppDatabase {
return Room.databaseBuilder(context, AppDatabase::class.java, "app.db")
.addMigrations(*migrationsProvider.ALL_MIGRATIONS.toTypedArray())
.addCallback(migrationsProvider.BOOKMARKS_DB_ON_CREATE)
.addCallback(migrationsProvider.CHANGE_JOURNAL_ON_OPEN)
.addCallback(databaseBookmarksMigrationCallbackProvider.provideCallbacks())
.setJournalMode(RoomDatabase.JournalMode.TRUNCATE)
.build()
return databaseProvider.buildRoomDatabase(
AppDatabase::class.java,
"app.db",
config = RoomDatabaseConfig(
callbacks = listOf(
migrationsProvider.BOOKMARKS_DB_ON_CREATE,
migrationsProvider.CHANGE_JOURNAL_ON_OPEN,
databaseBookmarksMigrationCallbackProvider.provideCallbacks(),
),
journalMode = TRUNCATE,
migrations = migrationsProvider.ALL_MIGRATIONS,
),
)
}

@Provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import logcat.LogPriority.WARN
import logcat.asLog
import logcat.logcat
import javax.inject.Inject
import javax.inject.Provider

@ContributesBinding(
scope = AppScope::class,
Expand All @@ -55,13 +56,14 @@ import javax.inject.Inject
@SingleInstanceIn(AppScope::class)
class RxPixelSender @Inject constructor(
private val api: PixelService,
private val pendingPixelDao: PendingPixelDao,
private val pendingPixelDaoProvider: Provider<PendingPixelDao>,
private val statisticsDataStore: StatisticsDataStore,
private val deviceInfo: DeviceInfo,
private val statisticsLibraryConfig: StatisticsLibraryConfig?,
private val pixelFiredRepository: PixelFiredRepository,
) : PixelSender, MainProcessLifecycleObserver {

private val pendingPixelDao by lazy { pendingPixelDaoProvider.get() }
private val compositeDisposable = CompositeDisposable()

private val shouldFirePixelsAsDev: Int? by lazy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class RxPixelSenderTest {

testee = RxPixelSender(
api,
pendingPixelDao,
{ pendingPixelDao },
mockStatisticsDataStore,
mockDeviceInfo,
object : StatisticsLibraryConfig {
Expand Down
Loading