konmik / nucleus

Nucleus is an Android library, which utilizes the Model-View-Presenter pattern to properly connect background tasks with visual parts of an application.
MIT License
1.98k stars 253 forks source link

Nucleus with Dagger 2 #146

Closed srigiridharan closed 6 years ago

srigiridharan commented 7 years ago

Thank you so much for the Nucleus. It is great library for MVP. Now I am trying to integrate Dagger2 with Nucleus,So the issue is when i trying to Inject my activityComponent with the BaseDrawerActivity Dagger compiler throwing the error like,

Error:(19, 47) error: cannot find symbol class DaggerActivityComponent .. \utils\AppApplication.java Error:(7, 47) error: cannot find symbol class DaggerApplicationComponent F:... app\src\main\java\com...\MainActivity.java Error:(11, 47) error: cannot find symbol class DaggerActivityComponent F:..\app\src\main\java\com..\compondent\ActivityComponent.java Error:(19, 10) error:....BaseDrawerActivity has type parameters, cannot members inject the raw type. via: .. BaseDrawerActivity is injected at .. .compondent.ActivityComponent.inject(baseDrawerActivity) Error:Execution failed for task ':app:compileDebugJavaWithJavac'.

Compilation failed; see the compiler error output for details. Information:BUILD FAILED](url)

@RequiresPresenter(BaseDrawerPresenter.class)
public class BaseDrawerActivity<PresenterType extends Presenter> extends NucleusAppCompatActivity<PresenterType>
        implements NavigationView.OnNavigationItemSelectedListener {

    @BindView(R.id.imageViewTestPicassoD2)
    ImageView picassoImageView;

    ActivityComponent activityComponent;

    @Inject
    Picasso picasso;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dashboard);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        ButterKnife.bind(this);

        activityComponent = DaggerActivityComponent.builder()
                .activityModule(new ActivityModule(this))
                .applicationComponent(((AppApplication)getApplication()).getAppComponent())
                .build();
        activityComponent.inject(BaseDrawerActivity.this);

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.addDrawerListener(toggle);
        toggle.syncState();

        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);

    }
}

My component

@ActivityScope
@Component(modules = ActivityModule.class, dependencies = ApplicationComponent.class)
public interface ActivityComponent {

    void inject(BaseDrawerActivity baseDrawerActivity);
}

How can I inject my BaseDrawerActivity with ActivityComponent ?

srigiridharan commented 7 years ago

heyyy... The issue got resolved. The following changes on the existing code,

@RequiresPresenter(BaseDrawerPresenter.class)
public class BaseDrawerActivity extends NucleusAppCompatActivity<BaseDrawerPresenter>
        implements NavigationView.OnNavigationItemSelectedListener {... 
activityComponent = DaggerActivityComponent.builder()
                .activityModule(new ActivityModule(this))
                .applicationComponent(((AppApplication) getApplication()).getAppComponent())
                .build();
        activityComponent.inject(BaseDrawerActivity.this);

but still I cant understand why my activityModule says deprecated.

srigiridharan commented 7 years ago

@konmik can you please tell me why the module say unused when we building with corresponding component.

konmik commented 6 years ago

I have no idea. We could try to find the problem (I need a minimal size example with reproduced problem), but I suspect you already did it, so I'm closing it.