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

278 lines
16 KiB
Kotlin
Raw Normal View History

2019-12-13 02:12:19 +01:00
package info.nightscout.androidaps.dependencyInjection
import android.content.Context
import androidx.preference.PreferenceManager
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
import dagger.android.ContributesAndroidInjector
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-03-10 18:58:27 +01:00
import info.nightscout.androidaps.data.Profile
2020-02-05 17:40:13 +01:00
import info.nightscout.androidaps.data.ProfileStore
2020-03-06 23:43:29 +01:00
import info.nightscout.androidaps.data.PumpEnactResult
2020-01-01 23:23:16 +01:00
import info.nightscout.androidaps.db.BgReading
2020-03-19 18:02:24 +01:00
import info.nightscout.androidaps.db.ProfileSwitch
import info.nightscout.androidaps.interfaces.ActivePluginProvider
import info.nightscout.androidaps.interfaces.CommandQueueProvider
2020-03-25 23:51:04 +01:00
import info.nightscout.androidaps.interfaces.PluginBase
2019-12-28 01:52:20 +01:00
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.AAPSLoggerProduction
2020-03-08 22:42:36 +01:00
import info.nightscout.androidaps.plugins.aps.loop.APSResult
import info.nightscout.androidaps.plugins.aps.openAPSAMA.DetermineBasalResultAMA
2020-04-06 12:00:17 +02:00
import info.nightscout.androidaps.plugins.aps.logger.LoggerCallback
2020-03-08 22:42:36 +01:00
import info.nightscout.androidaps.plugins.aps.openAPSSMB.DetermineBasalAdapterSMBJS
import info.nightscout.androidaps.plugins.aps.openAPSSMB.DetermineBasalResultSMB
2020-03-16 21:40:29 +01:00
import info.nightscout.androidaps.plugins.configBuilder.PluginStore
2019-12-26 23:26:00 +01:00
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctionImplementation
2019-12-30 00:53:44 +01:00
import info.nightscout.androidaps.plugins.constraints.objectives.objectives.*
2020-01-05 12:02:32 +01:00
import info.nightscout.androidaps.plugins.general.automation.AutomationEvent
2020-01-02 19:20:36 +01:00
import info.nightscout.androidaps.plugins.general.automation.actions.*
2020-01-05 12:02:32 +01:00
import info.nightscout.androidaps.plugins.general.automation.elements.*
import info.nightscout.androidaps.plugins.general.automation.triggers.*
2020-03-21 15:09:14 +01:00
import info.nightscout.androidaps.plugins.general.overview.graphData.GraphData
import info.nightscout.androidaps.plugins.general.maintenance.ImportExportPrefs
import info.nightscout.androidaps.plugins.general.maintenance.formats.ClassicPrefsFormat
import info.nightscout.androidaps.plugins.general.maintenance.formats.EncryptedPrefsFormat
2020-01-01 23:23:16 +01:00
import info.nightscout.androidaps.plugins.general.overview.notifications.NotificationWithAction
2020-03-09 23:49:00 +01:00
import info.nightscout.androidaps.plugins.general.smsCommunicator.AuthRequest
2020-01-10 23:14:58 +01:00
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensData
2020-03-10 18:58:27 +01:00
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus
2020-01-10 23:14:58 +01:00
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobOref1Thread
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobThread
2020-01-01 23:23:16 +01:00
import info.nightscout.androidaps.plugins.treatments.Treatment
2020-01-10 23:14:58 +01:00
import info.nightscout.androidaps.queue.CommandQueue
import info.nightscout.androidaps.queue.commands.*
2020-03-21 13:11:17 +01:00
import info.nightscout.androidaps.setupwizard.SWEventListener
import info.nightscout.androidaps.setupwizard.SWScreen
import info.nightscout.androidaps.setupwizard.elements.*
import info.nightscout.androidaps.utils.CryptoUtil
2020-03-21 15:09:14 +01:00
import info.nightscout.androidaps.utils.FabricPrivacy
2019-12-26 17:50:16 +01:00
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.resources.ResourceHelperImplementation
2019-12-13 02:12:19 +01:00
import info.nightscout.androidaps.utils.sharedPreferences.SP
2019-12-26 15:12:12 +01:00
import info.nightscout.androidaps.utils.sharedPreferences.SPImplementation
import info.nightscout.androidaps.utils.storage.FileStorage
import info.nightscout.androidaps.utils.storage.Storage
2019-12-31 11:57:58 +01:00
import info.nightscout.androidaps.utils.wizard.BolusWizard
import info.nightscout.androidaps.utils.wizard.QuickWizardEntry
2019-12-13 02:12:19 +01:00
import javax.inject.Singleton
2020-03-25 23:51:04 +01:00
@Module(includes = [AppModule.AppBindings::class, PluginsModule::class])
2019-12-30 23:26:48 +01:00
open class AppModule {
2019-12-13 02:12:19 +01:00
@Provides
@Singleton
2019-12-30 08:50:27 +01:00
fun provideSharedPreferences(context: Context, resourceHelper: ResourceHelper): SP {
return SPImplementation(PreferenceManager.getDefaultSharedPreferences(context), resourceHelper)
2019-12-13 02:12:19 +01:00
}
2019-12-26 23:26:00 +01:00
@Provides
@Singleton
2020-03-21 15:09:14 +01:00
fun provideProfileFunction(injector: HasAndroidInjector, aapsLogger: AAPSLogger, sp: SP, resourceHelper: ResourceHelper, activePlugin: ActivePluginProvider, fabricPrivacy: FabricPrivacy): ProfileFunction {
return ProfileFunctionImplementation(injector, aapsLogger, sp, resourceHelper, activePlugin, fabricPrivacy)
2019-12-27 19:20:38 +01:00
}
2019-12-26 17:50:16 +01:00
@Provides
@Singleton
fun provideResources(mainApp: MainApp): ResourceHelper {
return ResourceHelperImplementation(mainApp)
}
2019-12-28 01:52:20 +01:00
@Provides
@Singleton
fun provideAAPSLogger(): AAPSLogger {
2020-01-12 23:43:44 +01:00
return AAPSLoggerProduction()
/* if (BuildConfig.DEBUG) {
2019-12-28 01:52:20 +01:00
AAPSLoggerDebug()
} else {
AAPSLoggerProduction()
}
2020-01-12 23:43:44 +01:00
*/
2019-12-28 01:52:20 +01:00
}
2020-03-25 23:51:04 +01:00
@Provides
fun providesPlugins(@PluginsModule.AllConfigs allConfigs: Map<@JvmSuppressWildcards Int, @JvmSuppressWildcards PluginBase>,
@PluginsModule.PumpDriver pumpDrivers: Lazy<Map<@JvmSuppressWildcards Int, @JvmSuppressWildcards PluginBase>>,
@PluginsModule.NotNSClient notNsClient: Lazy<Map<@JvmSuppressWildcards Int, @JvmSuppressWildcards PluginBase>>,
@PluginsModule.APS aps: Lazy<Map<@JvmSuppressWildcards Int, @JvmSuppressWildcards PluginBase>>): List<@JvmSuppressWildcards PluginBase> {
val plugins = allConfigs.toMutableMap()
if (Config.PUMPDRIVERS) plugins += pumpDrivers.get()
if (Config.APS) plugins += aps.get()
if (!Config.NSCLIENT) plugins += notNsClient.get()
return plugins.toList().sortedBy { it.first }.map { it.second }
}
@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
2020-02-05 17:40:13 +01:00
@ContributesAndroidInjector fun profileStoreInjector(): ProfileStore
2020-03-06 23:43:29 +01:00
@ContributesAndroidInjector fun pumpEnactResultInjector(): PumpEnactResult
2020-03-08 22:42:36 +01:00
@ContributesAndroidInjector fun apsResultInjector(): APSResult
@ContributesAndroidInjector fun determineBasalResultSMBInjector(): DetermineBasalResultSMB
@ContributesAndroidInjector fun determineBasalResultAMAInjector(): DetermineBasalResultAMA
2020-03-17 22:56:14 +01:00
2020-03-10 18:58:27 +01:00
@ContributesAndroidInjector
fun determineBasalAdapterSMBJSInjector(): DetermineBasalAdapterSMBJS
2020-03-08 22:42:36 +01:00
2020-01-10 23:14:58 +01:00
@ContributesAndroidInjector fun commandQueueInjector(): CommandQueue
@ContributesAndroidInjector fun commandBolusInjector(): CommandBolus
2020-03-08 22:42:36 +01:00
2020-01-10 23:14:58 +01:00
@ContributesAndroidInjector
fun commandCancelExtendedBolusInjector(): CommandCancelExtendedBolus
@ContributesAndroidInjector fun commandCancelTempBasalInjector(): CommandCancelTempBasal
@ContributesAndroidInjector fun commandExtendedBolusInjector(): CommandExtendedBolus
2020-03-08 22:42:36 +01:00
2020-01-10 23:14:58 +01:00
@ContributesAndroidInjector
fun commandInsightSetTBROverNotificationInjector(): CommandInsightSetTBROverNotification
@ContributesAndroidInjector fun commandLoadEventsInjector(): CommandLoadEvents
@ContributesAndroidInjector fun commandLoadHistoryInjector(): CommandLoadHistory
2020-01-12 23:43:44 +01:00
@ContributesAndroidInjector fun commandLoadTDDsInjector(): CommandLoadTDDs
2020-01-10 23:14:58 +01:00
@ContributesAndroidInjector fun commandReadStatusInjector(): CommandReadStatus
2019-12-30 00:53:44 +01:00
@ContributesAndroidInjector fun commandSetProfileInjector(): CommandSetProfile
2020-01-10 23:14:58 +01:00
@ContributesAndroidInjector fun commandCommandSMBBolusInjector(): CommandSMBBolus
@ContributesAndroidInjector fun commandStartPumpInjector(): CommandStartPump
@ContributesAndroidInjector fun commandStopPumpInjector(): CommandStopPump
@ContributesAndroidInjector fun commandTempBasalAbsoluteInjector(): CommandTempBasalAbsolute
@ContributesAndroidInjector fun commandTempBasalPercentInjector(): CommandTempBasalPercent
2020-01-12 23:43:44 +01:00
@ContributesAndroidInjector fun commandSetUserSettingsInjector(): CommandSetUserSettings
2020-01-10 02:27:14 +01:00
2020-03-14 16:47:48 +01:00
@ContributesAndroidInjector fun objectiveInjector(): Objective
2019-12-30 00:53:44 +01:00
@ContributesAndroidInjector fun objective0Injector(): Objective0
@ContributesAndroidInjector fun objective1Injector(): Objective1
@ContributesAndroidInjector fun objective2Injector(): Objective2
@ContributesAndroidInjector fun objective3Injector(): Objective3
2020-03-14 16:47:48 +01:00
@ContributesAndroidInjector fun objective4Injector(): Objective4
2019-12-30 00:53:44 +01:00
@ContributesAndroidInjector fun objective5Injector(): Objective5
@ContributesAndroidInjector fun objective6Injector(): Objective6
2020-03-14 16:47:48 +01:00
@ContributesAndroidInjector fun objective7Injector(): Objective7
@ContributesAndroidInjector fun objective8Injector(): Objective8
@ContributesAndroidInjector fun objective9Injector(): Objective9
2020-01-01 23:23:16 +01:00
2020-01-05 12:02:32 +01:00
@ContributesAndroidInjector fun automationEventInjector(): AutomationEvent
@ContributesAndroidInjector fun triggerInjector(): Trigger
@ContributesAndroidInjector fun triggerAutosensValueInjector(): TriggerAutosensValue
@ContributesAndroidInjector fun triggerBgInjector(): TriggerBg
@ContributesAndroidInjector fun triggerBolusAgoInjector(): TriggerBolusAgo
@ContributesAndroidInjector fun triggerCOBInjector(): TriggerCOB
@ContributesAndroidInjector fun triggerConnectorInjector(): TriggerConnector
@ContributesAndroidInjector fun triggerDeltaInjector(): TriggerDelta
@ContributesAndroidInjector fun triggerDummyInjector(): TriggerDummy
@ContributesAndroidInjector fun triggerIobInjector(): TriggerIob
@ContributesAndroidInjector fun triggerLocationInjector(): TriggerLocation
@ContributesAndroidInjector fun triggerProfilePercentInjector(): TriggerProfilePercent
2020-03-08 22:42:36 +01:00
2020-01-10 02:27:14 +01:00
@ContributesAndroidInjector
fun triggerPumpLastConnectionInjector(): TriggerPumpLastConnection
2020-04-02 18:48:37 +02:00
@ContributesAndroidInjector fun triggerBTDeviceInjector(): TriggerBTDevice
2020-01-05 12:02:32 +01:00
@ContributesAndroidInjector fun triggerRecurringTimeInjector(): TriggerRecurringTime
@ContributesAndroidInjector fun triggerTempTargetInjector(): TriggerTempTarget
@ContributesAndroidInjector fun triggerTime(): TriggerTime
@ContributesAndroidInjector fun triggerTimeRangeInjector(): TriggerTimeRange
@ContributesAndroidInjector fun triggerWifiSsidInjector(): TriggerWifiSsid
2020-01-02 19:20:36 +01:00
@ContributesAndroidInjector fun actionInjector(): Action
@ContributesAndroidInjector fun actionLoopDisableInjector(): ActionLoopDisable
@ContributesAndroidInjector fun actionLoopEnableInjector(): ActionLoopEnable
2020-01-05 12:02:32 +01:00
@ContributesAndroidInjector fun actionLoopResumeInjector(): ActionLoopResume
2020-01-02 19:20:36 +01:00
@ContributesAndroidInjector fun actionLoopSuspendInjector(): ActionLoopSuspend
@ContributesAndroidInjector fun actionNotificationInjector(): ActionNotification
@ContributesAndroidInjector fun actionProfileSwitchInjector(): ActionProfileSwitch
2020-03-08 22:42:36 +01:00
2020-01-10 23:14:58 +01:00
@ContributesAndroidInjector
fun actionProfileSwitchPercentInjector(): ActionProfileSwitchPercent
2020-01-02 19:20:36 +01:00
@ContributesAndroidInjector fun actionSendSMSInjector(): ActionSendSMS
@ContributesAndroidInjector fun actionStartTempTargetInjector(): ActionStartTempTarget
@ContributesAndroidInjector fun actionStopTempTargetInjector(): ActionStopTempTarget
@ContributesAndroidInjector fun actionDummyInjector(): ActionDummy
2020-01-05 12:02:32 +01:00
@ContributesAndroidInjector fun elementInjector(): Element
@ContributesAndroidInjector fun inputBgInjector(): InputBg
@ContributesAndroidInjector fun inputButtonInjector(): InputButton
2020-01-05 17:19:03 +01:00
@ContributesAndroidInjector fun comparatorInjector(): Comparator
2020-04-02 18:48:37 +02:00
@ContributesAndroidInjector fun comparatorConnectInjector(): ComparatorConnect
2020-01-05 17:19:03 +01:00
@ContributesAndroidInjector fun comparatorExistsInjector(): ComparatorExists
2020-01-05 19:23:20 +01:00
@ContributesAndroidInjector fun inputDateTimeInjector(): InputDateTime
2020-01-05 12:02:32 +01:00
@ContributesAndroidInjector fun inputDeltaInjector(): InputDelta
@ContributesAndroidInjector fun inputDoubleInjector(): InputDouble
2020-04-02 18:48:37 +02:00
@ContributesAndroidInjector fun inputDropdownMenuInjector(): InputDropdownMenu
2020-01-05 12:02:32 +01:00
@ContributesAndroidInjector fun inputDurationInjector(): InputDuration
@ContributesAndroidInjector fun inputInsulinInjector(): InputInsulin
@ContributesAndroidInjector fun inputLocationModeInjector(): InputLocationMode
@ContributesAndroidInjector fun inputPercentInjector(): InputPercent
@ContributesAndroidInjector fun inputProfileNameInjector(): InputProfileName
@ContributesAndroidInjector fun inputStringInjector(): InputString
@ContributesAndroidInjector fun inputTempTargetInjector(): InputTempTarget
2020-01-05 17:19:03 +01:00
@ContributesAndroidInjector fun inputTimeRangeInjector(): InputTimeRange
2020-01-05 19:23:20 +01:00
@ContributesAndroidInjector fun inputTimeInjector(): InputTime
@ContributesAndroidInjector fun inputWeekDayInjector(): InputWeekDay
2020-01-05 12:02:32 +01:00
@ContributesAndroidInjector fun labelWithElementInjector(): LabelWithElement
@ContributesAndroidInjector fun staticLabelInjector(): StaticLabel
2020-01-10 23:14:58 +01:00
@ContributesAndroidInjector fun autosensDataInjector(): AutosensData
@ContributesAndroidInjector fun iobCobThreadInjector(): IobCobThread
@ContributesAndroidInjector fun iobCobOref1ThreadInjector(): IobCobOref1Thread
2020-01-01 23:23:16 +01:00
@ContributesAndroidInjector fun bgReadingInjector(): BgReading
@ContributesAndroidInjector fun treatmentInjector(): Treatment
2020-03-19 18:02:24 +01:00
@ContributesAndroidInjector fun profileSwitchInjector(): ProfileSwitch
2020-01-01 23:23:16 +01:00
@ContributesAndroidInjector fun notificationWithActionInjector(): NotificationWithAction
2019-12-30 00:53:44 +01:00
@ContributesAndroidInjector fun loggerCallbackInjector(): LoggerCallback
2019-12-31 11:57:58 +01:00
@ContributesAndroidInjector fun loggerBolusWizard(): BolusWizard
@ContributesAndroidInjector fun loggerQuickWizardEntry(): QuickWizardEntry
2019-12-28 01:14:04 +01:00
2020-03-09 23:49:00 +01:00
@ContributesAndroidInjector fun authRequestInjector(): AuthRequest
2020-03-21 13:11:17 +01:00
@ContributesAndroidInjector fun swBreakInjector(): SWBreak
@ContributesAndroidInjector fun swButtonInjector(): SWButton
@ContributesAndroidInjector fun swEditNumberWithUnitsInjector(): SWEditNumberWithUnits
@ContributesAndroidInjector fun swEditStringInjector(): SWEditString
@ContributesAndroidInjector fun swEditUrlInjector(): SWEditUrl
@ContributesAndroidInjector fun swFragmentInjector(): SWFragment
@ContributesAndroidInjector fun swHtmlLinkInjector(): SWHtmlLink
@ContributesAndroidInjector fun swInfotextInjector(): SWInfotext
@ContributesAndroidInjector fun swItemInjector(): SWItem
@ContributesAndroidInjector fun swPluginInjector(): SWPlugin
@ContributesAndroidInjector fun swRadioButtonInjector(): SWRadioButton
@ContributesAndroidInjector fun swScreenInjector(): SWScreen
@ContributesAndroidInjector fun swEventListenerInjector(): SWEventListener
2020-03-10 18:58:27 +01:00
@ContributesAndroidInjector fun profileInjector(): Profile
@ContributesAndroidInjector fun glucoseStatusInjector(): GlucoseStatus
2020-03-21 15:09:14 +01:00
@ContributesAndroidInjector fun graphDataInjector(): GraphData
@ContributesAndroidInjector fun cryptoUtilInjector(): CryptoUtil
@ContributesAndroidInjector fun importExportPrefsInjector(): ImportExportPrefs
@ContributesAndroidInjector fun encryptedPrefsFormatInjector(): EncryptedPrefsFormat
@ContributesAndroidInjector fun classicPrefsFormatInjector(): ClassicPrefsFormat
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-01-10 23:14:58 +01:00
@Binds
2020-03-16 21:40:29 +01:00
fun bindActivePluginProvider(pluginStore: PluginStore): ActivePluginProvider
2020-01-10 23:14:58 +01:00
@Binds fun commandQueueProvider(commandQueue: CommandQueue): CommandQueueProvider
2019-12-13 02:12:19 +01:00
}
}