AndroidAPS/app/src/main/java/info/nightscout/androidaps/di/AppModule.kt

116 lines
5.6 KiB
Kotlin
Raw Normal View History

2022-01-06 17:45:00 +01:00
package info.nightscout.androidaps.di
2019-12-13 02:12:19 +01:00
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
2019-12-26 17:50:16 +01:00
import info.nightscout.androidaps.MainApp
2022-11-02 11:22:34 +01:00
import info.nightscout.androidaps.implementations.ActivityNamesImpl
2022-11-21 22:43:34 +01:00
import info.nightscout.androidaps.implementations.ConfigImpl
2020-05-10 11:03:19 +02:00
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctionImpl
2021-04-14 19:15:10 +02:00
import info.nightscout.androidaps.plugins.general.maintenance.ImportExportPrefsImpl
2021-02-22 17:22:30 +01:00
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin
2022-11-23 22:27:51 +01:00
import info.nightscout.androidaps.workflow.CalculationWorkflowImpl
2022-11-21 22:43:34 +01:00
import info.nightscout.core.utils.fabric.FabricPrivacy
2022-11-23 22:27:51 +01:00
import info.nightscout.core.workflow.CalculationWorkflow
2022-11-10 14:01:14 +01:00
import info.nightscout.database.impl.AppRepository
import info.nightscout.implementation.constraints.ConstraintsImpl
2022-11-08 17:34:47 +01:00
import info.nightscout.interfaces.Config
2022-11-09 15:56:59 +01:00
import info.nightscout.interfaces.ConfigBuilder
2022-11-11 21:42:50 +01:00
import info.nightscout.interfaces.aps.Loop
2022-11-10 14:01:14 +01:00
import info.nightscout.interfaces.autotune.Autotune
2022-11-11 18:54:30 +01:00
import info.nightscout.interfaces.constraints.Constraints
2022-11-11 23:17:09 +01:00
import info.nightscout.interfaces.iob.IobCobCalculator
2022-11-10 14:01:14 +01:00
import info.nightscout.interfaces.maintenance.ImportExportPrefs
2022-11-11 23:17:09 +01:00
import info.nightscout.interfaces.plugin.ActivePlugin
2022-11-10 14:01:14 +01:00
import info.nightscout.interfaces.plugin.PluginBase
2022-11-11 18:54:30 +01:00
import info.nightscout.interfaces.profile.ProfileFunction
2022-11-10 14:01:14 +01:00
import info.nightscout.interfaces.smsCommunicator.SmsCommunicator
2022-11-08 17:34:47 +01:00
import info.nightscout.interfaces.storage.FileStorage
import info.nightscout.interfaces.storage.Storage
2022-11-11 18:54:30 +01:00
import info.nightscout.interfaces.sync.DataSyncSelector
2022-11-10 14:01:14 +01:00
import info.nightscout.interfaces.ui.ActivityNames
2022-11-10 19:27:04 +01:00
import info.nightscout.interfaces.utils.HardLimits
2022-11-21 11:48:26 +01:00
import info.nightscout.plugins.aps.loop.LoopPlugin
2022-11-21 12:52:36 +01:00
import info.nightscout.plugins.general.autotune.AutotunePlugin
2022-11-02 11:22:34 +01:00
import info.nightscout.plugins.general.smsCommunicator.SmsCommunicatorPlugin
2022-11-08 17:34:47 +01:00
import info.nightscout.plugins.sync.nsclient.DataSyncSelectorImplementation
import info.nightscout.plugins.sync.nsclient.data.ProcessedDeviceStatusData
2022-11-06 12:28:35 +01:00
import info.nightscout.rx.AapsSchedulers
import info.nightscout.rx.bus.RxBus
import info.nightscout.rx.logging.AAPSLogger
2022-11-08 17:34:47 +01:00
import info.nightscout.shared.interfaces.ResourceHelper
2021-12-10 12:17:03 +01:00
import info.nightscout.shared.sharedPreferences.SP
2022-11-08 17:34:47 +01:00
import info.nightscout.shared.utils.DateUtil
2019-12-13 02:12:19 +01:00
import javax.inject.Singleton
2021-05-03 09:33:14 +02:00
@Suppress("unused")
2022-11-04 14:34:05 +01:00
@Module(
includes = [
AppModule.AppBindings::class
]
)
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
2022-11-04 14:34:05 +01:00
fun providesPlugins(
2022-11-21 13:51:47 +01:00
config: Config,
2022-11-04 16:55:32 +01:00
@PluginsListModule.AllConfigs allConfigs: Map<@JvmSuppressWildcards Int, @JvmSuppressWildcards PluginBase>,
@PluginsListModule.PumpDriver pumpDrivers: Lazy<Map<@JvmSuppressWildcards Int, @JvmSuppressWildcards PluginBase>>,
@PluginsListModule.NotNSClient notNsClient: Lazy<Map<@JvmSuppressWildcards Int, @JvmSuppressWildcards PluginBase>>,
@PluginsListModule.APS aps: Lazy<Map<@JvmSuppressWildcards Int, @JvmSuppressWildcards PluginBase>>,
@PluginsListModule.Unfinished unfinished: Lazy<Map<@JvmSuppressWildcards Int, @JvmSuppressWildcards PluginBase>>
2022-11-04 14:34:05 +01:00
)
2020-04-24 22:39:56 +02:00
: List<@JvmSuppressWildcards PluginBase> {
2020-03-25 23:51:04 +01:00
val plugins = allConfigs.toMutableMap()
2021-04-14 18:42:12 +02:00
if (config.PUMPDRIVERS) plugins += pumpDrivers.get()
if (config.APS) plugins += aps.get()
if (!config.NSCLIENT) plugins += notNsClient.get()
2022-11-21 13:51:47 +01:00
if (config.isUnfinishedMode()) plugins += unfinished.get()
2020-03-25 23:51:04 +01:00
return plugins.toList().sortedBy { it.first }.map { it.second }
}
@Provides
@Singleton
2021-05-29 23:38:19 +02:00
fun provideStorage(): Storage = FileStorage()
2021-05-03 10:56:26 +02:00
@Provides
@Singleton
2021-10-03 19:01:03 +02:00
fun provideProfileFunction(
2021-11-04 10:56:12 +01:00
aapsLogger: AAPSLogger, sp: SP, rxBus: RxBus, rh:
2021-10-03 19:01:03 +02:00
ResourceHelper, activePlugin:
2021-10-10 23:26:50 +02:00
ActivePlugin, repository: AppRepository, dateUtil: DateUtil, config: Config, hardLimits: HardLimits,
aapsSchedulers: AapsSchedulers, fabricPrivacy: FabricPrivacy, processedDeviceStatusData: ProcessedDeviceStatusData
2021-10-03 19:01:03 +02:00
): ProfileFunction =
ProfileFunctionImpl(
2021-11-04 10:56:12 +01:00
aapsLogger, sp, rxBus, rh, activePlugin, repository, dateUtil,
config, hardLimits, aapsSchedulers, fabricPrivacy, processedDeviceStatusData
2021-10-03 19:01:03 +02:00
)
2021-05-03 10:56:26 +02:00
@Provides
@Singleton
internal fun provideConstraints(activePlugin: ActivePlugin): Constraints = ConstraintsImpl(activePlugin)
2022-11-04 14:34:05 +01:00
2019-12-21 20:17:08 +01:00
@Module
interface AppBindings {
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
2021-04-14 18:42:12 +02:00
@Binds fun bindConfigInterface(config: ConfigImpl): Config
2021-05-29 23:38:19 +02:00
@Binds fun bindConfigBuilderInterface(configBuilderPlugin: ConfigBuilderPlugin): ConfigBuilder
2021-04-14 19:15:10 +02:00
@Binds fun bindImportExportPrefsInterface(importExportPrefs: ImportExportPrefsImpl): ImportExportPrefs
2021-05-28 16:06:44 +02:00
@Binds fun bindLoopInterface(loopPlugin: LoopPlugin): Loop
2022-11-21 12:52:36 +01:00
@Binds fun bindAutotuneInterface(autotunePlugin: AutotunePlugin): Autotune
@Binds fun bindIobCobCalculatorInterface(iobCobCalculatorPlugin: IobCobCalculatorPlugin): IobCobCalculator
2021-04-14 22:37:34 +02:00
@Binds fun bindSmsCommunicatorInterface(smsCommunicatorPlugin: SmsCommunicatorPlugin): SmsCommunicator
@Binds fun bindDataSyncSelectorInterface(dataSyncSelectorImplementation: DataSyncSelectorImplementation): DataSyncSelector
2022-11-02 11:22:34 +01:00
@Binds fun bindActivityNamesInterface(activityNames: ActivityNamesImpl): ActivityNames
2022-11-23 22:27:51 +01:00
@Binds fun bindCalculationWorkflowInterface(calculationWorkflow: CalculationWorkflowImpl): CalculationWorkflow
2019-12-13 02:12:19 +01:00
}
}
2021-03-19 21:32:12 +01:00