Nimrodda / dagger-androidinjector

This sample is part of a tutorial on how to use the new dagger-android module, which was released in Dagger 2.10.
https://medium.com/@nimroddayan/android-and-dagger-2-10-androidinjector-5e9c523679a3
135 stars 22 forks source link

Question/Info: Get ID from extra #2

Closed nucle closed 6 years ago

nucle commented 7 years ago

I think we can change this:

@Provides @Named("someId") static String provideSomeId(FeatureActivity featureActivity) {
        return featureActivity.someId;
}

to this:

@Provides @Named("someId") static String provideSomeId(FeatureActivity featureActivity) {
        return featureActivity.getIntent().getStringExtra(EXTRA_SOME_ID);
}

So we don't need to save someID in the activity. What do you think?

chrisjenx commented 7 years ago

@nucle correct, should be able to remove reference to someId from the Activity. As Activity is avaliable in your module you can @Provide what you need from your Bundle

mussa-ibragimov commented 7 years ago

How do we convert this class to Kotlin?

Nimrodda commented 6 years ago

@nucle

So we don't need to save someID in the activity. What do you think?

Yes that's correct. The sample is pretty old. I'll update it.

@mussa-ibragimov

How do we convert this class to Kotlin?

I normally don't write Dagger modules with Kotlin, specifically modules that have static provide methods. The reason is that Kotlin doesn't support static directly in class. We have to use Companion objects which means there's an extra class generated as a singleton + an extra Dagger module generated.