2019-12-13 02:12:19 +01:00
|
|
|
package info.nightscout.androidaps.dependencyInjection
|
|
|
|
|
|
|
|
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-09 10:52:20 +02:00
|
|
|
import info.nightscout.androidaps.db.DatabaseHelperProvider
|
2020-05-07 09:54:36 +02:00
|
|
|
import info.nightscout.androidaps.interfaces.*
|
2021-03-19 21:32:12 +01:00
|
|
|
import info.nightscout.androidaps.logging.AAPSLogger
|
2021-02-22 17:22:30 +01:00
|
|
|
import info.nightscout.androidaps.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
|
2021-05-03 10:56:26 +02:00
|
|
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctionImplementation
|
2021-04-14 19:15:10 +02:00
|
|
|
import info.nightscout.androidaps.plugins.general.maintenance.ImportExportPrefsImpl
|
2021-03-26 16:23:47 +01:00
|
|
|
import info.nightscout.androidaps.plugins.general.nsclient.DataSyncSelectorImplementation
|
2021-02-22 17:22:30 +01:00
|
|
|
import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin
|
|
|
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin
|
2021-03-29 00:31:40 +02:00
|
|
|
import info.nightscout.androidaps.plugins.pump.PumpSyncImplementation
|
2020-05-07 09:54:36 +02:00
|
|
|
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
2020-01-10 23:14:58 +01:00
|
|
|
import info.nightscout.androidaps.queue.CommandQueue
|
2021-05-03 10:56:26 +02:00
|
|
|
import info.nightscout.androidaps.utils.DateUtil
|
2021-04-14 22:44:24 +02:00
|
|
|
import info.nightscout.androidaps.utils.androidNotification.NotificationHolderImpl
|
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
|
2021-05-03 10:56:26 +02:00
|
|
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
2021-02-04 20:54:09 +01:00
|
|
|
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
|
|
|
import info.nightscout.androidaps.utils.rx.DefaultAapsSchedulers
|
2021-03-19 21:32:12 +01:00
|
|
|
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
2020-02-11 19:34:56 +01:00
|
|
|
import info.nightscout.androidaps.utils.storage.FileStorage
|
|
|
|
import info.nightscout.androidaps.utils.storage.Storage
|
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")
|
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
|
2021-04-14 18:42:12 +02:00
|
|
|
fun providesPlugins(config: Config,
|
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>>,
|
2020-04-24 22:39:56 +02:00
|
|
|
@PluginsModule.APS aps: Lazy<Map<@JvmSuppressWildcards Int, @JvmSuppressWildcards PluginBase>>)
|
|
|
|
: 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()
|
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
|
|
|
|
fun provideStorage(): Storage {
|
|
|
|
return FileStorage()
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
fun provideProfileFunction(aapsLogger: AAPSLogger, sp: SP, resourceHelper: ResourceHelper, activePlugin: ActivePlugin, repository: AppRepository, dateUtil: DateUtil): ProfileFunction {
|
|
|
|
return ProfileFunctionImplementation(aapsLogger, sp, resourceHelper, activePlugin, repository, dateUtil)
|
|
|
|
}
|
|
|
|
|
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-04-14 00:45:30 +02:00
|
|
|
@Binds fun bindActivePluginProvider(pluginStore: PluginStore): ActivePlugin
|
2020-05-10 23:45:49 +02:00
|
|
|
@Binds fun bindCommandQueueProvider(commandQueue: CommandQueue): CommandQueueProvider
|
2021-04-14 18:42:12 +02:00
|
|
|
@Binds fun bindConfigInterface(config: ConfigImpl): Config
|
2021-05-26 14:14:17 +02:00
|
|
|
|
2021-05-24 17:57:54 +02:00
|
|
|
@Binds
|
|
|
|
fun bindConfigBuilderInterface(configBuilderPlugin: ConfigBuilderPlugin): ConfigBuilder
|
2021-04-10 12:19:31 +02:00
|
|
|
@Binds fun bindTreatmentsInterface(treatmentsPlugin: TreatmentsPlugin): TreatmentsInterface
|
2021-05-26 14:14:17 +02:00
|
|
|
|
2020-05-10 23:45:49 +02:00
|
|
|
@Binds fun bindDatabaseHelperInterface(databaseHelperProvider: DatabaseHelperProvider): DatabaseHelperInterface
|
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
|
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
|
2021-03-26 16:23:47 +01:00
|
|
|
@Binds fun bindDataSyncSelector(dataSyncSelectorImplementation: DataSyncSelectorImplementation): DataSyncSelector
|
2021-05-26 14:14:17 +02:00
|
|
|
|
2021-03-29 00:31:40 +02:00
|
|
|
@Binds fun bindPumpSync(pumpSyncImplementation: PumpSyncImplementation): PumpSync
|
2021-03-26 16:23:47 +01:00
|
|
|
|
2019-12-13 02:12:19 +01:00
|
|
|
}
|
|
|
|
}
|
2021-03-19 21:32:12 +01:00
|
|
|
|