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-04 14:34:05 +01:00
|
|
|
import info.nightscout.androidaps.interfaces.stats.DexcomTirCalculator
|
|
|
|
import info.nightscout.androidaps.interfaces.stats.TddCalculator
|
|
|
|
import info.nightscout.androidaps.interfaces.stats.TirCalculator
|
2022-11-18 19:51:39 +01:00
|
|
|
import info.nightscout.plugins.aps.loop.LoopPlugin
|
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
|
2022-11-03 13:33:22 +01:00
|
|
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctionImpl
|
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
|
2021-02-22 17:22:30 +01:00
|
|
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin
|
2021-04-14 22:44:24 +02:00
|
|
|
import info.nightscout.androidaps.utils.androidNotification.NotificationHolderImpl
|
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-11-09 15:56:59 +01:00
|
|
|
import info.nightscout.core.fabric.FabricPrivacy
|
2022-11-10 14:01:14 +01:00
|
|
|
import info.nightscout.database.impl.AppRepository
|
2022-11-01 11:39:40 +01:00
|
|
|
import info.nightscout.implementation.AndroidPermissionImpl
|
2022-10-31 20:20:41 +01:00
|
|
|
import info.nightscout.implementation.BolusTimerImpl
|
|
|
|
import info.nightscout.implementation.CarbTimerImpl
|
2022-11-01 11:39:40 +01:00
|
|
|
import info.nightscout.implementation.LocalAlertUtilsImpl
|
2022-11-03 23:07:58 +01:00
|
|
|
import info.nightscout.implementation.TrendCalculatorImpl
|
2022-11-01 11:39:40 +01:00
|
|
|
import info.nightscout.implementation.XDripBroadcastImpl
|
2022-11-03 13:33:22 +01:00
|
|
|
import info.nightscout.implementation.constraints.ConstraintsImpl
|
2022-11-08 17:34:47 +01:00
|
|
|
import info.nightscout.implementation.pump.PumpSyncImplementation
|
2022-11-01 11:39:40 +01:00
|
|
|
import info.nightscout.implementation.queue.CommandQueueImplementation
|
2022-11-04 14:34:05 +01:00
|
|
|
import info.nightscout.implementation.stats.DexcomTirCalculatorImpl
|
|
|
|
import info.nightscout.implementation.stats.TddCalculatorImpl
|
|
|
|
import info.nightscout.implementation.stats.TirCalculatorImpl
|
2022-11-08 17:34:47 +01:00
|
|
|
import info.nightscout.interfaces.AndroidPermission
|
|
|
|
import info.nightscout.interfaces.BolusTimer
|
|
|
|
import info.nightscout.interfaces.BuildHelper
|
|
|
|
import info.nightscout.interfaces.CarbTimer
|
|
|
|
import info.nightscout.interfaces.Config
|
2022-11-09 15:56:59 +01:00
|
|
|
import info.nightscout.interfaces.ConfigBuilder
|
2022-11-08 17:34:47 +01:00
|
|
|
import info.nightscout.interfaces.LocalAlertUtils
|
|
|
|
import info.nightscout.interfaces.NotificationHolder
|
2022-11-11 18:54:30 +01:00
|
|
|
import info.nightscout.interfaces.XDripBroadcast
|
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 19:27:04 +01:00
|
|
|
import info.nightscout.interfaces.pump.PumpSync
|
2022-11-11 18:54:30 +01:00
|
|
|
import info.nightscout.interfaces.queue.CommandQueue
|
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
|
|
|
|
import info.nightscout.interfaces.ui.IconsProvider
|
2022-11-10 19:27:04 +01:00
|
|
|
import info.nightscout.interfaces.utils.HardLimits
|
2022-11-11 18:54:30 +01:00
|
|
|
import info.nightscout.interfaces.utils.TrendCalculator
|
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
|
|
|
|
2021-03-29 00:31:40 +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(
|
|
|
|
config: Config, buildHelper: BuildHelper,
|
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-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 }
|
|
|
|
}
|
|
|
|
|
2020-02-11 19:34:56 +01:00
|
|
|
@Provides
|
|
|
|
@Singleton
|
2021-05-29 23:38:19 +02:00
|
|
|
fun provideStorage(): Storage = FileStorage()
|
2020-02-11 19:34:56 +01:00
|
|
|
|
2021-07-31 13:25:20 +02:00
|
|
|
@Provides
|
|
|
|
@Singleton
|
|
|
|
fun provideBuildHelper(config: Config, fileListProvider: PrefFileListProvider): BuildHelper = BuildHelperImpl(config, fileListProvider)
|
|
|
|
|
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,
|
2022-11-08 09:23:46 +01:00
|
|
|
aapsSchedulers: AapsSchedulers, fabricPrivacy: FabricPrivacy, processedDeviceStatusData: ProcessedDeviceStatusData
|
2021-10-03 19:01:03 +02:00
|
|
|
): ProfileFunction =
|
2022-11-03 13:33:22 +01:00
|
|
|
ProfileFunctionImpl(
|
2021-11-04 10:56:12 +01:00
|
|
|
aapsLogger, sp, rxBus, rh, activePlugin, repository, dateUtil,
|
2022-11-08 09:23:46 +01:00
|
|
|
config, hardLimits, aapsSchedulers, fabricPrivacy, processedDeviceStatusData
|
2021-10-03 19:01:03 +02:00
|
|
|
)
|
2021-05-03 10:56:26 +02:00
|
|
|
|
2022-11-03 13:33:22 +01: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 {
|
2021-05-24 17:57:54 +02: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
|
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-26 14:14:17 +02:00
|
|
|
|
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-11-14 23:14:37 +01:00
|
|
|
@Binds fun bindAutotuneInterface(autotunePlugin: info.nightscout.plugins.general.autotune.AutotunePlugin): Autotune
|
2021-03-29 19:15:46 +02:00
|
|
|
@Binds fun bindIobCobCalculatorInterface(iobCobCalculatorPlugin: IobCobCalculatorPlugin): IobCobCalculator
|
2021-04-14 22:37:34 +02:00
|
|
|
@Binds fun bindSmsCommunicatorInterface(smsCommunicatorPlugin: SmsCommunicatorPlugin): SmsCommunicator
|
2022-11-03 13:33:22 +01:00
|
|
|
@Binds fun bindDataSyncSelectorInterface(dataSyncSelectorImplementation: DataSyncSelectorImplementation): DataSyncSelector
|
2022-11-01 11:39:40 +01:00
|
|
|
@Binds fun bindPumpSyncInterface(pumpSyncImplementation: PumpSyncImplementation): PumpSync
|
|
|
|
@Binds fun bindXDripBroadcastInterface(xDripBroadcastImpl: XDripBroadcastImpl): XDripBroadcast
|
|
|
|
@Binds fun bindCarbTimerInterface(carbTimer: CarbTimerImpl): CarbTimer
|
|
|
|
@Binds fun bindBolusTimerInterface(bolusTimer: BolusTimerImpl): BolusTimer
|
|
|
|
@Binds fun bindAndroidPermissionInterface(androidPermission: AndroidPermissionImpl): AndroidPermission
|
|
|
|
@Binds fun bindLocalAlertUtilsInterface(localAlertUtils: LocalAlertUtilsImpl): LocalAlertUtils
|
2022-11-02 11:22:34 +01:00
|
|
|
@Binds fun bindActivityNamesInterface(activityNames: ActivityNamesImpl): ActivityNames
|
2022-11-03 23:07:58 +01:00
|
|
|
@Binds fun bindTrendCalculatorInterface(trendCalculator: TrendCalculatorImpl): TrendCalculator
|
2022-11-04 14:34:05 +01:00
|
|
|
@Binds fun bindTddCalculatorInterface(tddCalculator: TddCalculatorImpl): TddCalculator
|
|
|
|
@Binds fun bindTirCalculatorInterface(tirCalculator: TirCalculatorImpl): TirCalculator
|
|
|
|
@Binds fun bindDexcomTirCalculatorInterface(dexcomTirCalculator: DexcomTirCalculatorImpl): DexcomTirCalculator
|
2019-12-13 02:12:19 +01:00
|
|
|
}
|
|
|
|
}
|
2021-03-19 21:32:12 +01:00
|
|
|
|