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

83 lines
2.6 KiB
Kotlin
Raw Normal View History

2019-12-13 02:12:19 +01:00
package info.nightscout.androidaps.dependencyInjection
import android.content.Context
import android.preference.PreferenceManager
2019-12-21 20:17:08 +01:00
import dagger.Binds
2019-12-13 02:12:19 +01:00
import dagger.Module
import dagger.Provides
import dagger.android.ContributesAndroidInjector
2019-12-28 01:52:20 +01:00
import info.nightscout.androidaps.BuildConfig
2019-12-26 17:50:16 +01:00
import info.nightscout.androidaps.MainApp
2019-12-28 01:52:20 +01:00
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.AAPSLoggerDebug
import info.nightscout.androidaps.logging.AAPSLoggerProduction
2019-12-27 19:20:38 +01:00
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
2019-12-26 23:26:00 +01:00
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctionImplementation
2019-12-28 01:14:04 +01:00
import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective5
import info.nightscout.androidaps.plugins.general.automation.actions.ActionSendSMS
import info.nightscout.androidaps.queue.commands.CommandSetProfile
import info.nightscout.androidaps.services.DataService
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
2019-12-13 02:12:19 +01:00
import javax.inject.Singleton
2019-12-21 20:17:08 +01:00
@Module(includes = [AppModule.AppBindings::class])
2019-12-23 13:27:15 +01:00
class AppModule {
2019-12-13 02:12:19 +01:00
@Provides
@Singleton
2019-12-21 20:17:08 +01:00
fun provideSharedPreferences(context: Context): SP {
2019-12-26 15:12:12 +01:00
return SPImplementation(PreferenceManager.getDefaultSharedPreferences(context))
2019-12-13 02:12:19 +01:00
}
2019-12-26 23:26:00 +01:00
@Provides
@Singleton
fun provideProfileFunction(sp: SP): ProfileFunction {
2019-12-26 23:26:00 +01:00
return ProfileFunctionImplementation(sp)
}
2019-12-27 19:20:38 +01:00
@Provides
@Singleton
fun provideConstraintChecker(mainApp: MainApp): ConstraintChecker {
return ConstraintChecker(mainApp)
}
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 {
return if (BuildConfig.DEBUG) {
AAPSLoggerDebug()
} else {
AAPSLoggerProduction()
}
}
2019-12-21 20:17:08 +01:00
@Module
interface AppBindings {
2019-12-13 02:12:19 +01:00
@ContributesAndroidInjector
fun bindDataService(): DataService
@ContributesAndroidInjector
fun bindCommandSetProfile(): CommandSetProfile
@ContributesAndroidInjector
fun bindActionSendSMS(): ActionSendSMS
2019-12-28 01:14:04 +01:00
@ContributesAndroidInjector
fun bindObjective5(): Objective5
2019-12-21 20:17:08 +01:00
@Binds
2019-12-26 17:50:16 +01:00
fun bindContext(mainApp: MainApp): Context
2019-12-13 02:12:19 +01:00
}
}