97 lines
5 KiB
Kotlin
97 lines
5 KiB
Kotlin
package info.nightscout.androidaps.dependencyInjection
|
|
|
|
import android.content.Context
|
|
import dagger.Binds
|
|
import dagger.Lazy
|
|
import dagger.Module
|
|
import dagger.Provides
|
|
import dagger.android.HasAndroidInjector
|
|
import info.nightscout.androidaps.interfaces.Config
|
|
import info.nightscout.androidaps.MainApp
|
|
import info.nightscout.androidaps.db.DatabaseHelperProvider
|
|
import info.nightscout.androidaps.interfaces.*
|
|
import info.nightscout.androidaps.logging.AAPSLogger
|
|
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin
|
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
|
import info.nightscout.androidaps.plugins.configBuilder.PluginStore
|
|
import info.nightscout.androidaps.plugins.general.maintenance.ImportExportPrefsImpl
|
|
import info.nightscout.androidaps.plugins.general.nsclient.DataSyncSelectorImplementation
|
|
import info.nightscout.androidaps.plugins.general.nsclient.UploadQueue
|
|
import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin
|
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin
|
|
import info.nightscout.androidaps.plugins.pump.PumpSyncImplementation
|
|
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
|
import info.nightscout.androidaps.queue.CommandQueue
|
|
import info.nightscout.androidaps.utils.androidNotification.NotificationHolder
|
|
import info.nightscout.androidaps.utils.buildHelper.ConfigImpl
|
|
import info.nightscout.androidaps.utils.resources.IconsProviderImplementation
|
|
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
|
import info.nightscout.androidaps.utils.rx.DefaultAapsSchedulers
|
|
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
|
import info.nightscout.androidaps.utils.storage.FileStorage
|
|
import info.nightscout.androidaps.utils.storage.Storage
|
|
import javax.inject.Singleton
|
|
@Suppress("unused")
|
|
@Module(includes = [
|
|
AppModule.AppBindings::class
|
|
])
|
|
open class AppModule {
|
|
|
|
@Provides
|
|
fun providesPlugins(config: Config,
|
|
@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()
|
|
}
|
|
|
|
@Provides
|
|
@Singleton
|
|
internal fun provideSchedulers(): AapsSchedulers = DefaultAapsSchedulers()
|
|
|
|
@Provides
|
|
@Singleton
|
|
fun providesUploadQueue(
|
|
aapsLogger: AAPSLogger,
|
|
databaseHelper: DatabaseHelperInterface,
|
|
context: Context,
|
|
sp: SP,
|
|
rxBus: RxBusWrapper
|
|
): UploadQueueAdminInterface = UploadQueue(aapsLogger, databaseHelper, context, sp, rxBus)
|
|
|
|
@Module
|
|
interface AppBindings {
|
|
@Binds fun bindContext(mainApp: MainApp): Context
|
|
@Binds fun bindInjector(mainApp: MainApp): HasAndroidInjector
|
|
@Binds fun bindActivePluginProvider(pluginStore: PluginStore): ActivePlugin
|
|
@Binds fun bindCommandQueueProvider(commandQueue: CommandQueue): CommandQueueProvider
|
|
@Binds fun bindConfigInterface(config: ConfigImpl): Config
|
|
@Binds fun bindConfigBuilderInterface(configBuilderPlugin: ConfigBuilderPlugin): ConfigBuilder
|
|
@Binds fun bindTreatmentsInterface(treatmentsPlugin: TreatmentsPlugin): TreatmentsInterface
|
|
@Binds fun bindDatabaseHelperInterface(databaseHelperProvider: DatabaseHelperProvider): DatabaseHelperInterface
|
|
@Binds fun bindNotificationHolderInterface(notificationHolder: NotificationHolder): NotificationHolderInterface
|
|
@Binds fun bindImportExportPrefsInterface(importExportPrefs: ImportExportPrefsImpl): ImportExportPrefs
|
|
@Binds fun bindIconsProviderInterface(iconsProvider: IconsProviderImplementation): IconsProvider
|
|
@Binds fun bindLoopInterface(loopPlugin: LoopPlugin): LoopInterface
|
|
@Binds fun bindIobCobCalculatorInterface(iobCobCalculatorPlugin: IobCobCalculatorPlugin): IobCobCalculator
|
|
@Binds fun bindSmsCommunicatorInterface(smsCommunicatorPlugin: SmsCommunicatorPlugin): SmsCommunicator
|
|
@Binds fun bindUploadQueueAdminInterfaceToUploadQueue(uploadQueueAdminInterface: UploadQueueAdminInterface) : UploadQueueInterface
|
|
@Binds fun bindDataSyncSelector(dataSyncSelectorImplementation: DataSyncSelectorImplementation): DataSyncSelector
|
|
@Binds fun bindPumpSync(pumpSyncImplementation: PumpSyncImplementation): PumpSync
|
|
|
|
}
|
|
}
|
|
|