Closed JamesSmartCell closed 2 years ago
@JamesSmartCell, we need to use dagger-hilt right?
Task Update Jan 19, Wednesday:
@Component, @ContributesAndroidInjector,
etc are removed. ViewModelModule
. @HiltAndroidApp
generates it. @InstallIn(ActivityComponent.class)
can provide dependencies to all activities. @AndroidEntryPoint
.
@HiltViewModel
and @Inject
on constructor. @ApplicationContext
to inject application context. References, guides & tutorials used:
@AndroidEntryPoint
. This will allow the activity/fragment to access dependencies from the components.@Inject
for injecting dependencies. @InstallIn(SingletonComponent.class)
, @InstallIn(ActivityRetainedComponent.class)
& @InstallIn(ActivityComponent.class)
. @HiltViewModel
. @Inject
. @InstallIn(SingletonComponent.class)
, @InstallIn(ActivityRetainedComponent.class)
& @InstallIn(ViewModelComponent.class)
. ViewModelModule
. AndroidEntryPoint
and fields/constructor with @Inject
. ServiceModule
. Task Update Jan 20:
@JamesSmartCell can you please test it on your end and let me know if I should make any changes?
Thanks, I'll check it, it's this branch right:
https://github.com/AlphaWallet/alpha-wallet-android/tree/2321_migrate-dagger-to-latest
Thanks, I'll check it, it's this branch right:
https://github.com/AlphaWallet/alpha-wallet-android/tree/2321_migrate-dagger-to-latest
Yes.
Currently we are stuck on Dagger 2.22 - the latest version (as this issue is written) is 2.35.1 / 2.28.3
To upgrade you can go through this tutorial, as above 2.22 Dagger changes quite a bit:
https://proandroiddev.com/getting-started-with-dagger-2-27-on-android-by-example-8534f468175
After this refactor, the injection code should look a little less complex, and the effort to add a new Activity should be slightly less.
Things to watch out for:
some ViewModels serve multiple activities, for example:
This may be quite a big project - if you encounter difficulties please let me know.