{"id":296511,"date":"2019-12-27T15:00:34","date_gmt":"2019-12-27T15:00:34","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=296511"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=296511","title":{"rendered":"\u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0438\u0437 ViewModel \u0432 Activity\/Fragment \u0432 MVVM"},"content":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/company\/homecredit\/blog\/477314\/\">\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u0440\u0435\u0447\u044c \u043f\u043e\u0439\u0434\u0435\u0442 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u043e\u0431\u043c\u0435\u043d\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043c\u0435\u0436\u0434\u0443 Activities\/Fragments \u0438 ViewModel \u0432 MVVM. \u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 ViewModel, \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u0432 Activity\/Fragment \u043f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0435 LiveData, \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0438\u0435\u0441\u044f \u0432\u043e ViewModel. \u041d\u043e \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0435\u0434\u0438\u043d\u0438\u0447\u043d\u044b\u0445 (\u0438 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e) \u0441\u043e\u0431\u044b\u0442\u0438\u0439, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0435 \u0438\u043b\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u0434\u0440\u0443\u0433\u043e\u0439 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442? <\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/td\/ey\/cp\/tdeycpvhsyngrmfgzco-mpmjzta.jpeg\"><br \/>  <a name=\"habracut\"><\/a><\/p>\n<p>  \u0418\u0442\u0430\u043a, \u0432\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442!<br \/>  \u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0410\u043b\u0435\u043a\u0441\u0435\u0439, \u044f \u0430\u043d\u0434\u0440\u043e\u0438\u0434-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0432 \u0411\u0430\u043d\u043a\u0435 \u00ab\u0425\u043e\u0443\u043c \u041a\u0440\u0435\u0434\u0438\u0442\u00bb. <br \/>  \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u043e\u0434\u0435\u043b\u044e\u0441\u044c \u043d\u0430\u0448\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u043e\u0442 ViewModels \u043a Views (Activities\/Fragments).<br \/>  <i>\u0412 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 <a href=\"https:\/\/play.google.com\/store\/apps\/details?id=ru.homecredit.marketplace\">\u00ab\u0422\u043e\u0432\u0430\u0440\u044b \u0432 \u0440\u0430\u0441\u0441\u0440\u043e\u0447\u043a\u0443 \u043e\u0442 \u0411\u0430\u043d\u043a\u0430 \u0425\u043e\u0443\u043c \u041a\u0440\u0435\u0434\u0438\u0442\u00bb<\/a> \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u044b, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0431\u0443\u0434\u0435\u043c \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u043e \u043d\u0438\u0445, \u043d\u043e \u0432\u0441\u0451 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u043e \u0438 \u0434\u043b\u044f Activity.<\/i><\/p>\n<h3>\u0427\u0442\u043e \u043c\u044b \u0445\u043e\u0442\u0438\u043c?<\/h3>\n<p>  \u0423 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c Fragment, \u0432\u043a\u043b\u044e\u0447\u0430\u044e\u0449\u0438\u0439 \u0432 \u0441\u0435\u0431\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e ViewModel-\u0435\u0439, \u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f <code>DataBinding<\/code>-\u043e\u043c. \u0412\u0441\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u043f\u043e\u043b\u0443\u0447\u0430\u044e\u0442 ViewModel-\u0438. \u0415\u0441\u043b\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u043c: \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u0434\u0440\u0443\u0433\u043e\u0439 fragment\/activity, \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c <code>AlertDialog<\/code>, <code>Snackbar<\/code>, \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 Permissions \u0438 \u0442.\u043f., \u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c\u0441\u044f \u0432\u043e \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0435.<br \/>  <cut><\/cut><\/p>\n<h3>\u0410 \u0432 \u0447\u0435\u043c, \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430?<\/h3>\n<p>  \u0416\u0438\u0437\u043d\u0435\u043d\u043d\u044b\u0435 \u0446\u0438\u043a\u043b\u044b Views \u0438 ViewModels \u043d\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u044b. \u0421\u0432\u044f\u0437\u044b\u0432\u0430\u0442\u044c \u043a\u043e\u043b\u0431\u0435\u043a\u0430\u043c\u0438 (Listeners) \u043d\u0435\u043b\u044c\u0437\u044f, \u0442\u0430\u043a \u043a\u0430\u043a ViewModel \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u043d\u0438\u0447\u0435\u0433\u043e \u0437\u043d\u0430\u0442\u044c \u043e \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0430\u0445, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0432 \u0441\u0435\u0431\u0435 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u044b, \u0438\u043d\u0430\u0447\u0435, \u043a\u0430\u043a \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u043f\u0430\u043c\u044f\u0442\u044c \u043d\u0430\u0447\u043d\u0435\u0442 \u00ab<a href=\"https:\/\/developer.android.com\/topic\/performance\/memory\">\u043b\u0438\u043a\u043e\u0432\u0430\u0442\u044c<\/a>\u00bb.<\/p>\n<p>  \u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u043c \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f Fragments \u0438 ViewModels \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0430 \u043d\u0430 <code>LiveData<\/code>, \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0443\u044e\u0441\u044f \u0432\u043e ViewModel. \u0421\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0443 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0447\u0435\u0440\u0435\u0437 <code>LiveData<\/code> \u043d\u0435\u043b\u044c\u0437\u044f, \u0432\u0441\u0432\u044f\u0437\u0438 \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043d\u0435 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442, \u0431\u044b\u043b\u043e \u0443\u0436\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0438\u043b\u0438 \u043d\u0435\u0442. <\/p>\n<h3>\u041a\u0430\u043a\u0438\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0440\u0435\u0448\u0435\u043d\u0438\u044f:<\/h3>\n<p>  1. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/github.com\/googlesamples\/android-architecture\/blob\/dev-todo-mvvm-live\/todoapp\/app\/src\/main\/java\/com\/example\/android\/architecture\/blueprints\/todoapp\/SingleLiveEvent.java\"><code>SingleLiveEvent<\/code><\/a> <br \/>  <b>\u041f\u043b\u044e\u0441\u044b:<\/b> \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043e\u0434\u0438\u043d \u0440\u0430\u0437.<br \/>  <b>\u041c\u0438\u043d\u0443\u0441\u044b:<\/b> \u043e\u0434\u043d\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u2013 \u043e\u0434\u0438\u043d <code>SingleLiveEvent<\/code>. \u041f\u0440\u0438 \u0431\u043e\u043b\u044c\u0448\u043e\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0432\u043e ViewModel \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f N event-\u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0432\u043e \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0435.<\/p>\n<p>  2. \u041d\u0435\u043f\u043b\u043e\u0445\u043e\u0439 <a href=\"https:\/\/android.jlelse.eu\/sending-events-from-viewmodel-to-activities-fragments-the-right-way-26bb68502b24\">\u043f\u0440\u0438\u043c\u0435\u0440<\/a>. <br \/>  <b>\u041f\u043b\u044e\u0441\u044b:<\/b> \u043e\u0434\u043d\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0442\u0430\u043a\u0436\u0435 \u0435\u0434\u0438\u043d\u043e\u0436\u0434\u044b, \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 viewModel \u0432\u043e fragment.<br \/>  <b>\u041c\u0438\u043d\u0443\u0441\u044b:<\/b> \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0441\u043e\u0431\u044b\u0442\u0438\u0438 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b, \u0435\u0441\u043b\u0438 \u0436\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0431\u0435\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 <code>(val content: T)<\/code>, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u043a\u043b\u0430\u0441\u0441. \u041d\u0435 \u0440\u0435\u0448\u0430\u0435\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043e\u0434\u0438\u043d \u0440\u0430\u0437 (\u0441\u0430\u043c\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043e\u0434\u0438\u043d \u0440\u0430\u0437, \u043d\u043e \u0434\u0430\u043d\u043d\u044b\u0439 \u0442\u0438\u043f \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u0441\u044f \u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u044b \u0435\u0433\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u0438\u0437 ViewModel). \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0443 \u043d\u0430\u0441 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e \u0443\u0445\u043e\u0434\u044f\u0442 N-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043d\u043e \u0441\u0435\u0442\u0438 \u043d\u0435\u0442. \u041a\u0430\u0436\u0434\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432\u0435\u0440\u043d\u0435\u0442\u0441\u044f \u0441 \u043e\u0448\u0438\u0431\u043a\u043e\u0439 \u0441\u0435\u0442\u0438, \u0438 \u0437\u0430\u043f\u0443\u043b\u0438\u0442 \u0432\u043e \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 N \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435 \u0441\u0435\u0442\u0438, \u0432\u043e \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0435 \u043e\u0442\u043a\u0440\u043e\u0435\u0442\u0441\u044f N \u0430\u043b\u0435\u0440\u0442\u043e\u0432. \u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043d\u0435 \u043e\u0434\u043e\u0431\u0440\u0438\u0442 \u0442\u0430\u043a\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 :). \u041c\u044b \u0435\u043c\u0443 \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0441 \u0434\u0430\u043d\u043d\u043e\u0439 \u043e\u0448\u0438\u0431\u043a\u043e\u0439. \u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0439 \u0442\u0438\u043f \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u0441\u044f \u043e\u0434\u0438\u043d \u0440\u0430\u0437.<\/p>\n<h3>\u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/h3>\n<p>  \u0417\u0430 \u043e\u0441\u043d\u043e\u0432\u0443 \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u0438\u0434\u0435\u044e <code>SingleLiveEvent<\/code> \u043f\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u0445\u0435\u043d\u0434\u043b\u0438\u043d\u0433\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f.<\/p>\n<h4>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u0441\u043e\u0431\u044b\u0442\u0438\u0439<\/h4>\n<p>  <\/p>\n<pre><code class=\"kotlin\">enum class Type {     EXECUTE_WITHOUT_LIMITS, \/\/\u0421\u0430\u043c\u044b\u0439 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0439 \u0442\u0438\u043f \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u2013 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u044b\u043b\u043e \u0432\u044b\u0437\u0432\u0430\u043d\u043e \u0431\u0435\u0437 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043b\u0438 \u0445\u043e\u0442\u044c \u043e\u0434\u0438\u043d \u043f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a \u0438\u043b\u0438 \u043d\u0435\u0442     EXECUTE_ONCE, \/\/\u0412\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0439 \u0442\u0438\u043f \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043e\u0434\u0438\u043d \u0440\u0430\u0437     WAIT_OBSERVER_IF_NEEDED,\/\/\u0421\u043e\u0431\u044b\u0442\u0438\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043e\u0436\u0434\u0430\u0442\u044c\u0441\u044f \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a\u0430-\u043e\u0431\u0437\u0451\u0440\u0432\u0435\u0440\u0430 \u043d\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0435\u0433\u043e     WAIT_OBSERVER_IF_NEEDED_AND_EXECUTE_ONCE \/\/\u0421\u043e\u0431\u044b\u0442\u0438\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043e\u0436\u0434\u0430\u0442\u044c\u0441\u044f \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a\u0430-\u043e\u0431\u0437\u0451\u0440\u0432\u0435\u0440\u0430 \u043d\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0439 \u0442\u0438\u043f \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043e\u0434\u0438\u043d \u0440\u0430\u0437 }<\/code><\/pre>\n<h4>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u2013 <code>NavigationEvent<\/code><\/h4>\n<p>  <code>isHandled<\/code> \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430 \u0442\u043e, \u0431\u044b\u043b\u043e \u043b\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043e (\u043c\u044b \u0441\u0447\u0438\u0442\u0430\u0435\u043c, \u0447\u0442\u043e \u043e\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u043e, \u0435\u0441\u043b\u0438 \u0431\u044b\u043b\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043e Observer \u0432\u043e \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0435).  <\/p>\n<pre><code class=\"kotlin\">open class NavigationEvent(var isHandled: Boolean = false, var type: Events.Type)<\/code><\/pre>\n<h4>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043a\u043b\u0430\u0441\u0441 \u042d\u043c\u0438\u0442\u0442\u0435\u0440\u0430 \u2013 <code>Emitter<\/code><\/h4>\n<p>  \u041a\u043b\u0430\u0441\u0441 \u044d\u043c\u0438\u0442\u0442\u0435\u0440\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442\u0441\u044f \u043e\u0442 <code>LiveData<\/code>&lt;<code>NavigationEvent<\/code>&gt;. \u0414\u0430\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432\u043e ViewModel \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0439.  <\/p>\n<pre><code class=\"kotlin\">class Emitter : MutableLiveData&lt;NavigationEvent&gt;() {     private val waitingEvents: ArrayList&lt;NavigationEvent&gt; = ArrayList()     private var isActive = false      override fun onInactive() {         isActive = false     }      override fun onActive() {         isActive = true         val postingEvents = ArrayList&lt;NavigationEvent&gt;()         waitingEvents             .forEach {                 if (hasObservers()) {                     this.value = it                     postingEvents.add(it)                 }             }.also { waitingEvents.removeAll(postingEvents) }     }      private fun newEvent(event: NavigationEvent, type: Type) {         event.type = type         this.value = when (type) {             Type.EXECUTE_WITHOUT_LIMITS,             Type.EXECUTE_ONCE -&gt; if (hasObservers()) event else null              Type.WAIT_OBSERVER_IF_NEEDED,             Type.WAIT_OBSERVER_IF_NEEDED_AND_EXECUTE_ONCE -&gt; {                 if (hasObservers() &amp;&amp; isActive) event                 else {                     waitingEvents.add(event)                     null                 }             }         }     }      \/** Clear All Waiting Events *\/     fun clearWaitingEvents() =  waitingEvents.clear() }<\/code><\/pre>\n<p>  <code>isActive<\/code> \u2013 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c \u043d\u0430\u043c \u0434\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u2013 \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u043d \u043b\u0438 \u043d\u0430 <code>Emitter<\/code> \u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u0438\u043d <code>Observer<\/code>. \u0418 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435, \u043a\u043e\u0433\u0434\u0430 \u043f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u0438 \u043d\u0430\u043a\u043e\u043f\u0438\u043b\u0438\u0441\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f, \u043e\u0436\u0438\u0434\u0430\u044e\u0449\u0438\u0435 \u0435\u0433\u043e, \u043c\u044b \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u044d\u0442\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u044f. \u0412\u0430\u0436\u043d\u043e\u0435 \u0443\u0442\u043e\u0447\u043d\u0435\u043d\u0438\u0435: \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u0435 \u0447\u0435\u0440\u0435\u0437 <code>this.postValue(event)<\/code>, \u0430 \u0447\u0435\u0440\u0435\u0437 \u0441\u0435\u0442\u0442\u0435\u0440 <code>this.value = event<\/code>. \u0418\u043d\u0430\u0447\u0435, \u043f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a \u043f\u043e\u043b\u0443\u0447\u0438\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0432 \u0441\u043f\u0438\u0441\u043a\u0435.<\/p>\n<p>  \u0421\u0430\u043c \u043c\u0435\u0442\u043e\u0434 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u043d\u043e\u0432\u043e\u0433\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u044f <code>newEvent(event, type)<\/code> \u2013 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0434\u0432\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u2013 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0441\u0430\u043c\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0438 \u0442\u0438\u043f \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u044f. <\/p>\n<p>  \u0427\u0442\u043e\u0431\u044b \u043d\u0435 \u0437\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0442\u044c \u0432\u0441\u0435 \u0442\u0438\u043f\u044b \u0441\u043e\u0431\u044b\u0442\u0438\u0439 (\u0434\u043b\u0438\u043d\u043d\u044b\u0435 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f), \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 public-\u043c\u0435\u0442\u043e\u0434\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0430\u043c\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0435:  <\/p>\n<pre><code class=\"kotlin\">class Emitter : MutableLiveData&lt;NavigationEvent&gt;() {     \u2026      \/** Default: Emit Event for Execution *\/     fun emitAndExecute(event: NavigationEvent) = newEvent(event, Type.EXECUTE_WITHOUT_LIMITS)      \/** Emit Event for Execution Once *\/     fun emitAndExecuteOnce(event: NavigationEvent) = newEvent(event, Type.EXECUTE_ONCE)      \/** Wait Observer Available and Emit Event for Execution *\/     fun waitAndExecute(event: NavigationEvent) = newEvent(event, Type.WAIT_OBSERVER_IF_NEEDED)      \/** Wait Observer Available and Emit Event for Execution Once *\/     fun waitAndExecuteOnce(event: NavigationEvent) = newEvent(event, Type.WAIT_OBSERVER_IF_NEEDED_AND_EXECUTE_ONCE) }<\/code><\/pre>\n<p>  \u0424\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e, \u0443\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 <code>Emitter<\/code> \u0432\u043e ViewModel \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0431\u0435\u0437 \u0443\u0447\u0435\u0442\u0430 \u0438\u0445 \u0445\u0435\u043d\u0434\u043b\u0438\u043d\u0433\u0430 (\u0431\u044b\u043b\u043e \u043b\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0443\u0436\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043e \u0438\u043b\u0438 \u043d\u0435\u0442).<\/p>\n<h4>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043b\u0430\u0441\u0441 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u2013 <code>EventObserver<\/code><\/h4>\n<p>  <\/p>\n<pre><code class=\"kotlin\">class EventObserver(private val handlerBlock: (NavigationEvent) -&gt; Unit) : Observer&lt;NavigationEvent&gt; {     private val executedEvents: HashSet&lt;String&gt; = hashSetOf()          \/** Clear All Executed Events *\/     fun clearExecutedEvents() =  executedEvents.clear()          override fun onChanged(it: NavigationEvent?) {         when (it?.type) {             Type.EXECUTE_WITHOUT_LIMITS,             Type.WAIT_OBSERVER_IF_NEEDED -&gt; {                 if (!it.isHandled) {                     it.isHandled = true                     it.apply(handlerBlock)                 }             }             Type.EXECUTE_ONCE,             Type.WAIT_OBSERVER_IF_NEEDED_AND_EXECUTE_ONCE -&gt; {                 if (it.javaClass.simpleName !in executedEvents) {                     if (!it.isHandled) {                         it.isHandled = true                         executedEvents.add(it.javaClass.simpleName)                         it.apply(handlerBlock)                     }                 }             }         }     } } <\/code><\/pre>\n<p>  \u041d\u0430 \u0432\u0445\u043e\u0434 \u0434\u0430\u043d\u043d\u044b\u0439 Observer \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0432\u044b\u0441\u0448\u0435\u0433\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u2013 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0430 \u0432\u043e \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0435 (\u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0438\u0436\u0435).<\/p>\n<p>  \u041c\u0435\u0442\u043e\u0434 <code>clearExecutedEvents()<\/code> \u0434\u043b\u044f \u043e\u0447\u0438\u0441\u0442\u043a\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u044b\u0445 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 (\u0442\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u043b\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u0441\u044f \u043e\u0434\u0438\u043d \u0440\u0430\u0437). \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c \u043f\u0440\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0438 \u044d\u043a\u0440\u0430\u043d\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 <code>swipeToRefresh()<\/code>.<\/p>\n<p>  \u041d\u0443 \u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 <code>onChange()<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u043f\u0440\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0438 \u043d\u043e\u0432\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u044d\u043c\u0438\u0442\u0442\u0435\u0440\u0430, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0439 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u044c.<br \/>  \u0412 \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0438\u043c\u0435\u0435\u0442 \u0442\u0438\u043f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043d\u0435\u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0440\u0430\u0437, \u0442\u043e \u043c\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0431\u044b\u043b\u043e \u043b\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u043e \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u0435\u0433\u043e. \u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0438 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c, \u0447\u0442\u043e \u043e\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043e \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043e.   <\/p>\n<pre><code class=\"kotlin\">if (!it.isHandled) {     it.isHandled = true     it.apply(handlerBlock) }<\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0441 \u0442\u0438\u043f\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u0441\u044f \u0435\u0434\u0438\u043d\u043e\u0436\u0434\u044b, \u0442\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043b\u0438 \u043a\u043b\u0430\u0441\u0441 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0432 \u0445\u0435\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0435. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u044f \u2013 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043a\u043b\u0430\u0441\u0441 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0432 \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0443.  <\/p>\n<pre><code class=\"kotlin\">if (it.javaClass.simpleName !in executedEvents) {     if (!it.isHandled) {         it.isHandled = true         executedEvents.add(it.javaClass.simpleName)         it.apply(handlerBlock)     } }<\/code><\/pre>\n<h3>\u0410 \u043a\u0430\u043a \u0436\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0439?<\/h3>\n<p>  \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code>MyFragmentNavigation<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u0442\u044c \u0438\u0437 \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u043c\u044b\u0445 \u043e\u0442 <code>NavigationEvent()<\/code>. \u041d\u0438\u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u044b \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u0441 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438 \u0438 \u0431\u0435\u0437 \u043d\u0438\u0445.<\/p>\n<pre><code class=\"kotlin\">interface MyFragmentNavigation {     class ShowCategoryList : NavigationEvent()     class OpenProduct(val productId: String, val productName: String) : NavigationEvent()     class PlayVideo(val url: String) : NavigationEvent()     class ShowNetworkError : NavigationEvent() }<\/code><\/pre>\n<h3>\u041a\u0430\u043a \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435<\/h3>\n<p>  \u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0438\u0437 ViewModel:  <\/p>\n<pre><code class=\"kotlin\">class MyViewModel : ViewModel() {     val emitter = Events.Enitter()          fun doOnShowCategoryListButtonClicked() = emitter.emitAndExecute(MyNavigation.ShowCategoryList())          fun doOnPlayClicked() = emitter.waitAndExecuteOnce(MyNavigation.PlayVideo(url = \"https:\/\/site.com\/abc\"))      fun doOnProductClicked() = emitter.emitAndExecute(MyNavigation.OpenProduct(             productId = \"123\",              productTitle = \"\u0427\u0430\u0441\u044b Samsung\")         )          fun doOnNetworkError() = emitter.emitAndExecuteOnce(MyNavigation.ShowNetworkError())      fun doOnSwipeRefresh(){         emitter.clearWaitingEvents()         ..\/\/loadData()     } }<\/code><\/pre>\n<p>  \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0432\u043e \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0435:  <\/p>\n<pre><code class=\"kotlin\">class MyFragment : Fragment() {     private val navigationEventsObserver = Events.EventObserver { event -&gt;             when (event) {                 is MyFragmentNavigation.ShowCategoryList -&gt; ShowCategoryList()                 is MyFragmentNavigation.PlayVideo -&gt; videoPlayerView.loadUrl(event.url)                 is MyFragmentNavigation.OpenProduct -&gt; openProduct(id = event.productId, name = event.otherInfo)                 is MyFragmentNavigation.ShowNetworkError -&gt; showNetworkErrorAlert()             }         }      override fun onViewCreated(view: View, savedInstanceState: Bundle?) {             super.onViewCreated(view, savedInstanceState)             \/\/\u041e\u0434\u0438\u043d Observer \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e ViewModels \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043e\u0434\u043d\u043e\u0433\u043e \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0430             myViewModel.emitter.observe(viewLifecycleOwner, navigationEventsObserver)             myViewModelSecond.emitter.observe(viewLifecycleOwner, navigationEventsObserver)             myViewModelThird.emitter.observe(viewLifecycleOwner, navigationEventsObserver)         }          private fun ShowCategoryList(){         ...     }          private fun openProduct(id: String, name: String){         ...     }          private fun showNetworkErrorAlert(){         ...     } }<\/code><\/pre>\n<p>  \u041f\u043e \u0441\u0443\u0442\u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0441\u044f \u0430\u043d\u0430\u043b\u043e\u0433 Rx-<code>BehaviorSubjec<\/code>t-a \u0438 <code>EventBus<\/code>-a, \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 <code>LiveData<\/code>, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c <code>Emitter<\/code> \u0443\u043c\u0435\u0435\u0442 \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0434\u043e \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044f-Observer-\u0430, \u0438 \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c Observer \u0443\u043c\u0435\u0435\u0442 \u0441\u043b\u0435\u0434\u0438\u0442\u044c \u0437\u0430 \u0442\u0438\u043f\u0430\u043c\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0438 \u043f\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0438\u0445 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u0440\u0430\u0437.<\/p>\n<p>  \u0412\u0435\u043b\u043a\u043e\u043c \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 \u0441 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u043c\u0438.<\/p>\n<p>  <a href=\"https:\/\/github.com\/klukwist\/EventEmitter\">\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438<\/a>.<br \/>  <a href=\"https:\/\/market.homecredit.ru\/\">\u0420\u0430\u0441\u0441\u0440\u043e\u0447\u043a\u0430 \u043e\u0442 \u0411\u0430\u043d\u043a\u0430 \u0425\u043e\u0443\u043c \u041a\u0440\u0435\u0434\u0438\u0442<\/a>.<\/div>\n<p>               <script class=\"js-mediator-script\">!function(e){function t(t,n){if(!(n in e)){for(var r,a=e.document,i=a.scripts,o=i.length;o--;)if(-1!==i[o].src.indexOf(t)){r=i[o];break}if(!r){r=a.createElement(\"script\"),r.type=\"text\/javascript\",r.async=!0,r.defer=!0,r.src=t,r.charset=\"UTF-8\";var d=function(){var e=a.getElementsByTagName(\"script\")[0];e.parentNode.insertBefore(r,e)};\"[object Opera]\"==e.opera?a.addEventListener?a.addEventListener(\"DOMContentLoaded\",d,!1):e.attachEvent(\"onload\",d):d() } } }t(\"\/\/mediator.mail.ru\/script\/2820404\/\",\"_mediator\")}(window);<\/script>      <br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/homecredit\/blog\/477314\/\"> https:\/\/habr.com\/ru\/company\/homecredit\/blog\/477314\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/company\/homecredit\/blog\/477314\/\">\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u0440\u0435\u0447\u044c \u043f\u043e\u0439\u0434\u0435\u0442 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u043e\u0431\u043c\u0435\u043d\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043c\u0435\u0436\u0434\u0443 Activities\/Fragments \u0438 ViewModel \u0432 MVVM. \u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 ViewModel, \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u0432 Activity\/Fragment \u043f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0435 LiveData, \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0438\u0435\u0441\u044f \u0432\u043e ViewModel. \u041d\u043e \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0435\u0434\u0438\u043d\u0438\u0447\u043d\u044b\u0445 (\u0438 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e) \u0441\u043e\u0431\u044b\u0442\u0438\u0439, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0435 \u0438\u043b\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u0434\u0440\u0443\u0433\u043e\u0439 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442? <\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/td\/ey\/cp\/tdeycpvhsyngrmfgzco-mpmjzta.jpeg\">  <\/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-296511","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/296511","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=296511"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/296511\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=296511"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=296511"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=296511"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}