2019-12-13 02:12:19 +01:00
|
|
|
package info.nightscout.androidaps.dependencyInjection
|
|
|
|
|
|
|
|
import android.content.Context
|
2019-12-21 20:17:08 +01:00
|
|
|
import dagger.Binds
|
2020-03-25 23:51:04 +01:00
|
|
|
import dagger.Lazy
|
2019-12-13 02:12:19 +01:00
|
|
|
import dagger.Module
|
|
|
|
import dagger.Provides
|
2020-01-10 02:27:14 +01:00
|
|
|
import dagger.android.HasAndroidInjector
|
2020-03-25 23:51:04 +01:00
|
|
|
import info.nightscout.androidaps.Config
|
2019-12-26 17:50:16 +01:00
|
|
|
import info.nightscout.androidaps.MainApp
|
2020-05-09 10:52:20 +02:00
|
|
|
import info.nightscout.androidaps.db.DatabaseHelperProvider
|
2020-05-07 09:54:36 +02:00
|
|
|
import info.nightscout.androidaps.interfaces.*
|
2020-05-10 11:03:19 +02:00
|
|
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
2020-03-16 21:40:29 +01:00
|
|
|
import info.nightscout.androidaps.plugins.configBuilder.PluginStore
|
2021-01-18 17:36:18 +01:00
|
|
|
import info.nightscout.androidaps.plugins.general.maintenance.ImportExportPrefs
|
2020-05-09 10:52:20 +02:00
|
|
|
import info.nightscout.androidaps.plugins.general.nsclient.UploadQueue
|
2020-05-07 09:54:36 +02:00
|
|
|
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
2020-01-10 23:14:58 +01:00
|
|
|
import info.nightscout.androidaps.queue.CommandQueue
|
2020-05-09 10:52:20 +02:00
|
|
|
import info.nightscout.androidaps.utils.androidNotification.NotificationHolder
|
2020-02-11 19:34:56 +01:00
|
|
|
import info.nightscout.androidaps.utils.storage.FileStorage
|
|
|
|
import info.nightscout.androidaps.utils.storage.Storage
|
2019-12-13 02:12:19 +01:00
|
|
|
import javax.inject.Singleton
|
|
|
|
|
2020-05-03 15:04:08 +02:00
|
|
|
@Module(includes = [
|
2020-05-10 23:45:49 +02:00
|
|
|
AppModule.AppBindings::class
|
2020-05-03 15:04:08 +02:00
|
|
|
])
|
2019-12-30 23:26:48 +01:00
|
|
|
open class AppModule {
|
2019-12-13 02:12:19 +01:00
|
|
|
|
2020-03-25 23:51:04 +01:00
|
|
|
@Provides
|
2020-05-07 09:54:36 +02:00
|
|
|
fun providesPlugins(configInterface: ConfigInterface,
|
|
|
|
@PluginsModule.AllConfigs allConfigs: Map<@JvmSuppressWildcards Int, @JvmSuppressWildcards PluginBase>,
|
2020-03-25 23:51:04 +01:00
|
|
|
@PluginsModule.PumpDriver pumpDrivers: Lazy<Map<@JvmSuppressWildcards Int, @JvmSuppressWildcards PluginBase>>,
|
|
|
|
@PluginsModule.NotNSClient notNsClient: Lazy<Map<@JvmSuppressWildcards Int, @JvmSuppressWildcards PluginBase>>,
|
2020-04-24 22:39:56 +02:00
|
|
|
@PluginsModule.APS aps: Lazy<Map<@JvmSuppressWildcards Int, @JvmSuppressWildcards PluginBase>>)
|
|
|
|
: List<@JvmSuppressWildcards PluginBase> {
|
2020-03-25 23:51:04 +01:00
|
|
|
val plugins = allConfigs.toMutableMap()
|
2020-05-07 09:54:36 +02:00
|
|
|
if (configInterface.PUMPDRIVERS) plugins += pumpDrivers.get()
|
|
|
|
if (configInterface.APS) plugins += aps.get()
|
|
|
|
if (!configInterface.NSCLIENT) plugins += notNsClient.get()
|
2020-03-25 23:51:04 +01:00
|
|
|
return plugins.toList().sortedBy { it.first }.map { it.second }
|
|
|
|
}
|
|
|
|
|
2020-02-11 19:34:56 +01:00
|
|
|
@Provides
|
|
|
|
@Singleton
|
|
|
|
fun provideStorage(): Storage {
|
|
|
|
return FileStorage()
|
|
|
|
}
|
|
|
|
|
2019-12-21 20:17:08 +01:00
|
|
|
@Module
|
|
|
|
interface AppBindings {
|
2019-12-13 02:12:19 +01:00
|
|
|
|
2019-12-30 00:53:44 +01:00
|
|
|
@Binds fun bindContext(mainApp: MainApp): Context
|
2020-01-10 02:27:14 +01:00
|
|
|
@Binds fun bindInjector(mainApp: MainApp): HasAndroidInjector
|
2020-05-04 00:42:13 +02:00
|
|
|
@Binds fun bindActivePluginProvider(pluginStore: PluginStore): ActivePluginProvider
|
2020-05-10 23:45:49 +02:00
|
|
|
@Binds fun bindCommandQueueProvider(commandQueue: CommandQueue): CommandQueueProvider
|
|
|
|
@Binds fun bindConfigInterface(config: Config): ConfigInterface
|
|
|
|
@Binds fun bindConfigBuilderInterface(configBuilderPlugin: ConfigBuilderPlugin): ConfigBuilderInterface
|
|
|
|
@Binds fun bindTreatmentInterface(treatmentsPlugin: TreatmentsPlugin): TreatmentsInterface
|
|
|
|
@Binds fun bindDatabaseHelperInterface(databaseHelperProvider: DatabaseHelperProvider): DatabaseHelperInterface
|
|
|
|
@Binds fun bindUploadQueueInterface(uploadQueue: UploadQueue): UploadQueueInterface
|
|
|
|
@Binds fun bindNotificationHolderInterface(notificationHolder: NotificationHolder): NotificationHolderInterface
|
2021-01-18 17:36:18 +01:00
|
|
|
@Binds fun bindImportExportPrefsInterface(importExportPrefs: ImportExportPrefs): ImportExportPrefsInterface
|
2019-12-13 02:12:19 +01:00
|
|
|
}
|
|
|
|
}
|