-
-
Save naj147/896632657cac6bbb573c46c5a2837b23 to your computer and use it in GitHub Desktop.
MVP
This file contains 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 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)); | |
} | |
} |
This file contains 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 CountryRepositoryImpl implements CountryRepository {...} |
This file contains 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 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) {...} | |
} |
This file contains 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
interface CountryRepository { | |
Observable<List<Country>> getCountries(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment