@Override public void loadFoods(String query) { if (mSubscription != null) mSubscription.unsubscribe(); Observable<List<Food>> observable = mDataManager .getFood(query) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()); mSubscription = observable.subscribe( new Subscriber<List<Food>>() { @Override public void onCompleted() { Log.d(SearchPresenter.class.getSimpleName(), "Food completed"); } @Override public void onError(Throwable e) { Log.d(SearchPresenter.class.getSimpleName(), e.getMessage()); mView.showError(); } @Override public void onNext(List<Food> foods) { Log.d(SearchPresenter.class.getSimpleName(), "Received " + foods.size() + " foods"); mView.showFoods(foods); } }); }
@Override public List<SearchItem> getPreviousSearches() { return mDataManager.getPreviousSearches(); }
@Override public void saveNewSearch(String search) { if (!search.isEmpty()) mDataManager.saveNewSearch(search); }