Skip to content

Commit

Permalink
Finally fixed threading error
Browse files Browse the repository at this point in the history
  • Loading branch information
saulmm committed Feb 6, 2016
1 parent ce1de88 commit 3f61c07
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
11 changes: 6 additions & 5 deletions domain/src/main/java/saulmm/avengers/GetCharactersUsecase.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,23 @@ public class GetCharactersUsecase extends Usecase<List<MarvelCharacter>> {
private final CharacterRepository mRepository;
private int mCurrentOffset;

Scheduler uiThread, executorThread;
private final Scheduler mUiThread;
private final Scheduler mExecutorThread;

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

mRepository = repository;
this.uiThread = uiThread;
this.executorThread = executorThread;
mUiThread = uiThread;
mExecutorThread = executorThread;
}

@Override
public Observable<List<MarvelCharacter>> buildObservable() {
return mRepository.getCharacters(mCurrentOffset)
.observeOn(uiThread)
.subscribeOn(executorThread)
.observeOn(mUiThread)
.subscribeOn(mExecutorThread)
.doOnError(new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
Expand Down
6 changes: 3 additions & 3 deletions model/src/main/java/saulmm/avengers/rest/RestDataSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import retrofit.Retrofit;
import retrofit.RxJavaCallAdapterFactory;
import rx.Observable;
import rx.functions.Action1;
import rx.functions.Func1;
import saulmm.avengers.entities.CollectionItem;
import saulmm.avengers.entities.MarvelCharacter;
Expand Down Expand Up @@ -78,13 +79,12 @@ public RestDataSource(MarvelAuthorizer marvelAuthorizer) {

@Override
public Observable<MarvelCharacter> getCharacter(final int characterId) {
return mMarvelApi.getCharacterById(characterId)
.flatMap(new Func1<List<MarvelCharacter>, Observable<MarvelCharacter>>() {
return mMarvelApi.getCharacterById(characterId)
.flatMap(new Func1<List<MarvelCharacter>, Observable<MarvelCharacter>>() {
@Override public Observable<MarvelCharacter> call(List<MarvelCharacter> characters) {
return Observable.just(characters.get(0));
}
});

}

@Override
Expand Down

0 comments on commit 3f61c07

Please sign in to comment.