匕首和登录凭据

时间:2017-09-12 19:16:28

标签: android kotlin dagger-2

我正在寻找一种在密码验证后创建Dagger2组件来存储UserCredentials的方法

我有3项活动 - >登录,主页,关于

我希望在登录时验证密码后创建一个LoggedUser组件,而不是@Inject这个UserLogged在Home和About,我试图避免多个数据库访问(我的情况要求它),而不是当用户单击关闭Home或About活动时,它返回登录并销毁UserLogged而不是重启过程,但是我有点失去了如何创建一个自定义组件,以便在登录时创建@ActivityScope,但在登录时也被销毁

Curreclty我以这种方式在演示者中使用Kotlin + MVP和Injecting Field:

init {
        println("Presenter Init: " + javaClass.simpleName)
        MyApplicationCloudant.getAppComponent().inject(this)
}

组件以这种方式构建:

component = DaggerAndroidComponent.builder()
                .androidModule(AndroidModule(this))
                .build()

我的AndroidModule:

@Module class AndroidModule(private val application: PontotelApplicationCloudant) {

    /**
     * Allow the application context to be injected but require that it be annotated with
     * [@Annotation][ForApplication] to explicitly differentiate it from an activity context.
     */
    @Provides @Singleton
//    @ForApplication
    fun provideApplicationContext(): Application {
        return application
    }

    @Provides @Singleton
    fun provideLocationManager(): LocationManager {
        return application.getSystemService(LOCATION_SERVICE) as LocationManager
    }

....

}

我的AndroidComponent

@Singleton
@Component(modules = arrayOf(AndroidModule::class))
interface AndroidComponent {

    fun inject(application: MyApplicationCloudant)
    fun inject(loginPresenter: loginPresenter)
    fun inject(homePresenter: HomePresenter)
    fun inject(aboutPresenter: aboutPresenter)
}

0 个答案:

没有答案
相关问题