skydoves / GithubFollows

:octocat: A demo project based on MVVM architecture and material design & animations.
MIT License
294 stars 46 forks source link

Refactor Code #5

Closed devKshitijJain closed 6 years ago

devKshitijJain commented 6 years ago

https://github.com/skydoves/GithubFollows/blob/966f1a36ca70b3bbdc4a49916ba49a66bb3f50d1/app/src/main/java/com/skydoves/githubfollows/ApplicationClazz.kt#L24

Here you are calling

DaggerAppComponent.builder()
                .application(this)
                .build()
                .inject(this)

and then you are returning

override fun applicationInjector(): AndroidInjector<out DaggerApplication> {
        return DaggerAppComponent.builder().application(this).build()
    }

can't you just make a var for DaggerAppComponent.builder().application(this).build() and then just call inject on that above.

skydoves commented 6 years ago

Oh you mean like this?

class ApplicationClazz : DaggerApplication() {

    private val appComponent = DaggerAppComponent.builder()
            .application(this)
            .build()

    override fun onCreate() {
        super.onCreate()

        if (!LeakCanary.isInAnalyzerProcess(this)) {
            LeakCanary.install(this)
        }

        if(BuildConfig.DEBUG) {
            Timber.plant(Timber.DebugTree())
        }

        appComponent.inject(this)

        PreferenceComponent_PrefAppComponent.init(this)
    }

    override fun applicationInjector(): AndroidInjector<out DaggerApplication> {
        return appComponent
    }
}

I think it looks better than before too. Thank you!!

If you want to contribute any codes or change something, welcome to Pull Request! :)

devKshitijJain commented 6 years ago

Let's discuss the approach that you have followed. I think we can make the code more robust and better. Add me on FB @kjain9878

devKshitijJain commented 6 years ago

Refactored with PR

skydoves commented 6 years ago

okay, Thanks!!