Created
October 19, 2016 16:27
-
-
Save miquelbeltran/b46c303f74d7a94a209b654650d22058 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BooksPresenter { | |
BooksView view; | |
private BooksInteractor interactor; | |
public BooksPresenter(BooksInteractor interactor) { | |
this.interactor = interactor; | |
} | |
public void bind(BooksView view) { | |
this.view = view; | |
} | |
public void unbind() { | |
view = null; | |
} | |
public void performSearch(String userInput) { | |
String formatUserInput = userInput.trim().replaceAll("\\s+", "+"); | |
// Just call the method on the GoogleBooksService | |
interactor.search("search+" + formatUserInput) | |
// enqueue runs the request on a separate thread | |
.enqueue(new Callback<BookSearchResult>() { | |
// We receive a Response with the content we expect already parsed | |
@Override | |
public void onResponse(Call<BookSearchResult> call, | |
Response<BookSearchResult> books) { | |
if (view != null) | |
view.updateUi(books.body().getBooks()); | |
} | |
// In case of error, this method gets called | |
@Override | |
public void onFailure(Call<BookSearchResult> call, Throwable t) { | |
t.printStackTrace(); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment