{"id":294593,"date":"2019-09-12T09:00:56","date_gmt":"2019-09-12T09:00:56","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=294593"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=294593","title":{"rendered":"\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 Paging library \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u043e \u0441 Realm"},"content":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\">\u041d\u0430 \u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u043c\u0438\u0442\u0438\u043d\u0433\u043e\u0432 Android-\u043e\u0442\u0434\u0435\u043b\u0430 \u044f \u043f\u043e\u0434\u0441\u043b\u0443\u0448\u0430\u043b, \u043a\u0430\u043a \u043e\u0434\u0438\u043d \u0438\u0437 \u043d\u0430\u0448\u0438\u0445 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0441\u0434\u0435\u043b\u0430\u043b \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0443\u044e \u043b\u0438\u0431\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u00ab\u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439\u00bb \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 Realm, \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0432 \u00ab\u043b\u0435\u043d\u0438\u0432\u0443\u044e \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0443\u00bb \u0438 \u043d\u043e\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438.<\/p>\n<p>  \u0421\u0434\u0435\u043b\u0430\u043b \u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0447\u0435\u0440\u043d\u043e\u0432\u0438\u043a \u0441\u0442\u0430\u0442\u044c\u0438, \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u043e\u0447\u0442\u0438 \u0432 \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u043d\u043e\u043c \u0432\u0438\u0434\u0435, \u0434\u0435\u043b\u044e\u0441\u044c \u0441 \u0432\u0430\u043c\u0438. \u041e\u043d \u0441\u043e \u0441\u0432\u043e\u0435\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b \u043f\u043e\u043e\u0431\u0435\u0449\u0430\u043b, \u0447\u0442\u043e \u0440\u0430\u0437\u0433\u0440\u0435\u0431\u0451\u0442\u0441\u044f \u0441 \u0437\u0430\u0434\u0430\u0447\u0430\u043c\u0438 \u0438 \u043f\u0440\u0438\u0434\u0451\u0442 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438, \u0435\u0441\u043b\u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442 \u0432\u043e\u043f\u0440\u043e\u0441\u044b.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h2>\u0411\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0438 \u0433\u043e\u0442\u043e\u0432\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f<\/h2>\n<p>  \u041e\u0434\u043d\u0430 \u0438\u0437 \u0437\u0430\u0434\u0430\u0447, \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u044b \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u0435\u043c\u0441\u044f \u2014 \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0441\u043f\u0438\u0441\u043a\u043e\u043c, \u043f\u0440\u0438 \u043f\u0440\u043e\u043a\u0440\u0443\u0447\u0438\u0432\u0430\u043d\u0438\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e, \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u0434\u0433\u0440\u0443\u0436\u0430\u044e\u0442\u0441\u044f \u0438 \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043d\u0435\u0437\u0430\u043c\u0435\u0442\u043d\u043e \u0434\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u0414\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u044d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a, \u0447\u0442\u043e \u043e\u043d \u0441\u043a\u0440\u043e\u043b\u043b\u0438\u0442 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a.<\/p>\n<p>  \u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439:<\/p>\n<ul>\n<li> \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u043a\u044d\u0448\u0430 \u0434\u043b\u044f \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b;<\/li>\n<li> \u0435\u0441\u043b\u0438 \u043a\u044d\u0448 \u043f\u0443\u0441\u0442 \u2014 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u0430, \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c \u0438\u0445 \u0432 \u0441\u043f\u0438\u0441\u043a\u0435 \u0438 \u043f\u0438\u0448\u0435\u043c \u0432 \u0411\u0414;<\/li>\n<li> \u0435\u0441\u043b\u0438 \u043a\u044d\u0448 \u0435\u0441\u0442\u044c \u2014 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0435\u0433\u043e \u0432 \u0441\u043f\u0438\u0441\u043e\u043a;<\/li>\n<li> \u0435\u0441\u043b\u0438 \u0434\u043e\u0445\u043e\u0434\u0438\u043c \u0434\u043e \u043a\u043e\u043d\u0446\u0430 \u0411\u0414, \u0442\u043e \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430, \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c \u0438\u0445 \u0432 \u0441\u043f\u0438\u0441\u043a\u0435 \u0438 \u043f\u0438\u0448\u0435\u043c \u0432 \u0411\u0414.<\/li>\n<\/ul>\n<p>  \u0423\u043f\u0440\u043e\u0449\u0451\u043d\u043d\u043e: \u0434\u043b\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0441\u043f\u0438\u0441\u043a\u0430 \u0432 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043e\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u044d\u0448, \u0430 \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u043c \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043d\u043e\u0432\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u043e\u043d\u0435\u0446 \u043a\u044d\u0448\u0430.<\/p>\n<p>  \u0414\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u043f\u0440\u043e\u043a\u0440\u0443\u0442\u043a\u0438 (endless scrolling) \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0433\u043e\u0442\u043e\u0432\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f:<\/p>\n<ul>\n<li>\u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e RecyclerView.OnScrollListener, \u0438\u043b\u0438 \u043d\u0430\u0439\u0442\u0438 \u043d\u0430 Github \u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u0433\u043e\u0442\u043e\u0432\u043e\u0435, \u0432\u0440\u043e\u0434\u0435 <a href=\"https:\/\/gist.github.com\/rogerhu\/d041b6467536842aa986\">EndlessRecyclerViewScrollListener<\/a>;<\/li>\n<li><a href=\"https:\/\/github.com\/matzuk\/PaginationSample\">\u0440\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434<\/a>, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f RxJava \u0434\u043b\u044f \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u043f\u043e\u0434\u0433\u0440\u0443\u0437\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445;<\/li>\n<li><a href=\"https:\/\/github.com\/cymcsg\/UltimateRecyclerView\">\u0433\u043e\u0442\u043e\u0432\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0441\u043f\u0438\u0441\u043a\u0430<\/a>;<\/li>\n<li><a href=\"https:\/\/developer.android.com\/topic\/libraries\/architecture\/paging\/\">Paging library \u0438\u0437 Jetpack<\/a>.<\/li>\n<\/ul>\n<p>  \u041c\u044b \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043c\u043e\u0431\u0438\u043b\u044c\u043d\u043e\u0439 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <a href=\"https:\/\/realm.io\">Realm<\/a>, \u0438, \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0432 \u0432\u0441\u0435 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b, \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b\u0438\u0441\u044c \u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 Paging library. <\/p>\n<p>  \u041d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u0437\u0433\u043b\u044f\u0434 Android Paging Library \u2014 \u043e\u0442\u043b\u0438\u0447\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 sqlite \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u043e \u0441 Room \u043e\u0442\u043b\u0438\u0447\u043d\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0411\u0414. \u041e\u0434\u043d\u0430\u043a\u043e, \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 Realm \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0411\u0414 \u043c\u044b \u043b\u0438\u0448\u0430\u0435\u043c\u0441\u044f \u0432\u0441\u0435\u0433\u043e, \u043a \u0447\u0435\u043c\u0443 \u0442\u0430\u043a \u043f\u0440\u0438\u0432\u044b\u043a\u043b\u0438 \u2014 \u043b\u0435\u043d\u0438\u0432\u043e\u0439 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 (lazy loading) \u0438 <a href=\"https:\/\/realm.io\/docs\/java\/latest\/#notifications\">data change notifications<\/a>. \u041d\u0430\u043c \u0436\u0435 \u043d\u0435 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u043e\u0442\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0442 \u0432\u0441\u0435\u0445 \u044d\u0442\u0438\u0445 \u0432\u0435\u0449\u0435\u0439, \u043d\u043e \u0432 \u0442\u043e \u0436\u0435 \u0432\u0440\u0435\u043c\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Paging library.<\/p>\n<h2>\u041c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c, \u043c\u044b \u043d\u0435 \u043f\u0435\u0440\u0432\u044b\u0435, \u043a\u043e\u043c\u0443 \u044d\u0442\u043e \u043d\u0443\u0436\u043d\u043e<\/h2>\n<p>  \u0411\u044b\u0441\u0442\u0440\u044b\u0439 \u043f\u043e\u0438\u0441\u043a \u0441\u0440\u0430\u0437\u0443 \u0432\u044b\u0434\u0430\u043b \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u2014 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <a href=\"https:\/\/github.com\/Zhuinden\/realm-monarchy\">Realm monarchy<\/a>. \u041f\u043e\u0441\u043b\u0435 \u0431\u0435\u0433\u043b\u043e\u0433\u043e \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f \u0432\u044b\u044f\u0441\u043d\u0438\u043b\u043e\u0441\u044c, \u0447\u0442\u043e \u044d\u0442\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0430\u0441 \u043d\u0435 \u0443\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442 \u2014 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043d\u0438 \u043b\u0435\u043d\u0438\u0432\u0443\u044e \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0443, \u043d\u0438 notifications. \u041f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0451.<\/p>\n<p>  \u0418\u0442\u0430\u043a, \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<ol>\n<li>\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Realm;<\/li>\n<li>\u0421\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c lazy loading \u0434\u043b\u044f Realm;<\/li>\n<li>\u0421\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c notifications;<\/li>\n<li>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Paging library \u0434\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0411\u0414 \u0438 \u043f\u043e\u0441\u0442\u0440\u0430\u043d\u0438\u0447\u043d\u043e\u0439 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430, \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u044d\u0442\u043e \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 Paging library.<\/li>\n<\/ol>\n<p>  \u0421 \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 Paging library, \u0438 \u0447\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u043c \u0431\u044b\u043b\u043e \u0445\u043e\u0440\u043e\u0448\u043e.<\/p>\n<p>  \u041a\u0440\u0430\u0442\u043a\u043e \u2014 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432:<\/p>\n<p>  <b>DataSource<\/b> \u2014 \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u0441\u0442\u0440\u0430\u043d\u0438\u0447\u043d\u043e.<br \/>  \u0418\u043c\u0435\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438: PageKeyedDataSource, PositionalDataSource \u0438 ItemKeyedDataSource, \u043d\u043e \u0438\u0445 \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0435\u0439\u0447\u0430\u0441 \u043d\u0430\u043c \u043d\u0435 \u0432\u0430\u0436\u043d\u043e.<\/p>\n<p>  <b>PagedList<\/b> \u2014 \u0441\u043f\u0438\u0441\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0434\u0433\u0440\u0443\u0436\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u0440\u0446\u0438\u044f\u043c\u0438 \u0438\u0437 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430 DataSource. \u041d\u043e \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c Realm \u2014 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u0440\u0446\u0438\u044f\u043c\u0438 \u0434\u043b\u044f \u043d\u0430\u0441 \u043d\u0435 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u0430.<br \/>  PagedListAdapter \u2014 \u043a\u043b\u0430\u0441\u0441, \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0437\u0430 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u044b\u0445 PagedList.<\/p>\n<p>  \u0412 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0430\u0445 \u044d\u0442\u0430\u043b\u043e\u043d\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u044b \u0443\u0432\u0438\u0434\u0438\u043c, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441\u0445\u0435\u043c\u0430.<\/p>\n<p>  1. PagedListAdapter \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 getItem(int index) \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0434\u043b\u044f PagedList \u043c\u0435\u0442\u043e\u0434 loadAround(int index):<\/p>\n<pre><code class=\"kotlin\">\/** * Get the item from the current PagedList at the specified index. * &lt;p&gt; * Note that this operates on both loaded items and null padding within the PagedList. * * @param index Index of item to get, must be &gt;= 0, and &lt; {@link #getItemCount()}. * @return The item, or null, if a null placeholder is at the specified position. *\/ @SuppressWarnings(\"WeakerAccess\") @Nullable public T getItem(int index) {    if (mPagedList == null) {        if (mSnapshot == null) {            throw new IndexOutOfBoundsException(                    \"Item count is zero, getItem() call is invalid\");        } else {            return mSnapshot.get(index);        }    }     mPagedList.loadAround(index);    return mPagedList.get(index); } <\/code><\/pre>\n<p>  2. PagedList \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 void tryDispatchBoundaryCallbacks(boolean post):<\/p>\n<pre><code class=\"kotlin\">\/** * Load adjacent items to passed index. * * @param index Index at which to load. *\/ public void loadAround(int index) {    if (index &lt; 0 || index &gt;= size()) {        throw new IndexOutOfBoundsException(\"Index: \" + index + \", Size: \" + size());    }     mLastLoad = index + getPositionOffset();    loadAroundInternal(index);     mLowestIndexAccessed = Math.min(mLowestIndexAccessed, index);    mHighestIndexAccessed = Math.max(mHighestIndexAccessed, index);     \/*     * mLowestIndexAccessed \/ mHighestIndexAccessed have been updated, so check if we need to     * dispatch boundary callbacks. Boundary callbacks are deferred until last items are loaded,     * and accesses happen near the boundaries.     *     * Note: we post here, since RecyclerView may want to add items in response, and this     * call occurs in PagedListAdapter bind.     *\/    tryDispatchBoundaryCallbacks(true); } <\/code><\/pre>\n<p>  3. \u0412 \u044d\u0442\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u043f\u043e\u0440\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0443:<\/p>\n<pre><code class=\"kotlin\">\/** * Call this when mLowest\/HighestIndexAccessed are changed, or * mBoundaryCallbackBegin\/EndDeferred is set. *\/ @SuppressWarnings(\"WeakerAccess\") \/* synthetic access *\/ void tryDispatchBoundaryCallbacks(boolean post) {    final boolean dispatchBegin = mBoundaryCallbackBeginDeferred            &amp;&amp; mLowestIndexAccessed &lt;= mConfig.prefetchDistance;    final boolean dispatchEnd = mBoundaryCallbackEndDeferred            &amp;&amp; mHighestIndexAccessed &gt;= size() - 1 - mConfig.prefetchDistance;     if (!dispatchBegin &amp;&amp; !dispatchEnd) {        return;    }     if (dispatchBegin) {        mBoundaryCallbackBeginDeferred = false;    }    if (dispatchEnd) {        mBoundaryCallbackEndDeferred = false;    }    if (post) {        mMainThreadExecutor.execute(new Runnable() {            @Override            public void run() {                dispatchBoundaryCallbacks(dispatchBegin, dispatchEnd);            }        });    } else {        dispatchBoundaryCallbacks(dispatchBegin, dispatchEnd);    } } <\/code><\/pre>\n<p>  4. \u0412 \u0438\u0442\u043e\u0433\u0435 \u0432\u0441\u0435 \u0432\u044b\u0437\u043e\u0432\u044b \u043f\u043e\u043f\u0430\u0434\u0430\u044e\u0442 \u0432 DataSource, \u0433\u0434\u0435 \u0438 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0411\u0414 \u0438\u043b\u0438 \u0438\u0437 \u0434\u0440\u0443\u0433\u0438\u0445 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432:<\/p>\n<pre><code class=\"kotlin\">@SuppressWarnings(\"WeakerAccess\") \/* synthetic access *\/ void dispatchBoundaryCallbacks(boolean begin, boolean end) {    \/\/ safe to deref mBoundaryCallback here, since we only defer if mBoundaryCallback present    if (begin) {        \/\/noinspection ConstantConditions        mBoundaryCallback.onItemAtFrontLoaded(mStorage.getFirstLoadedItem());    }    if (end) {        \/\/noinspection ConstantConditions        mBoundaryCallback.onItemAtEndLoaded(mStorage.getLastLoadedItem());    } } <\/code><\/pre>\n<p>  \u041f\u043e\u043a\u0430 \u0432\u0441\u0435 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u2014 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0432\u0437\u044f\u0442\u044c \u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c. \u0412\u0441\u0435\u0433\u043e-\u0442\u043e \u0434\u0435\u043b\u043e\u0432:<\/p>\n<ol>\n<li>\u0421\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0432\u043e\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e PagedList (RealmPagedList) \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 RealmModel;<\/li>\n<li>\u0421\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0432\u043e\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e PagedStorage (RealmPagedStorage), \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 OrderedRealmCollection;<\/li>\n<li>\u0421\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0432\u043e\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e DataSource (RealmDataSource) \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 RealmModel;<\/li>\n<li>\u0421\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u0430\u0434\u0430\u043f\u0442\u0435\u0440 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 RealmList;<\/li>\n<li>\u0423\u0431\u0440\u0430\u0442\u044c \u043d\u0435\u043d\u0443\u0436\u043d\u043e\u0435, \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043d\u0443\u0436\u043d\u043e\u0435;<\/li>\n<li>\u0413\u043e\u0442\u043e\u0432\u043e.<\/li>\n<\/ol>\n<p>  \u041e\u043f\u0443\u0441\u0442\u0438\u043c \u043d\u0435\u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0434\u0435\u0442\u0430\u043b\u0438, \u0438 \u0432\u043e\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u2014 <a href=\"https:\/\/github.com\/Magora-Android\/RealmPagination\">\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 RealmPagination<\/a>. \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439.<\/p>\n<p>  0. \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442:<\/p>\n<pre><code class=\"kotlin\">allprojects {     repositories {         maven { url \"https:\/\/jitpack.io\" }     } } implementation 'com.github.magora-android:realmpagination:1.0.0'<\/code><\/pre>\n<p>  1. \u0421\u043e\u0437\u0434\u0430\u0451\u043c \u043a\u043b\u0430\u0441\u0441 User:<\/p>\n<pre><code class=\"kotlin\">@Serializable @RealmClass open class User : RealmModel {    @PrimaryKey    @SerialName(\"id\") var id: Int = 0    @SerialName(\"login\") var login: String? = null    @SerialName(\"avatar_url\") var avatarUrl: String? = null    @SerialName(\"url\") var url: String? = null    @SerialName(\"html_url\") var htmlUrl: String? = null    @SerialName(\"repos_url\") var reposUrl: String? = null }<\/code><\/pre>\n<p>  2. \u0421\u043e\u0437\u0434\u0430\u0451\u043c DataSource:<\/p>\n<pre><code class=\"kotlin\">class UsersListDataSourceFactory(    private val getUsersUseCase: GetUserListUseCase,    private val localStorage: UserDataStorage ) : RealmDataSource.Factory&lt;Int, User&gt;() {     override fun create(): RealmDataSource&lt;Int, User&gt; {        val result = object : RealmPageKeyedDataSource&lt;Int, User&gt;() {             override fun loadInitial(params: LoadInitialParams&lt;Int&gt;, callback: LoadInitialCallback&lt;Int, User&gt;) {...}             override fun loadBefore(params: LoadParams&lt;Int&gt;, callback: LoadCallback&lt;Int, User&gt;) { \t...            }             override fun loadAfter(params: LoadParams&lt;Int&gt;, callback: LoadCallback&lt;Int, User&gt;) { \t...            }        }        return result    }     override fun destroy() {     } }<\/code><\/pre>\n<p>  3. \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0430\u0434\u0430\u043f\u0442\u0435\u0440:<\/p>\n<pre><code class=\"kotlin\">class AdapterUserList(    data: RealmPagedList&lt;*, User&gt;,    private val onClick: (Int, Int) -&gt; Unit ) : BaseRealmListenableAdapter&lt;User, RecyclerView.ViewHolder&gt;(data) {     override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {        val view = LayoutInflater.from(parent.context).inflate(R.layout.item_user, parent, false)        return UserViewHolder(view)    }     override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {       ...    } }<\/code><\/pre>\n<p>  4. \u0421\u043e\u0437\u0434\u0430\u0451\u043c ViewModel:<\/p>\n<pre><code class=\"kotlin\">private const val INITIAL_PAGE_SIZE = 50 private const val PAGE_SIZE = 30 private const val PREFETCH_DISTANCE = 10  class VmUsersList(    app: Application,    private val dsFactory: UsersListDataSourceFactory, ) : AndroidViewModel(app), KoinComponent {     val contentData: RealmPagedList&lt;Int, User&gt;        get() {            val config = RealmPagedList.Config.Builder()                .setInitialLoadSizeHint(INITIAL_PAGE_SIZE)                .setPageSize(PAGE_SIZE)                .setPrefetchDistance(PREFETCH_DISTANCE)                .build()             return RealmPagedListBuilder(dsFactory, config)                .setInitialLoadKey(0)                .setRealmData(localStorage.getUsers().users)                .build()        }       fun refreshData() { ... }     fun retryAfterPaginationError() { ...  }     override fun onCleared() {        super.onCleared()        dsFactory.destroy()    } }<\/code><\/pre>\n<p>  5. \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0441\u043f\u0438\u0441\u043e\u043a:<\/p>\n<pre><code class=\"kotlin\"> recyclerView.layoutManager = LinearLayoutManager(context) recyclerView.adapter = AdapterUserList(viewModel.contentData) { user, position -&gt; \/\/... }<\/code><\/pre>\n<p>  6. \u0421\u043e\u0437\u0434\u0430\u0451\u043c \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u0441\u043e \u0441\u043f\u0438\u0441\u043a\u043e\u043c:<\/p>\n<pre><code class=\"kotlin\">class FragmentUserList : BaseFragment() {  override fun onViewCreated(view: View, savedInstanceState: Bundle?) {  super.onViewCreated(view, savedInstanceState) recyclerView.layoutManager = LinearLayoutManager(context) recyclerView.adapter = AdapterUserList(viewModel.contentData) { user, position -&gt;  ...   } }<\/code><\/pre>\n<p>  7. \u0413\u043e\u0442\u043e\u0432\u043e.<\/p>\n<p>  \u041f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c, \u0447\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Realm \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u043e\u0441\u0442\u043e, \u043a\u0430\u043a \u0438 Room. \u0421\u0435\u0440\u0433\u0435\u0439 \u0432\u044b\u043b\u043e\u0436\u0438\u043b <a href=\"https:\/\/github.com\/Magora-Android\/RealmPagination\">\u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0438 \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f<\/a>. \u041d\u0435 \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u043f\u0438\u043b\u0438\u0442\u044c \u0435\u0449\u0451 \u043e\u0434\u0438\u043d \u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434, \u0435\u0441\u043b\u0438 \u0441\u0442\u043e\u043b\u043a\u043d\u0451\u0442\u0435\u0441\u044c \u0441 \u043f\u043e\u0445\u043e\u0436\u0435\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0435\u0439.<\/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\/post\/467097\/\"> https:\/\/habr.com\/ru\/post\/467097\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\">\u041d\u0430 \u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u043c\u0438\u0442\u0438\u043d\u0433\u043e\u0432 Android-\u043e\u0442\u0434\u0435\u043b\u0430 \u044f \u043f\u043e\u0434\u0441\u043b\u0443\u0448\u0430\u043b, \u043a\u0430\u043a \u043e\u0434\u0438\u043d \u0438\u0437 \u043d\u0430\u0448\u0438\u0445 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0441\u0434\u0435\u043b\u0430\u043b \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0443\u044e \u043b\u0438\u0431\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u00ab\u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439\u00bb \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 Realm, \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0432 \u00ab\u043b\u0435\u043d\u0438\u0432\u0443\u044e \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0443\u00bb \u0438 \u043d\u043e\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438.<\/p>\n<p>  \u0421\u0434\u0435\u043b\u0430\u043b \u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0447\u0435\u0440\u043d\u043e\u0432\u0438\u043a \u0441\u0442\u0430\u0442\u044c\u0438, \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u043e\u0447\u0442\u0438 \u0432 \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u043d\u043e\u043c \u0432\u0438\u0434\u0435, \u0434\u0435\u043b\u044e\u0441\u044c \u0441 \u0432\u0430\u043c\u0438. \u041e\u043d \u0441\u043e \u0441\u0432\u043e\u0435\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b \u043f\u043e\u043e\u0431\u0435\u0449\u0430\u043b, \u0447\u0442\u043e \u0440\u0430\u0437\u0433\u0440\u0435\u0431\u0451\u0442\u0441\u044f \u0441 \u0437\u0430\u0434\u0430\u0447\u0430\u043c\u0438 \u0438 \u043f\u0440\u0438\u0434\u0451\u0442 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438, \u0435\u0441\u043b\u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442 \u0432\u043e\u043f\u0440\u043e\u0441\u044b.  <\/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-294593","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/294593","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=294593"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/294593\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=294593"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=294593"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=294593"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}