Skip to content

Instantly share code, notes, and snippets.

@naj147
Forked from pkliang/CountriesPresenter.java
Created October 10, 2019 08:09
Show Gist options
  • Save naj147/896632657cac6bbb573c46c5a2837b23 to your computer and use it in GitHub Desktop.
Save naj147/896632657cac6bbb573c46c5a2837b23 to your computer and use it in GitHub Desktop.
MVP
public class CountriesPresenter {
private final CountryRepository repository = new CountryRepositoryImpl();
private CountriesActivity view;
public CountriesPresenter(CountriesActivity countryActivity) {
view = countryActivity;
}
public void getCountries() {
repository.getCountries()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(countries -> view.showCountries(countries), error -> view.showError(error));
}
}
public class CountryRepositoryImpl implements CountryRepository {...}
public class CountriesActivity extends Activity {
CountriesPresenter presenter;
@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(...);
presenter = new CountriesPresenter(this);
presenter.getCountries();
}
public void showError(Thowable error) {...}
public void shoCountries(List<Country> countries) {...}
}
interface CountryRepository {
Observable<List<Country>> getCountries();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment