From a629fd8a47d2338594260993a69fbeb1a5b77cb3 Mon Sep 17 00:00:00 2001 From: Sean Mac Gillicuddy Date: Tue, 10 Sep 2019 16:08:05 +0100 Subject: [PATCH] #1449 hack for ZimManageActivity test to present 2 separate application components creating boxStores --- .../kiwix/kiwixmobile/di/modules/DatabaseModule.kt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/kiwix/kiwixmobile/di/modules/DatabaseModule.kt b/app/src/main/java/org/kiwix/kiwixmobile/di/modules/DatabaseModule.kt index 76f860193..9fc05dcd1 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/di/modules/DatabaseModule.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/di/modules/DatabaseModule.kt @@ -33,8 +33,16 @@ import javax.inject.Singleton @Module class DatabaseModule { - @Provides @Singleton fun providesBoxStore(context: Context): BoxStore = - MyObjectBox.builder().androidContext(context.applicationContext).build() + companion object { + var boxStore: BoxStore? = null + } + + @Provides @Singleton fun providesBoxStore(context: Context): BoxStore { + if (boxStore == null) { + boxStore = MyObjectBox.builder().androidContext(context.applicationContext).build() + } + return boxStore!! + } @Provides @Singleton fun providesNewDownloadDao(boxStore: BoxStore): NewDownloadDao = NewDownloadDao(boxStore.boxFor())