<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Roman Iatcyna on Medium]]></title>
        <description><![CDATA[Stories by Roman Iatcyna on Medium]]></description>
        <link>https://medium.com/@yatsinar?source=rss-c38924ea5900------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*uuA1gMaJ0ntmDezI.</url>
            <title>Stories by Roman Iatcyna on Medium</title>
            <link>https://medium.com/@yatsinar?source=rss-c38924ea5900------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 20:39:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@yatsinar/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[UK Talent Visa tips for an engineer]]></title>
            <link>https://yatsinar.medium.com/uk-talent-visa-tips-for-an-engineer-e591d3ffe15f?source=rss-c38924ea5900------2</link>
            <guid isPermaLink="false">https://medium.com/p/e591d3ffe15f</guid>
            <category><![CDATA[uk]]></category>
            <category><![CDATA[global-talent-visa]]></category>
            <category><![CDATA[engineering]]></category>
            <dc:creator><![CDATA[Roman Iatcyna]]></dc:creator>
            <pubDate>Tue, 23 Feb 2021 19:09:27 GMT</pubDate>
            <atom:updated>2021-02-23T19:17:30.407Z</atom:updated>
            <content:encoded><![CDATA[<p>This is the recap for a Twitter thread of the same topic (<a href="https://twitter.com/Yatsinar/status/1364291659920535553">thread</a>).</p><p>I’ll try to cover the points that aren’t easily derived from public docs, and are based on the lawyer advices I personally received, as well a number of other people stories who were granted this visa.</p><p>I won’t be repeating publicly available info; your best place to start is the official guideline: <a href="https://technation.io/visa-tech-nation-visa-guide/#overview">https://technation.io/visa-tech-nation-visa-guide/#overview</a></p><p>The first topic that scares most people away is the Recommendation Letters. As official guideline says there must be 3 different letters, from executive level staff (excluding the HR). They must be specifically addressed to an endorsing body (Tech Nation) in this case.</p><p>So the very first thought is who can actually provide such letters for your specific case?</p><p>In case of an engineer, the best candidates are Head of Functions (Head of Mobile / Engineering, Web Development). Lead / Staff / Principal engineers are unfortunately not a good option (I don’t know a single case where it worked), even if they’re Google Dev Experts.</p><p>Additionally, Head of Your Department is also pretty safe bet. They’re usually much more business oriented folks, but that’s totally fine. It is also not strictly required that you should have directly reported to that person.</p><p>If you’ve been working in one company for last ~6 years, you can try and find your colleagues who moved on to other companies, or founded their own ones. Say if worked on 3 products in the same company, and 2 Heads moved on to different companies, it will tick two boxes.</p><p>If you ever presented on or organised a conference, maybe done a shared pet project, or massively contributed to someone open-source project, or engaged in some capacity with someone who’s currently a Head or Chief, than this person will do too.</p><p>Once you figured our who to ask for recommendation letter it’s time to begin writing those. Yep, recommendation letters are rarely written by the ones who signs them. Rule of thumb — to prepare a “draft” you would be totally fine to get signed without changes.</p><p>Letters better have a standard structure: introduction of a signee, their experience, current occupation; how did they know you and you worked together.</p><p>Now the most important part in the letter: they should state your achievements. Let’s overview some examples in details, what those achievements can be.</p><p>Important disclaimer: since December 2020, proofs of continued learning and improvement are no longer accepted. Previously online courses and various certifications had been accepted as a proof of talent, now they are not.</p><p>Sole or main ownership of a core library or framework. Rec. letter may describe this library in details; how it impacted the product: i.g. increases in loading speeds by 50% or reduces in errors by 20% increased user conversions, or maybe simply reduced development costs.</p><p>Note that this business impact coverage is super important, but the exact metrics not that much. It’s okay if those metrics have been lost, or if they were too low level and never actually translated to business KPIs. Do you best to estimate the impact in a hindsight.</p><p>Big role in bootstrapping a new product of a company. If you were a sole engineering working on a new product from scratch. No need to have a high role to make an impact in such a setup.</p><p>In this case metrics should be pretty obvious: new users, new revenues, user satisfaction score. If it’s a separate app then the rating will be the best option.</p><p>If you were rewarded significant bonuses, stocks or above the market salary, this can also be mentioned, though shouldn’t be an only point obviously.</p><p>Your achievements is obviously the biggest section of the letter. Don’t be dry here, explain your contribution in detail, in different words, with numbers and metrics. Always keep in mind the person who’s supposed to sign this.</p><p>Those were internal contributions, but the most important part is the external recognition. While Promising Talent applicant can get away without any current recognition only by demonstrating a potential, Exceptional Talent must some record already.</p><p>By the public nature of such achievements, it’s fine for any signee to just list all of those in the letter without being super specific as in “I’m aware that X is well regarded public speaker and gave a speech on Y”. This will later be reinforced with supporting documents.</p><p>If the signee profile implies some professional understanding of your public materials, you might put some personal judgements like “that conference topic was incredibly fresh and innovative”. Head of Business probably shouldn’t comment on your article about Coroutines 😬</p><p>Here your options are quite endless. It can be conferences, meetups, tech articles, authoring online courses, speaking on podcasts etc. State the biggest and most important ones in the letters, the rest you’ll attach in supporting documents.</p><p>And finish the letter with your future plans. Smth like “I’m aware that X is going to setup his own startup”. This one is important, you don’t wanna be looking is someone who just wanna drop the shackles of Tier 2 slavery. You’re expected to have some impactful plans.</p><p>This btw is also required in your Personal Statement. Detailed business plan isn’t needed here, but try exploring your opportunities here. Maybe your niche consultancy / joining an incubator / making your pet project an official business.</p><p>Also you need to describe why UK is a good option for your endeavours, and how UK will benefit from having you. Don’t overkill here, you’re requesting a visa, not government funding. Few lines like “crypto booms, could use some talent” will do the trick.</p><p>Now just a couple of technical live hacks. Letter requires a Headed Paper. There’s no strict definition of what Headed Paper is, neither there’s a way to validate that a document having the company’s logo and address is the official Headed Paper.</p><p>In many cases even the departments in mid-large companies have their own layouts for different purposes. So in this case, a basic Word document, with manually added headers, logos from Google, and a company address will be enough.</p><p>If you manage to get a signature on this custom layout, it pretty much means that the signee is okay with such layout, and so will be Tech Nation. You’ll also need a telephone and email contact of a signee. For highest level officers — a phone of a secretary will be fine.</p><p>So the simplest workflow for all letters — make a layout with company logo in Word / Google Doc, insert your text there, send for a review, when reviewed upload to DocuSign and resend for the signature.</p><p>Now the remaining part is proof documents. You can attach max 10 of those, 3 pages each. Easiest one is your employment contract extract. Either 3 first pages, or you can cut most important parts from there (remuneration, responsibilities, reporting lines).</p><p>Another one is stocks/options certificates. If you have an internal tool for them, screenshots will do.</p><p>For your conferences try and find any recordings. You can put links for the videos to the doc, along with a screenshot from YouTube showing viewings. Don’t be shy if you don’t have millions there. Links to official announcement will do too.</p><p>For a biggest conference you can request some sort of a participation letter. Mobius did one for me, stating number of people in the room and on the live stream.</p><p>Take a screenshot of viewing statistics in your techblog. And a screenshot of all articles there. This will be another document.</p><p>Weird advise: try googling yourself. You might discover that you were referred in someone else’s article. This would make a good additional document. If there’re many mentions of you, probably better pack it into one document.</p><p>Internal contributions proofs might be tougher. Try using some repository commit statistics tools that can demonstrate that you’re the main contributor. Or the dependency charting tools to prove that you artifact is indeed core to the product.</p><p>If you are still shy on documents, you can include additional letters following pretty much the same pattern as recommendation letters. You choice for signee will be less restricted here and you can find someone who’s able to tell something new about you.</p><p>And that would be it. Have someone native to spell check everything, and you’re ready to apply. I might take a look too shall someone here need my help.</p><p>And if you’re only in the beginning of your career, hope it really helps to know what kind of activities will matter in couple years time.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e591d3ffe15f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reactive data flow in Revolut Android app]]></title>
            <link>https://medium.com/revolut/reactive-data-flow-in-revolut-android-app-30a49fa1572e?source=rss-c38924ea5900------2</link>
            <guid isPermaLink="false">https://medium.com/p/30a49fa1572e</guid>
            <category><![CDATA[rxjava]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[reactive-programming]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Roman Iatcyna]]></dc:creator>
            <pubDate>Fri, 29 Nov 2019 10:01:01 GMT</pubDate>
            <atom:updated>2019-11-29T10:01:01.480Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kQTjYjI4qFjP6pb6pQdbgQ.png" /></figure><p>Quite a while ago I <a href="https://medium.com/revolut/building-new-features-using-recyclerview-only-aa7db3d8f282">wrote an article</a> explaining how almost every screen in the Revolut app is done with the RecyclerView.</p><p>Today I want to go further and tell you how all this is backed up by our Reactive Data Layer.</p><p>Let’s start with a high-level overview of the whole architecture:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CX3TivowEaA-bPLUwLb7Jg.png" /><figcaption>Pretty standard data flow architecture.</figcaption></figure><p>One important thing to know about the Revolut app is that it fully supports offline mode, thus there are at least two data sources under the hood of repositories.</p><p>But we wanted to keep this implementation detail abstracted away from developers so they wouldn’t need to bother writing this logic in every Interactor or Presenter. So the offline logic can reside in repositories.</p><p>However, some abstract knowledge about what’s happening with the data is still required and it can be expressed with the following wrapper class data:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/05958ca476ecf5493b56bd570adbaed7/href">https://medium.com/media/05958ca476ecf5493b56bd570adbaed7/href</a></iframe><p>When the <strong>loading</strong> value is true that implies: “there is a high chance data will be updated soon and that the currently present <strong>content</strong> value might be outdated”, regardless of a source. The<strong> error</strong> means that “something went wrong and probably needs some action from user”. Most of the time this is enough for a domain or presentation layer to decide what needs to be rendered.</p><p>The Repository contract looks pretty simple, it returns an Observable with domain class wrapped in above-mentioned Data class:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ab660fce275532071719b8b38610317d/href">https://medium.com/media/ab660fce275532071719b8b38610317d/href</a></iframe><p>The really important thing is how this Observable behaves which really depends on the offline strategy being used under the hood.</p><p>When deciding which offline strategy to implement, the two high-level approaches are — Cache-first or Network-first. Network-first means that cache is only used when a network request fails. Cache-first means that the cache is rendered first, and then network data is only used to update the UI.</p><p>Network-first approach is generally easier to implement, but it‘s also a lot less responsive, as network request results are always awaited before UI is fully rendered. Cache-first usually means that UI needs to support some sort of data differentiating, i.e. fluent transitions from data to data, since it will be the default case when data is first rendered, and then some updated data comes from the network. Lucky us, we have the <a href="https://medium.com/revolut/building-new-features-using-recyclerview-only-aa7db3d8f282">RecyclerView based framework</a> with DiffUtil rendering such transitions.</p><p>The old approach where the UI only observes DB and all network responses go to DB first to be observed later falls under the cache-first category. However, we found this approach to be inefficient since DB querying can be quite time-consuming.</p><p>So the way we went about it at Revolut was to use 2 levels of cache: memory and DB. Memory is superior to DB — DB is basically only queried once, and the result is put to memory, then DB is only used for writes. Let’s take a look at examples.</p><p>One major scenario is when the repository doesn’t contain data in the memory cache. In that case, it needs to query DB first before going to network, as it is much faster than a network call, and we try to populate UI as fast as possible:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*--ln57VT7bF-7mk_8UiNOg.png" /></figure><p>As mentioned before, Memory cache is superior to DB cache, so after the DB query, that data is put to Memory cache to be used later during the app session.</p><p>Here’s the diagram for Observable emits, when the Repository contains the requested data in the memory cache:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6KYsYlSdeFNFFaCttIeNQA.png" /></figure><p>If an item is present in the memory cache, it’s being emitted right after subscription. Then Repository queries the network for the same data and will emit it once it arrives. Remember the <strong>forceReload</strong> param in the observe method? Normally Repo won’t query the network if memory cache is present. <strong>forceReload</strong> literally forces Repo to query the network even if memory cache is present.</p><p>The important part is that we didn’t come up with this algorithm at once. Different places used slightly different strategies, sometimes skipping cache, or terminating the stream after network data arrival. We didn’t use the same approaches as well — somewhere it was Subjects, other places utilised concat or merge operators, and it all looked like a mess at first, but eventually, we identified the common behaviour that is essentially required from a Repository and decided to wrap it inside some single entity.</p><h3>Meet DataObservableDelegate</h3><p>Since the Repository is, in fact, delegating its own responsibility to follow the Data Flow Protocol to this entity, we called it DataObservableDelegate (DOD).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c40b57ae19103ab1bb98e24e9b1f9d7d/href">https://medium.com/media/c40b57ae19103ab1bb98e24e9b1f9d7d/href</a></iframe><p>Here is one example demonstrating a DOD for Portfolio. We now only have to declare the specific endpoint, lambdas for fetching cache from memory and DB, and lambdas for storing to memory and DB.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/610cb217a5a3c8570bf28619d71b25ce/href">https://medium.com/media/610cb217a5a3c8570bf28619d71b25ce/href</a></iframe><p>And DOD actually supports the partial declaration, e.g. only memory cache, or only DB cache.</p><p>Now it will take another line for a repository to expose a single convenient method for the Domain layer to observe Portfolio regardless of a source:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/39ba318c9771ac9baf556aab2f068c12/href">https://medium.com/media/39ba318c9771ac9baf556aab2f068c12/href</a></iframe><p>Domain layer has only one lever to control the data: it’s the <strong>forceReload</strong> flag. The whole algorithm for emitting particular source data might be now drawn as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_afygLX_dsob9mktjtv1cQ.png" /></figure><p>As DOD are delegates of a repository, they are allowed to talk to each other and to depend on each other. In the case of the portfolio, the mapping to Domain models actually depends on another entity: Config, which is separately being delegated to another DOD. And portfolio also has nested entities: Holdings, which are handled by one another instance of DOD. Let’s take a look at how to handle such cases.</p><p>Here the <strong>fromNetwork</strong> lambda returns a stream flatMapping to the getConfig() method. The stream returned by the <strong>fromNetwork</strong> is actually allowed to wait for any other events, it just needs to be careful not to introduce any circular dependencies.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fd310cd2bd4be6e1fce5f5ed11683062/href">https://medium.com/media/fd310cd2bd4be6e1fce5f5ed11683062/href</a></iframe><p>Here you can take a look at the getConfig() implementation: it actually just uses another DOD and extracts data and error from its stream (another useful extension that is commonly used in the project).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/19f83deab18796d98eae56f6049edb4f/href">https://medium.com/media/19f83deab18796d98eae56f6049edb4f/href</a></iframe><p>To deal with nested entities, we can make use of other sets of methods that DOD provides for managing state: <strong>updateAll()</strong>, and <strong>notifyRemoved()</strong>. “Update all” means that all lambdas responsible for storing (toStorage, toMemory) will be invoked with corresponding updated values. <strong>notifyRemoved() </strong>is<strong> </strong>used to notify about an item already removed in order for DOD to produce <em>Data(content = null).</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7b6d4cee97204959825866d68319d9a2/href">https://medium.com/media/7b6d4cee97204959825866d68319d9a2/href</a></iframe><h3>Tests</h3><p>The DOD behaviour described above is covered with tests like the one below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7cfdbb09b38dc1fd3340a6f441a38623/href">https://medium.com/media/7cfdbb09b38dc1fd3340a6f441a38623/href</a></iframe><p>So when new Repositories are implemented normally their tests only need to cover additional logic being introduced in DOD lambdas, like storing nested Holdings in our example.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/90fb90ea659081add9c770ed41cbbf9e/href">https://medium.com/media/90fb90ea659081add9c770ed41cbbf9e/href</a></iframe><h3>Conclusion</h3><p>DataObservableDelegate covers almost all of our needs for providing read-only offline mode. One obvious missing part, for now, is offline writes support. Currently writes or any other changes to the data on the server are only allowed via separate network calls which are responsible for updating the corresponding DOD. But maybe we will explore that area in the future.</p><p>And we’re happy to say that we finally outsourced this as a standalone library, so you can check the code in this repository:</p><p><a href="https://github.com/revolut-mobile/RxData">https://github.com/revolut-mobile/RxData</a></p><p>Or try it out as a library:</p><pre>compile &#39;com.revolut.rxdata:dod:1.0&#39;</pre><h3>Join Revolut</h3><p>See the newest job openings in our Technology department.</p><p><a href="https://www.revolut.com/careers/department/technology">Careers | Revolut</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=30a49fa1572e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/revolut/reactive-data-flow-in-revolut-android-app-30a49fa1572e">Reactive data flow in Revolut Android app</a> was originally published in <a href="https://medium.com/revolut">Revolut Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How the Android team Recycled our Screens]]></title>
            <link>https://medium.com/revolut/building-new-features-using-recyclerview-only-aa7db3d8f282?source=rss-c38924ea5900------2</link>
            <guid isPermaLink="false">https://medium.com/p/aa7db3d8f282</guid>
            <category><![CDATA[apps]]></category>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[recyclerview]]></category>
            <category><![CDATA[fintech]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Roman Iatcyna]]></dc:creator>
            <pubDate>Thu, 07 Sep 2017 17:16:35 GMT</pubDate>
            <atom:updated>2017-11-03T18:11:02.009Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello world! This article is addressed to the Android community and discusses our newly adopted development approach here at <a href="http://www.revolut.com/">Revolut</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8XUXAmY7L4fS4OZu." /><figcaption>Mockups of existing <a href="http://www.revolut.com/">Revolut</a> app screens</figcaption></figure><p>The question of a new approach was raised only recently, as our engineering team started to grow. Despite the plan to launch an array of new features including device insurance, travel insurance, cryptocurrencies, ETFs and more, they all share the same design considerations and follow a common pattern. At <a href="http://www.revolut.com/">Revolut</a>, everything we build is based on small independent modules (think of these as Lego blocks), which come together as one in the final product.</p><h3>A thing of the past</h3><p>Previously, we had implemented screens by laying out all the new elements inside RelativeLayout (or LinearLayout, ConstraintLayout, you name it), mapping every XML view to Fragment/Activity, before setting titles, colours and so on. Different screen states were controlled by each View visibility component, which meant that a screen XML file contained everything that could appear on that screen and also meant that it could take up to 500 strings.</p><p>The problem with this approach was that for each new screen the developers would have to copy and paste View, findViewBylds and so on from one XML to another — absolutely inefficient process. What’s more, the View was often not even a custom <strong>SomeView extends SomeLayout</strong>, but rather just the plain XML hierarchy. Of course you can wrap every part in CustomView or use XML <strong>includes</strong>, but that still leaves Java mapping to be dealt with. To make things even worse, the XML contains every View that could ever occur on the screen. All in all, it was an absolute torture to use such copy-paste-oriented programming. Luckily, our clever team managed to find a solution.</p><h3>RecyclerView Delegates</h3><p>You’ve probably heard of different approaches for creating generic adapters for RecyclerView. Libraries such as AdapterDelegates and LastAdapter give us the luxury to ‘forget’ about the dozens of purposely-built adapters and offer us a better way of applying the composite reuse principle. Essentially, this meant that every adapter can be composed from small blocks only responsible for displaying one concrete model — the solution to our problem.</p><p>We decided to build a common adapter that can display “independent blocks” for every screen. Basically, our adapter is a handmade version of the AdapterDelegates (thanks to <a href="https://medium.com/u/8d7e1c8b6297">Hannes Dorfmann</a> for his truly brilliant idea) and “blocks” are list item models, each displayed by their corresponding delegates.</p><p>It’s not worth going into too much detail here, since the source code can be found on <a href="https://github.com/sockeqwe/AdapterDelegates">github.</a> If you want a more detailed explanation, feel free to read <a href="https://medium.com/u/8d7e1c8b6297">Hannes</a>’s <a href="http://hannesdorfmann.com/android/adapter-delegates">article</a>. After some consideration, we decided to go one step further and make almost every screen a RecyclerView.</p><h3>Recycle everything</h3><p>But what are the actual benefits of ‘recycling’? Since screens are quite small, rarely occupying more than 200% of the screen height, there isn’t much point making these screens RecyclerViews.</p><p>The delegate class represents just a small part of Adapter, being only responsible for displaying one particular data type. Adapter proxies all methods (onBind, onCreate etc.) to the right delegate and the only logic inside Adapter is how to add, keep and select the correct delegate.</p><p>Here’s a Delegate API proxying Adapter method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bkmkHXIFMoXK4gSK." /></figure><p>Each Delegate is only responsible for its own item. Here are some examples:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NvuouBQwiXIG3bB5." /></figure><p>Each delegate represents one Recycler’s view type. So this is essentially just a list of different type models. Every type name is shown to the left of a mockup.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ECallTYkr0M_iev_." /></figure><h3>How to use</h3><p>Suppose we just want to reuse some of the existing delegates:</p><p>1. Create adapter instance inside Fragment/Activity and register needed delegates</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oAj8lNOEG0Efw28y." /></figure><p>2. Make a list of needed objects and set this list to adapter</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VJlaSSWEDzZvIDY8." /></figure><p>3. ….And that’s it. The delegates will do the rest!</p><h3>How to write</h3><p>Sometimes delegate is not available, so you need to create one.</p><p>Bassically, single delegate looks like RecyclerView.Adapter for single type items. The RecyclerView.Adapter should only implement ViewHolder creation (onCreateViewHolder), ViewHolder declaration (nested class extending RecyclerView.ViewHolder) and data binding (onBindViewHolder method).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TiHLf1fIZSn4lbBe." /></figure><p>You may also notice R.layout.delegate_button and small lambda being passed to the superclass. Layout id represents viewType in our example, but we can actually use separate ids and a different XML for the same Delegate. Lambda is the rule determining if this delegate suits the given model and ase the base class is only responsible for invoking that lambda.</p><p>So to sum up, this approach has lots of pros:</p><p>1. Reusability. Say we have transactions list implemented with the delegates. Then we can add few transactions to any screen in couple of strings: add <strong>TransactionItemDelegate</strong> to adapter and then add <strong>TransactionItem</strong> models to the items list of that screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*eOE-Z4DYMH1NksYc." /></figure><p>2. Another advantage is ease of testing. To test one screen, we simply need to test that list of models, its order and attributes for each screen state, because they are all simple data models.</p><p>3. RecyclerView ItemDecorators. You probably noticed that the same elements in some cases are surrounded by shadows and “gaps,” while in others they are arranged in a row on a white background. We do not need separate XMLs for every combination of shadows and gaps, as we can control these via decorators.</p><p>4. RecyclerView animations — ItemsAnimators allow us to animate items between different screen states.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*BmoY_pNWR97ITkEz_WGgpg.gif" /></figure><p>This is only a small part of what can be achieved by using RecyclerView delegates. We have adapted this approach to make complex forms with text input (we have lots of them), we’ve figured out a few tricks for handling separators, shadow and gaps between items with ease, but more on this in our next articles in the <a href="https://medium.com/revolut/engineering-blog/home">Revolut Engineering Blog</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aa7db3d8f282" width="1" height="1" alt=""><hr><p><a href="https://medium.com/revolut/building-new-features-using-recyclerview-only-aa7db3d8f282">How the Android team Recycled our Screens</a> was originally published in <a href="https://medium.com/revolut">Revolut Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kotlin and Rx2. How I wasted 5 hours because of wrong brackets]]></title>
            <link>https://medium.com/android-news/kotlin-and-rx2-how-i-wasted-5-hours-because-of-wrong-brackets-581021717774?source=rss-c38924ea5900------2</link>
            <guid isPermaLink="false">https://medium.com/p/581021717774</guid>
            <category><![CDATA[rxjava]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Roman Iatcyna]]></dc:creator>
            <pubDate>Thu, 24 Aug 2017 06:46:00 GMT</pubDate>
            <atom:updated>2017-08-24T06:46:00.707Z</atom:updated>
            <content:encoded><![CDATA[<p>I heard all that anecdotes about typos destroying a spaceship, wrong brackets blowing up atomic plants, but I thought “Hey, I’m Java developer, it won’t let me build a project with wrong brackets or stuff like that“ so I was pretty confident accepting IntelliSense autocompletions and didn’t know troubles for last few years. Until this time, when Kotlin and Rx2 came into play, the one single replacement of <strong>()</strong> to <strong>{}</strong> completely changed the behaviour of the app without any warnings in compile-time. <br>So let me tell you how I wasted about 5 hours to commit only two characters fix.</p><p>Let’s start right from the troubled code snippet. It’s almost the same I wrote it initially in the project. Can anyone notice what’s wrong in this snippet?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0UFMaCb3_5f30VP9Lriezg.png" /></figure><p>This is a part of some Presenter whose interactor is supposed to upload documents and then let router navigate somewhere. <br><strong>Router.goToNextStep()</strong> is a <strong>Completable</strong> which performs some routing action on subscribe, <strong>toMainThread()</strong> is a shortcut for<strong> observeOn(AndroidScheduler.mainThread())</strong>.</p><p>But for some reason nothing happened after uploading.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*k21sPtn6qXFkpPf89wmSZw.gif" /><figcaption>When .andThen{} doesn’t work</figcaption></figure><p>Let’s skip tons of theories that I had managed to check until I found the actual reason.</p><p>The thing was in <strong>andThen()</strong> operator parameters:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WW_yzRoVDyWxB_bjr_L8cw.png" /></figure><p>It expects CompletableSource to be passed. And this is CompletableSource:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bCcqFY-aXHay5bZhCoLqGg.png" /></figure><p>As you can see this interface can be represented as lambda, since it has only one method. <br>And this is what you can read in official Kotlin docs:</p><blockquote>Note that parentheses in a call can be omitted entirely if the lambda is the only argument to that call.</blockquote><p>Which makes the following string possible:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/1*rSDe7ErMFIM74akrv7JFVQ.png" /></figure><p>But what this lambda is actually expanded to is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/916/1*B91-Kmju7sshZTdExGVgRQ.png" /></figure><p>Where <strong>p0</strong> is actually a subscriber waiting for <strong>onNext()</strong>/<strong>onCompleted(</strong>) calls. So the <strong>router.goToNextStep()</strong> is never even subscribed to.</p><p>So I basically made an empty <strong>Completable</strong> that invokes this line of code <strong>onSubscribe</strong>. And it was executed instead of actual Completable <strong>router.goToNextStep()</strong>.</p><p>And you can say man, just RTFM. But you’ll be surprised how much questions like “mergeWith() not working” or “concatWith() not working” on SOF are caused by these damned brackets.</p><p>And I understand the reasons why this can easily happen to experienced developer using Rx2+Kotlin:</p><p>The first problem is that Android Studio’s autocomplete offer you to use <strong>{}</strong> when the method has only one parameter that can be passed as lambda.</p><p>The second problem is the fact that most of Rx2 methods do accept actual lambdas, some of methods take <strong>Callable&lt;ObservableSource&lt;T&gt;&gt;</strong> instead of <strong>ObservableSource</strong>, others take <strong>Function&lt;T, ObservableSource&lt;R&gt;&gt;</strong>.</p><p><strong>Observable.defer { Observable.just(1) }</strong> — this will work fine.</p><p>Or <strong>observable</strong>.<strong>flatMap { Observable.just(1) } </strong>— will work as expected too (if you’re ignoring incoming param purposely).</p><p>And the third one is the fact that developers are probably got used to Rx1 which always took <strong>Observable</strong> in its <strong>andThen() </strong>method<strong>, </strong>which couldn’t be represented as lambda thus hadn’t been offered to you by IntelliSense.</p><p>To sum up: be careful with Kotlin+Rx2 code using lambdas in parameters where parameter type is <strong>ObservableSource</strong> or <strong>CompletableSource</strong> or <strong>FlowableSource</strong>. Because most likely in that case lambda is not what you want.</p><p>P.S. When the actual fix to mine problem was replace <strong>{}</strong> to <strong>()</strong>:</p><p><em>.andThen(router.goToNextStep())</em></p><p>I actually offer you to use more reliable construction:</p><p><em>.andThen(Completable.defer { router.goToNextStep() } )</em></p><p>In that case calculation of <strong>router.goToNextStep()</strong>, which can depend on some state, will be postponed to the time of actual subscription. When the first option constructs Completable at the time the outer Completable is constructed.</p><p>In my case there were no difference, since <strong>STEP</strong> is static field and router doesn’t have states, but consider this option too.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2F3e491f%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2F3e491f%2F&amp;image=http%3A%2F%2Fapi.screenshotlayer.com%2Fapi%2Fcapture%3Faccess_key%3Dfe59908dad3baab69ffab249a2224b03%26viewport%3D1024x612%26width%3D1000%26url%3Dhttps%253A%252F%252Fupscri.be%252F3e491f%253Fscreenshot&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/fedb9f91e907af2468a937c944ed32ab/href">https://medium.com/media/fedb9f91e907af2468a937c944ed32ab/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=581021717774" width="1" height="1" alt=""><hr><p><a href="https://medium.com/android-news/kotlin-and-rx2-how-i-wasted-5-hours-because-of-wrong-brackets-581021717774">Kotlin and Rx2. How I wasted 5 hours because of wrong brackets</a> was originally published in <a href="https://medium.com/android-news">AndroidPub</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android — WeakReferences — ‘how-not-to’]]></title>
            <link>https://medium.com/android-news/android-weakreferences-how-not-to-5522bb325935?source=rss-c38924ea5900------2</link>
            <guid isPermaLink="false">https://medium.com/p/5522bb325935</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Roman Iatcyna]]></dc:creator>
            <pubDate>Tue, 13 Jun 2017 11:27:11 GMT</pubDate>
            <atom:updated>2017-06-15T09:17:46.444Z</atom:updated>
            <content:encoded><![CDATA[<p>I was really surprised that lot of experienced Android developers do not know or probably forget how WeakReferences actually work, when I came across significant amount of wrong usages inside quite big project. <br>So I wrote this just as friendly quick reminder how not to use WRs.</p><p>The first snippet intended to incapsulate network call execution has single parametrised method doSomeStuff. Command is an abstract entity which loads something from network and calls Callback’s method on finish:</p><pre>public void doSomeStuff(Callback callback) {<br>    <strong>final WeakReference&lt;Callback&lt;Response&gt;&gt; callbackRef = new       WeakReference&lt;&gt;(callback);</strong><br>    new Command().execute(new Callback&lt;Response&gt;() {<br>        @Override<br>        public void onSuccess(Response response) {<br>            <strong>Callback&lt;Response&gt; responseHandler = callbackRef.get();</strong><br>            if (responseHandler != null) {<br>                responseHandler.onSuccess(response);<br>            }<br>        }<br>     });<br>}</pre><p>The idea was to separate the real callback, which is created inside <br>as anonymous class instance, from the callback that will be passed to this method and probably contains links to something that’s undesired to be leaked.</p><p>The problem is in the mechanism WR is based on. In simple words : WeakReference is only alive when someone else is referring via strong link to the object instance (i.e. keeping this object as a class field).</p><p>What do we see searching usages of <strong>doSomeStuff()</strong> is:</p><pre>public void onSomeEvent() {<br>    manager.doSomeStuff(new Callback {<br>        <a href="http://twitter.com/Override">@Override</a><br>        public void onSuccess(Response response) {<br>            Callback&lt;Response&gt; responseHandler = callbackRef.get();<br>            if (responseHandler != null) {<br>                responseHandler.onSuccess(response);<br>            } <br>        }<br>    });<br>}</pre><p>The problem is that the Callback object passed to the manager’s method isn’t referred from any other place, thus WR will be GCed almost instantly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*yhF8VqfKBx2bJLxxNdTTLQ.gif" /><figcaption>When there’s no one to handle response</figcaption></figure><p>Another dangerous thing about WRs that the code above can actually work if app is small or the device carries 4Gb RAM. That’s probably the point why this hasn’t been spotted earlier. But when app starts to grow, memory usage increases rapidly and GC runs way more frequently (even without leaks), all these WR-based callbacks fall off.</p><p>Another piece of code I came across:</p><pre>public void doSomeStuff() {<br>    registerSubscription(repository.loadEntities()<br>                                   .subscribe());<br>}</pre><p><strong>RegisterSubscription()</strong> is actually looking reliable. I hadn’t even opened the implementation in the first time I called this method. But then I noticed a small leak in the Monitor. And decided to look into the code.</p><p>The <strong>registerSubscription()</strong> method is implemented inside BaseFragment and looks like this:</p><pre>void registerSubscription(<a href="http://twitter.com/NonNull">@NonNull</a> Subscription subscription) {<br>    subscriptionList.add(new WeakReference&lt;&gt;(subscription));<br>}</pre><p>The list is being looked up <strong>onStop()</strong> and all subscriptions are being unsubscribed. Except they are not. Because</p><pre>subscriptionList.get(i).get()</pre><p>always returns null.</p><p>Actually all these methods could work if caller kept object in a class field. But this is really unreliable and unobvious contract. When you see <strong>registerSubscription(Subscription subscription)</strong> method you don’t expect that anything else except calling is needed from you. Actually method name should be <strong>registerSubscriptionButDontForgetToStoreTheInstanceOtherwiseThisWontWork(Subscription subscription).</strong></p><p>To sum up: the only objects that worth be keeping inside WeakReferences are objects that are kept by SDK somewhere: <br>Activities, Fragments, Views. Do not store local methods objects in WeakReferences.</p><p>And look into your project now. You likely have such thing inside BaseSomething.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2F3e491f%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2F3e491f%2F&amp;image=http%3A%2F%2Fapi.screenshotlayer.com%2Fapi%2Fcapture%3Faccess_key%3Dfe59908dad3baab69ffab249a2224b03%26viewport%3D1024x612%26width%3D1000%26url%3Dhttps%253A%252F%252Fupscri.be%252F3e491f%253Fscreenshot&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/fedb9f91e907af2468a937c944ed32ab/href">https://medium.com/media/fedb9f91e907af2468a937c944ed32ab/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5522bb325935" width="1" height="1" alt=""><hr><p><a href="https://medium.com/android-news/android-weakreferences-how-not-to-5522bb325935">Android — WeakReferences — ‘how-not-to’</a> was originally published in <a href="https://medium.com/android-news">AndroidPub</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RxAndroid. Grokking retryWhen and repeatWhen operators on examples]]></title>
            <link>https://medium.com/android-news/rx-grokking-retrywhen-and-repeatwhen-on-android-development-examples-af5c3ed0872b?source=rss-c38924ea5900------2</link>
            <guid isPermaLink="false">https://medium.com/p/af5c3ed0872b</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[rxandroid]]></category>
            <category><![CDATA[rxjava]]></category>
            <dc:creator><![CDATA[Roman Iatcyna]]></dc:creator>
            <pubDate>Sat, 29 Apr 2017 17:07:31 GMT</pubDate>
            <atom:updated>2017-05-09T11:53:55.469Z</atom:updated>
            <content:encoded><![CDATA[<p>There’re tons of articles and manuals on Rx operators retryWhen and repeatWhen in Internet. Despite that I often see reluctance to use those due to the syntax complexity and incomprehensible diagrams that offer only stupid and easy cases such as resubscribing with delay or resubscribing several times.</p><p>I’ll show a few examples from Android development practise how to effectively restart chain segments on errors and completions and delegate control to other entities.</p><p>Examples will contain Java-code with Retrolambdas but there’s no problem to rewrite them in Kotlin or pure-Java (but who use Rx with callbacks).</p><h3>Imperative way of restarting the chain</h3><p>Suppose we use Retrofit and start loading in <strong>load()</strong> method. <strong>Repository.getSomething()</strong> returns <strong>Single&lt;Something&gt;().</strong></p><pre><strong>@NonNull</strong><br><strong>private</strong> Subscription loadingSubscription = Subscriptions.unsubscribed();</pre><pre><strong>private</strong> <strong>void</strong> <strong>load</strong>() {<br>    subscription.unsubscribe();<br>    subscription = repository<br>             .getSomething()<br>             .subscribe(result -&gt; {}, err -&gt; {});<br>}</pre><pre><strong>private</strong> <strong>void</strong> <strong>update</strong>() {<br>    load();<br>}</pre><p>We can call <strong>update()</strong> from any updates listener<strong> </strong>(e.g. SwipeRefreshLayout.OnRefreshListener) which in turn will call<strong> load()</strong> where new subscription will be created from scratch.</p><p>I suggest the more reactive (in my opinion) way using above-mentioned <strong>repeatWhen</strong> operator.</p><h3>Reactive way of restarting the chain — repeatWhen operator.</h3><p>Let’s create <strong>PublishSubject </strong>instance<strong> </strong>and pass following lambda to the operator:<br><em>repeatHandler -&gt; repeatHandler.flatMap(nothing -&gt; updateSubject.asObservable())</em></p><pre><strong>@NonNull</strong><br><strong>private</strong> <strong>final</strong> PublishSubject&lt;Void&gt; updateSubject = PublishSubject.create();</pre><pre><strong>private</strong> <strong>void</strong> <strong>load</strong>() {<br>    repository<br>            .getSomething()<br>            .repeatWhen(repeatHandler -&gt;<br>                                repeatHandler.flatMap(nothing -&gt; updateSubject.asObservable()))<br>            .subscribe(result -&gt; {}, err -&gt; {});<br>}</pre><p>When <strong>getSomething() </strong>Single emits the result it calls <strong>onComplete()</strong> right away. But subscriber won’t get completion event, since retryWhen handles this completion till repeatHandler emits complete.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PaNXbT50NX0BN3Q-xiwj4w.png" /><figcaption>Official repeatWhen documentation</figcaption></figure><p>On the picture above repeatHandler emission is shown on the second stream. Resubscribing happens when repeatHandler emits items. That’s why we flat mapped it to our <strong>updateSubject</strong>.</p><p>Now for updating loaded data we are to emit <strong>null</strong> to <strong>updateSubject</strong>. This will cause resubscribing to <strong>getSomething()</strong> Single.</p><pre><strong>private</strong> <strong>void</strong> <strong>update</strong>() {<br>    updateSubject.onNext(<strong>null</strong>);<br>}</pre><p>It’s important to remember that this works only with Singles, which calls <strong>onComplete()</strong> after first emitted object (will work with Observable but only after stream is finished).</p><h3>Reactive way of handling errors — retryWhen operator</h3><p>The same way you can handle errors. Suppose user has no connection which cause an error inside <strong>getSomething()</strong> Single and <strong>onError()</strong> called.</p><p>At this point we can show some kind of No Network dialog asking to check connection and on Ok button press we call <strong>retry() </strong>method.</p><pre><strong>@NonNull</strong><br><strong>private</strong> <strong>final</strong> PublishSubject&lt;Void&gt; retrySubject = PublishSubject.create();</pre><pre><strong>private</strong> <strong>void</strong> <strong>load</strong>() {<br>    repository<br>            .getSomething()<br>            .doOnError(err -&gt; showConnectionDialog())<br>            .retryWhen(retryHandler -&gt; retryHandler.flatMap(nothing -&gt; retrySubject.asObservable()))<br>            .subscribe(result -&gt; {}, err -&gt; {});<br>}</pre><pre><strong>private</strong> <strong>void</strong> <strong>retry</strong>() {<br>    retrySubject.onNext(<strong>null</strong>);<br>}</pre><p>After calling <strong>retrySubject.onNext(null) </strong>the whole chain above<strong> retryWhen() </strong>will resubscribe to<strong> getSomething() s</strong>ource which will retry the request.</p><p>It’s important that <strong>doOnError()</strong> must be declared above the <strong>retryWhen() </strong>in the chain, since <strong>retryWhen()</strong> prevents the chain below from getting error events.</p><p>This concrete example don’t give us any advantage before imperative way and there’s way more code now. But these examples can help to comprehend the reactive way and think reactive patterns.</p><p>In the next example we can finally take advantage using this bunch of code.</p><p>Say we need to combine two sources loading in the <strong>load() </strong>method. We’ll use <strong>combineLatest</strong> for that.</p><p>First source is <strong>repository.getSomething()</strong> loads data from network, other one, <strong>localStorage.fetchSomethingReallyHuge()</strong>, fetches something really huge from the local storage (maybe even processes it somehow).</p><pre><strong>public</strong> <strong>void</strong> <strong>load</strong>() {<br>   Observable.combineLatest(repository.getSomething(),<br>                            localStorage.fetchSomethingReallyHuge(),<br>                            (something, hugeObject) -&gt; <br>                                  <strong>new </strong>Stuff(something, hugeObject))<br>             .subscribe(stuff -&gt; {}, err -&gt; {});<br>}</pre><p>If we handle error imperatively calling <strong>load()</strong> after either error we are going to resubscribe to both sources which is absolutely unnecessary. In case of network error second source successfully emits data — error happens only in first source. In this case imperative way will be slower.</p><p>Let’s see how reactive way looks:</p><pre><strong>public</strong> <strong>void</strong> <strong>load</strong>() {<br>    Observable.combineLatest(<br>            repository.getSomething()<br>                    .retryWhen(retryHandler -&gt;<br>                                       retryHandler.flatMap(<br>                                               err -&gt;   retrySubject.asObservable())),<br>            localStorage.fetchSomethingReallyHuge()<br>                    .retryWhen(retryHandler -&gt;<br>                                       retryHandler.flatMap(<br>                                               err -&gt;                retrySubject.asObservable())),<br>            (something, hugeObject) -&gt; <strong>new</strong> Stuff(something, hugeObject))<br>            .subscribe(stuff -&gt; {}, err -&gt; {});<br>}</pre><p>The charm of this approach is that lambda passed to <strong>retryWhen() </strong>operator is only executed after error in the source. Hence if error happens in one source then only this source gets re-subscription and <strong>combineLatest</strong> will wait for its result.</p><p>And if error happens in both sources then both will get re-subscription.</p><h3>Delegating error handling</h3><p>Next step we can delegate error management to abstract entity called <strong>RetryManager</strong>.</p><p>Also we can prepare for migrating to Rx2 and replace <strong>nulls</strong> from our streams (they are forbidden to emission). Let’s create a simple class for the purpose of being our event object:</p><pre><strong>public</strong> <strong>class</strong> <strong>RetryEvent</strong> {</pre><pre>}</pre><p>Later we can add some stuff there: different flags, error codes etc. But that’s another story.</p><p><strong>RetryManager</strong> interface looks something like this:</p><pre><strong>interface</strong> <strong>RetryManager</strong> {</pre><pre>    Observable&lt;RetryEvent&gt; <strong>observeRetries</strong>(@NonNull Throwable error);</pre><pre>}</pre><p>Its implementation may check errors, show dialogs, setup silent timeout — anything business logic requires. And to listen callbacks from any UI component to emit <strong>RetryEvent </strong>into any<strong> </strong>chain.</p><p>Previous example with <strong>RetryEvent</strong> usage looks something like this:</p><pre><em>//pass this through constructor, DI or use singleton (please don&#39;t)</em><br><strong>private</strong> <strong>final</strong> RetryManager retryManager;</pre><pre><strong>public</strong> <strong>void</strong> <strong>load</strong>() {<br>    Observable.combineLatest(<br>            repository.getSomething()<br>                    .retryWhen(retryHandler -&gt;<br>                                       retryHandler.flatMap(<br>                                               err -&gt; retryManager.observeRetries())),<br>            localStorage.fetchSomethingReallyHuge()<br>                    .retryWhen(retryHandler -&gt;<br>                                       retryHandler.flatMap(<br>                                               nothing -&gt; retryManager.observeRetries())),<br>            (something, hugeObject) -&gt; <strong>new</strong> Stuff(something, hugeObject))<br>            .subscribe(stuff -&gt; {}, err -&gt; {});<br>}</pre><p>In a simple manner we delegated error handling logic to the third party entity which may be injected as a dependency and can control any chain in project that uses <strong>retryWhen</strong>.</p><p>I hope my examples will help to comprehend this two undeservedly unpopular operators.</p><p>Article had been first published in Habrahabr.ru in Russian and was translated to English by its author.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2F3e491f%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2F3e491f%2F&amp;image=http%3A%2F%2Fapi.screenshotlayer.com%2Fapi%2Fcapture%3Faccess_key%3Dfe59908dad3baab69ffab249a2224b03%26viewport%3D1024x612%26width%3D1000%26url%3Dhttps%253A%252F%252Fupscri.be%252F3e491f%253Fscreenshot&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/fedb9f91e907af2468a937c944ed32ab/href">https://medium.com/media/fedb9f91e907af2468a937c944ed32ab/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=af5c3ed0872b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/android-news/rx-grokking-retrywhen-and-repeatwhen-on-android-development-examples-af5c3ed0872b">RxAndroid. Grokking retryWhen and repeatWhen operators on examples</a> was originally published in <a href="https://medium.com/android-news">AndroidPub</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>