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

119 lines
6.2 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
2021-05-03 10:56:26 +02:00
import info.nightscout.androidaps.database.AppRepository
2020-05-07 09:54:36 +02:00
import info.nightscout.androidaps.interfaces.*
2021-12-10 15:19:19 +01:00
import info.nightscout.shared.logging.AAPSLogger
2021-02-22 17:22:30 +01:00
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin
2021-10-15 14:56:22 +02:00
import info.nightscout.androidaps.plugins.bus.RxBus
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-05-03 10:56:26 +02:00
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctionImplementation
2022-05-05 22:37:20 +02:00
import info.nightscout.androidaps.plugins.general.autotune.AutotunePlugin
2021-04-14 19:15:10 +02:00
import info.nightscout.androidaps.plugins.general.maintenance.ImportExportPrefsImpl
2021-07-31 13:25:20 +02:00
import info.nightscout.androidaps.plugins.general.maintenance.PrefFileListProvider
import info.nightscout.androidaps.plugins.general.nsclient.DataSyncSelectorImplementation
import info.nightscout.androidaps.plugins.general.nsclient.data.DeviceStatusData
2021-02-22 17:22:30 +01:00
import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin
import info.nightscout.androidaps.plugins.pump.PumpSyncImplementation
2021-11-07 17:19:06 +01:00
import info.nightscout.androidaps.queue.CommandQueueImplementation
2021-05-03 10:56:26 +02:00
import info.nightscout.androidaps.utils.DateUtil
2021-10-10 23:26:50 +02:00
import info.nightscout.androidaps.utils.FabricPrivacy
2021-10-03 19:01:03 +02:00
import info.nightscout.androidaps.utils.HardLimits
2021-04-14 22:44:24 +02:00
import info.nightscout.androidaps.utils.androidNotification.NotificationHolderImpl
2022-06-09 15:51:57 +02:00
import info.nightscout.androidaps.interfaces.BuildHelper
2021-07-31 13:25:20 +02:00
import info.nightscout.androidaps.utils.buildHelper.BuildHelperImpl
2021-04-14 18:42:12 +02:00
import info.nightscout.androidaps.utils.buildHelper.ConfigImpl
2021-04-13 23:02:47 +02:00
import info.nightscout.androidaps.utils.resources.IconsProviderImplementation
2022-04-23 18:34:04 +02:00
import info.nightscout.androidaps.interfaces.ResourceHelper
2022-10-31 20:20:41 +01:00
import info.nightscout.implementation.XDripBroadcastImpl
2021-02-04 20:54:09 +01:00
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.androidaps.utils.rx.DefaultAapsSchedulers
import info.nightscout.androidaps.utils.storage.FileStorage
import info.nightscout.androidaps.utils.storage.Storage
2022-10-31 20:20:41 +01:00
import info.nightscout.implementation.BolusTimerImpl
import info.nightscout.implementation.CarbTimerImpl
2021-12-10 12:17:03 +01:00
import info.nightscout.shared.sharedPreferences.SP
2019-12-13 02:12:19 +01:00
import javax.inject.Singleton
2021-05-03 09:33:14 +02:00
@Suppress("unused")
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
2022-10-24 17:37:09 +02:00
fun providesPlugins(config: Config, buildHelper: BuildHelper,
2020-05-07 09:54:36 +02:00
@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>>,
2022-10-24 17:37:09 +02:00
@PluginsModule.APS aps: Lazy<Map<@JvmSuppressWildcards Int, @JvmSuppressWildcards PluginBase>>,
@PluginsModule.Unfinished unfinished: Lazy<Map<@JvmSuppressWildcards Int, @JvmSuppressWildcards PluginBase>>)
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-10-24 17:37:09 +02:00
if (buildHelper.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-07-31 13:25:20 +02:00
@Provides
@Singleton
fun provideBuildHelper(config: Config, fileListProvider: PrefFileListProvider): BuildHelper = BuildHelperImpl(config, fileListProvider)
2021-02-04 20:54:09 +01:00
@Provides
@Singleton
internal fun provideSchedulers(): AapsSchedulers = DefaultAapsSchedulers()
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, deviceStatusData: DeviceStatusData
2021-10-03 19:01:03 +02:00
): ProfileFunction =
ProfileFunctionImplementation(
2021-11-04 10:56:12 +01:00
aapsLogger, sp, rxBus, rh, activePlugin, repository, dateUtil,
config, hardLimits, aapsSchedulers, fabricPrivacy, deviceStatusData
2021-10-03 19:01:03 +02:00
)
2021-05-03 10:56:26 +02: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-11-07 17:19:06 +01:00
@Binds fun bindActivePlugin(pluginStore: PluginStore): ActivePlugin
@Binds fun bindCommandQueue(commandQueue: CommandQueueImplementation): CommandQueue
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 22:44:24 +02:00
@Binds fun bindNotificationHolderInterface(notificationHolder: NotificationHolderImpl): NotificationHolder
2021-04-14 19:15:10 +02:00
@Binds fun bindImportExportPrefsInterface(importExportPrefs: ImportExportPrefsImpl): ImportExportPrefs
2021-04-13 23:02:47 +02:00
@Binds fun bindIconsProviderInterface(iconsProvider: IconsProviderImplementation): IconsProvider
2021-05-28 16:06:44 +02:00
@Binds fun bindLoopInterface(loopPlugin: LoopPlugin): Loop
2022-05-05 22:37:20 +02: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 bindDataSyncSelector(dataSyncSelectorImplementation: DataSyncSelectorImplementation): DataSyncSelector
@Binds fun bindPumpSync(pumpSyncImplementation: PumpSyncImplementation): PumpSync
2022-10-31 20:20:41 +01:00
@Binds fun bindXDripBroadcast(xDripBroadcastImpl: XDripBroadcastImpl): XDripBroadcast
@Binds fun bindCarbTimer(carbTimer: CarbTimerImpl): CarbTimer
@Binds fun bindBolusTimer(bolusTimer: BolusTimerImpl): BolusTimer
2019-12-13 02:12:19 +01:00
}
}
2021-03-19 21:32:12 +01:00