Skip to content

Commit

Permalink
Moved Schedulers to the application module
Browse files Browse the repository at this point in the history
  • Loading branch information
saulmm committed Feb 2, 2016
1 parent ee959e2 commit e3eb910
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
16 changes: 16 additions & 0 deletions app/src/main/java/saulmm/avengers/injector/AppModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@

import dagger.Module;
import dagger.Provides;

import javax.inject.Named;
import javax.inject.Singleton;

import rx.Scheduler;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
import saulmm.avengers.AvengersApplication;
import saulmm.avengers.BuildConfig;
import saulmm.avengers.repository.CharacterRepository;
Expand Down Expand Up @@ -40,4 +46,14 @@ Endpoint provideRestEndpoint() {
@Provides @Singleton
CharacterRepository provideDataRepository(RestDataSource restDataSource) {
return restDataSource; }

@Provides @Named("executor_thread")
Scheduler provideExecutorThread() {
return Schedulers.newThread();
}

@Provides @Named("ui_thread")
Scheduler provideUiThread() {
return AndroidSchedulers.mainThread();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import dagger.Component;
import javax.inject.Singleton;

import rx.Scheduler;
import saulmm.avengers.AvengersApplication;
import saulmm.avengers.injector.AppModule;
import saulmm.avengers.repository.CharacterRepository;
Expand All @@ -19,4 +21,6 @@ public interface AppComponent {
CharacterRepository dataRepository();
Endpoint restEndpoint();
MarvelAuthorizer marvelAuthorizer();

Scheduler uiThread();
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,6 @@ public ActivityModule(Context mContext) {
this.mContext = mContext;
}

@Provides @Activity @Named("executor_thread")
Scheduler provideExecutorThread() {
return Schedulers.newThread();
}

@Provides @Activity @Named("ui_thread")
Scheduler provideUiThread() {
return AndroidSchedulers.mainThread();
}

@Provides @Activity
Context provideActivityContext() {
return mContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ public class GetCharactersUsecase extends Usecase<List<MarvelCharacter>> {
Scheduler uiThread, executorThread;


@Inject public GetCharactersUsecase(CharacterRepository repository, @Named("ui_thread") Scheduler uiThread, @Named("executor_thread") Scheduler executorThread) {
@Inject public GetCharactersUsecase(CharacterRepository repository,
@Named("ui_thread") Scheduler uiThread, @Named("executor_thread") Scheduler executorThread) {

mRepository = repository;
this.uiThread = uiThread;
this.executorThread = executorThread;
Expand Down

0 comments on commit e3eb910

Please sign in to comment.