Hi,
I am following same app structure for my app as:
ActivityBuilder.java:
`@Module
public abstract class ActivityBuilder {
@ContributesAndroidInjector(modules = SplashActivityModule.class)
abstract SplashActivity bindSplashActivity();
@ContributesAndroidInjector(modules = {NavigationActivityModule.class,
CatalogueFragmentProvider.class })
abstract NavigationActivity bindNavigationActivity();
}`
NavigationActivityModule.Java (NavigationActivity which draws Navigation View with NavigationViewModel):
`@Module
public class NavigationActivityModule {
@Provides
NavigationViewModel provideNavigationViewModel(Application application) {
return new NavigationViewModel(application);
}
@provides
ViewModelProvider.Factory mainViewModelProvider(NavigationViewModel navigationViewModel) {
return new TraderViewModelFactory<>(navigationViewModel);
}
}`
CatalogueFragmentProvider.Java (CatalogueFragment which shows as the first fragment inside NavigationView container):
@module
public abstract class CatalogueFragmentProvider {
@ContributesAndroidInjector(modules = CataloguesFragmentModule.class)
abstract CataloguesFragment provideCataloguesFragment();
}
Lastly, CataloguesFragmentModule.Java (contain catalogue view such as RecyclerView inside CatalogueFragment):
@module
public class CataloguesFragmentModule {
@Provides
CatalogueFragmentViewModel provideAboutViewModel(CataloguesRepository cataloguesRepository, Application application) {
return new CatalogueFragmentViewModel(cataloguesRepository, application);
}
@Provides
ViewModelProvider.Factory catalogueViewModelProvider(CatalogueFragmentViewModel catalogueFragmentViewModel) {
return new TraderViewModelFactory<>(catalogueFragmentViewModel);
}
}
The problem is I am getting the same instance of NavigationViewModel inside the CatalogueViewModel. This throws error by ViewModelFactory since modelClass.isAssignableFrom returns false.
Please help. I stuck into this from last three days and couldn't find any solution by googling too.
Thanks.