Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public interface ExampleModel {
- Observable<String> getResponse(String request);
- }
- public interface ExampleView {
- Observable<String> changeText();
- void showResponse(String response);
- }
- public interface ExamplePresenter {
- void onCreate();
- }
- public class ExamplePresenerImpl implementation ExamplePresenter {
- private ExampleView view;
- private Model model;
- private Subscription subscription;
- public ExamplePresenterImpl(ExampleView view) {
- this.view = view;
- this.model = new RetrofitAdapter.Builder(ExampleModel.class).addUrl(...).build();
- }
- public void onCreate() {
- subscription = view
- .changeText()
- .flatMap(query -> model.getResponse(query))
- .subscribe(response -> view.showResponse(response));
- }
- public void onDestroy() {
- subscription.unsubscribe();
- }
- }
- public class ExampleActivity extends Activity implementation ExampleView {
- private EditText editText;
- private TextView textView;
- private ExamplePresenter presenter;
- public void onCreate(...) {
- this.editText = (EditText) findViewById(...);
- this.textView = (TextView) findViewById(...);
- presenter = new ExamplePresenterImpl(this);
- presenter.onCreate();
- }
- public void onDestroy() {
- presenter.onDestroy();
- }
- @Override
- public Observable<String> changeText() {
- return ObservableWidge.text(editText);
- }
- @Override
- void showResponse(String response) {
- textView.setText(response);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement