1

I am trying to make a CustomBaseFragment that receives a base View Model and then initializes it and performs the providers based on the view model that is being passed in raw. I also created a TestFragment that inherits the CustomBaseFragment and passes a View Model TestViewModel. Something like this:

Custom Base Fragment:

 public class CustomBaseFragment<V extends BaseViewModel> extends DaggerFragment
{
    public V viewModel;
    @Inject
    ViewModelProviderFactory providerFactory;

    void initViewModel()
    {
        viewModel = (V) ViewModelProviders.of(this, providerFactory).get(viewModel.getClass());
    }
}

BaseViewModel:

public class BaseViewModel extends ViewModel
{
    @Inject

    public BaseViewModel()
    {
        
    }
}

TestFragment:

    public class TestFragment extends CustomBaseFragment<TestViewModel>
{

}

TestViewModel:

      public class TestViewModel extends BaseViewModel
{
    @Inject
    public TestViewModel()
    {
    }
}

Apparently in code everything is fine, but the dagger is complaining about some things that I don't know how to solve :( The error follows:

Cannot inject members into raw type oficial.com.v2.ui.CustomBaseFragment    
.di.FragmentBuildersModule_ContributeCustom.CustomBaseFragmentSubcomponent.Factory does not implement AndroidInjector <oficial.com.v2.ui.CustomBaseFragment <V>>
       @ClassKey (CustomBaseFragment.class)
       ^

My FragmentBuildersModule:

 @ContributesAndroidInjector()
abstract CustomBaseFragment contributeCustom();

if I try:

 @ContributesAndroidInjector()
    abstract CustomBaseFragment<BaseViewModel> contributeCustom();

I get

error: @ContributesAndroidInjector methods cannot return parameterized types

Does anyone have an idea how to solve?

0 Answers0