Permalink
Browse files

@Inject implemeneted in out HomeActivty.class

  • Loading branch information...
Hafiz Waleed Hussain
Hafiz Waleed Hussain committed Aug 12, 2017
1 parent d9413a7 commit f4998dcdb63e6e9f996a607f3e797f7d97e04262
@@ -12,6 +12,8 @@

import java.util.ArrayList;

import javax.inject.Inject;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
@@ -25,24 +27,35 @@

private RecyclerView recyclerView;
private ProgressBar progressBar;
private GitHubRepository gitHubRepository;
private HomeAdapter homeAdapter;
private RecyclerView.LayoutManager layoutManager;
private Disposable disposable;
// private Glide glide;

private HomeActivityComponent homeActivityComponent;

@Inject
GitHubRepository gitHubRepository;
@Inject
HomeAdapter homeAdapter;
@Inject
RecyclerView.LayoutManager layoutManager;


// private HomeActivityComponent homeActivityComponent;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);

homeActivityComponent = DaggerHomeActivityComponent.builder()
DaggerHomeActivityComponent.builder()
.homeActivityModule(new HomeActivityModule(this, App.getApp().getGlide()))
.build();
.build().inject(this);
// homeActivityComponent = DaggerHomeActivityComponent.builder()
// .homeActivityModule(new HomeActivityModule(this, App.getApp().getGlide()))
// .build();

// gitHubRepository = App.getApp().getGitHubRepository();
// gitHubRepository = homeActivityComponent.getGitHubRepository();

gitHubRepository = App.getApp().getGitHubRepository();
// glide = App.getApp().getGlide();
initViews();
initRecyclerView();
@@ -65,10 +78,10 @@ private void initViews() {

private void initRecyclerView() {
// layoutManager = new LinearLayoutManager(this);
layoutManager = homeActivityComponent.getLayoutManager();
// layoutManager = homeActivityComponent.getLayoutManager();

// homeAdapter = new HomeAdapter(new ArrayList<>(), glide);
homeAdapter = homeActivityComponent.getHomeAdapter();
// homeAdapter = homeActivityComponent.getHomeAdapter();
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(homeAdapter);
}
@@ -4,16 +4,21 @@

import dagger.Component;
import uwanttolearn.dagger2.java.home.adapter.HomeAdapter;
import uwanttolearn.dagger2.java.repositories.github.GitHubRepository;

/**
* Created by waleed on 06/08/2017.
*/
@Component(modules = HomeActivityModule.class)
public interface HomeActivityComponent {

RecyclerView.LayoutManager getLayoutManager();
void inject(HomeActivity homeActivity);

HomeAdapter getHomeAdapter();
// RecyclerView.LayoutManager getLayoutManager();
//
// HomeAdapter getHomeAdapter();
//
// GitHubRepository getGitHubRepository();

}

@@ -10,7 +10,9 @@

import dagger.Module;
import dagger.Provides;
import uwanttolearn.dagger2.java.app.App;
import uwanttolearn.dagger2.java.home.adapter.HomeAdapter;
import uwanttolearn.dagger2.java.repositories.github.GitHubRepository;

/**
* Created by waleed on 06/08/2017.
@@ -36,4 +38,8 @@ public HomeAdapter homeAdapter() {
return new HomeAdapter(new ArrayList<>(), glide);
}

@Provides
public GitHubRepository gitHubRepository() {
return App.getApp().getGitHubRepository();
}
}

0 comments on commit f4998dc

Please sign in to comment.