{"id":252948,"date":"2015-03-12T17:17:06","date_gmt":"2015-03-12T13:17:06","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=252948"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=252948","title":{"rendered":"Android. \u041f\u0430\u0440\u0443 \u0441\u043b\u043e\u0432 \u043e\u0431 MVP + rxJava"},"content":{"rendered":"<p> \t\t\t<img decoding=\"async\" src=\"\/\/habrastorage.org\/files\/c76\/a46\/f49\/c76a46f49398451ea2724cee56b5f481.png\"\/><\/p>\n<p>  \u0420\u0430\u0431\u043e\u0442\u0430\u044f \u0441 Android \u0447\u0430\u0441\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0432\u0438\u0434\u0435\u0442\u044c, \u043a\u0430\u043a \u0432\u0435\u0441\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u043c\u0435\u0442\u043e\u0434\u044b \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430 <b>activity\/fragment<\/b>. \u0412 \u043e\u0431\u0449\u0435\u043c-\u0442\u043e \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043e\u0431\u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0435 \u2014 \u00ab\u043c\u0435\u0442\u043e\u0434\u044b \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430\u00bb \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u0445\u044d\u043d\u0434\u043b\u0435\u0440\u044b, \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0449\u0438\u0435 \u044d\u0442\u0430\u043f\u044b \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0441\u0438\u0441\u0442\u0435\u043c\u043e\u0439 \u0438 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u043d\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0438\u0445 \u043a\u043e\u0434\u043e\u043c. \u0414\u043e\u0431\u0430\u0432\u0438\u0432 \u0441\u044e\u0434\u0430 \u0442\u043e, \u0447\u0442\u043e \u043a\u0430\u0440\u043a\u0430\u0441 UI \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 xml \u0444\u0430\u0439\u043b\u044b, \u043c\u044b \u0443\u0436\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0431\u0430\u0437\u043e\u0432\u043e\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043b\u043e\u0433\u0438\u043a\u0438 \u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430. \u041e\u0434\u043d\u0430\u043a\u043e \u0438\u0437-\u0437\u0430 \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u00ab\u0438\u0437\u044f\u0449\u043d\u043e\u0439\u00bb \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430, \u0435\u0433\u043e \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u0444\u043b\u0430\u0433\u043e\u0432 \u0437\u0430\u043f\u0443\u0441\u043a\u0430, \u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u043e\u0439 (\u0445\u043e\u0442\u044c \u0438 \u043f\u043e\u0445\u043e\u0436\u0435\u0439) \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432, \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435\u043c \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u044b\u0432\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0447\u0442\u043e \u0432 \u0438\u0442\u043e\u0433\u0435 \u0432\u044b\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u0432\u0441\u0435\u0433\u043e \u043a\u043e\u0434\u0430 \u0432 <b>onCreate()<\/b>.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h4>Model-View-Presenter+rxJava<\/h4>\n<p>  <b>MVP<\/b> \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0434\u043b\u044f android, \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e\u0449\u0438\u0439 \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0447\u0430\u0441\u0442\u0438:<\/p>\n<ol>\n<li><b>Model<\/b> \u2014 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u0437 \u0441\u0435\u0431\u044f \u0442\u043e\u0447\u043a\u0443 \u0432\u0445\u043e\u0434\u0430 \u043a \u0434\u0430\u043d\u043d\u044b\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f (\u0447\u0430\u0441\u0442\u043e \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u044d\u043a\u0440\u0430\u043d \u0441\u0432\u043e\u044f \u043c\u043e\u0434\u0435\u043b\u044c). \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043e\u0441\u043e\u0431\u043e\u0439 \u0440\u0430\u0437\u043d\u0438\u0446\u044b \u043e\u0442\u043a\u0443\u0434\u0430 \u0434\u0430\u043d\u043d\u044b\u0435 \u0431\u044b\u0442\u044c \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u2014 \u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u0435\u0442\u0435\u0432\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0438\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0441 UI (\u043a\u043b\u0438\u043a\u0438, \u0441\u0432\u0430\u0439\u043f\u044b \u0438 \u0442.\u0434). \u0425\u043e\u0440\u043e\u0448\u0435\u0435 \u043c\u0435\u0441\u0442\u043e \u0434\u043b\u044f \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u044f \u00ab\u0440\u0443\u043a\u043e\u043f\u0438\u0441\u043d\u044b\u0445\u00bb \u043a\u044d\u0448\u0435\u0439. \u0412 \u0441\u0432\u044f\u0437\u043a\u0435 \u0441 <a href=\"https:\/\/github.com\/ReactiveX\/RxJava\">rxJava<\/a> \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0438\u0437 \u0441\u0435\u0431\u044f \u043d\u0430\u0431\u043e\u0440 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u043e\u0442\u0434\u0430\u044e\u0449\u0438\u0445 Observable.<\/li>\n<li><b>View<\/b> \u2014 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u0437 \u0441\u0435\u0431\u044f \u043a\u043b\u0430\u0441\u0441, \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u044e\u0449\u0438\u0439 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 UI \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432. \u041d\u0435 \u043f\u0443\u0442\u0430\u0442\u044c \u0442\u0435\u0440\u043c\u0438\u043d \u0441 <a href=\"http:\/\/developer.android.com\/reference\/android\/view\/View.html\">android.view.View<\/a><\/li>\n<li><b>Presenter<\/b> \u2014 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0441\u0432\u044f\u0437\u044c \u043c\u0435\u0436\u0434\u0443 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c\u044b\u0445 \u0438\u0437 Model \u0438 \u0432\u044b\u0437\u043e\u0432\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0443 View, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044f \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u0440\u0435\u0430\u043a\u0446\u0438\u044e UI \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u043d\u0430 \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0435. \u041c\u0435\u0442\u043e\u0434\u044b Presenter \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0438\u0437 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430 activity\/fragment \u0438 \u0447\u0430\u0441\u0442\u043e \u00ab\u0441\u0438\u043c\u043c\u0435\u0442\u0440\u0438\u0447\u043d\u044b\u00bb \u0438\u043c.<\/li>\n<\/ol>\n<p>  <b>Model\/View\/Presenter<\/b> \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0438\u0437 \u0441\u0435\u0431\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u0434\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u0433\u0438\u0431\u043a\u043e\u0441\u0442\u0438 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043a\u043e\u0434\u0430.<\/p>\n<h4>\u041f\u0440\u0438\u043c\u0435\u0440<\/h4>\n<p>  \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0435\u0433\u043e \u0438\u0437 \u043e\u0434\u043d\u043e\u0433\u043e \u044d\u043a\u0440\u0430\u043d\u0430, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f <b>EditText<\/b> \u0438 <b>TextView<\/b>. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043f\u043e \u043c\u0435\u0440\u0435 \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0442\u0435\u043a\u0441\u0442\u0430 \u0432 <b>EditText<\/b> \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0441\u0435\u0442\u0435\u0432\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b, \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0434\u043e\u043b\u0436\u0435\u043d \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c\u0441\u044f \u0432 <b>TextView<\/b> (\u043a\u043e\u043d\u043a\u0440\u0435\u0442\u0438\u043a\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u0430 \u043d\u0430\u0441 \u0432\u043e\u043b\u043d\u043e\u0432\u0430\u0442\u044c, \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0435\u0440\u0435\u0432\u043e\u0434, \u043a\u0440\u0430\u0442\u043a\u0430\u044f \u0441\u043f\u0440\u0430\u0432\u043a\u0430 \u043f\u043e \u0442\u0435\u0440\u043c\u0438\u043d\u0443 \u0438\u043b\u0438 \u0447\u0442\u043e \u0442\u043e \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0435). <\/p>\n<p>  <i>ExampleModel.java<\/i>:<\/p>\n<pre><code class=\"java\">public interface ExampleModel {       Observable&lt;String&gt; changeText();       Observable&lt;String&gt; request(String query);   }   <\/code><\/pre>\n<p>  <i>ExampleView.java<\/i>:<\/p>\n<pre><code class=\"java\">public interface ExampleView {       void showResponse(String result);   }   <\/code><\/pre>\n<p>  <i>ExamplePresenter.java<\/i>:<\/p>\n<pre><code class=\"java\">public interface ExamplePresenter {       void onCreate(Activity activity, Bundle savedInstanceState); }   <\/code><\/pre>\n<p>  <\/p>\n<h4>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/h4>\n<p>  \u0422\u0430\u043a \u043a\u0430\u043a <b>Model<\/b> \u0438 <b>View<\/b> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u043e\u0434\u043d\u0438 \u0438 \u0442\u0435\u0431\u0435 \u0432\u0438\u0434\u0436\u0435\u0442\u044b (\u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 <b>EditText<\/b> \u0438 <b>TextView<\/b>) \u0434\u043b\u044f \u0441\u0432\u043e\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u044b, \u0440\u0430\u0437\u0443\u043c\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u0438\u0445 \u043a\u043b\u0430\u0441\u0441.<\/p>\n<p>  <i>ExampleViewHolder.java<\/i>:<\/p>\n<pre><code class=\"java\">public class ExampleViewHolder {       public final EditText editText;       public final TextView textView;        public ExampleViewHolder(EditText editText, TextView textView) {           this.editText = editText;           this.textView = textView;       }   }   <\/code><\/pre>\n<p>  \u041f\u0440\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 Model \u043c\u044b \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 rxAndroid, \u0434\u043b\u044f \u00ab\u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u044f\u00bb <b>EditTetx<\/b>, \u0438 <b>retrofit<\/b> \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0435\u0442\u0435\u0432\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432.<\/p>\n<p>  <i>ExampleModelImpl.java<\/i>:<\/p>\n<pre><code class=\"java\">public class ExampleModelImpl implements ExampleModel {       private final ExampleViewHolder viewHolder;         public ExampleModelImpl(final ExampleViewHolder viewHolder) {           this.viewHolder = viewHolder;       }      @Override       public Observable&lt;String&gt; changeText() {           return WidgetObservable               .text(viewHolder.editText)               .map(new Func1&lt;OnTextChangeEvent, String&gt;() {                   @Override                   public String call(OnTextChangeEvent event) {                       return event.toString().trim();                   }               });       }        @Override       public Observable&lt;String&gt; request(String query) {         \/\/\u0432\u0441\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u0431\u0435\u0440\u0435\u0442 \u043d\u0430 \u0441\u0435\u0431\u044f retrofit           return RestManager.newInstance().request(query);      }   }  <\/code><\/pre>\n<p>  <i>ExampleViewImpl.java<\/i>:<\/p>\n<pre><code class=\"java\">public class ExampleViewImpl implements ExampleView {       private final ExampleViewHolder viewHolder;               public ExampleViewImpl(final ExampleViewHolder viewHolder) {           this.viewHolder = viewHolder;       }           @Override       public void showResponse(final String result) {           viewHolder.textView.setText(result);       }   }  <\/code><\/pre>\n<p>  \u0422\u0430\u043a \u043a\u0430\u043a \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0435\u0442\u0435\u0432\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 \u043d\u0430\u0431\u043e\u0440\u0430 \u0442\u0435\u043a\u0441\u0442\u0430 (\u0430 \u043e\u043d\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0432\u044b\u0441\u043e\u043a\u0430), \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0436\u0435\u043b\u0430\u043d\u0438\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u044c \u0447\u0430\u0441\u0442\u043e\u0442\u0443 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0435\u043a\u0441\u0442\u0430 \u0432 <b>EditText<\/b>. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u043e\u0439 <a href=\"http:\/\/reactivex.io\/documentation\/operators\/debounce.html\">debounce<\/a> (\u043f\u0440\u0438 \u044d\u0442\u043e\u043c, \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0432\u0432\u043e\u0434 \u0442\u0435\u043a\u0441\u0442\u0430 \u043d\u0435 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442\u0441\u044f, \u0430 \u043b\u0438\u0448\u044c \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u0435\u0434\u0448\u0438\u0445 \u0432 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u043a \u0432 150 \u043c\u0438\u043b\u043b\u0438\u0441\u0435\u043a\u0443\u043d\u0434).<\/p>\n<p>  <i>ExamplePresenterImpl.java<\/i>:<\/p>\n<pre><code class=\"java\">public class ExamplePresenterImpl implements ExamplePresenter {       private final ExampleModel model;       private final ExampleView view;       private Subscription subscription;        public ExamplePresenterImpl(ExampleModel model, ExampleView view) {           this.model = model;           this.view = view;       }        @Override       public void onCreate(Activity activity, Bundle savedInstanceState) {           subscription = model               .changeText()               \/\/\u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u0447\u0430\u0441\u0442\u043e\u0442\u0443 \u0441\u043e\u0431\u044b\u0442\u0438\u0439             .debounce(150, TimeUnit.MILLISECONDS)               .switchMap(new Func1&lt;String, Observable&lt;String&gt;&gt;() {                   @Override                    public Observable&lt;String&gt; call(String query) {                        return model.request(query);                    }               })            .subscribe(new Action1&lt;String&gt;() {                  @Override                  public void call(String result) {                      view.showResponse(result);                  }                 });       }          @Override       public void onDestroy() {           if (subscription != null) {               subscription.unsubscribe();            }       }   }   <\/code><\/pre>\n<p>  \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f activity, \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0449\u0430\u044f \u0432\u0441\u044e \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u043d\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u044b <b>Presenter<\/b>:<\/p>\n<p>  <i>ExampleActivity.java<\/i>  <\/p>\n<pre><code class=\"java\">public class ExampleActivity extends Activity {       private ExamplePresenter examplePresenter;        @Override       protected void onCreate(Bundle savedInstanceState) {           super.onCreate(savedInstanceState);           setContentView(R.layout.example_activity);            final ExampleViewHolder exampleViewHolder = new ExampleViewHolder(             (TextView) findViewById(R.id.text_view),               (EditText) findViewById(R.id.edit_text)           );            final ExampleModel exampleModel              = new ExampleModelImpl(exampleViewHolder);            final ExampleView exampleView              = new ExampleViewImpl(exampleViewHolder);            examplePresenter            = new ExamplePresenterImpl(exampleModel, exampleView);                   examplePresenter.onCreate(this, savedInstanceState);       }        @Override       protected void onDestroy() {           super.onDestroy();           examplePresenter.onDestroy();       }   } <\/code><\/pre>\n<p>  <\/p>\n<h4>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h4>\n<p>  \u0425\u043e\u0442\u044f \u043d\u0430\u0448 \u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0435\u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e \u0443\u043f\u0440\u043e\u0449\u0435\u043d, \u0432 \u043d\u0435\u043c \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u043d\u0435\u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0435\u043c \u0447\u0430\u0441\u0442\u043e\u0442\u044b \u0441\u043e\u0431\u044b\u0442\u0438\u0439. \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0436\u0435 \u044d\u0432\u043e\u043b\u044e\u0446\u0438\u044e \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432 \u0440\u0430\u0437\u0440\u0435\u0437\u0435 mvp \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043b\u0435\u0433\u043a\u043e:<\/p>\n<ul>\n<li><b>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u0441\u0435\u0442\u0438<\/b> \u2014 \u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 Model-\u0438 \u0438 View.<br \/>  \u041a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 Model (\u043c\u043e\u0436\u043d\u043e \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 retrofit, \u043f\u0443\u0442\u0435\u043c \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 okhttp.Cache \u0438\u043b\u0438 HttpResponsecache \u2014 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f).<\/li>\n<li><b>\u041e\u0431\u0449\u0430\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u0448\u0438\u0431\u043e\u043a<\/b> \u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 Presenter \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u043e\u0448\u0438\u0431\u043e\u043a \u043f\u0440\u0438 subscribe.<\/li>\n<li><b>\u041b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/b> \u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043d\u0430\u0434\u043e \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c.<\/li>\n<li><b>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e UI, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u0438<\/b> \u2014 \u043d\u0443\u0436\u043d\u043e \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c ViewHolder, View.<\/li>\n<\/ul>\n<p>  <\/p>\n<h4>\u042d\u043f\u0438\u043b\u043e\u0433<\/h4>\n<p>  <b>MVP<\/b> \u2014 \u043d\u0435 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u044f Android-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b, \u0438 \u0443\u0436 \u0442\u0435\u043c \u0431\u043e\u043b\u0435\u0435 \u043e\u043d \u043d\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f rxJava \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043d\u0438\u043c. \u041e\u0434\u043d\u0430\u043a\u043e \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0435 \u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u0430\u0435\u0442 \u043f\u0440\u0438\u0435\u043c\u043b\u0435\u043c\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0432 \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043c\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \t\t\t<\/p>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/252903\/\"> http:\/\/habrahabr.ru\/post\/252903\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p> \t\t\t<img decoding=\"async\" src=\"\/\/habrastorage.org\/files\/c76\/a46\/f49\/c76a46f49398451ea2724cee56b5f481.png\"\/><\/p>\n<p>  \u0420\u0430\u0431\u043e\u0442\u0430\u044f \u0441 Android \u0447\u0430\u0441\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0432\u0438\u0434\u0435\u0442\u044c, \u043a\u0430\u043a \u0432\u0435\u0441\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u043c\u0435\u0442\u043e\u0434\u044b \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430 <b>activity\/fragment<\/b>. \u0412 \u043e\u0431\u0449\u0435\u043c-\u0442\u043e \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043e\u0431\u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0435 \u2014 \u00ab\u043c\u0435\u0442\u043e\u0434\u044b \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430\u00bb \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u0445\u044d\u043d\u0434\u043b\u0435\u0440\u044b, \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0449\u0438\u0435 \u044d\u0442\u0430\u043f\u044b \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0441\u0438\u0441\u0442\u0435\u043c\u043e\u0439 \u0438 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u043d\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0438\u0445 \u043a\u043e\u0434\u043e\u043c. \u0414\u043e\u0431\u0430\u0432\u0438\u0432 \u0441\u044e\u0434\u0430 \u0442\u043e, \u0447\u0442\u043e \u043a\u0430\u0440\u043a\u0430\u0441 UI \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 xml \u0444\u0430\u0439\u043b\u044b, \u043c\u044b \u0443\u0436\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0431\u0430\u0437\u043e\u0432\u043e\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043b\u043e\u0433\u0438\u043a\u0438 \u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430. \u041e\u0434\u043d\u0430\u043a\u043e \u0438\u0437-\u0437\u0430 \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u00ab\u0438\u0437\u044f\u0449\u043d\u043e\u0439\u00bb \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430, \u0435\u0433\u043e \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u0444\u043b\u0430\u0433\u043e\u0432 \u0437\u0430\u043f\u0443\u0441\u043a\u0430, \u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u043e\u0439 (\u0445\u043e\u0442\u044c \u0438 \u043f\u043e\u0445\u043e\u0436\u0435\u0439) \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432, \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435\u043c \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u044b\u0432\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0447\u0442\u043e \u0432 \u0438\u0442\u043e\u0433\u0435 \u0432\u044b\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u0432\u0441\u0435\u0433\u043e \u043a\u043e\u0434\u0430 \u0432 <b>onCreate()<\/b>.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-252948","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/252948","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=252948"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/252948\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=252948"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=252948"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=252948"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}