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

144 lines
7.2 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-04-24 22:39:56 +02:00
import info.nightscout.androidaps.db.CareportalEvent
2020-03-19 18:02:24 +01:00
import info.nightscout.androidaps.db.ProfileSwitch
2020-04-24 22:39:56 +02:00
import info.nightscout.androidaps.db.TemporaryBasal
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-04-24 22:39:56 +02:00
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
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-04-26 23:52:29 +02:00
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkCommunicationManager
2020-04-27 20:22:00 +02:00
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RFSpy
2020-04-27 18:14:06 +02:00
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RileyLinkBLE
2020-04-27 20:22:00 +02:00
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.command.SendAndListen
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.command.SetPreamble
2020-04-27 22:19:50 +02:00
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.RadioPacket
2020-04-27 18:14:06 +02:00
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.RadioResponse
2020-04-26 22:47:13 +02:00
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.*
2020-04-26 23:52:29 +02:00
import info.nightscout.androidaps.plugins.pump.medtronic.comm.MedtronicCommunicationManager
import info.nightscout.androidaps.plugins.pump.medtronic.comm.ui.MedtronicUITask
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>>,
2020-04-24 22:39:56 +02:00
@PluginsModule.NSClient nsClient: Lazy<Map<@JvmSuppressWildcards Int, @JvmSuppressWildcards PluginBase>>,
@PluginsModule.APS aps: Lazy<Map<@JvmSuppressWildcards Int, @JvmSuppressWildcards PluginBase>>)
: List<@JvmSuppressWildcards PluginBase> {
2020-03-25 23:51:04 +01:00
val plugins = allConfigs.toMutableMap()
if (Config.PUMPDRIVERS) plugins += pumpDrivers.get()
if (Config.APS) plugins += aps.get()
if (!Config.NSCLIENT) plugins += notNsClient.get()
2020-04-24 22:39:56 +02:00
if (Config.NSCLIENT) plugins += nsClient.get()
2020-03-25 23:51:04 +01:00
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
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
}
}