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-21 22:43:34 +01:00
|
|
|
import info.nightscout.androidaps.implementations.ConfigImpl
|
2022-11-23 22:27:51 +01:00
|
|
|
import info.nightscout.androidaps.workflow.CalculationWorkflowImpl
|
2022-11-28 09:25:19 +01:00
|
|
|
import info.nightscout.androidaps.workflow.WorkerClassesImpl
|
2022-11-23 22:27:51 +01:00
|
|
|
import info.nightscout.core.workflow.CalculationWorkflow
|
2022-11-08 17:34:47 +01:00
|
|
|
import info.nightscout.interfaces.Config
|
2022-11-10 14:01:14 +01:00
|
|
|
import info.nightscout.interfaces.plugin.PluginBase
|
|
|
|
import info.nightscout.interfaces.ui.ActivityNames
|
2022-11-28 09:25:19 +01:00
|
|
|
import info.nightscout.interfaces.workflow.WorkerClasses
|
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(
|
2022-11-21 13:51:47 +01:00
|
|
|
config: Config,
|
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-11-21 13:51:47 +01:00
|
|
|
if (config.isUnfinishedMode()) plugins += unfinished.get()
|
2020-03-25 23:51:04 +01:00
|
|
|
return plugins.toList().sortedBy { it.first }.map { it.second }
|
|
|
|
}
|
|
|
|
|
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 18:42:12 +02:00
|
|
|
@Binds fun bindConfigInterface(config: ConfigImpl): Config
|
2021-05-26 14:14:17 +02:00
|
|
|
|
2022-11-28 09:25:19 +01:00
|
|
|
@Binds fun bindActivityNames(activityNames: ActivityNamesImpl): ActivityNames
|
|
|
|
@Binds fun bindWorkerClasses(workerClassesImpl: WorkerClassesImpl): WorkerClasses
|
|
|
|
@Binds fun bindCalculationWorkflow(calculationWorkflow: CalculationWorkflowImpl): CalculationWorkflow
|
2019-12-13 02:12:19 +01:00
|
|
|
}
|
|
|
|
}
|
2021-03-19 21:32:12 +01:00
|
|
|
|