<?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 Bogdan Voiko on Medium]]></title>
        <description><![CDATA[Stories by Bogdan Voiko on Medium]]></description>
        <link>https://medium.com/@bogdan.vvv?source=rss-fbe76663c785------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*roiDemIyBZFtdp25c17yVQ.jpeg</url>
            <title>Stories by Bogdan Voiko on Medium</title>
            <link>https://medium.com/@bogdan.vvv?source=rss-fbe76663c785------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 18:19:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bogdan.vvv/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[Breeze deep links with Android Architecture Components Navigation]]></title>
            <link>https://medium.com/android-news/breeze-deep-links-with-android-architecture-components-navigation-98cc8da83928?source=rss-fbe76663c785------2</link>
            <guid isPermaLink="false">https://medium.com/p/98cc8da83928</guid>
            <category><![CDATA[deep-linking]]></category>
            <category><![CDATA[navigation]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[architecture-components]]></category>
            <dc:creator><![CDATA[Bogdan Voiko]]></dc:creator>
            <pubDate>Mon, 11 Jun 2018 14:45:05 GMT</pubDate>
            <atom:updated>2018-10-13T20:33:49.883Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YIQHQmS_wneHSl3Ur055OA.png" /><figcaption>googlesamples/android-architecture-components/NavigationBasicSample</figcaption></figure><p>While developing Android apps you can face this exact task “Integrate Deep Linking support” and it’ll be your nightmare because of several reasons. And those reasons are:</p><ul><li>Add all links to manifest file (also should consider http or https)</li><li>Handle link parameters (it could be GET Query or path parameters)</li><li>Handle user navigation after opening app from deep link</li></ul><p>Each of those reasons can be painful one by one, but all together it’s straight hell to handle.</p><h4>How to handle either http, or https?</h4><p>It’s simple, you just declare two filters. Isn’t it simple or obvious?…</p><h4>How to extract parameters</h4><p>You just parse them into Uri and then do your business. But even if it’s quite simple for query parameter :</p><pre>val myUri = Uri.parse(myLink) // http://mysite.com?myParam=VALUE<br>val myParamValue = myUri.getQueryParameter(&quot;myParam&quot;)</pre><p>It’s not as simple for path parameters:</p><pre>val myUri = Uri.parse(myLink) // http://mysite.com/VALUE/stuff<br>val myParamValue = myUri.<em>pathSegments</em>[0]</pre><p>Here you need to know exactly what and where it’ll be in order to access it</p><h4>How to handle navigation</h4><p>Here’s most painful part. How do you handle if user press back/up? Imagine situation where you have links like this http://mysite.com/posts/POST_ID/comments and your UI flow like following Posts -&gt; Post -&gt; Comments , so you need to return user to post screen and then on another back press you need to show posts screen. How can you achieve this?</p><ol><li>You can set up global deep links handler that will not only start comments screen, but also fill stack with other screens (posts and post in this case). Something like this:</li></ol><pre>val stackBuilder = TaskStackBuilder.create(this)<br>stackBuilder.addParentStack(MainActivity.class)<br>stackBuilder.addNextIntent(postIntent)<br>stackBuilder.addNextIntent(commentsIntent)<br>stackBuilder.startActivities()</pre><p>2. You can handle this situation directly when comments screen is about to close</p><pre>fun closeScreen() {<br>    if (<em>isTaskRoot</em>) {<br>        // do same as above but without comments<br>    }<br>    finish()<br>}</pre><h3>AAC Navigation to rescue</h3><p>When I read release notes for AAC Navigation I was like “wow, it is it?” . Yes, they had full chapter to describe Deep Link solution.</p><h4>Briefly about AAC Navigation</h4><p>Android Architecture Components Navigation it’s Google’s solution to navigation handling in Android. With it you describe your navigation destinations and required actions (move from one destination to another) in XML file and then you’r just calling Navigator.navigate(id) to go to some destination.</p><p>And also worth considering that it can be done and pretty visualized in visual editor window.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/853/1*jtjmSPj8pIZM41-PwGvqog.png" /><figcaption>Navigation for my example</figcaption></figure><p>You can read more about Android Navigation Architecture Component in <a href="https://medium.com/u/8c3c80794b1f">Jovche Mitrejchevski</a> article:</p><p><a href="https://proandroiddev.com/android-navigation-arch-component-a-curious-investigation-3e56e24126e1">Android Navigation Arch Component — A Curious Investigation</a></p><h4>Deep stuff</h4><p>And finally why are we all here, the new way to handle Deep Links by Google looks like this</p><pre>&lt;fragment<br>    android:id=&quot;@+id/pagesListFragment&quot;<br>    android:name=&quot;com.ekalips.navigatortest.pages.PagesListFragment&quot;<br>    android:label=&quot;Pages&quot;<br>    tools:layout=&quot;@layout/fragment_pages_list&quot;&gt;<br>    &lt;action<br>        android:id=&quot;@+id/viewPage&quot;<br>        app:destination=&quot;@id/pageFragment&quot;/&gt;<br>    &lt;deepLink app:uri=&quot;myapp.com&quot; /&gt;<br>&lt;/fragment&gt;</pre><p>Yep, that small fragment with deepLink tag handles all for you. You can see, that it doesn’t contain http or https because as written in documentation “URIs without a scheme are assumed as http and https”. Hooray, it’s solved first problem.</p><p>But wait, what with another two problems? Let’s go further.</p><p>Here I have declared another destination:</p><pre>&lt;fragment<br>    android:id=&quot;@+id/pageFragment&quot;<br>    android:name=&quot;com.ekalips.navigatortest.page.PageFragment&quot;<br>    android:label=&quot;Page&quot;<br>    tools:layout=&quot;@layout/fragment_page&quot;&gt;<br>    &lt;argument<br>        android:name=&quot;title&quot;<br>        app:type=&quot;string&quot; /&gt;<br>    &lt;action<br>        android:id=&quot;@+id/viewPageComments&quot;<br>        app:destination=&quot;@id/pageCommentsFragment&quot;/&gt;<br>    &lt;deepLink app:uri=&quot;myapp.com/{title}&quot; /&gt;<br>&lt;/fragment&gt;</pre><p>This fragment requires “title” parameter in order to start. Take a look at deepLink tag now. It has some weird {title} thingy. And yes, if link has some parameter name in curly brackets and parameter matches one of destination arguments — i’ll be parsed and handled automatically. So you can do your navigation either with bundles or with deep links, all params will be handled identically.</p><p>When you are done declaring deep urls and destinations, you should only add one line to your manifest activity declaration to tie app all together</p><pre>&lt;nav-graph android:value=&quot;@navigation/your_navigator&quot; /&gt;</pre><p>(Note that &lt;nav-graph&gt; will only work on Android Studio 3.2+, in older versions you still need to add all by hand :) )</p><h4>But there are few rotten apples that spoil the bunch</h4><ol><li>That automatic url parameters handling has some issues with GET Query parameters (in my example all urls with this pattern myapp.com/yet/some/another/path?title={title} always led me to page that handled just myapp.com ). I really hope that it’s a bug that will be fixed in future</li><li>Back navigation is still a problem. For some reason back navigation still doesn’t work in my example, although docs clearly say that back navigation will be handled like user came to this page by himself. And also it even behaves differently when I press Up on AppBar and when I press Back on phone’s NavBar. So it’s clearly something broken here.</li></ol><h3>Conclusion</h3><p>I think that Google came up with really great tool for handling navigation in Android. And even if I’m not quite big fan of single-acitivty application, I can clearly see reasons for this solution (there are plenty of answers in the internet why Google made a bet on single-activity applications).</p><p>You can checkout my example on GitHub:</p><p><a href="https://github.com/Ekalips/DeepUrlNavigatorTest">Ekalips/DeepUrlNavigatorTest</a></p><p>Feel free to read more about Deep Links handling in AAC Navigation in <a href="https://developer.android.com/topic/libraries/architecture/navigation/navigation-implementing#Deeplink">official docs</a>.</p><h3>UPDATE: 13th October 2018</h3><p>Google just responded to me on the issue tracker that Deep Links with GET query parameters will be fixed in the next release of navigation library. You can read full thread <a href="https://issuetracker.google.com/issues/110057514">here</a>.</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=98cc8da83928" width="1" height="1" alt=""><hr><p><a href="https://medium.com/android-news/breeze-deep-links-with-android-architecture-components-navigation-98cc8da83928">Breeze deep links with Android Architecture Components Navigation</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[Things that you’ll know about DataBinding in future]]></title>
            <link>https://medium.com/android-news/things-that-youll-know-about-databinding-in-future-1cfe62cf8a10?source=rss-fbe76663c785------2</link>
            <guid isPermaLink="false">https://medium.com/p/1cfe62cf8a10</guid>
            <category><![CDATA[android-data-binding]]></category>
            <category><![CDATA[android-tutorials]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Bogdan Voiko]]></dc:creator>
            <pubDate>Thu, 07 Sep 2017 10:18:11 GMT</pubDate>
            <atom:updated>2017-09-14T12:18:42.237Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/506/1*MnxpFJkAwikGi4MjeJ7K_Q.png" /></figure><p>I’m using Android DataBinding for a long time now and I completely fell in love with it. As you know the more time you spend with your loved one the more secrets you know and some of them you would like to know earlier.</p><h3>First thing: You can use context in DataBinding layout files</h3><p>There are barely few StackOverflow posts that can tell you that and zero official docs, but I bet that it’s thing you want to know.</p><p>So, imagine that you have class with function like this :</p><pre>class MyButtonHandler {<br><br>    public static int getColorForButton(Context context, int buttonType) {<br>        switch (buttonType) {<br>            case 0:<br>                return ContextCompat.<em>getColor</em>(context, android.R.color.<em>holo_green_light</em>);<br>            case 1:<br>                return ContextCompat.<em>getColor</em>(context, android.R.color.<em>holo_red_light</em>);<br>        ....<br>        }<br>    }<br>}</pre><p>And you can use it as simply as this:</p><pre>&lt;data&gt;<br>    &lt;import type=&quot;com.mypackage.MyButtonHandler&quot; /&gt;<br>    <br>    &lt;variable<br>       name=&quot;type&quot;<br>       type=&quot;int/&gt;<br>&lt;/data&gt;</pre><pre>...</pre><pre>&lt;Button<br>    android:layout_width=&quot;wrap_content&quot;<br>    android:layout_height=&quot;wrap_content&quot;<br>    android:textColor=&quot;@{MyButtonHandler.getColorForButton(context,type)}&quot; /&gt;</pre><p>As you can see, only variable that we declared is type , and context will be provided by ViewDataBinding .</p><h3>Second thing: don’t be afraid to create custom two-way binding</h3><p>When I came around binding one view to another view properties and received “could not resolve the two-way databinding attribute ….”, I was like “Okay, screw it, I’ll find another way”. But now it’s another thing.</p><p>Lets imagine that you want to bind your view padding to another’s view height (really I don’t think that you’ll want this particular example, but idea is common for all). You can do it like so:</p><pre>&lt;View<br>    android:layout_width=&quot;16dp&quot;<br>    android:layout_height=&quot;16dp&quot;<br>    android:paddingLeft=&quot;@{<strong>otherView.height</strong>}&quot;/&gt;</pre><p>And you’ll receive error like this:</p><pre>Could not resolve the two-way binding attribute ‘height’ on type ‘android.widget.FrameLayout’    (It can be any type of View)</pre><p>That’s expected, because system doesn’t know how to do and track such crazy things, but we know how.</p><p>First of all we need to tell the system about our height attribute.</p><pre>@InverseBindingAdapter(attribute = &quot;android:height&quot;)<br>public static int getHeightFromView(View view) {<br>    return view.getHeight();<br>}</pre><p>And then we need to tell the system how to watch changes of this attribute</p><pre>@BindingAdapter(&quot;<strong>android:heightAttrChanged</strong>&quot;)<br>public static void setHeightWatcher(View view, final InverseBindingListener listener) {<br>    View.OnLayoutChangeListener newValue = new View.OnLayoutChangeListener() {<br>        @Override<br>        public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {<br>            boolean isChanged = left != oldLeft || right != oldRight || top != oldTop || bottom != oldBottom;<br>            if (isChanged)<br>                listener.onChange();<br>        }<br>    };<br>    View.OnLayoutChangeListener oldValue = <strong>ListenerUtil.<em>trackListener</em></strong>(view, newValue, R.id.<em>layoutHeightChange</em>);<br>    if (oldValue != null) {<br>        view.removeOnLayoutChangeListener(oldValue);<br>    }<br>    view.addOnLayoutChangeListener(newValue);<br>}</pre><p>Note there 2 things:</p><ol><li>android:heightAttrChanged this name is not random, it corresponds to the rule attr_name + “AttrChanged&quot; ;</li><li>ListenerUtil.trackListener will save you from context leaks, so be sure to setup it properly.</li></ol><p>And there you have it, your view will react to height change of other view. Of course you might use it for more obvious stuff (like it’s already done for TextView’s text change, CheckBox’s check state change and so on). Be creative here :)</p><h3>Third thing: set what ever you want to</h3><p>Sometimes you want to set some attribute of view that you know that’s exists, but DataBinding library keeps telling you that it can’t find setter for it. Of course it can’t, because it relies only on two things: defined @BindingAdapters and named setters. And once you understand how it searches for setters, you’ll abuse it forever.</p><p>Let’s say you want to bind transientState.</p><pre>app:transientState=&quot;@{true}&quot;</pre><p>I bet you receive error on it, because actual setter for it called setHasTransientState . Note that difference is in “has” word.</p><p>But when you try to use full word, all will be OK.</p><pre>app:hasTransientState=&quot;@{true}&quot;</pre><p>You see now? DataBinding will simply look for set + “property_name” (that’s actually Java Beans naming) and as long as you will stick to this naming rule — all your sets will be executed correctly.</p><p>And that’s all, that was 3 things that I wish I knew earlier. Thanks for attention and happy coding :)</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=1cfe62cf8a10" width="1" height="1" alt=""><hr><p><a href="https://medium.com/android-news/things-that-youll-know-about-databinding-in-future-1cfe62cf8a10">Things that you’ll know about DataBinding in future</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[Animate Objects, not Views]]></title>
            <link>https://medium.com/android-news/animate-objects-not-views-250fe7880196?source=rss-fbe76663c785------2</link>
            <guid isPermaLink="false">https://medium.com/p/250fe7880196</guid>
            <category><![CDATA[android-data-binding]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-animations]]></category>
            <dc:creator><![CDATA[Bogdan Voiko]]></dc:creator>
            <pubDate>Wed, 06 Sep 2017 20:54:27 GMT</pubDate>
            <atom:updated>2017-09-07T05:57:37.667Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*TZd63qDfM7URwOHnZ7ga_w.gif" /></figure><p>Admit, we all love fancy animations. No customer loves dry jaggy apps with no transitions and animations. But same time no developer loves to spend hours and hours dealing with ValueAnimators, especially if you need to create bunch of them to achieve desired effect.</p><h4>So why wouldn’t we use power of DataBinding to animate some complex stuff?</h4><p>As all you know we have BaseObservable that can contain fields marked with @Bindable annotations.</p><p>Like this:</p><pre>public class ExpandStateItem extends BaseObservable {<br><br>    @Bindable<br>    private float padding;</pre><pre>    @Bindable<br>    private boolean expanded;</pre><pre>    @Bindable<br>    private boolean fast;<br>}</pre><p>And if you call notifyPropertyChanged(BR.field_name) any view that uses this field will be notified and then updated. So only one thing left is to bind right stuff to right values.</p><p>In my example there is 3 properties that can be bound. Lets look at them one by one.</p><p>First one is padding that we need to bind like this</p><pre>&lt;LinearLayout <br>    android:layout_width=&quot;match_parent&quot;<br>    android:layout_height=&quot;wrap_content&quot;<br>    android:paddingBottom=&quot;@{state.padding}&quot;<br>    android:paddingTop=&quot;@{state.padding}&quot;&gt;<br>....<br>&lt;/LinearLayout&gt;</pre><p><em>state variable is a variable of type </em><em>ExpandStateItem declared in layout file</em></p><p>Android DataBinding library even know how to set padding attributes, so you don’t need to create @BindingAdapter by your own.</p><p>By now if you set ExpandStateItem objects padding to some value you’ll see that all views that it corresponds to will actually change it’s padding.</p><p>And if you create some Animator and change this values on animation callback, all views will animate accordingly.</p><p>Here is little example of it. states is an array that is bound to RecyclerView.ViewHolders in RecyclerView .</p><pre>private ValueAnimator paddingAnimator = ValueAnimator.<em>ofFloat</em>(<em>MAX_MARGIN</em>, <em>MIN_MARGIN</em>);</pre><pre>paddingAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {<br>    @Override<br>    public void onAnimationUpdate(ValueAnimator animation) {<br>        for (ExpandStateItem item :<br>                states) {<br>            item.setPading((float) animation.getAnimatedValue());<br>        }<br>    }<br>});</pre><p>Next variable is expanded . If you noticed GIF image in the top of an article, it has some expandable cards, they are expanding/collapsing with this variable change. It bound this way:</p><pre>&lt;LinearLayout<br>    android:layout_width=&quot;match_parent&quot;<br>    android:layout_height=&quot;wrap_content&quot;<br>    android:orientation=&quot;vertical&quot;<br>    android:visibility=&quot;gone&quot;<br>    app:expand=&quot;@{state.expanded}&quot;<br>    app:fastExpand=&quot;@{state.fast}&quot;&gt;<br>...<br>&lt;/LinearLayout&gt;</pre><p>Also you can notice app:fastExpand there, I’ll tell you about this little bit later.</p><p>For our custom app:expand attribute we need to write our own @BindingAdapter .</p><pre>@BindingAdapter({&quot;expand&quot;, &quot;fastExpand&quot;})<br>public static void expandView(View view, boolean expand, boolean fast) {<br>    if (expand) {<br>        ViewAnimationUtils.<em>expand</em>(view, null, fast);<br>    } else if (view.getHeight() != 0) {<br>        ViewAnimationUtils.<em>collapse</em>(view, null, fast);<br>    }<br>}</pre><p>And now if I show you ViewAnimationUtils class I bet you’ll figure out why do we need fastExpand attribute.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6234552559cc96d7c79714dc708d32fd/href">https://medium.com/media/6234552559cc96d7c79714dc708d32fd/href</a></iframe><p>By specifying fastExpand as true there will be no animation time.</p><p>But why do we need to remove animation time? Actually you don’t really need to do so if you would use this in lists with recycling. When view will be recycled and used again (in RecyclerView it’s onBindViewHolder) all animations will occur again for this specific view, so we need to specify that we just want to expand view, with no progress exposing.</p><p>That was my example how you can interact (animate) with view without touching the view (actually you will, but indirectly). Thing that you can do with it are limited only by your imagination. View margins, paddings, width, height, TextView lines count, color, taste (no), thousands of them.</p><p>Source code for my example available on GitHub <a href="https://github.com/Ekalips/ExpandableCardViewList">here</a>.</p><p>Thanks for attention and happy coding :)</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=250fe7880196" width="1" height="1" alt=""><hr><p><a href="https://medium.com/android-news/animate-objects-not-views-250fe7880196">Animate Objects, not Views</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[Generate your own RecyclerView.Adapter with blackjack and DataBinding]]></title>
            <link>https://medium.com/android-news/generate-your-own-recyclerview-adapter-with-blackjack-and-databinding-8162294a795c?source=rss-fbe76663c785------2</link>
            <guid isPermaLink="false">https://medium.com/p/8162294a795c</guid>
            <category><![CDATA[annotation-processing]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[recyclerview]]></category>
            <category><![CDATA[android-data-binding]]></category>
            <category><![CDATA[annotations]]></category>
            <dc:creator><![CDATA[Bogdan Voiko]]></dc:creator>
            <pubDate>Sun, 06 Aug 2017 12:00:53 GMT</pubDate>
            <atom:updated>2017-08-17T14:30:24.222Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0B_V9X4nltbQpEev5Lpqpw.png" /></figure><p>Aren’t you tired of creating RecyclerView.Adapters over and over again? It would seem that with DataBinding coming we’ll “write more code by writing less code”, but this Adapters “generating” seems like to be endless. So, why wouldn’t you generate your adapters with few annotations and even less lines of code?</p><h3>How did I handle all this stuff before</h3><p>Until now one of my best approach was this:</p><pre>public class BindingViewHolder&lt;T extends ViewDataBinding&gt; extends RecyclerView.ViewHolder { </pre><pre>    private T binding; <br>    <br>    public BindingViewHolder(T binding){ <br>       super(binding.getRoot()); <br>       this.binding = binding; <br>    } </pre><pre>    public T getBinding() { return binding; }<br>}</pre><p>With this you basically can pass any DataBingingUtil.inflate(..) into this ViewHolder constructor and you’ll receive your fancy ViewHolder with DataBinding abilities.</p><p>What’s problem with this? Yes, really, you don’t need to create bunch of ViewHolders, but you still need to create bunch of Adapters, with onCreateViewHolder , onBindViewHolder and so on. And this is dramatic waste of time.</p><h3>When all started</h3><p>From past Google I/O I noticed one thing:</p><blockquote>We love Annotations</blockquote><p>So I thought, if Java and Android in part have power of annotation processing, why can’t I make something generate this endless code for me?</p><h3>The solution</h3><p>And with some time passed I came to this</p><pre>@Adapter( <br>    dataSetType = @DataSetType(dataSetType = TestData.class),       <br>    useViews = { @ViewFor(dataClass = TestData.class, viewRes = R.layout.rv_item_test_adapter) }, <br>    map = {<br>    @Bind(bindClass = TestData.class, bindMode = BindMode.variable, bindingResourceName = “testData”), <br>    @Bind(bindClass = Void.class, bindMode = BindMode.method, bindingResourceName = “clickAdapter”, methodName = “myMethod”, methodCallMode = MethodCallMode.onClick)<br>    }<br>)<br>public class TestAdapter { }</pre><p>Isn’t it smaller than one that you’r writing each time? Definitely smaller that mine ones.</p><p>“But this is not RecyclerView.Adapter ” you’ll say. You’ll be right, but created TestAdapterGenerated definitely will.</p><p>What is it? I’ll show you.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6da8b9d76c55026133844589f1c8c2c8/href">https://medium.com/media/6da8b9d76c55026133844589f1c8c2c8/href</a></iframe><p>Don’t worry, ViewTypeEnum isn’t something internal, it’s enum generated for each RecyclerView.Adapter to map view types with data. You can see it live when you’ll try it by your own.</p><p>All you need to do now it’s simply</p><pre>TestAdapterGenerated adapter = new TestAdapterGenerated() {<br>    @Override<br>    public Void myMethod(int position, BindingViewHolder holder, Object object) {<br>        // DO SOME FANCY STUFF ONCLICK<br>        return null;<br>    }<br>};<br>recyclerView.setAdapter(adapter);</pre><pre>adapter.setData(...);<br>// OR<br>yourBinding.setData(data); // where &quot;data&quot; is a list, your XML contains variable &quot;data&quot; of type List and your RecyclerView have &quot;app:src=&quot;@{data}&quot;&quot; attribute. </pre><p>Isn’t it cool, ha?</p><p>To <strong>try it</strong>, just paste this in your modules <em>build.gradle</em> file</p><pre>compile &#39;com.ekalips:adapter-annotation:0.1.1&#39;<br>annotationProcessor &#39;com.ekalips:adapter-processor:0.1.1&#39;</pre><p>And this to your projects <em>build.gradle</em></p><pre>maven {<br>    url &quot;http://dl.bintray.com/ekalips/Bapter&quot;<br>}</pre><p>Just be sure, that DataBinding is enabled in your project.</p><p>For additional info and feedback leaving visit my <a href="https://github.com/Ekalips/Bapter">GitHub project’s page</a></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=8162294a795c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/android-news/generate-your-own-recyclerview-adapter-with-blackjack-and-databinding-8162294a795c">Generate your own RecyclerView.Adapter with blackjack and DataBinding</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>